原文地址:http://mp.weixin.qq.com/s?__biz=MjM5MjIxNDA4NA==&mid=401131835&idx=1&sn=37c5fd9d3d8670fb379a1e0565e50eeb&scene=0#wechat_redirect
可惜的是上述SQL语句并不能工作在
MySQL 5.6版本下(即使最新的MySQL 5.6.28版本),因为目前5.6的STATISTICS表中关于Cardinality的统计是错误的!!!具体可见
MySQL bugs #78066。但是,表innodb_index_stats中关于Cardinality值得统计依然是正确的,那么问题来了:
-
有谁知道5.6下上述SQL该如何改写?
-
如何修复5.6下的Cardinality Bug?
版本《=5.6
-
查找未被使用的索引:
-
mysql> select OBJECT_SCHEMA,OBJECT_NAME,INDEX_NAME from performance_schema.table_io_waits_summary_by_index_usage where INDEX_NAME is not null and COUNT_STAR=0 and OBJECT_SCHEMA='xdq' and OBJECT_NAME='order_reasons_dispute' order by OBJECT_SCHEMA,OBJECT_NAME;
+---------------+-----------------------+------------+
| OBJECT_SCHEMA | OBJECT_NAME | INDEX_NAME |
+---------------+-----------------------+------------+
| xdq | order_reasons_dispute | PRIMARY |
| xdq | order_reasons_dispute | s_uid |
| xdq | order_reasons_dispute | b_uid |
| xdq | order_reasons_dispute | c_time |
| xdq | order_reasons_dispute | r_time |
+---------------+-----------------------+------------+
5 rows in set (0.15 sec)
版本=5.7
-
mysql> select * from sys.schema_redundant_indexes 冗余索引
-
mysql> select * from schema_unused_indexes ; 未使用索引 --详见mysql5.7 sys schema视图详解
-
mysql> select * from statements_with_full_table_scans; 使用全表扫描的sql语句 等