Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Geoghegan <pg(at)bowt(dot)ie>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?
Date: 2022-04-18 19:15:01
Message-ID: 2370771.1650309301@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Geoghegan <pg(at)bowt(dot)ie> writes:
> Commit 7c91a0364f standardized the approach we take to estimating
> pg_class.reltuples, so that everybody agrees on what that means.
> Follow-up work by commit 3d351d91 defined a pg_class.reltuples of -1
> as "unknown, probably never vacuumed".

> The former commit added this code and comment to vacuumlazy.c:

> /*
> * Now we can provide a better estimate of total number of surviving
> * tuples (we assume indexes are more interested in that than in the
> * number of nominally live tuples).
> */
> ivinfo.num_heap_tuples = vacrelstats->new_rel_tuples;
> ivinfo.strategy = vac_strategy;

> I don't see why it makes sense to treat indexes differently here. Why
> allow the special case? Why include dead tuples like this?

The index has presumably got entries corresponding to dead tuples,
so that the number of entries it has ought to be more or less
num_heap_tuples, not reltuples (with discrepancies for concurrent
insertions of course).

> We make a general assumption that pg_class.reltuples only includes
> live tuples, which this code contravenes.

Huh? This is not pg_class.reltuples. If an index AM wants that, it
knows where to find it.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2022-04-18 19:27:13 Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?
Previous Message Tom Lane 2022-04-18 19:07:15 Re: avoid multiple hard links to same WAL file after a crash