SELECT COUNT(*) does a scan?

From: David Wall <d(dot)wall(at)computer(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: SELECT COUNT(*) does a scan?
Date: 2005-09-08 15:22:56
Message-ID: 43205750.5070806@computer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

When I do an EXPLAIN SELECT COUNT(*) FROM tablename, I noted that it
does a table scan. I thought PG had some sort of table stat that kept
track of the current number of rows in a table, but that doesn't appear
to always be the case.

It seems that right after a VACUUM ANALYZE, that command is very fast
(on a table with 100,000+ rows), but it can also get quite slow, as if a
table scan is taking place.

Does this make sense? Is there an algorithm that says to use the stats
from analyze only until sufficient updates/inserts/deletes have taken
place to make them "out of date"?

David

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Richard Huxton 2005-09-08 15:27:03 Re: BUG #1864: Strange behavoir of batches
Previous Message Diego Gil 2005-09-08 15:04:13 Re: simple insert operation