Chinaunix首页 | 论坛 | 博客
  • 博客访问: 643310
  • 博文数量: 66
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 2204
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-26 21:43
个人简介

曾就职于阿里巴巴担任Oracle DBA,MySQL DBA,目前在新美大担任SRE。[是普罗米修斯还是一块石头,你自己选择!] 欢迎关注微信公众号 “自己的设计师”,不定期有原创运维文章推送。

文章分类

全部博文(66)

文章存档

2017年(2)

2016年(3)

2015年(7)

2014年(12)

2013年(42)

分类: Mysql/postgreSQL

2014-01-07 22:58:38

mysql high performace 关于MyISAM count的介绍,非常的好,在这里记录一下.

A common misconception is that MyISAM is extremely fast for COUNT() queries. It is fast, but only for a very special case: COUNT(*) without a WHERE clause,
which merely counts the number of rows in the entire table. MySQL can optimize this away because the storage engine always knows how many rows are in
the table. If MySQL knows col can never be NULL, it can also optimize a COUNT(col) expression by converting it to COUNT(*) internally.
MyISAM does not have any magical speed optimizations for counting rows when the query has a WHERE clause, or for the more general case of counting values
instead of rows. It might be faster than other storage engines for a given query, or it might not be.That depends on a lot of factors.

我们经常有一个错误的概念,就是MyISAM对于count()的查询时非常快的。的确,这种查询是非常的快,但是它只是在一些特殊的情况下会非常的快:count(*)没有where
条件,仅仅只是获取这个表的数据量。MySQL可以这样优化,是因为MyISAM storage engine总是知道表有多少行。当然,如果MySQL知道某列(col)非空,它同样可以将该列
的count(col)内部转换成count(*)去查询。当查询有where条件时,MyISAM并没有一些神奇的速度来count rows,或者更好的形式来记录rows的值(带where条件的行数)。
带where条件的count 在MyISAM上的查询的快慢,与其他存储引擎相比,有很多相关的条件,所以不能一概而论。
阅读(1811) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~