[英]Clustered and nonclustered index large data insert
I had a clustered index on 5 keys (columns).我在 5 个键(列)上有一个聚集索引。 I had an unclustered index on 2 columns.
我在 2 列上有一个非聚集索引。 Because I'm inserting 2-3 million rows in one run, I changed the 2 column unclustered index to clustered and changed the 5 column clustered index to 5 column unclustered index.
因为我在一次运行中插入了 2-3 百万行,所以我将 2 列非聚集索引更改为聚集索引,并将 5 列聚集索引更改为 5 列非聚集索引。 My question.
我的问题。
When making an index clustered (basically delete and recreate the index as clustered
), I don't need the include
(any columns) right since this is clustered?当使索引聚集时(基本上删除并重新创建索引作为
clustered
),我不需要include
(任何列),因为这是聚集的?
Is it generally correct that I switch the less column index into clustered and change the large column clustered index to unclustered?我将较少的列索引切换为聚集并将大列聚集索引更改为非聚集通常是否正确? In other words, clustered index should be simple and small?
换句话说,聚集索引应该是简单的还是小的?
Is there any performance issues if I switch these two indexes?如果我切换这两个索引会不会有任何性能问题?
Unless it's a link table, you normally have clustered index on 1 column.除非它是链接表,否则通常在 1 列上有聚集索引。 And a general recommendation is to choose the smallest possible type for clustered index column(surely which fits your requirements).
一般建议是为聚集索引列选择尽可能小的类型(当然这符合您的要求)。 Having many columns not only increases size ( each non-clustered index stores value of clustered index [includes clustered index]! ), but also greatly increases chances of external fragmentation and degrading performance even of
inserts
.拥有许多列不仅会增加大小(每个非聚集索引都存储聚集索引的值 [包括聚集索引]! ),而且还会大大增加外部碎片和降低性能甚至
inserts
。 Thus, my answers to your questions.因此,我对你的问题的回答。
Update I realized (thanks to Aaron Bertrand for pointing that out) I made quite vague statement regarding inclusion of clustered index to non-clustered indexes.更新我意识到(感谢Aaron Bertrand指出这一点)我对将聚集索引包含在非聚集索引中做了相当模糊的声明。 To be absolutely correct, each non-clustered index includes row locator which points to row.
为了绝对正确,每个非聚集索引都包含指向行的行定位器。 When table is clustered, row locator is the clustered index key.
当表被聚簇时,行定位器是聚簇索引键。 More info regarding clustered indexes: [1] , [2] .
有关聚集索引的更多信息: [1] , [2] 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.