v1-0001-vacuumdb-Analyze-partitioned-tables-with-analyze-.patch

application/octet-stream

Filename: v1-0001-vacuumdb-Analyze-partitioned-tables-with-analyze-.patch
Type: application/octet-stream
Part: 0
Message: Fix regression in vacuumdb --analyze-in-stages for partitioned tables
From bcef4667b618de169d17838f3edabdb90bc5f639 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Fri, 29 May 2026 16:36:05 +0800
Subject: [PATCH v1] vacuumdb: Analyze partitioned tables with
 --analyze-in-stages

Commit 6429e5b77 made vacuumdb process partitioned tables when running in
analyze-only mode, including both --analyze-only and --analyze-in-stages.
This matched the documented behavior that, when no target tables are specified,
these options analyze regular tables, partitioned tables, and materialized
views.

Later, commit c4067383cb2 refactored vacuumingOptions by replacing the
analyze_only flag with a mode field.  During that refactoring, the object
selection logic was changed to check only MODE_ANALYZE, so
MODE_ANALYZE_IN_STAGES no longer included partitioned tables.

Fix this by treating MODE_ANALYZE_IN_STAGES the same as MODE_ANALYZE when
selecting objects to process, and add a regression test to cover the case.

Author: Chao Li <lic@highgo.com>
---
 src/bin/scripts/t/100_vacuumdb.pl |  4 ++++
 src/bin/scripts/vacuuming.c       | 14 ++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl
index 84fcacd57fa..5fd55628507 100644
--- a/src/bin/scripts/t/100_vacuumdb.pl
+++ b/src/bin/scripts/t/100_vacuumdb.pl
@@ -363,6 +363,10 @@ $node->issues_sql_like(
 	[ 'vacuumdb', '--analyze-only', 'postgres' ],
 	qr/statement: ANALYZE public.parent_table/s,
 	'--analyze-only updates statistics for partitioned tables');
+$node->issues_sql_like(
+	[ 'vacuumdb', '--analyze-in-stages', 'postgres' ],
+	qr/statement: ANALYZE public.parent_table/s,
+	'--analyze-in-stages updates statistics for partitioned tables');
 $node->issues_sql_unlike(
 	[ 'vacuumdb', '--analyze-only', 'postgres' ],
 	qr/statement:\ VACUUM/sx,
diff --git a/src/bin/scripts/vacuuming.c b/src/bin/scripts/vacuuming.c
index faac9089a01..37608806056 100644
--- a/src/bin/scripts/vacuuming.c
+++ b/src/bin/scripts/vacuuming.c
@@ -650,13 +650,15 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
 	{
 		/*
 		 * vacuumdb should generally follow the behavior of the underlying
-		 * VACUUM and ANALYZE commands.  In MODE_ANALYZE mode, process regular
-		 * tables, materialized views, and partitioned tables, just like
-		 * ANALYZE (with no specific target tables) does. Otherwise, process
-		 * only regular tables and materialized views, since VACUUM skips
-		 * partitioned tables when no target tables are specified.
+		 * VACUUM and ANALYZE commands.  In MODE_ANALYZE or
+		 * MODE_ANALYZE_IN_STAGES modes, process regular tables, materialized
+		 * views, and partitioned tables, just like ANALYZE (with no specific
+		 * target tables) does. Otherwise, process only regular tables and
+		 * materialized views, since VACUUM skips partitioned tables when no
+		 * target tables are specified.
 		 */
-		if (vacopts->mode == MODE_ANALYZE)
+		if (vacopts->mode == MODE_ANALYZE ||
+			vacopts->mode == MODE_ANALYZE_IN_STAGES)
 			appendPQExpBufferStr(&catalog_query,
 								 " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
 								 CppAsString2(RELKIND_RELATION) ", "
-- 
2.50.1 (Apple Git-155)