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 6470A52A5E for ; Fri, 8 Jul 2005 12:34:36 -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 19099-03 for ; Fri, 8 Jul 2005 15:34:33 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.196]) by svr1.postgresql.org (Postfix) with ESMTP id 3139C52ADF for ; Fri, 8 Jul 2005 12:34:27 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id 13so206890nzn for ; Fri, 08 Jul 2005 08:34:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=rSzMgNRCaVSPzadQC/RpdmghDNKdbxhMRDpEetcElSksPb6PfmeyIpEDAty0/K/hYOJb++pH8Kk7APJodBVKl7WDm5eNdOumzHMm7VjkbgCZzOyXq1pS6gGncfhAmLm/8z5X7GlWy1ReQC7azaSVPQSZ6ZxpM085cQ49g853UPc= Received: by 10.36.222.60 with SMTP id u60mr714380nzg; Fri, 08 Jul 2005 08:34:27 -0700 (PDT) Received: by 10.36.22.20 with HTTP; Fri, 8 Jul 2005 08:34:27 -0700 (PDT) Message-ID: <758d5e7f050708083423c20c70@mail.gmail.com> Date: Fri, 8 Jul 2005 17:34:27 +0200 From: Dawid Kuroczko Reply-To: Dawid Kuroczko To: Rod Taylor Subject: Re: Make COUNT(*) Faster? Cc: Steve Wampler , pgsql-sql@postgresql.org, Bruno Wolff III In-Reply-To: <1120836150.24708.251.camel@home> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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> <1120836150.24708.251.camel@home> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.61 tagged_above=0 required=5 tests=AWL, FROM_ENDS_IN_NUMS, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200507/76 X-Sequence-Number: 22054 On 7/8/05, Rod Taylor wrote: > Create 2 sequences, one for counting tuple additions and one for > counting tuple deletions. >=20 > When you INSERT a tuple, bump the "added" sequence (select nextval()); >=20 > When you DELETE a tuple, bump the "deleted" sequence (select nextval()); >=20 > To retrieve an approximate count, take the current value of both > sequences (select directly -- don't use currval) and subtract the > "deletes" from the "adds". Never thought of that! Good idea. :-) Regards, Dawid PS: There aren't any on ROLLBACK triggers, right? ;-)))