Visual Studio 2017 年的 SSDT 和 ColumnStore 索引
SSDT in Visual Studio 2017 and ColumnStore Index
在 SSDT 中,我有一个 table 和列存储索引定义为:
CREATE TABLE [dbo].[FactBillPayTransaction] (
[NaturalKeyText] NVARCHAR (500) NOT NULL,
[RecordEffectiveDateTime] DATETIME2 (7) NOT NULL,
[SourceEffectiveUTCDateTime] DATETIME2 (7) NOT NULL,
[InsertJobRunSequenceNumber] BIGINT NOT NULL,
[LatestUpdateJobRunSequenceNumber] BIGINT NOT NULL,
[InsertDateTime] DATETIME2 (7) NOT NULL,
[LatestUpdateDateTime] DATETIME2 (7) NOT NULL,
[DeleteDateTime] DATETIME2 (7) NULL,
[ChangeControlChecksum] NVARCHAR (32) NOT NULL,
.......More Columns
);
GO
CREATE CLUSTERED COLUMNSTORE INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction];
When I generate scripts i get the following for SQL Server 2014:
CREATE TABLE [dbo].[FactBillPayTransaction] (
[NaturalKeyText] NVARCHAR (500) NOT NULL,
[RecordEffectiveDateTime] DATETIME2 (7) NOT NULL,
[SourceEffectiveUTCDateTime] DATETIME2 (7) NOT NULL,
[InsertJobRunSequenceNumber] BIGINT NOT NULL,
[LatestUpdateJobRunSequenceNumber] BIGINT NOT NULL,
[InsertDateTime] DATETIME2 (7) NOT NULL,
[LatestUpdateDateTime] DATETIME2 (7) NOT NULL,
[DeleteDateTime] DATETIME2 (7) NULL,
[ChangeControlChecksum] NVARCHAR (32) NOT NULL,
.......More Columns
);
CREATE CLUSTERED INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction]([NaturalKeyText]);
CREATE CLUSTERED COLUMNSTORE INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction] WITH (DROP_EXISTING = ON);
两条create "index"命令似乎不对,另外,为什么它引用了一个列?
这肯定是产品缺陷,但最终结果仍然是正确的。
每个行存储索引必须至少引用一列,这就是为什么在生成的第一个 CREATE CLUSTERED INDEX 语句中引用一列的原因。
为什么生成 CREATE CLUSTERED INDEX 最可能的解释在于 partitioning requirements of columnstore indexes:数据必须分区对齐,因此首先您需要在分区方案上创建一个聚集索引(分配每一行到它的分区)然后您需要使用 DROP_EXISTING=TRUE
子句创建具有相同分区方案的聚集列存储索引。因此,如果你有一个分区的 table 那么语法看起来像:
CREATE CLUSTERED INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction]([NaturalKeyText])
ON COLUMNSTORE_PARTITION_SCHEME (NaturalKeyText);
CREATE CLUSTERED COLUMNSTORE INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction] WITH (DROP_EXISTING = ON)
ON COLUMNSTORE_PARTITION_SCHEME (NaturalKeyText);
没关系。这不是问题。我的本地数据库版本不支持这个。目标做到了。该语句实际上是在创建一个约束,然后删除并再次创建它。
在 SSDT 中,我有一个 table 和列存储索引定义为:
CREATE TABLE [dbo].[FactBillPayTransaction] (
[NaturalKeyText] NVARCHAR (500) NOT NULL,
[RecordEffectiveDateTime] DATETIME2 (7) NOT NULL,
[SourceEffectiveUTCDateTime] DATETIME2 (7) NOT NULL,
[InsertJobRunSequenceNumber] BIGINT NOT NULL,
[LatestUpdateJobRunSequenceNumber] BIGINT NOT NULL,
[InsertDateTime] DATETIME2 (7) NOT NULL,
[LatestUpdateDateTime] DATETIME2 (7) NOT NULL,
[DeleteDateTime] DATETIME2 (7) NULL,
[ChangeControlChecksum] NVARCHAR (32) NOT NULL,
.......More Columns
);
GO
CREATE CLUSTERED COLUMNSTORE INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction];
When I generate scripts i get the following for SQL Server 2014:
CREATE TABLE [dbo].[FactBillPayTransaction] (
[NaturalKeyText] NVARCHAR (500) NOT NULL,
[RecordEffectiveDateTime] DATETIME2 (7) NOT NULL,
[SourceEffectiveUTCDateTime] DATETIME2 (7) NOT NULL,
[InsertJobRunSequenceNumber] BIGINT NOT NULL,
[LatestUpdateJobRunSequenceNumber] BIGINT NOT NULL,
[InsertDateTime] DATETIME2 (7) NOT NULL,
[LatestUpdateDateTime] DATETIME2 (7) NOT NULL,
[DeleteDateTime] DATETIME2 (7) NULL,
[ChangeControlChecksum] NVARCHAR (32) NOT NULL,
.......More Columns
);
CREATE CLUSTERED INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction]([NaturalKeyText]);
CREATE CLUSTERED COLUMNSTORE INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction] WITH (DROP_EXISTING = ON);
两条create "index"命令似乎不对,另外,为什么它引用了一个列?
这肯定是产品缺陷,但最终结果仍然是正确的。
每个行存储索引必须至少引用一列,这就是为什么在生成的第一个 CREATE CLUSTERED INDEX 语句中引用一列的原因。
为什么生成 CREATE CLUSTERED INDEX 最可能的解释在于 partitioning requirements of columnstore indexes:数据必须分区对齐,因此首先您需要在分区方案上创建一个聚集索引(分配每一行到它的分区)然后您需要使用 DROP_EXISTING=TRUE
子句创建具有相同分区方案的聚集列存储索引。因此,如果你有一个分区的 table 那么语法看起来像:
CREATE CLUSTERED INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction]([NaturalKeyText])
ON COLUMNSTORE_PARTITION_SCHEME (NaturalKeyText);
CREATE CLUSTERED COLUMNSTORE INDEX [ci_cs_FactBillPayTransaction]
ON [dbo].[FactBillPayTransaction] WITH (DROP_EXISTING = ON)
ON COLUMNSTORE_PARTITION_SCHEME (NaturalKeyText);
没关系。这不是问题。我的本地数据库版本不支持这个。目标做到了。该语句实际上是在创建一个约束,然后删除并再次创建它。