Mysql中Cardinality

来源:互联网 发布:丝路英雄转生数据 编辑:程序博客网 时间:2024/06/07 09:38

查看官方文档的解释:
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.

所以这个Cardinality会有如下的含义:
1. 列值代表的是此列中存储的唯一值的个数(如果此列为primary key 则值为记录的行数)
2. 列值只是个估计值,并不准确。
3. 列值不会自动更新,需要通过Analyze table来更新一张表或者mysqlcheck -Aa来进行更新整个数据库。
4. 列值的大小影响Join时是否选用这个Index的判断。
5. 创建Index时,MyISAM的表Cardinality的值为null,InnoDB的表Cardinality的值大概为行数。
6. MyISAM与InnoDB对于Cardinality的计算方式不同。

这篇文章介绍很详细:
http://www.mysqlperformanceblog.com/2008/09/03/analyze-myisam-vs-innodb/