How to optimize select count(*)..group by?

From: Bryan Field-Elliot <bryan_lists(at)netmeme(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: How to optimize select count(*)..group by?
Date: 2005-07-28 16:19:49
Message-ID: 1122567589.3880.19.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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).

Thank you,

Bryan

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2005-07-28 16:38:45 Re: How to optimize select count(*)..group by?
Previous Message Bryan Field-Elliot 2005-07-28 16:05:08