Re: count(*) optimization

From: "Nikola Ivacic" <nikola(at)rs-pi(dot)com>
To: "Ian Harding" <ianh(at)tpchd(dot)org>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: count(*) optimization
Date: 2003-01-08 17:06:03
Message-ID: 02cd01c2b738$39cc0a00$1100a8c0@rspi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I am not sure pgAdmin uses count(*) and I didn't have time to check
phpPgAdmin also, I presumed it from similarly slow response I get in psql

Nikola

----- Original Message -----
From: "Ian Harding" <ianh(at)tpchd(dot)org>
To: <nikola(at)rs-pi(dot)com>; <bruno(at)wolff(dot)to>
Cc: <PGSQL-sql(at)postgresql(dot)org>
Sent: Wednesday, January 08, 2003 5:20 PM
Subject: Re: [SQL] count(*) optimization

Bummer. I seem to remember PGAccess using the numbers generated by ANALYZE
to show the number of records. I noticed it was inaccurate until you ran a
vaccum. I guess pgAdmin chose accuracy over speed in this case.

Ian Harding
Programmer/Analyst II
Tacoma-Pierce County Health Department
iharding(at)tpchd(dot)org
(253) 798-3549

>>> "Nikola Ivacic" <nikola(at)rs-pi(dot)com> 01/08/03 08:15AM >>>
The problem is in other software I use,
witch uses count(*) function to display relation properties

pgAdmin II
phpPgAdmin

Nikola

----- Original Message -----
From: "Bruno Wolff III" <bruno(at)wolff(dot)to>
To: "Nikola Ivacic" <nikola(at)rs-pi(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Sent: Wednesday, January 08, 2003 5:22 PM
Subject: Re: [SQL] count(*) optimization

> On Wed, Jan 08, 2003 at 17:04:40 +0100,
> Nikola Ivacic <nikola(at)rs-pi(dot)com> wrote:
> > Hi
> >
> > I have trouble executing count(*) statement.
> > On a large dataset it takes quite a while to return result.
> > Is there any other way to get number of tupples in relation
> > or is the only way to optimize count() function to index it?
>
> Indexes won't help count.
>
> If you retrieve counts a lot more than you do updates that will change
their
> value, then you may want to keep the counts in another table and use
> triggers to keep them updated.
>

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2003-01-08 17:26:48 Re: What benefits can I expect from schemas ?
Previous Message Bob Lapique 2003-01-08 16:55:57 What benefits can I expect from schemas ?