由于PostgreSQL
不支持聚集索引,我正在考虑MSSQL
服务器。我读过article比较聚集索引和非聚集索引。这篇文章的要点是(强调我的):
Non clustered indexes store both a value and a pointer to the actual row that holds that value.
和
Clustered indexes don’t need to store a pointer to the actual row because of the fact that the rows in the table are stored on disk in the same exact order as the clustered index
据我所知there和 there支持表数据的物理排序非常困难,特别是当表被拆分到多个驱动器时。现在,我遇到了聚集索引概念,假设数据以某种物理顺序存储。这就是我困惑的地方。
问题:什么是聚集索引结构?它是否支持像 PosgtreSQL
对 btree
索引那样的类似 tree
结构进行遍历?
最佳答案
在 SQL Server 中,索引被组织为 B 树。索引 B 树中的每个页面称为 inode 。 B 树的顶部节点称为根节点。索引中最底层的节点称为叶节点。根节点和叶节点之间的任何索引级别统称为中间级别。在聚集索引中,叶节点包含基础表的数据页。根级节点和中间级节点包含保存索引行的索引页。每个索引行都包含一个键值和一个指向 B 树中的中间级页或索引叶级中的数据行的指针。索引每一级中的页面都以双向链表链接。
聚集索引在 sys.partitions 中有一行,索引使用的每个分区的 index_id = 1。默认情况下,聚集索引具有单个分区。当聚集索引具有多个分区时,每个分区都有一个 B 树结构,其中包含该特定分区的数据。例如,如果聚集索引有四个分区,则有四个 B 树结构;每个分区一个。
供引用
https://technet.microsoft.com/en-us/library/ms177443(v=sql.105).aspx http://www.sqlservercentral.com/blogs/practicalsqldba/2013/03/14/sql-server-part-4-explaining-the-non-clustered-index-structure-/
关于sql - 了解聚集索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32969559/