简体   繁体   English

非聚集索引与聚集索引

[英]Non clustered index vs clustered

我想我错过了为什么聚集索引比非聚集索引更快的要点,将原始记录存储在索引中与使用指针引用这些记录相比有什么好处?

In a clustered index, the data will be stored within the index, together with the index keys.在聚集索引中,数据将与索引键一起存储在索引中。 In a non-clustered index, the data will be stored in a heap file , and there will be a pointer from each index key to the heap file.在非聚集索引中,数据会存储在一个堆文件中,每个索引键都会有一个指向堆文件的指针。

A clustered index is faster for reads because there is no need for following a pointer to the heap file, as the data is stored together with the key in the index.聚集索引读取速度更快,因为不需要跟随指向堆文件的指针,因为数据与索引中的键一起存储。

Another benefit of clustered indices is that range queries will be fast, since the data will be physically sorted by the key.聚集索引的另一个好处是范围查询会很快,因为数据将按键进行物理排序。

Clustered indices can also be faster for updates, since updating a value in the heap file with a new value that has a larger size in memory requires moving the value into a different location in the heap.聚集索引的更新速度也更快,因为用内存中更大的新值更新堆文件中的值需要将该值移动到堆中的不同位置。 Then all indices pointing to the old location will have to be updated, or a forwarding pointer needs to be left behind in the old heap location.然后所有指向旧位置的索引都必须更新,或者需要在旧堆位置留下一个转发指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM