Index on Mysql column has lower cardinality than c

2019-09-11 08:03发布

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条回答
smile是对你的礼貌
2楼-- · 2019-09-11 08:43

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.

查看更多
登录 后发表回答