索引的选择性低,效果就多少有些折扣
索引是否有效,是否应该创建,需要具体情况具体分析.
大表的低CARDINALITY值索引,需要引起注意.
下面是 低选择性索引的查询
-
select t2.*,t1.table_rows,round(t2.CARDINALITY/t1.table_rows,2) seletivity
-
from information_schema.TABLES t1
-
inner join (
-
select table_schema,table_name,index_name,
-
group_concat(column_name order by seq_in_index) column_name,
-
max(CARDINALITY) CARDINALITY
-
from information_schema.STATISTICS
-
where index_name!='PRIMARY'
-
group by table_schema,table_name,index_name
-
) t2 on
-
(t1.table_schema=t2.table_schema and t1.table_name=t2.table_name)
-
where t1.table_rows>=100000 and t2.CARDINALITY/t1.table_rows<0.7
-
order by seletivity,t1.table_rows desc;
可以起到一些辅助分析的作用
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29254281/viewspace-2145169/
,如需转载,请注明出处,否则将追究法律责任。