agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Initialize bs_reltuples in parallel GIN builds
Date: Thu, 30 Jul 2026 13:10:51 +0000
Message-ID: <E1wpQXD-00000000xFy-1dpm@gemulon.postgresql.org> (raw)

Initialize bs_reltuples in parallel GIN builds

Index builds update pg_class.reltuples for the table. In parallel GIN
builds, workers track the number of processed rows, and report it to
the leader, who then updates the pg_class with a total. However,
gin_parallel_build_main failed to initialize the bs_reltuples field,
leaving it set to whatever happens to be on the stack (which may be
bogus values like Infinity or NaN, or just impossibly high values).

If such values get reported to the leader and stored in pg_class, that
can have serious consequences. The pg_class.reltuples field is used to
decide when a table is due for autovacuum or autoanalyze, and if it
happens to be set to a bogus value, that may never happen. The field is
also used by the optimizer when calculating costs.

Fixed by initializing bs_reltuples together with the rest of the build
state. The bs_numtuples was initialized later, but it seems cleaner to
just initialize all the fields at once.

After a bogus value gets persisted in pg_class, affected systems are
unlikely to self-heal. That would require an ANALYZE, but preventing
that is one of the consequences. We have considered forcing autoanalyze
in these cases, but there's not a good way to reliably identify bogus
values (except for a small minority like Infitiny/NaN).

A manual ANALYZE on (possibly) affected tables is the only solution.

Backpatch to 18, where parallel GIN builds were introduced.

Reported-by: Jan Nidzwetzki <jan@planetscale.com>
Discussion: https://postgr.es/m/518BA772-8026-412A-AA8F-A7FE4C6B3717@planetscale.com
Backpatch-through: 18

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5707d7517fa893f6d36b0e4a1173ee71699ada48

Modified Files
--------------
src/backend/access/gin/gininsert.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1wpQXD-00000000xFy-1dpm@gemulon.postgresql.org>
Permalink:  ../E1wpQXD-00000000xFy-1dpm@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wpQXD-00000000xFy-1dpm@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tomas.vondra@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Initialize bs_reltuples in parallel GIN builds
  In-Reply-To: <E1wpQXD-00000000xFy-1dpm@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox