读书人

目录的Cardinality是什么意思

发布时间: 2012-09-20 09:36:50 作者: rapoo

索引的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: 0mysql> 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: 0mysql> 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> 

读书人网 >Mysql

热点推荐