From bdc89983d9302ab47b94925ac9fe1f5888aeaaa1 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 19 Dec 2018 01:17:25 +0000 Subject: [PATCH v1 1/4] Do not process any relations if the catalog query returns no results. --- src/bin/scripts/vacuumdb.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index bcea9e556d..886895ed2f 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -378,8 +378,6 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts, fflush(stdout); } - initPQExpBuffer(&sql); - /* * If a table list is not provided and we're using multiple connections, * prepare the list of tables by querying the catalogs. @@ -390,8 +388,6 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts, PGresult *res; int ntups; - initPQExpBuffer(&buf); - res = executeQuery(conn, "SELECT c.relname, ns.nspname" " FROM pg_class c, pg_namespace ns\n" @@ -403,6 +399,14 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts, progname, echo); ntups = PQntuples(res); + if (ntups == 0) + { + PQclear(res); + PQfinish(conn); + return; + } + + initPQExpBuffer(&buf); for (i = 0; i < ntups; i++) { appendPQExpBufferStr(&buf, @@ -461,6 +465,8 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts, stage_commands[stage], progname, echo); } + initPQExpBuffer(&sql); + cell = tables ? tables->head : NULL; do { -- 2.16.5