Re: Database Select Slow - Mailing list pgsql-general

From Guido Neitzer
Subject Re: Database Select Slow
Date
Msg-id 5EB74578-FD29-4017-AED6-4A99450A4B13@event-s.net
Whole thread Raw
In response to Re: Database Select Slow  (".ep" <erick.papa@gmail.com>)
List pgsql-general
On 10.08.2007, at 06:58, .ep wrote:

> Hi, what if I need to do a count with a WHERE condition? E.g.,
>
> SELECT count(*) from customers where cust_id = 'georgebush' and
> created_on > current_date - interval '1 week' ;
>
> Can I get the info about this from somewhere in the pg system tables
> as well? Queries like these are very common in most applications, so
> I'm hoping I can avoid the sequential scans!

If you have a qualified count(*) it goes to the index first, than
checks whether the rows are live for your transaction. The problem is
only the unqualified count with

select count(*) from table_name;

without any qualification. Or, of course, if your qualifier is not
selective enough and you get a couple of millions rows back from a
slow IO system ...

I try to do counts only if I know that the selectivity is good enough
not to kill the performance. Or I use "pleas wait" pages in the my
application to tell the user, that his request is being processed and
not hung.

cug

pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: [PROPOSAL] DML value format
Next
From: Greg Smith
Date:
Subject: Re: UPDATES hang every 5 minutes