mysql - 非唯一索引基数

标签 mysql database

我的数据库中有一个名为 transaction 的表,其中有两个索引,如下图所示。有时,非唯一索引 (account_id) 显示不同的基数。例如,有时两个索引显示相同的基数,但事实并非如此,因为与仅具有唯一值的 PRIMARY 相比,非唯一索引具有许多重复项。到目前为止,我不得不删除然后重新创建非唯一索引来临时解决问题。可能是什么问题?

enter image description here

最佳答案

没问题。引用 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/

相关文章:

mysql - 如何更改日期格式并从mysql获取日期?

php - 我的数据未在数据库中获取

php - 用于存储连续变化值的数据库结构

mysql - #1064 错误 : While "If Then Insert"

php - 我将如何使用 JSON/PHP/Mysql 保存我的 Javascript 对象,以便在用户返回时重新加载它们?

php - 无法在 php mysql 中使用 union

database - 类似于 TPC-H 和 TPC-DS 的基准测试

database - 数据库中的索引文件

mysql - VS2017 MYSQL SQLDataSource - 对象引用未设置为对象的实例

mysql - 如何使用附加表通过参数从基础获取项目?