MySQL 聚簇索引 clustered index

Typically, an index is a separate data structure such as B-Tree that stores the key values used for faster lookups.

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.

Once a clustered index is created, all rows in the table will be stored according to the key columns used to create the clustered index.

Because a clustered index store the rows in sorted order, each table have only one clustered index.

1.聚簇索引是物理索引,数据在表里是按顺序存储的,物理上是连续的,一般选主键id作为聚簇索引,且一张表里只能有一个聚簇索引。

2.只有InnoDB支持聚簇索引。

3.非聚簇索引是逻辑索引,将数据的某个字段抽取出来组成独立的B-Tree,原数据的存储顺序可能不是物理连续的。

4.对于非聚簇索引,索引字段越紧凑,每页可以存储的索引越多,单次IO可以读到的信息越多,查询效率越高。

 

If you do not have a primary key for a table, MySQL will search for the first UNIQUE index where all the key columns are NOT NULL and use this UNIQUE index as the clustered index.

In case the InnoDB table has no primary key or suitable UNIQUE index, MySQL internally generates a hidden clustered index named GEN_CLUST_INDEX on a synthetic column which contains the row ID values.

5.一般地,InnoDB把 primary key作为聚簇索引,没有指定 primary key,则MySQL将唯一索引作为聚簇索引,如果也没有唯一索引,MySQL将创建一个隐藏的索引GEN_CLUST_INDEX。

6.聚集索引就是以主键创建的索引,非聚集索引就是以非主键创建的索引,聚集索引的叶子节点存储的是表中的数据,非聚集索引的叶子节点存储的是主键和索引列,拿到叶子节点上的存储的主键再去查询想要查询的数据,这个过程叫做回表。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
MySQL中的聚簇索引是将索引和数据存储在同一个文件中的索引类型。聚簇索引的叶子节点中存放的是整张表的行记录数据,也被称为数据页。而非聚簇索引则是将索引文件和数据文件分开存储的。在一张表上最多只能创建一个聚簇索引,因为真实数据的物理顺序只能有一种。 要建立MySQL聚簇索引,可以使用CREATE INDEX语句并指定CLUSTERED关键字。例如,下面的示例演示了如何为表中的某个列建立聚簇索引: CREATE CLUSTERED INDEX index_name ON table_name (column_name); 其中,index_name表示聚簇索引的名称,table_name表示表的名称,column_name表示要建立聚簇索引的列名。 需要注意的是,聚簇索引的建立会对插入和更新操作的性能产生影响,因此在使用聚簇索引时需要全面衡量。可以根据具体的需求和查询模式来选择是否使用聚簇索引。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Mysql聚簇索引](https://blog.csdn.net/qq_37933128/article/details/127186227)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [详解MySQL 聚簇索引与非聚簇索引](https://download.csdn.net/download/weixin_38667849/13682520)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值