X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9BF29D7BF1 for ; Thu, 8 Sep 2005 12:22:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28443-02 for ; Thu, 8 Sep 2005 15:22:56 +0000 (GMT) Received: from mail2.yozons.com (mail2.yozons.com [206.80.109.180]) by svr1.postgresql.org (Postfix) with ESMTP id 65D90D6F0D for ; Thu, 8 Sep 2005 12:22:55 -0300 (ADT) Received: from [192.168.1.51] (soho2.yozons.com [206.80.109.178] (may be forged)) (authenticated bits=0) by mail2.yozons.com (8.12.8/8.12.8) with ESMTP id j88FMr2m020304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 8 Sep 2005 08:22:54 -0700 Message-ID: <43205750.5070806@computer.org> Date: Thu, 08 Sep 2005 08:22:56 -0700 From: David Wall User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: SELECT COUNT(*) does a scan? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.304 required=5 tests=[AWL=-0.070, DNS_FROM_RFC_ABUSE=0.374] X-Spam-Level: X-Archive-Number: 200509/23 X-Sequence-Number: 13808 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