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

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

From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Shridhar Daithankar <shridhar_daithankar(at)persistent(dot)co(dot)in>,Postgresql Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Select max(foo) and select count(*) optimization
Date: 2004-01-06 12:18:08
Message-ID: 200401060718.08444.darcy@druid.net (view raw or flat)
Thread:
Lists: pgsql-performance
On January 6, 2004 01:42 am, Shridhar Daithankar wrote:
> On Tuesday 06 January 2004 01:22, Rod Taylor wrote:
> > Anyway, with Rules you can force this:
> >
> > ON INSERT UPDATE counter SET tablecount = tablecount + 1;
> >
> > ON DELETE UPDATE counter SET tablecount = tablecount - 1;
>
> That would generate lot of dead tuples in counter table. How about
>
> select relpages,reltuples from pg_class where relname=<tablename>;
>
> Assuming the stats are recent enough, it would be much faster and
> accurate..

Well, I did this:

cert=# select relpages,reltuples from pg_class where relname= 'certificate';
 relpages |  reltuples
----------+-------------
   399070 | 2.48587e+07
(1 row)

Casting seemed to help:

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.

-- 
D'Arcy J.M. Cain <darcy(at){druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

In response to

Responses

pgsql-performance by date

Next:From: Shridhar DaithankarDate: 2004-01-06 12:20:09
Subject: Re: Select max(foo) and select count(*) optimization
Previous:From: CoLDate: 2004-01-06 11:51:13
Subject: Re: Select max(foo) and select count(*) optimization

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