Re: Make COUNT(*) Faster? - Mailing list pgsql-sql

FromDawid Kuroczko
SubjectRe: Make COUNT(*) Faster?
Date
Msg-id[email protected]
Whole thread Raw
In response toRe: Make COUNT(*) Faster?  (Rod Taylor <[email protected]>)
ResponsesRe: Make COUNT(*) Faster?
Listpgsql-sql
On 7/8/05, Rod Taylor <[email protected]> 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? ;-)))


pgsql-sql by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: Make COUNT(*) Faster?
Next
From: Tom Lane
Date:
Subject: Re: Make COUNT(*) Faster?