Re: [HACKERS] Much Ado About COUNT(*)

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Frank D(dot) Engel, Jr(dot)" <fde101(at)fjrhome(dot)net>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: [HACKERS] Much Ado About COUNT(*)
Date: 2005-01-14 18:38:16
Message-ID: 41E81198.6070105@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Frank D. Engel, Jr. wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> This is probably stupid for some reason, but why not use a 64-bit
> integer to track the number of records in the table? Increment when
> adding records, decrement when deleting them... then COUNT(*) could just
> return that in cases where a query is known to be looking at all of the
> records?

Check the list archives for details, but you need to consider multiple
backends inserting/deleting concurrently. What you need is a separate
little table where you can log your transaction-id and number of rows
added/removed then you can figure out how many rows there are from
different viewpoints.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2005-01-14 18:38:39 Re: [HACKERS] Much Ado About COUNT(*)
Previous Message Tom Lane 2005-01-14 18:34:18 Re: C locale + unicode

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2005-01-14 18:38:39 Re: [HACKERS] Much Ado About COUNT(*)
Previous Message Frank D. Engel, Jr. 2005-01-14 17:39:04 Re: [HACKERS] Much Ado About COUNT(*)