pgsql: Reject non-finite reltuples when restoring stats

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Reject non-finite reltuples when restoring stats
Date: 2026-07-30 14:47:38
Message-ID: E1wpS2s-00000000y0Z-3nag@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)planetscale(dot)com>
Discussion: https://postgr.es/m/518BA772-8026-412A-AA8F-A7FE4C6B3717@planetscale.com
Backpatch-through: 18

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a0369dd8448fba99d22068f533764bf2fb001278

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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2026-07-30 19:48:49 pgsql: Fix races between deactivation of logical decoding and slot crea
Previous Message Tomas Vondra 2026-07-30 14:47:29 pgsql: Reject non-finite reltuples when restoring stats