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 7998052A7B for ; Fri, 8 Jul 2005 12:35:05 -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 19887-02 for ; Fri, 8 Jul 2005 15:35:03 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 820D552A78 for ; Fri, 8 Jul 2005 12:35:02 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j68FZ00Y022917; Fri, 8 Jul 2005 11:35:00 -0400 (EDT) To: Steve Wampler Cc: Bruno Wolff III , pgsql-sql@postgresql.org Subject: Re: Make COUNT(*) Faster? In-reply-to: <42CE96AF.3020903@noao.edu> 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> Comments: In-reply-to Steve Wampler message dated "Fri, 08 Jul 2005 08:07:27 -0700" Date: Fri, 08 Jul 2005 11:35:00 -0400 Message-ID: <22916.1120836900@sss.pgh.pa.us> From: Tom Lane 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/77 X-Sequence-Number: 22055 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. regards, tom lane