在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/