MySQL的聚集索引
概要
MySQL的聚集索引。
博客
原帖收藏于IT老兵驿站。
正文
什么是聚集索引?
参考这里
A clustered index, on the other hand, is actually the table. It is an index that enforces the ordering on the rows of the table physically.
聚集索引就是说索引和数据是在一起的。一般的索引是单独的一个数据结构,而数据是一个数据结构;而聚集索引是说这两块内容是在一起的,并且是有顺序的。
参考官网:
14.6.2.1 Clustered and Secondary Indexes
Every InnoDB table has a special index called the clustered index where the data for the rows is stored. Typically, the clustered index is synonymous with the primary key. To get the best performance from queries, inserts, and other database operations, you must understand how InnoDB uses the clustered index to optimize the most common lookup and DML operations for each table.
When you define a PRIMARY KEY on your table, InnoDB uses it as the clustered index. Define a primary key for each table that you create. If there is no logical unique and non-null column or set of columns, add a new auto-increment column, whose values are filled in automatically.
If you do not define a PRIMARY KEY for your table, MySQL locates the first UNIQUE index where all the key columns are NOT NULL and InnoDB uses it as the clustered index.
If the table has no PRIMARY KEY or suitable UNIQUE index, InnoDB internally generates a hidden clustered index named GEN_CLUST_INDEX on a synthetic column containing row ID values. The rows are ordered by the ID that InnoDB assigns to the rows in such a table. The row ID is a 6-byte field that increases monotonically as new rows are inserted. Thus, the rows ordered by the row ID are physically in insertion order.
上文讲了MySQL是如何使用聚集索引的。
参考
http://www.mysqltutorial.org/mysql-index/mysql-clustered-index/
https://dev.mysql.com/doc/refman/5.7/en/innodb-index-types.html
posted on 2019-12-15 17:05 chaiyu2002 阅读(154) 评论(0) 编辑 收藏 举报