vacuumdb: Don't skip empty relations in --missing-stats-only mode.
authorNathan Bossart <nathan@postgresql.org>
Wed, 30 Apr 2025 19:12:59 +0000 (14:12 -0500)
committerNathan Bossart <nathan@postgresql.org>
Wed, 30 Apr 2025 19:12:59 +0000 (14:12 -0500)
commit987910502420b77eaf7c3e807f6b0fc1cffced29
treec977f659a4a76e90a36a79066c623bede363de6d
parentd5f1b6a75ba3f55a78959c957c3fd25d9569057c
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@debian.org>
Reviewed-by: Christoph Berg <myon@debian.org>
Discussion: https://postgr.es/m/aAjyvW5_fRGNr7yF%40msg.df7cb.de
src/bin/scripts/vacuumdb.c