From: Varun Mehta <vmehta@apple.com>
To: pgsql-sql@postgresql.org
Subject: Make COUNT(*) Faster?
Date: Thu, 7 Jul 2005 15:48:39 -0700
Message-ID: <9EF2931D-1097-470D-8ECB-59D00166C96F@apple.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: vmehta@apple.com
Subject: Re: Make COUNT(*) Faster?
In-Reply-To: <9EF2931D-1097-470D-8ECB-59D00166C96F@apple.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox