Skip to content

Commit cbbf3ee

Browse files
author
Commitfest Bot
committed
[CF 5871] v3 - Make "vacuumdb --analyze-only" process partitioned tables
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5871 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAHGQGwGje3mv5sOmyCJ0NroNPF8938OYCOHMJZbegTekccZZ=g@mail.gmail.com Author(s): Laurenz Albe
2 parents c6abf24 + 2e810c5 commit cbbf3ee

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

doc/src/sgml/ref/vacuumdb.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,15 @@ PostgreSQL documentation
397397
Multiple tables can be vacuumed by writing multiple
398398
<option>-t</option> switches.
399399
</para>
400+
<para>
401+
If no tables are specified with the <option>--table</option> option,
402+
<application>vacuumdb</application> will clean all regular tables
403+
and materialized views in the connected database.
404+
If <option>--analyze-only</option> or
405+
<option>--analyze-in-stages</option> is also specified,
406+
it will analyze all regular tables, partitioned tables,
407+
and materialized views (but not foreign tables).
408+
</para>
400409
<tip>
401410
<para>
402411
If you specify columns, you probably have to escape the parentheses

src/bin/scripts/t/100_vacuumdb.pl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,15 @@
340340
qr/statement:\ ANALYZE/sx,
341341
'--missing-stats-only with no missing partition stats');
342342

343+
$node->safe_psql('postgres',
344+
"CREATE TABLE parent_table (a INT) PARTITION BY LIST (a);\n"
345+
. "CREATE TABLE child_table PARTITION OF parent_table FOR VALUES IN (1);\n"
346+
. "INSERT INTO parent_table VALUES (1);\n");
347+
$node->issues_sql_like(
348+
[
349+
'vacuumdb', '--analyze-only', 'postgres'
350+
],
351+
qr/statement: ANALYZE public.parent_table/s,
352+
'--analyze-only updates statistics for partitioned tables');
353+
343354
done_testing();

src/bin/scripts/vacuumdb.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,26 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
911911
*/
912912
if ((objfilter & OBJFILTER_TABLE) == 0)
913913
{
914-
appendPQExpBufferStr(&catalog_query,
915-
" AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
916-
CppAsString2(RELKIND_RELATION) ", "
917-
CppAsString2(RELKIND_MATVIEW) "])\n");
914+
/*
915+
* vacuumdb should generally follow the behavior of the underlying
916+
* VACUUM and ANALYZE commands. If analyze_only is true, process
917+
* regular tables, materialized views, and partitioned tables, just
918+
* like ANALYZE (with no specific target tables) does. Otherwise,
919+
* process only regular tables and materialized views, since VACUUM
920+
* skips partitioned tables when no target tables are specified.
921+
*/
922+
if (vacopts->analyze_only)
923+
appendPQExpBufferStr(&catalog_query,
924+
" AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
925+
CppAsString2(RELKIND_RELATION) ", "
926+
CppAsString2(RELKIND_MATVIEW) ", "
927+
CppAsString2(RELKIND_PARTITIONED_TABLE) "])\n");
928+
else
929+
appendPQExpBufferStr(&catalog_query,
930+
" AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
931+
CppAsString2(RELKIND_RELATION) ", "
932+
CppAsString2(RELKIND_MATVIEW) "])\n");
933+
918934
}
919935

920936
/*

0 commit comments

Comments
 (0)