pgsql: vacuumdb: Don't skip empty relations in --missing-stats-only mod

From: Nathan Bossart <nathan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: vacuumdb: Don't skip empty relations in --missing-stats-only mod
Date: 2025-04-30 19:13:29
Message-ID: E1uACs5-000Myo-1K@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

vacuumdb: Don't skip empty relations in --missing-stats-only mode.

Presently, --missing-stats-only skips relations with reltuples set
to 0 because empty relations don't get optimizer statistics.
However, before v14, a reltuples value of 0 was ambiguous: it could
either mean the relation is empty, or it could mean that it hadn't
yet been vacuumed or analyzed. (Commit 3d351d916b taught v14 and
newer to use -1 for the latter case.) This ambiguity can cause
--missing-stats-only to inadvertently skip relations that need
optimizer statistics after upgrades to v18 and newer (since
reltuples is now transferred from the old cluster).

To fix, simply remove the check for reltuples != 0. This will
cause --missing-stats-only to analyze some empty tables, but that
doesn't seem too terrible a trade-off.

Reported-by: Christoph Berg <myon(at)debian(dot)org>
Reviewed-by: Christoph Berg <myon(at)debian(dot)org>
Discussion: https://postgr.es/m/aAjyvW5_fRGNr7yF%40msg.df7cb.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/987910502420b77eaf7c3e807f6b0fc1cffced29

Modified Files
--------------
src/bin/scripts/vacuumdb.c | 5 -----
1 file changed, 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2025-04-30 19:22:17 Re: vacuumdb --missing-stats-only and pg_upgrade from PG13
Previous Message Daniel Gustafsson 2025-04-30 18:47:34 pgsql: Fix assertion failure in snapshot building