Re: How to optimize select count(*)..group by? - Mailing list pgsql-general

From David Fetter
Subject Re: How to optimize select count(*)..group by?
Date
Msg-id 20050728163845.GB22658@fetter.org
Whole thread Raw
In response to How to optimize select count(*)..group by?  (Bryan Field-Elliot <bryan_lists@netmeme.org>)
Responses Re: How to optimize select count(*)..group by?
List pgsql-general
On Thu, Jul 28, 2005 at 09:19:49AM -0700, Bryan Field-Elliot wrote:
> We have this simple query:
>
> select status, count(*) from customer group by status;
>
> There is already a btree index on status, but, the customer table is
> huge, and this query must be executed very frequently... an
> "explain" on this query shows that it is quite costly (and we notice
> it runs slowly)...
>
> Can someone recommend the best technique to optimize this? We can
> create new indices, we can re-write this query.. But we'd rather not
> add new tables or columns if possible (not just to solve this
> problem).

You're pretty much stuck with either writing triggers that modify a
cache table or having your performance the way it is now.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

pgsql-general by date:

Previous
From: Bryan Field-Elliot
Date:
Subject: How to optimize select count(*)..group by?
Next
From: Roman Neuhauser
Date:
Subject: Re: Cursor Issue??