有没有办法显式确定现有 InnoDB 表中的聚集索引。我知道文档中列出的确定聚集索引的规则,但我想知道是否有一种方法可以在现有表中显式检查它。
最佳答案
正如您所读到的,InnoDB 表始终使用 PRIMARY KEY 或第一个非 NULL UNIQUE KEY 作为其聚集索引。
如果表没有这些,它会生成自己的聚集索引,并将其称为“GEN_CLUST_INDEX”。
mysql> create table test.testy ( i int ); -- no eligible clustered index
mysql> select t.name as table_name, i.name as index_name
from information_schema.innodb_sys_tables t
join information_schema.innodb_sys_indexes i using (table_id)
where i.name = 'GEN_CLUST_INDEX';
+------------+-----------------+
| table_name | index_name |
+------------+-----------------+
| test/testy | GEN_CLUST_INDEX |
+------------+-----------------+
关于mysql - InnoDB:在现有表中查找聚集索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54446161/