mysql - 在MySQL中,我们如何判断表的索引是否是聚集索引?

标签 mysql clustered-index

在MySQL中,我们如何判断表的索引是否是聚集索引?

我们可以使用show index from table-name来获取有关表索引的信息。但我没有发现它显示每个索引是聚集还是非聚集。

这是为了If a table in MySQL has any index, must the table have a clustered index?的目的

最佳答案

在默认存储引擎InnoDB中,主键索引始终是聚集索引。

如果您没有 PRIMARY KEY,则它是非空列上的第一个 UNIQUE KEY 索引。

如果非空列上没有主键或唯一键,则 InnoDB 有一个隐藏的聚集索引。在这种情况下,您无法使用此聚集索引进行查询。

参见https://dev.mysql.com/doc/refman/8.0/en/innodb-index-types.html

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.

MyISAM 是另一种常见的存储引擎。 MyISAM 不支持聚集索引。

关于mysql - 在MySQL中,我们如何判断表的索引是否是聚集索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51182951/

相关文章:

html - 在没有功能的sql查询中剥离图像标签

mysql - 有一个 mysql 查询,我希望能够从第二个表运行 order by

php - 如何将 id 从 jquery 方法传递到服务器端

php,postgresql,mysql

MySQL:乱序插入 PK B+ 树是否比乱序插入二级索引 B+ 树慢?

mysql - 在大分区 MySQL 表中使用 GUID 作为 PK

sql-server - SQL Server 2005 中没有聚集索引的原因

sql-server - Sql Server 索引包含主键吗?

mysql - 即使使用 --skip-grant-tables 启动 mysql 服务器后也会出错

mysql - 优化 InnoDB 表和有问题的查询