好家伙,我得到了与下面的代码表
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)