From 2a119c39e642906fb3c69e8ce7932e3e0663c941 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 29 Jan 2019 20:03:09 +0000 Subject: [PATCH v7 1/2] Do not filter by relkind in vacuumdb's catalog query if --table is used. --- src/bin/scripts/t/100_vacuumdb.pl | 11 ++++++++++- src/bin/scripts/vacuumdb.c | 13 ++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl index ff0d97971b..7fd8881e13 100644 --- a/src/bin/scripts/t/100_vacuumdb.pl +++ b/src/bin/scripts/t/100_vacuumdb.pl @@ -3,7 +3,7 @@ use warnings; use PostgresNode; use TestLib; -use Test::More tests => 35; +use Test::More tests => 37; program_help_ok('vacuumdb'); program_version_ok('vacuumdb'); @@ -60,6 +60,15 @@ $node->command_ok( [qw(vacuumdb -Zt pg_am(amname);ABORT postgres)], 'trailing command in "-t", with COLUMNS'); +$node->safe_psql( + 'postgres', q| + CREATE TABLE parted (a INT) PARTITION BY LIST (a); +|); +$node->issues_sql_like( + [ 'vacuumdb', '--analyze', 'postgres', '--table', 'parted'], + qr/statement: VACUUM \(ANALYZE\) public.parted;/, + 'vacuumdb --analyze processes partitioned table'); + $node->safe_psql( 'postgres', q| CREATE TABLE "need""q(uot" (")x" text); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 05321edb8d..52853505b6 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -484,9 +484,16 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts, appendPQExpBuffer(&catalog_query, " JOIN listed_tables" " ON listed_tables.table_oid OPERATOR(pg_catalog.=) c.oid\n"); - appendPQExpBuffer(&catalog_query, " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array[" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) "])\n"); + /* + * If no tables were listed, filter for the relevant relation types. If + * tables were given via --table, don't bother filtering by relation type. + * Instead, let the server decide whether a given relation can be + * processed. + */ + if (!tables_listed) + appendPQExpBuffer(&catalog_query, " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array[" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) "])\n"); /* * Execute the catalog query. We use the default search_path for this -- 2.16.5