X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 3770CD1B567 for ; Mon, 6 Oct 2003 15:11:08 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 81338-08 for ; Mon, 6 Oct 2003 12:10:22 -0300 (ADT) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by svr1.postgresql.org (Postfix) with ESMTP id E71D7D1B51E for ; Mon, 6 Oct 2003 12:10:21 -0300 (ADT) Received: from root by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A6X08-0003KO-00 for ; Mon, 06 Oct 2003 17:10:20 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org Received: from sea.gmane.org ([80.91.224.252]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A6Wxn-0003Hh-00 for ; Mon, 06 Oct 2003 17:07:55 +0200 Received: from news by sea.gmane.org with local (Exim 3.35 #1 (Debian)) id 1A6Wxn-0006U8-00 for ; Mon, 06 Oct 2003 17:07:55 +0200 From: Harald Fuchs Subject: Re: count(*) slow on large tables Date: 06 Oct 2003 17:08:36 +0200 Organization: Linux Private Site Lines: 21 Message-ID: References: <20031002191547.GZ87525@rlx11.zapatec.com> <20031002193905.GD18417@wolff.to> <3F7C98B8.C892D0E5@nsd.ca> <60brszcng5.fsf@dev6.int.libertyrms.info> <20031002223313.GE87525@rlx11.zapatec.com> <20031003042754.GH87525@rlx11.zapatec.com> <3F7D172E.3060107@persistent.co.in> Reply-To: hf99@protecting.net Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-No-Archive: yes User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/190 X-Sequence-Number: 3938 In article <3F7D172E.3060107@persistent.co.in>, Shridhar Daithankar writes: > Dror Matalon wrote: >> I smell a religious war in the aii:-). Can you go several days in a >> row without doing select count(*) on any >> of your tables? I suspect that this is somewhat a domain specific >> issue. In some areas >> you don't need to know the total number of rows in your tables, in >> others you do. > If I were you, I would have an autovacuum daemon running and rather > than doing select count(*), I would look at stats generated by > vacuums. They give approximate number of tuples and it should be good > enough it is accurate within a percent. The stats might indeed be a good estimate presumed there were not many changes since the last VACUUM. But how about a variant of COUNT(*) using an index? It would not be quite exact since it might contain tuples not visible in the current transaction, but it might be a much better estimate than the stats.