mysql - 低 mysql 索引基数但数据多样

标签 mysql sql indexing cardinality

所以我在列卡上有一个带有索引的表

当我运行时

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/

相关文章:

mysql - 编写Sql子查询

mysql - SQL连接两个表

python - pandas 中的索引日期时间列

python - 单位置索引器越界迭代 Pandas 数据框

MySQL 选择具有公共(public)列的行

mysql - 如果我重新启动 Clickhouse 服务器,则无法看到 Clickhouse 中加载的数据

mysql - 强大的容错 MySQL 复制

mysql - 如何使用 Valentina Studio 制作主键?

SQL存储过程仅返回函数创建的表的第一行

mysql - 使用主键索引删除 MySQL 中的行