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

From: "Frank D(dot) Engel, Jr(dot)" <fde101(at)fjrhome(dot)net>
To: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: [HACKERS] Much Ado About COUNT(*)
Date: 2005-01-14 17:39:04
Message-ID: 2F4ADFB8-6653-11D9-9E6D-0050E410655F@fjrhome.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

-----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?

On Jan 14, 2005, at 12:04 PM, Wes wrote:

> On 1/13/05 6:44 PM, "Greg Stark" <gsstark(at)mit(dot)edu> wrote:
>
>> That's simply false. Oracle does indeed have to count the records one
>> by one.
>>
>> It doesn't have to read and ignore the dead records since they're in a
>> separate place (but on the other hand it sometimes have to go read
>> that
>> separate place when it sees records that were committed after your
>> transaction).
>>
>> It can also do index-only scans, which often helps, but it's still not
>> instantaneous.
>
> Ok, I stand corrected - I was given some wrong information. However,
> my
> experience has been that count(*) on Oracle is a whole lot faster than
> PostgreSQL - what appeared instantaneous on Oracle took some time on
> PostgreSQL. That was one of the first things I noticed when moving a
> database application to PostgreSQL. I've since disposed of the Oracle
> database, so can't go back and retest.
>
> Wes
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
>
- -----------------------------------------------------------
Frank D. Engel, Jr. <fde101(at)fjrhome(dot)net>

$ ln -s /usr/share/kjvbible /usr/manual
$ true | cat /usr/manual | grep "John 3:16"
John 3:16 For God so loved the world, that he gave his only begotten
Son, that whosoever believeth in him should not perish, but have
everlasting life.
$
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFB6AO47aqtWrR9cZoRAs7UAKCQL3VnSu3770AyFoKW/X7xR7REfQCeK1Ud
M/sIP2jY+6LIfOcrJM5vvUQ=
=Qlbi
-----END PGP SIGNATURE-----

___________________________________________________________
$0 Web Hosting with up to 120MB web space, 1000 MB Transfer
10 Personalized POP and Web E-mail Accounts, and much more.
Signup at www.doteasy.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-01-14 17:41:54 Re: OID Usage
Previous Message Greg Stark 2005-01-14 17:22:11 Re: [HACKERS] Much Ado About COUNT(*)

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Huxton 2005-01-14 18:38:16 Re: [HACKERS] Much Ado About COUNT(*)
Previous Message Marc G. Fournier 2005-01-14 17:24:16 Re: FATAL: catalog is missing 1 attribute(s) for relid