List:Internals« Previous MessageNext Message »
From:Sergei Golubchik Date:January 10 2011 11:03am
Subject:Re: Optimization about count(*)
View as plain text  
Hi, sky.jian!

On Jan 10, sky.jian wrote:
> I think MySQL just need to read the B-Tree index for this count(*).

Yes, and it does that.
Assuming the engine supports "just reading the index" - not every
storage engine does.

> On 01/09/2011 11:41 PM, Sergei Golubchik wrote:
>>> sql:
>>> select count(*) from t where id>  10 and id<  1000000;
>>> In table t, there is an B-tree index on id field, this sql will read
>>> hundreds of thousandes of lines from the storage engine, this is a
>>> time-consuming operation.
>>> If tell the storage engine computing the count in the range, does it
>>> have higher performance? (using records_in_range() api and so on)
>> There's no API for that in MySQL yet.
>> records_in_range() is approximate, it cannot be used for count(*).
Optimization about count(*)谢立超9 Jan
  • Re: Optimization about count(*)Sergei Golubchik9 Jan
    • Re: Optimization about count(*)sky.jian10 Jan
      • Re: Optimization about count(*)Sergei Golubchik10 Jan