在MySQL中如何找出没有索引的表? 下面分享一个脚本,使用此脚本可以轻松找出MySQL数据库中没有索引的表。
/***************************************************************************************************
-- Script Name : get_without_index_tables.sql
-- Script Funtion : 找出MySQL数据库中没有索引的表
****************************************************************************************************/
SELECT t.table_schema
,t.table_name
,t.table_type
,t.engine
,t.table_rows
,t.row_format
,t.avg_row_length
,t.create_time
FROM information_schema.tables t
LEFT JOIN information_schema.statistics s
ON t.table_schema = s.table_schema AND t.table_name = s.table_name
WHERE t.table_schema NOT IN ( 'mysql', 'information_schema', 'performance_schema', 'sys', 'ndbinfo')
AND s.index_name IS NULL;
有时候,一些基础数据表或维度表,本身的数据量很少,例如可能只有几十条数据,那么这些表没有索引可能也正常。我们在查询过程,需要排除这些表,例如,我们希望找出记录数超过一千条记录但是没有索引的表,那么可以使用下面脚本,但是information_schema.tables中的table_rows是一个近似值,不是很精确,所以下面脚本仅供参考。
/***************************************************************************************************
-- Script Name : get_without_index_tables.sql
-- Script Funtion : 查询记录数超过1000,没有索引的表。table_rows是个近似值,数据不精确,仅供参考
-- MyISAM存储引擎的表值是准确的。
****************************************************************************************************/
SELECT t.table_schema
,t.table_name
,t.table_type
,t.engine
,t.table_rows
,t.row_format
,t.avg_row_length
,t.create_time
FROM information_schema.tables t
LEFT JOIN information_schema.statistics s
ON t.table_schema = s.table_schema AND t.table_name = s.table_name
WHERE t.table_schema NOT IN ( 'mysql', 'information_schema', 'performance_schema', 'sys', 'ndbinfo')
AND s.index_name IS NULL
AND t.table_rows >1000;
原文始发于微信公众号(DBA闲思杂想录):MySQL中如何找出没有索引的表?
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/227434.html