Index on Mysql column has lower cardinality than count distinct?

允我心安 提交于 2020-01-07 05:38:06

问题


I have a varchar(50) field named token. When I do

count(distinct token) from table 

I get ~ 400k. However, if I do

create index idx on table (token)

The cardinality is only 200. What could be going on here? Shouldn't cardinality be the same as the number of distinct tokens?


回答1:


The cardinality is an estimate of the number of unique values in the index. According to the documentation:

Cardinality is counted based on statistics stored as integers, so the value is not necessarily exact even for small tables.



来源:https://stackoverflow.com/questions/29441260/index-on-mysql-column-has-lower-cardinality-than-count-distinct

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