Re: pg_class.reltuples can become non-finite and never recovers

From: Tomas Vondra <tomas(at)vondra(dot)me>
To: Jan Nidzwetzki <jan(at)planetscale(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg_class.reltuples can become non-finite and never recovers
Date: 2026-07-30 14:55:48
Message-ID: 03f065d7-d4eb-4a95-864e-0e0762ee68b0@vondra.me
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7/28/26 16:08, Jan Nidzwetzki wrote:
> ...
>
> As discussed upthread, here's the follow-up patch to validate and
> reject clearly bogus reltuples at import.
>
> Currently, the function relation_statistics_update_internal() validates
> the incoming reltuples only with
>
> if (reltuples < -1.0) { ereport(WARNING, ...); result = false; }
>
> This means that both Infinity and NaN values pass this test since
> neither is less than -1.0. As a result, non-finite values are accepted
> and stored in pg_class.reltuples.
>
> The patch rejects non-finite reltuples the same non-fatal way the
> existing out-of-range check does: ereport(WARNING), set result = false,
> and skip that field, so an otherwise-valid stats import (or pg_upgrade)
> still proceeds and only the bad value is dropped.
>
> It also adds a regression test to stats_import covering the rejected
> values (Infinity, -Infinity, NaN) and confirming that a legitimate -1
> is still accepted.
>
> The statistics import functions are new in v18, so this applies to v18+.
>

Thanks! I've now pushed both this fix and the fix for the GIN build.

I agree we don't need to do anything about "bogus" values between -1.0
and 0.0, because as you say, that should be treated as "unknown" (same
as -1.0).

I'll make sure we mention this (and the suggestion to run an explicit
ANALYZE on possibly-affected tables) in the release notes.

regards

--
Tomas Vondra

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayoub Kazar 2026-07-30 15:50:18 Re: [PATCH] Rewrite undirected edge patterns in GRAPH_TABLE using UNION ALL
Previous Message Amit Kapila 2026-07-30 14:53:46 Re: [Bug] pg_upgrade could fail for non-superuser subscriptions using foreign servers