Re: Select max(foo) and select count(*) optimization - Mailing list pgsql-performance

From Shridhar Daithankar
Subject Re: Select max(foo) and select count(*) optimization
Date
Msg-id 200401061750.09530.shridhar_daithankar@persistent.co.in
Whole thread Raw
In response to Re: Select max(foo) and select count(*) optimization  ("D'Arcy J.M. Cain" <darcy@druid.net>)
Responses Re: Select max(foo) and select count(*) optimization  (Robert Treat <xzilla@users.sourceforge.net>)
Re: Select max(foo) and select count(*) optimization  ("D'Arcy J.M. Cain" <darcy@druid.net>)
List pgsql-performance
On Tuesday 06 January 2004 17:48, D'Arcy J.M. Cain wrote:
> On January 6, 2004 01:42 am, Shridhar Daithankar wrote:
> cert=# select relpages,reltuples::bigint from pg_class where relname=
> 'certificate';
>  relpages | reltuples
> ----------+-----------
>    399070 |  24858736
> (1 row)
>
> But:
>
> cert=# select count(*) from certificate;
> [*Crunch* *Crunch* *Crunch*]
>   count
> ----------
>  19684668
> (1 row)
>
> Am I missing something?  Max certificate_id is 20569544 btw.

Do 'vacuum analyze certificate' and try..:-)

The numbers from pg_class are estimates updated by vacuum /analyze. Of course
you need to run vacuum frequent enough for that statistics to be updated all
the time or run autovacuum daemon..

Ran into same problem on my machine till I remembered about vacuum..:-)

 Shridhar


pgsql-performance by date:

Previous
From: "D'Arcy J.M. Cain"
Date:
Subject: Re: Select max(foo) and select count(*) optimization
Next
From: Clive Page
Date:
Subject: Inefficient SELECT with OFFSET and LIMIT