Re: Slow count(*) - Mailing list pgsql-hackers

From Andrew Sullivan
Subject Re: Slow count(*)
Date
Msg-id 20080102162539.GU22706@crankycanuck.ca
Whole thread Raw
In response to Slow count(*)  ("Abraham, Danny" <danny_abraham@bmc.com>)
List pgsql-hackers
On Wed, Jan 02, 2008 at 09:29:24AM -0600, Abraham, Danny wrote:
> We are looking for a patch that will help us  count using the indexes.

Is this for 
SELECT count(*) FROM table;
or 
SELECT count(1) FROM table WHERE. . .
The latter _will_ use an index, if the index is correct, the statistics are
right, and the index selectivity is worth the cost of reading the index. 
The former will not use an index at all, because the answer depends on
visibility, and you can't know that without reading the table.  If you're
counting how many rows are in the table (for, for instance, display
purposes), you probably need to do something else.

> Our product is about 20 times slower on Postgres compared to MS SQL
> Server.
> 
> Any ideas?

Not without the queries, the EXPLAIN ANALYZE plans, and some information
about the database.

A


pgsql-hackers by date:

Previous
From: "Brian Modra"
Date:
Subject: Index performance
Next
From: Andrew Sullivan
Date:
Subject: Re: Index performance