X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CC2903A61D9 for ; Fri, 28 Jan 2005 05:24:16 +0000 (GMT) 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 01341-09 for ; Fri, 28 Jan 2005 05:24:13 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 1435E3A61C8 for ; Fri, 28 Jan 2005 05:24:12 +0000 (GMT) Received: (qmail 11415 invoked by uid 500); 28 Jan 2005 05:38:34 -0000 Date: Thu, 27 Jan 2005 23:38:34 -0600 From: Bruno Wolff III To: Zavier Sheran Cc: pgsql-performance@postgresql.org Subject: Re: slow count() Message-ID: <20050128053834.GA11394@wolff.to> Mail-Followup-To: Zavier Sheran , pgsql-performance@postgresql.org References: <20050128051756.54352.qmail@web14424.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050128051756.54352.qmail@web14424.mail.yahoo.com> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200501/563 X-Sequence-Number: 10253 On Thu, Jan 27, 2005 at 21:17:56 -0800, Zavier Sheran wrote: > quote from manual: > -- > Unfortunately, there is no similarly trivial query > that can be used to improve the performance of count() > when applied to the entire table > -- > > does count(1) also cause a sequential scan of the > entire table? It should be able to just use the > primary keys. No it can't just use the index file, so that an index scan will be slower than the sequential scan unless there is a where clause restricting the number of rows to a small fraction (about 5%) of the table. Search the archives for if you want to read more about this.