Chinaunix首页 | 论坛 | 博客
  • 博客访问: 128986
  • 博文数量: 89
  • 博客积分: 2580
  • 博客等级: 少校
  • 技术积分: 775
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-05 20:09
文章分类

全部博文(89)

文章存档

2009年(89)

我的朋友

分类: Mysql/postgreSQL

2009-06-15 21:23:01


show index from table 会有以下结果列

| Table          | Non_unique | Key_name  | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |

其中本文需要讨论的是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.

总结下来cardinality列的值有以下特性:

1. 列值代表的是此列中存储的唯一值的个数(如果此列为primary key 则值为记录的行数)
2. 列值只是个估计值,并不准确。
3. 列值不会自动更新,需要通过analyze table来进行更新。
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/
阅读(595) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~