日期:2014-05-16  浏览次数:20730 次

索引的Cardinality是什么意思?
show index from tbl的结果中会有Cardinality这一项,
一直不明白是什么意思,这个值对于索引的效率有什么影响吗?

------解决方案--------------------
的确是,很奇怪。应该是MYSQL的问题。
但当你再多插入几行后,倒是正确了。


SQL code
mysql> insert into tt(a, b, c, d)
    -> values(1, 1, 1, 1), (1, 1, 1, 2),
    -> (1, 1, 2, 1), (1, 1, 2, 1),
    -> (1, 1, 2, 2), (1, 2, 1, 1),
    -> (1, 2, 2, 1), (1, 2, 2, 2);
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> insert into tt(a, b, c, d)
    -> values(1, 1, 1, 1), (1, 1, 1, 2),
    -> (1, 1, 2, 1), (1, 1, 2, 1),
    -> (1, 1, 2, 2), (1, 2, 1, 1),
    -> (1, 2, 2, 1), (1, 2, 2, 2);
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> explain select * from tt where a = 1;
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
|  1 | SIMPLE      | tt    | ALL  | ind_a         | NULL | NULL    | NULL |   48 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

mysql>