Make COUNT(*) Faster? - Mailing list pgsql-sql

From Varun Mehta
Subject Make COUNT(*) Faster?
Date
Msg-id 9EF2931D-1097-470D-8ECB-59D00166C96F@apple.com
Whole thread Raw
Responses Re: Make COUNT(*) Faster?
List pgsql-sql
Hello all you PostgreSQL/SQL gurus!

I've started using PostgreSQL pretty recently, and I am quite  
disturbed about the performance of a simple SELECT COUNT(*) FROM  
table.  What should (in my mind) be a nearly instantaneous operation  
instead takes nearly 700ms in a table with only 87k rows of data!

If I run an EXPLAIN on this query I can see that it is doing a  
sequential scan, which seems quite needless, as surely this  
information is cached in some secret location.

It is very possible that I am missing something, so I ask you: is  
there a faster way to find out how many rows are in a table?  I've  
tried doing a COUNT(column) where I have an index on column, but it  
still does a sequential scan and it is still very very slow.  What  
are my options?

I offer you many thanks in advance,
Varun Mehta


pgsql-sql by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: getting back autonumber just inserted
Next
From: PFC
Date:
Subject: Re: getting back autonumber just inserted