Re: [HACKERS] Much Ado About COUNT(*) - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: [HACKERS] Much Ado About COUNT(*)
Date
Msg-id 20050114183835.GB1724@svana.org
Whole thread Raw
In response to Re: [HACKERS] Much Ado About COUNT(*)  ("Frank D. Engel, Jr." <fde101@fjrhome.net>)
Responses Re: [HACKERS] Much Ado About COUNT(*)
List pgsql-general
On Fri, Jan 14, 2005 at 12:39:04PM -0500, Frank D. Engel, Jr. wrote:
> 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?

Because there is no single value for count(*), if you're in a
transaction that has added records it will be bigger than in a
transaction that hasn't. How does your integer deal with this?

The usual solutions this involve locking, which is precisely what MVCC
is designed to avoid.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: [HACKERS] Much Ado About COUNT(*)
Next
From: Bo Lorentsen
Date:
Subject: Re: OID Usage