Can cardinality differ for duplicate indexes in mysql?

删除回忆录丶 提交于 2019-12-02 02:46:42

Cardinality in mysql is an estimate, and mysql bases its estimate on table usage statistics:

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.

You can read more abot the statistics collected for myisam and innodb table engines in mysql's and innodb's documentation and how to configure these:

All statistics are stored in the STATISTICS table within information_schema.

The indexes, those estimated cardinality is closer to their exact cardinality (number of distinct values within the field) were created longer time ago, therefore mysql collected more statistics for them and its estimate is more accurate. If you run analyse table on this particular table, probably the cardinalities of the duplicate indexes will be a lot closer to each other, than now.

The huge question is, why do you have duplicate indexes at all?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!