ITPub博客

首页 > 数据库 > MySQL > 分析索引是否有效

分析索引是否有效

原创 MySQL 作者:壹頁書 时间:2017-09-19 15:27:44 0 删除 编辑
索引的选择性低,效果就多少有些折扣
索引是否有效,是否应该创建,需要具体情况具体分析.
大表的低CARDINALITY值索引,需要引起注意.
下面是 低选择性索引的查询

  1. select t2.*,t1.table_rows,round(t2.CARDINALITY/t1.table_rows,2) seletivity  
  2. from information_schema.TABLES t1   
  3. inner join (  
  4.     select table_schema,table_name,index_name,  
  5.     group_concat(column_name order by seq_in_index) column_name,  
  6.     max(CARDINALITY) CARDINALITY   
  7.     from information_schema.STATISTICS   
  8.     where index_name!='PRIMARY'  
  9.     group by table_schema,table_name,index_name  
  10. ) t2 on   
  11. (t1.table_schema=t2.table_schema and t1.table_name=t2.table_name)  
  12. where t1.table_rows>=100000 and t2.CARDINALITY/t1.table_rows<0.7  
  13. order by seletivity,t1.table_rows  desc;  

可以起到一些辅助分析的作用

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29254281/viewspace-2145169/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 动态固定行转列
请登录后发表评论 登录
全部评论

注册时间:2013-10-19

  • 博文量
    620
  • 访问量
    6339932