gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:41:51 25 4
gpt4 key购买 nike

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

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

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

最佳答案

在默认的存储引擎 InnoDB 中,PRIMARY KEY 索引始终是聚集索引。

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

如果您在非空列上没有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com