【问题标题】:Index on Mysql column has lower cardinality than count distinct?Mysql 列上的索引基数低于计数不同?
【发布时间】:2015-04-03 23:57:16
【问题描述】:

我有一个名为 token 的 varchar(50) 字段。当我这样做时

count(distinct token) from table 

我得到〜400k。但是,如果我这样做

create index idx on table (token)

基数只有 200。这里会发生什么?基数不应该与不同标记的数量相同吗?

【问题讨论】:

  • 尝试使用ANALYZE TABLE table,看看它是否更新。

标签: mysql sql indexing distinct cardinality


【解决方案1】:

基数是索引中唯一值数量的估计。根据documentation

基数是根据存储为整数的统计信息计算的,因此即使对于小表,该值也不一定准确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-19
    • 2011-01-24
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    相关资源
    最近更新 更多