原文地址: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語句 等