Skip site navigation (1) Skip section navigation (2)

Re: Slow count(*)

From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Slow count(*)
Date: 2008-01-02 16:25:39
Message-ID: 20080102162539.GU22706@crankycanuck.ca (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-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

In response to

pgsql-hackers by date

Next:From: Andrew SullivanDate: 2008-01-02 16:31:55
Subject: Re: Index performance
Previous:From: Brian ModraDate: 2008-01-02 15:53:35
Subject: Index performance

pgsql-general by date

Next:From: Glyn AstillDate: 2008-01-02 16:32:39
Subject: Table auditing / Pg/tcl help
Previous:From: A. KretschmerDate: 2008-01-02 15:50:52
Subject: Re: Slow count(*)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group