0
好傢伙,我得到了與代碼表下面執行計劃
CREATE TABLE [dbo].[PTableMediumPart](
[PK] [int] NOT NULL,
[Col1] [int] NOT NULL,
[Col2] [int] NULL,
[Col3] [money] NOT NULL,
[Col4] [money] NULL,
[Col5] [nvarchar](60) NOT NULL,
[Col6] [nvarchar](60) NULL,
[Col7] [varchar](255) NOT NULL,
[Col8] [varchar](255) NULL,
[Col9] [smallint] NOT NULL,
[Col10] [smallint] NULL,
[Col11] [decimal](20, 3) NOT NULL,
[Col12] [decimal](20, 3) NULL,
[Col13] [char](8) NOT NULL,
[Col14] [datetime2](7) NULL,
[PartitionKey] [tinyint] NOT NULL
)
GO
的partitionkey柱填充了CAST((PK%3) AS TINYINT)
和 我已經明確分區功能和方案如下
CREATE PARTITION FUNCTION [PFTest](tinyint) AS RANGE LEFT FOR VALUES (0, 1)
GO
CREATE PARTITION SCHEME [PSTEST] AS PARTITION [PFTest] TO ([FGTest1], [FGTest2], [FGTest3])
GO
,然後我所創建的簇索引等
CREATE UNIQUE CLUSTERED INDEX [CI_PArt] ON [dbo].[PTableMediumPart]
(
[PK] ASC,
[PartitionKey] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PSTEST]([PartitionKey])
GO
但是當我用相同的未分區表運行查詢時,我在查詢中獲得了更好的性能或相同的性能,例如,當我運行以下查詢時,我得到50-50%的exution計劃,而在其他情況下,未分區表變得更好執行計劃,爲什麼會發生?我在這裏錯了什麼?
SELECT *
FROM dbo.PTableMedium
WHERE PK = 789
SELECT *
FROM dbo.PTableMediumPart
WHERE PK = 789 AND PartitionKey = CAST((789 % 3) AS TINYINT)
感謝響應,它是一個適當的比較有表2的副本,一個有三個分區,另一個不分區,並運行相同的查詢,比較執行計劃?我們是否可以比較計劃以確定分區是否可以提高我們的績效? – MAK
你可以運行這些測試,但對於這種類型的查詢:'SELECT * FROM dbo.PTableMedium WHERE PK ='最好的選擇(在我看來)是在'PK'列上有一個聚集[唯一]索引。 –