Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?
Date
Msg-id 2370771.1650309301@sss.pgh.pa.us
Whole thread Raw
In response to Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?  (Peter Geoghegan <pg@bowt.ie>)
Responses Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?  (Peter Geoghegan <pg@bowt.ie>)
List pgsql-hackers
Peter Geoghegan <pg@bowt.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



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: avoid multiple hard links to same WAL file after a crash
Next
From: Peter Geoghegan
Date:
Subject: Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?