我的数据库中有一个名为 transaction 的表,其中有两个索引,如下图所示。有时,非唯一索引 (account_id) 显示不同的基数。例如,有时两个索引显示相同的基数,但事实并非如此,因为与仅具有唯一值的 PRIMARY 相比,非唯一索引具有许多重复项。到目前为止,我不得不删除然后重新创建非唯一索引来临时解决问题。可能是什么问题?
最佳答案
没问题。引用 reference manual :
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.
由于基数中的值只是一个估计值,因此您不应期望它 100% 准确。
关于mysql - 非唯一索引基数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43370679/