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

Поиск
Список
Период
Сортировка
От Peter Geoghegan
Тема Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?
Дата
Msg-id CAH2-Wz=S2nLZakxOAhc=JuDrn3FkL1e3O1YH60sVejutJk=H3A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Mon, Apr 18, 2022 at 12:15 PM Tom Lane <tgl@sss.pgh.pa.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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Why does pg_class.reltuples count only live tuples in indexes (after VACUUM runs)?
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: Postgres perl module namespace