MySQL5.6怎么快速定位不合理索引
这篇文章主要讲解了“MySQL5.6怎么快速定位不合理索引”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL5.6怎么快速定位不合理索引”吧!
成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、成都做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的清河网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
# 若CARDINALITY / TABLE_ROWS小于10%(经验值),那么表示数据重复率较高,通常需要考虑是否有必要创建该索引
#########################################################
# mysql 5.6
目前5.6的STATISTICS表中关于Cardinality的统计是错误的!!!具体可见MySQL bugs #78066。
但是,表innodb_index_stats中关于Cardinality值得统计依然是正确的
#########################################################
SELECT
t.TABLE_SCHEMA,
t.TABLE_NAME,INDEX_NAME,
s.CARDINALITY,
t.TABLE_ROWS,
s.CARDINALITY/t.TABLE_ROWS AS SELECTIVITY
FROM
information_schema.TABLES t,
(SELECT database_name,table_name,index_name,stat_value AS CARDINALITY
FROM mysql.innodb_index_stats
WHERE (database_name,table_name,index_name,stat_name) IN
(SELECT table_schema,table_name,index_name,CONCAT('n_diff_pfx0',MAX(seq_in_index))
FROM information_schema.STATISTICS
-- where table_name='xxxxx'
GROUP BY table_schema , table_name , index_name )) s
WHERE t.table_schema = s.database_name
AND t.table_name = s.table_name
AND t.table_rows != 0
AND t.table_schema NOT IN ( 'mysql','performance_schema','information_schema')
ORDER BY SELECTIVITY;
以下部分出自:http://mp.weixin.qq.com/s?__biz=MjM5MjIxNDA4NA==&mid=401131835&idx=1&sn=37c5fd9d3d8670fb379a1e0565e50eeb&scene=0#wechat_redirect
#############################################################
# mysql 5.7 表STATISTICS记录了各个索引的CARDINALITY值
#############################################################
SELECT
t.TABLE_SCHEMA,t.TABLE_NAME,INDEX_NAME, CARDINALITY,
TABLE_ROWS, CARDINALITY/TABLE_ROWS AS SELECTIVITY
FROM
information_schema.TABLES t,
(
SELECT table_schema,table_name,index_name,cardinality
FROM information_schema.STATISTICS
WHERE (table_schema,table_name,index_name,seq_in_index) IN (
SELECT table_schema,table_name,index_name,MAX(seq_in_index)
FROM information_schema.STATISTICS
GROUP BY table_schema , table_name , index_name )
) s
WHERE
t.table_schema = s.table_schema
AND t.table_name = s.table_name AND t.table_rows != 0
AND t.table_schema NOT IN ( 'mysql','performance_schema','information_schema')
ORDER BY SELECTIVITY;
感谢各位的阅读,以上就是“MySQL5.6怎么快速定位不合理索引”的内容了,经过本文的学习后,相信大家对MySQL5.6怎么快速定位不合理索引这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
本文题目:MySQL5.6怎么快速定位不合理索引
标题URL:http://pwwzsj.com/article/igoehs.html