如何查看我的数据库是否有索引?
如果是特定的桌子呢?
如何查看我的数据库是否有索引?
如果是特定的桌子呢?
当前回答
查询数据库中所有已禁用的索引
SELECT INDEX_SCHEMA, COLUMN_NAME, COMMENT
FROM information_schema.statistics
WHERE table_schema = 'mydb'
AND COMMENT = 'disabled'
其他回答
按顺序获取一列中每个索引的所有索引列。
SELECT table_name AS `Table`,
index_name AS `Index`,
GROUP_CONCAT(column_name ORDER BY seq_in_index) AS `Columns`
FROM information_schema.statistics
WHERE table_schema = 'sakila'
GROUP BY 1,2;
裁判:http://blog.9minutesnooze.com/mysql-information-schema-indexes/
我提出这样的质疑:
SELECT DISTINCT s.*
FROM INFORMATION_SCHEMA.STATISTICS s
LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t
ON t.TABLE_SCHEMA = s.TABLE_SCHEMA
AND t.TABLE_NAME = s.TABLE_NAME
AND s.INDEX_NAME = t.CONSTRAINT_NAME
WHERE 0 = 0
AND t.CONSTRAINT_NAME IS NULL
AND s.TABLE_SCHEMA = 'YOUR_SCHEMA_SAMPLE';
您已找到所有索引索引。
把。
select
table_name,
index_name,
seq_in_index,
column_name,
non_unique,
index_type,
comment
from
information_schema.statistics
where 1=1
and table_schema = 'my_schema'
and table_name = 'my_table'
order by 1,2,3,4,5,6
为什么不显示创建表myTable ?
有人告诉过我,但我没看到有人提到,有什么不好的吗?
如果您只想看一下索引和列信息,那就很简单了。
您可以在MySQL工作台中检查您的索引。在性能报告选项卡下,您可以看到系统上所有已使用的索引和未使用的索引。或者可以触发查询。
select * from sys.schema_index_statistics;