From a40757f2b27948c510496b89a36a1667c3eac947 Mon Sep 17 00:00:00 2001 From: Baji Shaik Date: Tue, 16 Jun 2026 12:01:36 -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, and removing the now-redundant stainherit filter since index stats never have stainherit = true. Author: Baji Shaik --- src/bin/scripts/vacuuming.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c index 37608806056..4121ce5b12c 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,10 +739,10 @@ 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" - " AND s.stainherit OPERATOR(pg_catalog.=) p.inherited))\n"); + " AND s.staattnum OPERATOR(pg_catalog.=) a.attnum))\n"); /* inheritance and regular stats */ appendPQExpBufferStr(&catalog_query, -- 2.50.1 (Apple Git-155)