pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <pg@rbt.ca>
To: Dawid Kuroczko <qnex42@gmail.com>
Cc: Steve Wampler <swampler@noao.edu>
Cc: pgsql-sql@postgresql.org, Bruno Wolff III <bruno@wolff.to>
Subject: Re: Make COUNT(*) Faster?
Date: Fri, 08 Jul 2005 11:38:31 -0400
Message-ID: <1120837111.24708.252.camel@home> (raw)
In-Reply-To: <758d5e7f050708083423c20c70@mail.gmail.com>
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>
	<758d5e7f050708083423c20c70@mail.gmail.com>

On Fri, 2005-07-08 at 17:34 +0200, Dawid Kuroczko wrote:
> On 7/8/05, Rod Taylor <pg@rbt.ca> wrote:
> > Create 2 sequences, one for counting tuple additions and one for
> > counting tuple deletions.
> > 
> > When you INSERT a tuple, bump the "added" sequence (select nextval());
> > 
> > When you DELETE a tuple, bump the "deleted" sequence (select nextval());
> > 
> > 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? ;-)))

No. You could make then RI triggers and have them deferred until commit
though.

-- 




view thread (21+ messages)  latest in thread

Message-ID: <1120837111.24708.252.camel@home>
Permalink:  ../1120837111.24708.252.camel@home/
Also on:    postgresql.org/message-id/1120837111.24708.252.camel@home

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pg@rbt.ca, qnex42@gmail.com, swampler@noao.edu, bruno@wolff.to
  Subject: Re: Make COUNT(*) Faster?
  In-Reply-To: <1120837111.24708.252.camel@home>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox