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 4461A5280F for ; Tue, 9 Aug 2005 19:39:44 -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 19615-07 for ; Tue, 9 Aug 2005 22:39:42 +0000 (GMT) Received: from mail.osl.com (216-21-133-98.ip.van.radiant.net [216.21.133.98]) by svr1.postgresql.org (Postfix) with ESMTP id 0AC23529BB for ; Tue, 9 Aug 2005 19:39:39 -0300 (ADT) Received: from scottpj ([90.1.0.155]) (authenticated) by mail.osl.com (8.11.6/8.11.2) with ESMTP id j79Mdks13697 for ; Tue, 9 Aug 2005 15:39:47 -0700 From: "Owen Jacobson" To: Subject: Faster count(*)? Date: Tue, 9 Aug 2005 15:39:33 -0700 Message-ID: <000101c59d33$36a4a560$9b00015a@osl.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200508/42 X-Sequence-Number: 22270 Salve. I understand from various web searches and so on that PostgreSQL's MVCC mechanism makes it very hard to use indices or table metadata to optimise count(*). Is there a better way to guess the "approximate size" of a table? I'm trying to write a trigger that fires on insert and performs some maintenance (collapsing overlapping boxes into a single large box, specifically) as the table grows. My initial attempt involved count(*) and, as the number of pages in the table grew, that trigger bogged down the database. Any thoughts? -O