From 42563c65ca9b1b2c35f008108502e3f725fda8e4 Mon Sep 17 00:00:00 2001 From: Baji Shaik Date: Tue, 16 Jun 2026 11:17:17 -0500 Subject: [PATCH] Fix vacuumdb --missing-stats-only false positive for partitioned expression indexes vacuumdb --missing-stats-only incorrectly flags partitioned tables with expression indexes on every run, regardless of whether stats are current. The expression-index subquery checks for pg_statistic entries with stainherit matching p.inherited, but partitioned indexes never accumulate their own stats (only leaf indexes do). Fix by adding AND NOT p.inherited to the expression-index existence check, skipping it for the inherited-stats row of partitioned tables. Author: Baji Shaik --- src/bin/scripts/vacuuming.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c index 37608806056..6055b8831da 100644 --- a/src/bin/scripts/vacuuming.c +++ b/src/bin/scripts/vacuuming.c @@ -727,7 +727,8 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, " WHERE d.stxoid OPERATOR(pg_catalog.=) e.oid\n" " AND d.stxdinherit OPERATOR(pg_catalog.=) p.inherited))\n"); - /* expression indexes */ + /* expression indexes (skip for partitioned tables; their partitioned + * indexes don't accumulate stats -- only leaf partition indexes do) */ appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n" " JOIN pg_catalog.pg_index i" @@ -738,6 +739,7 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, " AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n" " AND NOT a.attisdropped\n" " AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" + " AND NOT p.inherited\n" " AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic s\n" " WHERE s.starelid OPERATOR(pg_catalog.=) a.attrelid\n" " AND s.staattnum OPERATOR(pg_catalog.=) a.attnum\n" -- 2.50.1 (Apple Git-155)