List:Internals« Previous MessageNext Message »
From:Michael Widenius Date:April 20 2002 12:47pm
Subject:COUNT optimization based on cardinality ?
View as plain text  
Hi!

>>>>> "Fournier" == Fournier Jocelyn <[Presence-PC]"
> <joc@stripped>> writes:

Fournier> Hi,
Fournier> I wonder if it would be possible to optimize COUNT, based on cardinality
Fournier> index.
Fournier> Example :

Fournier> In my application I have the following query :

Fournier> SELECT COUNT(*) FROM inscrit WHERE forum='someid';

Fournier> It's possible that the column 'forum' contains only one value, and in this
Fournier> case it will be much more faster to optimize the query in executing :

Fournier> SELECT COUNT(*) FROM inscrit;

<cut>

Just looking at cardinality is not enough for deciding this issue, as
the cardinality is not exact.

I don't think this optimization is that easy to worth doing at this
point, as this is not a very likely scenario and doing the extra check
would slow down most index queries a bit, which is likely to slow down
the total server much more than the gain you could get.

Regards,
Monty

Thread
COUNT optimization based on cardinality ?Fournier Jocelyn [Presence-PC]13 Apr
  • COUNT optimization based on cardinality ?Michael Widenius22 Apr