mysql的聚集索引_MySQL的聚集索引

聚集索引是InnoDB表的实际存储方式,它将数据与索引存储在一起,按照物理顺序组织行。当定义主键时,InnoDB会使用其作为聚集索引。如果没有主键,InnoDB会选择第一个唯一的非空索引或创建隐藏的合成列作为聚集索引。聚集索引对于查询性能优化至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概要

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值