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 9D2295285D for ; Tue, 9 Aug 2005 20:29:59 -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 30544-06 for ; Tue, 9 Aug 2005 23:29:50 +0000 (GMT) Received: from av1.karneval.cz (av1.karneval.cz [81.27.192.107]) by svr1.postgresql.org (Postfix) with ESMTP id 9689952824 for ; Tue, 9 Aug 2005 20:29:49 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by av1.karneval.cz (Postfix) with ESMTP id C8EA7A513A for ; Wed, 10 Aug 2005 02:06:19 +0200 (CEST) Received: from av1.karneval.cz ([127.0.0.1]) by localhost (av1 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 23185-09 for ; Wed, 10 Aug 2005 02:06:19 +0200 (CEST) Received: from mail.karneval.cz (mx1.karneval.cz [81.27.192.53]) by av1.karneval.cz (Postfix) with ESMTP id 857EBA5110 for ; Wed, 10 Aug 2005 02:06:19 +0200 (CEST) Received: from [127.0.0.1] (unknown [10.5.148.16]) by mail.karneval.cz (Postfix) with ESMTP id 246255BE3F1 for ; Wed, 10 Aug 2005 01:29:47 +0200 (CEST) Date: Wed, 10 Aug 2005 01:29:58 +0200 From: dracula007@atlas.cz X-Mailer: The Bat! (v2.12.00) UNREG / CD5BF9353B3B7091 Reply-To: dracula007@atlas.cz X-Priority: 3 (Normal) Message-ID: <196456155.20050810012958@karneval.cz> To: pgsql-sql@postgresql.org Subject: Re: **SPAM** Faster count(*)? In-Reply-To: <000101c59d33$36a4a560$9b00015a@osl.com> References: <000101c59d33$36a4a560$9b00015a@osl.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 0532-1, 09.08.2005), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: by karneval.cz X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.113 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, FORGED_RCVD_HELO, FROM_ENDS_IN_NUMS, NO_REAL_NAME X-Spam-Level: ** X-Archive-Number: 200508/43 X-Sequence-Number: 22271 I believe running count(*) means fulltable scan, and there's no way to do it without it. But what about some "intermediate" table, with the necessary counts? That means to create a table with values (counts) you need, and on every insert/delete/update increment or decrement the appropriate values. This way you won't need the count(*) query anymore, and the performance should be much better. t.v. > 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?