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: Reject non-finite reltuples when restoring stats
Date: Thu, 30 Jul 2026 14:47:18 +0000
Message-ID: <E1wpS2Y-00000000xzG-2UoM@gemulon.postgresql.org> (raw)

Reject non-finite reltuples when restoring stats

When restoring relation stats, pg_restore_relation_stats() rejected
calls with (reltuples < -1.0). But that is insufficient - Infinity and
NaN values both pass that check, and get stored in pg_class verbatim.
This can have various undesirable consequences.

Fixed by rejecting non-finite reltuple values, in the same non-fatal way
as for the existing checks (emit WARNING and skip the update). Adds a
regression test to stats_import for these non-finite values, and to
check the -1.0 special value is still accepted.

Backpatch to 18, where pg_restore_relation_stats() was introduced.

Patch by Jan Nidzwetzki, minor commit message tweaks by me.

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7cb9060dcde08ca63df1f0d701b0674e0e8ae811

Modified Files
--------------
src/backend/statistics/relation_stats.c    | 11 ++++-
src/test/regress/expected/stats_import.out | 79 ++++++++++++++++++++++++++++++
src/test/regress/sql/stats_import.sql      | 43 ++++++++++++++++
3 files changed, 132 insertions(+), 1 deletion(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1wpS2Y-00000000xzG-2UoM@gemulon.postgresql.org>
Permalink:  ../E1wpS2Y-00000000xzG-2UoM@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wpS2Y-00000000xzG-2UoM@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: Reject non-finite reltuples when restoring stats
  In-Reply-To: <E1wpS2Y-00000000xzG-2UoM@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