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 1338FD88E3 for ; Thu, 8 Sep 2005 15:15:27 -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 74666-01 for ; Thu, 8 Sep 2005 18:15:23 +0000 (GMT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id 66808D8528 for ; Thu, 8 Sep 2005 15:15:22 -0300 (ADT) Received: (qmail 2569 invoked from network); 8 Sep 2005 18:15:23 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.2?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 8 Sep 2005 18:15:23 -0000 In-Reply-To: <43205750.5070806@computer.org> References: <43205750.5070806@computer.org> Mime-Version: 1.0 (Apple Message framework v734) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <82B89335-B770-4326-B524-5B9B5461CFEE@fastcrypt.com> Cc: pgsql-jdbc@postgresql.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: SELECT COUNT(*) does a scan? Date: Thu, 8 Sep 2005 14:15:21 -0400 To: David Wall X-Mailer: Apple Mail (2.734) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.034 required=5 tests=[AWL=0.034] X-Spam-Level: X-Archive-Number: 200509/25 X-Sequence-Number: 13810 See Oliver's post: Additionally you can get count to use an index, but you need a where clause. Dave On 8-Sep-05, at 11:22 AM, David Wall wrote: > 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 > > ---------------------------(end of > broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > >