X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 733B352A5E for ; Fri, 8 Jul 2005 13:00:20 -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 82127-01 for ; Fri, 8 Jul 2005 16:00:15 +0000 (GMT) Received: from noao.edu (noao.edu [140.252.1.54]) by svr1.postgresql.org (Postfix) with ESMTP id BDC1E52995 for ; Fri, 8 Jul 2005 13:00:13 -0300 (ADT) X-TFF-CGPSA-Version: 1.4f1 X-TFF-CGPSA-Filter: Scanned Received: from [140.252.14.8] (HELO weaver.tuc.noao.edu) by noao.edu (CommuniGate Pro SMTP 4.3.6) with ESMTPS id 19191228; Fri, 08 Jul 2005 09:00:07 -0700 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by weaver.tuc.noao.edu (8.13.1/8.13.1) with ESMTP id j68G056T030276; Fri, 8 Jul 2005 09:00:05 -0700 Message-ID: <42CEA305.1050904@noao.edu> Date: Fri, 08 Jul 2005 09:00:05 -0700 From: Steve Wampler User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Make COUNT(*) Faster? References: <9EF2931D-1097-470D-8ECB-59D00166C96F@apple.com> <60vf3mklue.fsf@dba2.int.libertyrms.com> <42CE89CA.2070607@noao.edu> <20050708143508.GD22725@wolff.to> <42CE96AF.3020903@noao.edu> <22916.1120836900@sss.pgh.pa.us> In-Reply-To: <22916.1120836900@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/80 X-Sequence-Number: 22058 Tom Lane wrote: > Steve Wampler writes: > >>So, leave COUNT(*) alone. But it would be very handy to have a >>way to get an approximate table size that is more accurate than is >>provided by a pg_class.reltuples that is only updated on vacuums. > > If you want something cheap, you could use the same technique the > planner uses nowadays: take RelationGetNumberOfBlocks() (which is > guaranteed accurate) and multiply by reltuples/relpages. I don't > see anyplace where RelationGetNumberOfBlocks is directly exposed to > users now, but it'd be trivial to code up a couple of C functions to > provide this functionality. Yes - this would be an excellent approximation for my needs! The solution that Dawid Kuroczko suggested (just call "explain select * on ..." and parse the result) would be equivalent these days, right? (I think in the 7.x versions the planner was just using pg_class.reltuples, which wouldn't have helped.) If true, I can handle that parsing myself easily enough without exposing RelationGetNumberOfBlocks. Thanks (Tom and Dawid)! -- Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.