Question

so I have a table with index on the column card

When I run

SELECT COUNT(DISTINCT(card)) FROM table

it returns 490 distinct entries

However when I run

SHOW INDEXES FROM s_edge_type_group_join;

It revealls that the cardinality of index card on the column card is only 1. That index only has that column in it

Why is this the case? Why is isn't the cardinality of the index reflect the diversity of the data?

Was it helpful?

Solution

Cardinality as returned by SHOW INDEX is an estimate, mostly used by the optimizer to build the query execution plan:

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.

Depending the way you populated your table, those values might be outdated. And, to paraphrase the doc, in that case you should use ANALYZE TABLE to update those statistics.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top