Re: Make COUNT(*) Faster?

From: Dawid Kuroczko <qnex42(at)gmail(dot)com>
To: Rod Taylor <pg(at)rbt(dot)ca>
Cc: Steve Wampler <swampler(at)noao(dot)edu>, pgsql-sql(at)postgresql(dot)org, Bruno Wolff III <bruno(at)wolff(dot)to>
Subject: Re: Make COUNT(*) Faster?
Date: 2005-07-08 15:34:27
Message-ID: 758d5e7f050708083423c20c70@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 7/8/05, Rod Taylor <pg(at)rbt(dot)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? ;-)))

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2005-07-08 15:35:00 Re: Make COUNT(*) Faster?
Previous Message Andrew Sullivan 2005-07-08 15:31:00 Re: Make COUNT(*) Faster?