From 26dca9affeefa274d46f0e77847e0621f4caa58e Mon Sep 17 00:00:00 2001 From: Baji Shaik Date: Mon, 15 Jun 2026 12:35:48 -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 NOT p.inherited to the expression-index existence check. Author: Baji Shaik --- src/bin/scripts/vacuuming.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c index 37608806056..17bb5eb571c 100644 --- a/src/bin/scripts/vacuuming.c +++ b/src/bin/scripts/vacuuming.c @@ -727,9 +727,11 @@ 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" + " OR (NOT p.inherited" + " AND EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n" " JOIN pg_catalog.pg_index i" " ON i.indexrelid OPERATOR(pg_catalog.=) a.attrelid\n" " WHERE i.indrelid OPERATOR(pg_catalog.=) c.oid\n" @@ -741,7 +743,7 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, " 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.stainherit OPERATOR(pg_catalog.=) p.inherited)))\n"); /* inheritance and regular stats */ appendPQExpBufferStr(&catalog_query, -- 2.50.1 (Apple Git-155)