Fix regression in vacuumdb --analyze-in-stages for partitioned tables
Hi,
While testing "vacuumdb: Make vacuumdb --analyze-only process partitioned tables”, I found a regression from later commit c4067383cb2.
The original feature commit 6429e5b77 made "--analyze-in-stages" work for partitioned tables, as the doc change states:
```
--- a/doc/src/sgml/ref/vacuumdb.sgml
+++ b/doc/src/sgml/ref/vacuumdb.sgml
@@ -397,6 +397,15 @@ PostgreSQL documentation
Multiple tables can be vacuumed by writing multiple
<option>-t</option> switches.
</para>
+ <para>
+ If no tables are specified with the <option>--table</option> option,
+ <application>vacuumdb</application> will clean all regular tables
+ and materialized views in the connected database.
+ If <option>--analyze-only</option> or
+ <option>--analyze-in-stages</option> is also specified,
+ it will analyze all regular tables, partitioned tables,
+ and materialized views (but not foreign tables).
+ </para>
```
The corresponding code was:
```
+ /*
+ * vacuumdb should generally follow the behavior of the underlying
+ * VACUUM and ANALYZE commands. If analyze_only is true, 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->analyze_only)
+ appendPQExpBufferStr(&catalog_query,
+ " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
+ CppAsString2(RELKIND_RELATION) ", "
+ CppAsString2(RELKIND_MATVIEW) ", "
+ CppAsString2(RELKIND_PARTITIONED_TABLE) "])\n");
```
However, the refactoring commit c4067383cb2 removed the `analyze_only` field from `vacuumingOptions` and switched to a new `mode` field. The new code is:
```
+ /*
+ * 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.
+ */
+ if (vacopts->mode == MODE_ANALYZE)
+ appendPQExpBufferStr(&catalog_query,
+ " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
+ CppAsString2(RELKIND_RELATION) ", "
+ CppAsString2(RELKIND_MATVIEW) ", "
+ CppAsString2(RELKIND_PARTITIONED_TABLE) "])\n");
```
analyze_only used to be true when "--analyze-in-stages" was specified, but that meaning was lost in c4067383cb2:
```
case 3:
- analyze_in_stages = vacopts.analyze_only = true;
+ vacopts.mode = MODE_ANALYZE_IN_STAGES;
break;
```
The fix is very straightforward, just add check for vacopts->mode == MODE_ANALYZE_IN_STAGES. I also added a test. If we had had this test earlier, the regression should have been caught.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachments:
v1-0001-vacuumdb-Analyze-partitioned-tables-with-analyze-.patchapplication/octet-stream; name=v1-0001-vacuumdb-Analyze-partitioned-tables-with-analyze-.patch; x-unix-mode=0644Download+12-7
On Fri, May 29, 2026 at 5:41 PM Chao Li <li.evan.chao@gmail.com> wrote:
The fix is very straightforward, just add check for vacopts->mode == MODE_ANALYZE_IN_STAGES. I also added a test. If we had had this test earlier, the regression should have been caught.
Thanks for reporting the issue and providing the patch! The patch
looks good to me.
Regards,
--
Fujii Masao
On May 30, 2026, at 00:08, Fujii Masao <masao.fujii@gmail.com> wrote:
On Fri, May 29, 2026 at 5:41 PM Chao Li <li.evan.chao@gmail.com> wrote:
The fix is very straightforward, just add check for vacopts->mode == MODE_ANALYZE_IN_STAGES. I also added a test. If we had had this test earlier, the regression should have been caught.
Thanks for reporting the issue and providing the patch! The patch
looks good to me.Regards,
--
Fujii Masao
For tracking purpose, I just added this to v19 open items.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
On Tue, Jun 2, 2026 at 2:57 PM Chao Li <li.evan.chao@gmail.com> wrote:
Thanks for reporting the issue and providing the patch! The patch
looks good to me.
I've pushed the patch. Thanks!
Regards,
--
Fujii Masao
On Jun 3, 2026, at 15:55, Fujii Masao <masao.fujii@gmail.com> wrote:
On Tue, Jun 2, 2026 at 2:57 PM Chao Li <li.evan.chao@gmail.com> wrote:
Thanks for reporting the issue and providing the patch! The patch
looks good to me.I've pushed the patch. Thanks!
Regards,
--
Fujii Masao
Thanks for pushing.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/