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上的查询的快慢,与其他存储引擎相比,有很多相关的条件,所以不能一概而论。
阅读(1892) | 评论(0) | 转发(0) |