1

I'm quite new in MySQL and databases, I've just discovered and tried out indexes and something is not clear. I checked this question and the answers about cardinality and as I understood the value of cardinality represents the unique objects in the indexed column. Am I right? Or it's just an approximate value?

I'm asking this because I have a table with 40.000 rows, one of it's indexed column, call it column1 has 49 unique values, however it's cardinality has a value of 102. How is that possible? I tried to add new rows with totally unique values for the column1, but the cardinality value haven't changed. Is it normal?

Community
  • 1
  • 1
gatto
  • 333
  • 2
  • 10
  • MySQL is really bad at numbers sometimes. The estimates can be off by a factor of 100 or more. – tadman Apr 25 '16 at 15:48

1 Answers1

1

From the MySQL Manual - http://dev.mysql.com/doc/refman/5.7/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.

David Stokes
  • 120
  • 3