From: | Peter Geoghegan <pg(at)bowt(dot)ie> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
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:27:13 |
Message-ID: | CAH2-Wz=S2nLZakxOAhc=JuDrn3FkL1e3O1YH60sVejutJk=H3A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, Apr 18, 2022 at 12:15 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > 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).
I guess that pg_class.reltuples has to include some "recently dead"
tuples in the case of an index, just because of the impracticality of
accurately counting index tuples while knowing if they're dead or
alive. However, it would be practical to update pg_class.reltuples to
a value "IndexBulkDeleteResult.num_index_tuples -
recently_dead_tuples" in update_relstats_all_indexes to compensate.
Then everything is consistent.
> > 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.
It's not, but it is how we calculate
IndexBulkDeleteResult.num_index_tuples, which is related. Granted,
that won't be used to update pg_class for the index in the case where
it's just an estimate anyway.
--
Peter Geoghegan
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2022-04-18 19:29:18 | Re: Postgres perl module namespace |
Previous Message | Tom Lane | 2022-04-18 19:15:01 | Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)? |