Skip site navigation (1) Skip section navigation (2)

Re: Select max(foo) and select count(*) optimization

From: Shridhar Daithankar <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: Postgresql Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Select max(foo) and select count(*) optimization
Date: 2004-01-06 12:20:09
Message-ID: 200401061750.09530.shridhar_daithankar@persistent.co.in (view raw or flat)
Thread:
Lists: 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


In response to

Responses

pgsql-performance by date

Next:From: Clive PageDate: 2004-01-06 15:40:48
Subject: Inefficient SELECT with OFFSET and LIMIT
Previous:From: D'Arcy J.M. CainDate: 2004-01-06 12:18:08
Subject: Re: Select max(foo) and select count(*) optimization

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group