Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 4A3F02E00DD for ; Sat, 8 Mar 2008 01:08:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 72940-03 for ; Sat, 8 Mar 2008 01:08:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from westnet.com (westnet.com [216.187.52.2]) by postgresql.org (Postfix) with ESMTP id 7D1902E00A3 for ; Sat, 8 Mar 2008 01:08:40 -0400 (AST) Received: from westnet.com (localhost [127.0.0.1]) by westnet.com (8.14.0/8.14.0) with ESMTP id m2858dFF008111 for ; Sat, 8 Mar 2008 00:08:40 -0500 (EST) Received: from localhost (gsmith@localhost) by westnet.com (8.14.0/8.13.2/Submit) with ESMTP id m2858dpR008108 for ; Sat, 8 Mar 2008 00:08:39 -0500 (EST) X-Authentication-Warning: westnet.com: gsmith owned process doing -bs Date: Sat, 8 Mar 2008 00:08:39 -0500 (EST) From: Greg Smith X-X-Sender: gsmith@westnet.com To: pgsql-performance@postgresql.org Subject: Re: count * performance issue In-Reply-To: <13345.1204940295@sss.pgh.pa.us> Message-ID: References: <47D00DB2.7040007@emolecules.com> <18451.1204824562@sss.pgh.pa.us> <200803071727.36146.josh@agliodbs.com> <13345.1204940295@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/176 X-Sequence-Number: 29130 On Fri, 7 Mar 2008, Tom Lane wrote: > Well, scanning an index to get a count might be significantly faster > than scanning the main table, but it's hardly "instantaneous". It's > still going to take time proportional to the table size. If this is something that's happening regularly, you'd have to hope that most of the index is already buffered in memory somewhere though, so now you're talking a buffer/OS cache scan that doesn't touch disk much. Should be easier for that to be true because the index is smaller than the table, right? I know when I'm playing with pgbench the primary key index on the big accounts table is 1/7 the size of the table, and when using that table heavily shared_buffers ends up being mostly filled with that index. The usage counts are so high on the index blocks relative to any section of the table itself that they're very sticky in memory. And that's toy data; on some of the webapps people want these accurate counts for the ratio of index size to table data is even more exaggerated (think web forum). -- * Greg Smith gsmith@gregsmith.com http://www.gregsmith.com Baltimore, MD