所以我在列卡上有一个带有索引的表
当我运行时
SELECT COUNT(DISTINCT(card)) FROM table
它返回 490 个不同的条目
但是当我运行的时候
SHOW INDEXES FROM s_edge_type_group_join;
它揭示了 card
列上的索引卡的基数仅为 1。该索引中只有该列
为什么会这样?为什么索引的基数不能反射(reflect)数据的多样性?
最佳答案
SHOW INDEX
返回的
Cardinality 是一个估计,主要由优化器用于构建查询执行计划:
http://dev.mysql.com/doc/refman/5.0/en/show-index.html
Cardinality
An estimate of the number of unique values in the index. This is updated by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on statistics stored as integers, so the value is not necessarily exact even for small tables. The higher the cardinality, the greater the chance that MySQL uses the index when doing joins.
根据您填充表格的方式,这些值可能已过时。而且,为了解释文档,在这种情况下你应该使用 ANALYZE TABLE
更新这些统计数据。
关于mysql - 低 mysql 索引基数但数据多样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18262750/