Skip to content

Commit 9879105

Browse files
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 3d351d9 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
1 parent d5f1b6a commit 9879105

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

src/bin/scripts/vacuumdb.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
954954
appendPQExpBufferStr(&catalog_query,
955955
" EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n"
956956
" WHERE a.attrelid OPERATOR(pg_catalog.=) c.oid\n"
957-
" AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n"
958957
" AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n"
959958
" AND NOT a.attisdropped\n"
960959
" AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
@@ -967,7 +966,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
967966
appendPQExpBufferStr(&catalog_query,
968967
" OR EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext e\n"
969968
" WHERE e.stxrelid OPERATOR(pg_catalog.=) c.oid\n"
970-
" AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n"
971969
" AND e.stxstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
972970
" AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext_data d\n"
973971
" WHERE d.stxoid OPERATOR(pg_catalog.=) e.oid\n"
@@ -979,7 +977,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
979977
" JOIN pg_catalog.pg_index i"
980978
" ON i.indexrelid OPERATOR(pg_catalog.=) a.attrelid\n"
981979
" WHERE i.indrelid OPERATOR(pg_catalog.=) c.oid\n"
982-
" AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n"
983980
" AND i.indkey[a.attnum OPERATOR(pg_catalog.-) 1::pg_catalog.int2]"
984981
" OPERATOR(pg_catalog.=) 0::pg_catalog.int2\n"
985982
" AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n"
@@ -994,7 +991,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
994991
appendPQExpBufferStr(&catalog_query,
995992
" OR EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n"
996993
" WHERE a.attrelid OPERATOR(pg_catalog.=) c.oid\n"
997-
" AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n"
998994
" AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n"
999995
" AND NOT a.attisdropped\n"
1000996
" AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
@@ -1011,7 +1007,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
10111007
appendPQExpBufferStr(&catalog_query,
10121008
" OR EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext e\n"
10131009
" WHERE e.stxrelid OPERATOR(pg_catalog.=) c.oid\n"
1014-
" AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n"
10151010
" AND e.stxstattarget IS DISTINCT FROM 0::pg_catalog.int2\n"
10161011
" AND c.relhassubclass\n"
10171012
" AND NOT p.inherited\n"

0 commit comments

Comments
 (0)