public inbox for [email protected]
help / color / mirror / Atom feedFrom: Daniel Gustafsson <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Additional minor pg_dump cleanups
Date: Wed, 3 Jul 2024 09:37:32 +0200
Message-ID: <[email protected]> (raw)
Re-reading Nathans recent 8213df9effaf I noticed a few more small things which
can be cleaned up. In two of the get<Object> functions we lack a fast-path for
when no tuples are found which leads to pg_malloc(0) calls. Another thing is
that we in one place reset the PQExpBuffer immediately after creating it which
isn't required.
--
Daniel Gustafsson
Attachments:
[application/octet-stream] 0001-Remove-superfluous-PQExpBuffer-resetting.patch (784B, ../[email protected]/2-0001-Remove-superfluous-PQExpBuffer-resetting.patch)
download | inline diff:
From f1a0952d441dfcfe45e77d939598b427c1e40bb9 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <[email protected]>
Date: Wed, 3 Jul 2024 09:11:05 +0200
Subject: [PATCH 1/2] Remove superfluous PQExpBuffer resetting
Since the buffer was just created, there is no reason to immediately
reset it.
---
src/bin/pg_dump/pg_dump.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 7aec016a9f..7ccf943522 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -4198,8 +4198,6 @@ getPublications(Archive *fout)
query = createPQExpBuffer();
- resetPQExpBuffer(query);
-
/* Get the publications. */
if (fout->remoteVersion >= 130000)
appendPQExpBufferStr(query,
--
2.39.3 (Apple Git-146)
[application/octet-stream] 0002-Add-fastpaths-for-when-no-objects-are-found.patch (1.6K, ../[email protected]/3-0002-Add-fastpaths-for-when-no-objects-are-found.patch)
download | inline diff:
From 4777fc98ee642b99c2bdab250e2a6311ee3022e6 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <[email protected]>
Date: Wed, 3 Jul 2024 09:12:12 +0200
Subject: [PATCH 2/2] Add fastpaths for when no objects are found
If there are no objects found, there is no reason to inspect the
result columns and mallocing a zero-sized (which will be 1 byte
in reality) heap buffer for it. Add fast-paths like how other
object inspection functions are already doing it.
---
src/bin/pg_dump/pg_dump.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 7ccf943522..6e0ddb637e 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -4222,6 +4222,9 @@ getPublications(Archive *fout)
ntups = PQntuples(res);
+ if (ntups == 0)
+ goto cleanup;
+
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
i_pubname = PQfnumber(res, "pubname");
@@ -4260,6 +4263,8 @@ getPublications(Archive *fout)
/* Decide whether we want to dump it */
selectDumpableObject(&(pubinfo[i].dobj), fout);
}
+
+cleanup:
PQclear(res);
destroyPQExpBuffer(query);
@@ -5701,6 +5706,8 @@ getExtensions(Archive *fout, int *numExtensions)
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
ntups = PQntuples(res);
+ if (ntups == 0)
+ goto cleanup;
extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
@@ -5730,6 +5737,7 @@ getExtensions(Archive *fout, int *numExtensions)
selectDumpableExtension(&(extinfo[i]), dopt);
}
+cleanup:
PQclear(res);
destroyPQExpBuffer(query);
--
2.39.3 (Apple Git-146)
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Additional minor pg_dump cleanups
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox