From 00aa23cb2273063ed33d69a28938b4020b897245 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 4 Jan 2019 20:47:35 +0000 Subject: [PATCH v2 1/6] 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 e0a8303f3e..7aa5980b51 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