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

Re: Number of tuples in pg_class - bug or misunderstanding?

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Martin Neumann <mne(at)mne(dot)de>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Number of tuples in pg_class - bug or misunderstanding?
Date: 2000-05-11 15:12:59
Message-ID: 200005111512.LAA11713@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
> I'm just digging a little bit in PostgreSQL internals and I found the
> following thing. Shouldn't the reltuples field in pg_class contain the
> real number of tuples? It is always a little bit to low ...
> 
> irc=# SELECT reltuples FROM pg_class WHERE relname = 'events';
>  reltuples 
> -----------
>        188
> (1 row)
> 
> irc=# SELECT COUNT(*) FROM events;
>  count 
> -------
>    195
> (1 row)
> 
> 
> This annoys me a little bit as I can do
>   SELECT reltuples FROM pg_class WHERE relname = $1;
> from plpgsql, but not
>   SELECT COUNT(*) FROM $1;

reltuples is updated only by VACUUM.  The performance hit is too great
to keep it up-to-date, we think, though if it was accurate, we could
optimize COUNT(*) with no WHERE.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

In response to

pgsql-bugs by date

Next:From: Tom LaneDate: 2000-05-15 14:06:40
Subject: Re: Small bug with numeric in 7.0 (also in 6.5.3)
Previous:From: Denis SbragionDate: 2000-05-11 10:24:27
Subject: Small bug with numeric in 7.0 (also in 6.5.3)

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