Subject: small pg_dump code cleanup

From: Nathan Bossart <[email-masked]>
Date: Wed, 5 Jun 2024 10:13:57 -0500

While reviewing Daniel's pg_dump patch [0], I was initially confused
because the return value of getTypes() isn't saved anywhere.  Once I found
commit 92316a4, I realized that data was actually stored in a separate hash
table.  In fact, many of the functions in this area don't actually need to
return anything, so we can trim some code and hopefully reduce confusion a
bit.  Patch attached.

[0] https://postgr.es/m/8F1F1E1D-D17B-4B33-B014-EDBCD15F3F0B%40yesql.se

-- 
nathan
>From a6b8585cd55c0758ffb1cabb4c4deacbb65af9d3 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <[email-masked]>
Date: Tue, 4 Jun 2024 22:32:20 -0500
Subject: [PATCH v1 1/1] Trim some unnecessary pg_dump code.

---
 src/bin/pg_dump/common.c  |  69 ++++------
 src/bin/pg_dump/pg_dump.c | 282 +++++++++-----------------------------
 src/bin/pg_dump/pg_dump.h |  49 ++++---
 3 files changed, 113 insertions(+), 287 deletions(-)

diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index 64e7dc89f1..c323b5bd3d 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -101,31 +101,8 @@ getSchemaData(Archive *fout, int *numTablesPtr)
 	ExtensionInfo *extinfo;
 	InhInfo    *inhinfo;
 	int			numTables;
-	int			numTypes;
-	int			numFuncs;
-	int			numOperators;
-	int			numCollations;
-	int			numNamespaces;
 	int			numExtensions;
-	int			numPublications;
-	int			numAggregates;
 	int			numInherits;
-	int			numRules;
-	int			numProcLangs;
-	int			numCasts;
-	int			numTransforms;
-	int			numAccessMethods;
-	int			numOpclasses;
-	int			numOpfamilies;
-	int			numConversions;
-	int			numTSParsers;
-	int			numTSTemplates;
-	int			numTSDicts;
-	int			numTSConfigs;
-	int			numForeignDataWrappers;
-	int			numForeignServers;
-	int			numDefaultACLs;
-	int			numEventTriggers;
 
 	/*
 	 * We must read extensions and extension membership info first, because
@@ -139,7 +116,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
 	getExtensionMembership(fout, extinfo, numExtensions);
 
 	pg_log_info("reading schemas");
-	(void) getNamespaces(fout, &numNamespaces);
+	getNamespaces(fout);
 
 	/*
 	 * getTables should be done as soon as possible, so as to minimize the
@@ -153,69 +130,69 @@ getSchemaData(Archive *fout, int *numTablesPtr)
 	getOwnedSeqs(fout, tblinfo, numTables);
 
 	pg_log_info("reading user-defined functions");
-	(void) getFuncs(fout, &numFuncs);
+	getFuncs(fout);
 
 	/* this must be after getTables and getFuncs */
 	pg_log_info("reading user-defined types");
-	(void) getTypes(fout, &numTypes);
+	getTypes(fout);
 
 	/* this must be after getFuncs, too */
 	pg_log_info("reading procedural languages");
-	getProcLangs(fout, &numProcLangs);
+	getProcLangs(fout);
 
 	pg_log_info("reading user-defined aggregate functions");
-	getAggregates(fout, &numAggregates);
+	getAggregates(fout);
 
 	pg_log_info("reading user-defined operators");
-	(void) getOperators(fout, &numOperators);
+	getOperators(fout);
 
 	pg_log_info("reading user-defined access methods");
-	getAccessMethods(fout, &numAccessMethods);
+	getAccessMethods(fout);
 
 	pg_log_info("reading user-defined operator classes");
-	getOpclasses(fout, &numOpclasses);
+	getOpclasses(fout);
 
 	pg_log_info("reading user-defined operator families");
-	getOpfamilies(fout, &numOpfamilies);
+	getOpfamilies(fout);
 
 	pg_log_info("reading user-defined text search parsers");
-	getTSParsers(fout, &numTSParsers);
+	getTSParsers(fout);
 
 	pg_log_info("reading user-defined text search templates");
-	getTSTemplates(fout, &numTSTemplates);
+	getTSTemplates(fout);
 
 	pg_log_info("reading user-defined text search dictionaries");
-	getTSDictionaries(fout, &numTSDicts);
+	getTSDictionaries(fout);
 
 	pg_log_info("reading user-defined text search configurations");
-	getTSConfigurations(fout, &numTSConfigs);
+	getTSConfigurations(fout);
 
 	pg_log_info("reading user-defined foreign-data wrappers");
-	getForeignDataWrappers(fout, &numForeignDataWrappers);
+	getForeignDataWrappers(fout);
 
 	pg_log_info("reading user-defined foreign servers");
-	getForeignServers(fout, &numForeignServers);
+	getForeignServers(fout);
 
 	pg_log_info("reading default privileges");
-	getDefaultACLs(fout, &numDefaultACLs);
+	getDefaultACLs(fout);
 
 	pg_log_info("reading user-defined collations");
-	(void) getCollations(fout, &numCollations);
+	getCollations(fout);
 
 	pg_log_info("reading user-defined conversions");
-	getConversions(fout, &numConversions);
+	getConversions(fout);
 
 	pg_log_info("reading type casts");
-	getCasts(fout, &numCasts);
+	getCasts(fout);
 
 	pg_log_info("reading transforms");
-	getTransforms(fout, &numTransforms);
+	getTransforms(fout);
 
 	pg_log_info("reading table inheritance information");
 	inhinfo = getInherits(fout, &numInherits);
 
 	pg_log_info("reading event triggers");
-	getEventTriggers(fout, &numEventTriggers);
+	getEventTriggers(fout);
 
 	/* Identify extension configuration tables that should be dumped */
 	pg_log_info("finding extension tables");
@@ -250,13 +227,13 @@ getSchemaData(Archive *fout, int *numTablesPtr)
 	getTriggers(fout, tblinfo, numTables);
 
 	pg_log_info("reading rewrite rules");
-	getRules(fout, &numRules);
+	getRules(fout);
 
 	pg_log_info("reading policies");
 	getPolicies(fout, tblinfo, numTables);
 
 	pg_log_info("reading publications");
-	(void) getPublications(fout, &numPublications);
+	getPublications(fout);
 
 	pg_log_info("reading publication membership of tables");
 	getPublicationTables(fout, tblinfo, numTables);
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index e324070828..7aec016a9f 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -4173,8 +4173,8 @@ dumpPolicy(Archive *fout, const PolicyInfo *polinfo)
  * getPublications
  *	  get information about publications
  */
-PublicationInfo *
-getPublications(Archive *fout, int *numPublications)
+void
+getPublications(Archive *fout)
 {
 	DumpOptions *dopt = fout->dopt;
 	PQExpBuffer query;
@@ -4194,10 +4194,7 @@ getPublications(Archive *fout, int *numPublications)
 				ntups;
 
 	if (dopt->no_publications || fout->remoteVersion < 100000)
-	{
-		*numPublications = 0;
-		return NULL;
-	}
+		return;
 
 	query = createPQExpBuffer();
 
@@ -4268,9 +4265,6 @@ getPublications(Archive *fout, int *numPublications)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	*numPublications = ntups;
-	return pubinfo;
 }
 
 /*
@@ -5547,13 +5541,10 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer,
 
 /*
  * getNamespaces:
- *	  read all namespaces in the system catalogs and return them in the
- * NamespaceInfo* structure
- *
- *	numNamespaces is set to the number of namespaces read in
+ *	  get information about all namespaces in the system catalogs
  */
-NamespaceInfo *
-getNamespaces(Archive *fout, int *numNamespaces)
+void
+getNamespaces(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -5660,10 +5651,6 @@ getNamespaces(Archive *fout, int *numNamespaces)
 
 	PQclear(res);
 	destroyPQExpBuffer(query);
-
-	*numNamespaces = ntups;
-
-	return nsinfo;
 }
 
 /*
@@ -5755,16 +5742,13 @@ getExtensions(Archive *fout, int *numExtensions)
 
 /*
  * getTypes:
- *	  read all types in the system catalogs and return them in the
- * TypeInfo* structure
- *
- *	numTypes is set to the number of types read in
+ *	  get information about all types in the system catalogs
  *
  * NB: this must run after getFuncs() because we assume we can do
  * findFuncByOid().
  */
-TypeInfo *
-getTypes(Archive *fout, int *numTypes)
+void
+getTypes(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -5917,24 +5901,17 @@ getTypes(Archive *fout, int *numTypes)
 		}
 	}
 
-	*numTypes = ntups;
-
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return tyinfo;
 }
 
 /*
  * getOperators:
- *	  read all operators in the system catalogs and return them in the
- * OprInfo* structure
- *
- *	numOprs is set to the number of operators read in
+ *	  get information about all operators in the system catalogs
  */
-OprInfo *
-getOperators(Archive *fout, int *numOprs)
+void
+getOperators(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -5964,7 +5941,6 @@ getOperators(Archive *fout, int *numOprs)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numOprs = ntups;
 
 	oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo));
 
@@ -5996,19 +5972,14 @@ getOperators(Archive *fout, int *numOprs)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return oprinfo;
 }
 
 /*
  * getCollations:
- *	  read all collations in the system catalogs and return them in the
- * CollInfo* structure
- *
- *	numCollations is set to the number of collations read in
+ *	  get information about all collations in the system catalogs
  */
-CollInfo *
-getCollations(Archive *fout, int *numCollations)
+void
+getCollations(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -6036,7 +6007,6 @@ getCollations(Archive *fout, int *numCollations)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numCollations = ntups;
 
 	collinfo = (CollInfo *) pg_malloc(ntups * sizeof(CollInfo));
 
@@ -6064,19 +6034,14 @@ getCollations(Archive *fout, int *numCollations)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return collinfo;
 }
 
 /*
  * getConversions:
- *	  read all conversions in the system catalogs and return them in the
- * ConvInfo* structure
- *
- *	numConversions is set to the number of conversions read in
+ *	  get information about all conversions in the system catalogs
  */
-ConvInfo *
-getConversions(Archive *fout, int *numConversions)
+void
+getConversions(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -6104,7 +6069,6 @@ getConversions(Archive *fout, int *numConversions)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numConversions = ntups;
 
 	convinfo = (ConvInfo *) pg_malloc(ntups * sizeof(ConvInfo));
 
@@ -6132,19 +6096,14 @@ getConversions(Archive *fout, int *numConversions)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return convinfo;
 }
 
 /*
  * getAccessMethods:
- *	  read all user-defined access methods in the system catalogs and return
- *	  them in the AccessMethodInfo* structure
- *
- *	numAccessMethods is set to the number of access methods read in
+ *	  get information about all user-defined access methods
  */
-AccessMethodInfo *
-getAccessMethods(Archive *fout, int *numAccessMethods)
+void
+getAccessMethods(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -6159,10 +6118,7 @@ getAccessMethods(Archive *fout, int *numAccessMethods)
 
 	/* Before 9.6, there are no user-defined access methods */
 	if (fout->remoteVersion < 90600)
-	{
-		*numAccessMethods = 0;
-		return NULL;
-	}
+		return;
 
 	query = createPQExpBuffer();
 
@@ -6174,7 +6130,6 @@ getAccessMethods(Archive *fout, int *numAccessMethods)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numAccessMethods = ntups;
 
 	aminfo = (AccessMethodInfo *) pg_malloc(ntups * sizeof(AccessMethodInfo));
 
@@ -6202,20 +6157,15 @@ getAccessMethods(Archive *fout, int *numAccessMethods)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return aminfo;
 }

 /*
  * getOpclasses:
- *	  read all opclasses in the system catalogs and return them in the
- * OpclassInfo* structure
- *
- *	numOpclasses is set to the number of opclasses read in
+ *	  get information about all opclasses in the system catalogs
  */
-OpclassInfo *
-getOpclasses(Archive *fout, int *numOpclasses)
+void
+getOpclasses(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -6241,7 +6191,6 @@ getOpclasses(Archive *fout, int *numOpclasses)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numOpclasses = ntups;
 
 	opcinfo = (OpclassInfo *) pg_malloc(ntups * sizeof(OpclassInfo));
 
@@ -6269,19 +6218,14 @@ getOpclasses(Archive *fout, int *numOpclasses)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return opcinfo;
 }
 
 /*
  * getOpfamilies:
- *	  read all opfamilies in the system catalogs and return them in the
- * OpfamilyInfo* structure
- *
- *	numOpfamilies is set to the number of opfamilies read in
+ *	  get information about all opfamilies in the system catalogs
  */
-OpfamilyInfo *
-getOpfamilies(Archive *fout, int *numOpfamilies)
+void
+getOpfamilies(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -6309,7 +6253,6 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numOpfamilies = ntups;
 
 	opfinfo = (OpfamilyInfo *) pg_malloc(ntups * sizeof(OpfamilyInfo));
 
@@ -6337,19 +6280,14 @@ getOpfamilies(Archive *fout, int *numOpfamilies)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return opfinfo;
 }
 
 /*
  * getAggregates:
- *	  read all the user-defined aggregates in the system catalogs and
- * return them in the AggInfo* structure
- *
- * numAggs is set to the number of aggregates read in
+ *	  get information about all user-defined aggregates in the system catalogs
  */
-AggInfo *
-getAggregates(Archive *fout, int *numAggs)
+void
+getAggregates(Archive *fout)
 {
 	DumpOptions *dopt = fout->dopt;
 	PGresult   *res;
@@ -6431,7 +6369,6 @@ getAggregates(Archive *fout, int *numAggs)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numAggs = ntups;
 
 	agginfo = (AggInfo *) pg_malloc(ntups * sizeof(AggInfo));
 
@@ -6484,19 +6421,14 @@ getAggregates(Archive *fout, int *numAggs)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return agginfo;
 }
 
 /*
  * getFuncs:
- *	  read all the user-defined functions in the system catalogs and
- * return them in the FuncInfo* structure
- *
- * numFuncs is set to the number of functions read in
+ *	  get information about all user-defined functions in the system catalogs
  */
-FuncInfo *
-getFuncs(Archive *fout, int *numFuncs)
+void
+getFuncs(Archive *fout)
 {
 	DumpOptions *dopt = fout->dopt;
 	PGresult   *res;
@@ -6629,8 +6561,6 @@ getFuncs(Archive *fout, int *numFuncs)
 
 	ntups = PQntuples(res);
 
-	*numFuncs = ntups;
-
 	finfo = (FuncInfo *) pg_malloc0(ntups * sizeof(FuncInfo));
 
 	i_tableoid = PQfnumber(res, "tableoid");
@@ -6683,8 +6613,6 @@ getFuncs(Archive *fout, int *numFuncs)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return finfo;
 }
 
 /*
@@ -7985,11 +7913,9 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
 /*
  * getRules
  *	  get basic information about every rule in the system
- *
- * numRules is set to the number of rules read in
  */
-RuleInfo *
-getRules(Archive *fout, int *numRules)
+void
+getRules(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -8015,8 +7941,6 @@ getRules(Archive *fout, int *numRules)
 
 	ntups = PQntuples(res);
 
-	*numRules = ntups;
-
 	ruleinfo = (RuleInfo *) pg_malloc(ntups * sizeof(RuleInfo));
 
 	i_tableoid = PQfnumber(res, "tableoid");
@@ -8078,8 +8002,6 @@ getRules(Archive *fout, int *numRules)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return ruleinfo;
 }
 
 /*
@@ -8285,8 +8207,8 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
  * getEventTriggers
  *	  get information about event triggers
  */
-EventTriggerInfo *
-getEventTriggers(Archive *fout, int *numEventTriggers)
+void
+getEventTriggers(Archive *fout)
 {
 	int			i;
 	PQExpBuffer query;
@@ -8304,10 +8226,7 @@ getEventTriggers(Archive *fout, int *numEventTriggers)
 
 	/* Before 9.3, there are no event triggers */
 	if (fout->remoteVersion < 90300)
-	{
-		*numEventTriggers = 0;
-		return NULL;
-	}
+		return;
 
 	query = createPQExpBuffer();
 
@@ -8325,8 +8244,6 @@ getEventTriggers(Archive *fout, int *numEventTriggers)
 
 	ntups = PQntuples(res);
 
-	*numEventTriggers = ntups;
-
 	evtinfo = (EventTriggerInfo *) pg_malloc(ntups * sizeof(EventTriggerInfo));
 
 	i_tableoid = PQfnumber(res, "tableoid");
@@ -8359,21 +8276,17 @@ getEventTriggers(Archive *fout, int *numEventTriggers)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return evtinfo;
 }
 
 /*
  * getProcLangs
  *	  get basic information about every procedural language in the system
  *
- * numProcLangs is set to the number of langs read in
- *
  * NB: this must run after getFuncs() because we assume we can do
  * findFuncByOid().
  */
-ProcLangInfo *
-getProcLangs(Archive *fout, int *numProcLangs)
+void
+getProcLangs(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -8405,8 +8318,6 @@ getProcLangs(Archive *fout, int *numProcLangs)
 
 	ntups = PQntuples(res);
 
-	*numProcLangs = ntups;
-
 	planginfo = (ProcLangInfo *) pg_malloc(ntups * sizeof(ProcLangInfo));
 
 	i_tableoid = PQfnumber(res, "tableoid");
@@ -8449,21 +8360,17 @@ getProcLangs(Archive *fout, int *numProcLangs)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return planginfo;
 }
 
 /*
  * getCasts
  *	  get basic information about most casts in the system
  *
- * numCasts is set to the number of casts read in
- *
  * Skip casts from a range to its multirange, since we'll create those
  * automatically.
  */
-CastInfo *
-getCasts(Archive *fout, int *numCasts)
+void
+getCasts(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -8503,8 +8410,6 @@ getCasts(Archive *fout, int *numCasts)
 
 	ntups = PQntuples(res);
 
-	*numCasts = ntups;
-
 	castinfo = (CastInfo *) pg_malloc(ntups * sizeof(CastInfo));
 
 	i_tableoid = PQfnumber(res, "tableoid");
@@ -8551,8 +8456,6 @@ getCasts(Archive *fout, int *numCasts)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return castinfo;
 }
 
 static char *
@@ -8575,11 +8478,9 @@ get_language_name(Archive *fout, Oid langid)
 /*
  * getTransforms
  *	  get basic information about every transform in the system
- *
- * numTransforms is set to the number of transforms read in
  */
-TransformInfo *
-getTransforms(Archive *fout, int *numTransforms)
+void
+getTransforms(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -8595,10 +8496,7 @@ getTransforms(Archive *fout, int *numTransforms)
 
 	/* Transforms didn't exist pre-9.5 */
 	if (fout->remoteVersion < 90500)
-	{
-		*numTransforms = 0;
-		return NULL;
-	}
+		return;
 
 	query = createPQExpBuffer();
 
@@ -8611,8 +8509,6 @@ getTransforms(Archive *fout, int *numTransforms)
 
 	ntups = PQntuples(res);
 
-	*numTransforms = ntups;
-
 	transforminfo = (TransformInfo *) pg_malloc(ntups * sizeof(TransformInfo));
 
 	i_tableoid = PQfnumber(res, "tableoid");
@@ -8658,8 +8554,6 @@ getTransforms(Archive *fout, int *numTransforms)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return transforminfo;
 }
 
 /*
@@ -9239,13 +9133,10 @@ shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno)
 
 /*
  * getTSParsers:
- *	  read all text search parsers in the system catalogs and return them
- *	  in the TSParserInfo* structure
- *
- *	numTSParsers is set to the number of parsers read in
+ *	  get information about all text search parsers in the system catalogs
  */
-TSParserInfo *
-getTSParsers(Archive *fout, int *numTSParsers)
+void
+getTSParsers(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -9277,7 +9168,6 @@ getTSParsers(Archive *fout, int *numTSParsers)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numTSParsers = ntups;
 
 	prsinfo = (TSParserInfo *) pg_malloc(ntups * sizeof(TSParserInfo));
 
@@ -9313,19 +9203,14 @@ getTSParsers(Archive *fout, int *numTSParsers)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return prsinfo;
 }
 
 /*
  * getTSDictionaries:
- *	  read all text search dictionaries in the system catalogs and return them
- *	  in the TSDictInfo* structure
- *
- *	numTSDicts is set to the number of dictionaries read in
+ *	  get information about all text search dictionaries in the system catalogs
  */
-TSDictInfo *
-getTSDictionaries(Archive *fout, int *numTSDicts)
+void
+getTSDictionaries(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -9350,7 +9235,6 @@ getTSDictionaries(Archive *fout, int *numTSDicts)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numTSDicts = ntups;
 
 	dictinfo = (TSDictInfo *) pg_malloc(ntups * sizeof(TSDictInfo));
 
@@ -9385,19 +9269,14 @@ getTSDictionaries(Archive *fout, int *numTSDicts)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return dictinfo;
 }
 
 /*
  * getTSTemplates:
- *	  read all text search templates in the system catalogs and return them
- *	  in the TSTemplateInfo* structure
- *
- *	numTSTemplates is set to the number of templates read in
+ *	  get information about all text search templates in the system catalogs
  */
-TSTemplateInfo *
-getTSTemplates(Archive *fout, int *numTSTemplates)
+void
+getTSTemplates(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -9420,7 +9299,6 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numTSTemplates = ntups;
 
 	tmplinfo = (TSTemplateInfo *) pg_malloc(ntups * sizeof(TSTemplateInfo));
 
@@ -9450,19 +9328,14 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return tmplinfo;
 }
 
 /*
  * getTSConfigurations:
- *	  read all text search configurations in the system catalogs and return
- *	  them in the TSConfigInfo* structure
- *
- *	numTSConfigs is set to the number of configurations read in
+ *	  get information about all text search configurations
  */
-TSConfigInfo *
-getTSConfigurations(Archive *fout, int *numTSConfigs)
+void
+getTSConfigurations(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -9485,7 +9358,6 @@ getTSConfigurations(Archive *fout, int *numTSConfigs)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numTSConfigs = ntups;
 
 	cfginfo = (TSConfigInfo *) pg_malloc(ntups * sizeof(TSConfigInfo));
 
@@ -9515,19 +9387,14 @@ getTSConfigurations(Archive *fout, int *numTSConfigs)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return cfginfo;
 }
 
 /*
  * getForeignDataWrappers:
- *	  read all foreign-data wrappers in the system catalogs and return
- *	  them in the FdwInfo* structure
- *
- *	numForeignDataWrappers is set to the number of fdws read in
+ *	  get information about all foreign-data wrappers in the system catalogs
  */
-FdwInfo *
-getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
+void
+getForeignDataWrappers(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -9563,7 +9430,6 @@ getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numForeignDataWrappers = ntups;
 
 	fdwinfo = (FdwInfo *) pg_malloc(ntups * sizeof(FdwInfo));
 
@@ -9605,19 +9471,14 @@ getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return fdwinfo;
 }
 
 /*
  * getForeignServers:
- *	  read all foreign servers in the system catalogs and return
- *	  them in the ForeignServerInfo * structure
- *
- *	numForeignServers is set to the number of servers read in
+ *	  get information about all foreign servers in the system catalogs
  */
-ForeignServerInfo *
-getForeignServers(Archive *fout, int *numForeignServers)
+void
+getForeignServers(Archive *fout)
 {
 	PGresult   *res;
 	int			ntups;
@@ -9652,7 +9513,6 @@ getForeignServers(Archive *fout, int *numForeignServers)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numForeignServers = ntups;
 
 	srvinfo = (ForeignServerInfo *) pg_malloc(ntups * sizeof(ForeignServerInfo));
 
@@ -9699,19 +9559,14 @@ getForeignServers(Archive *fout, int *numForeignServers)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return srvinfo;
 }
 
 /*
  * getDefaultACLs:
- *	  read all default ACL information in the system catalogs and return
- *	  them in the DefaultACLInfo structure
- *
- *	numDefaultACLs is set to the number of ACLs read in
+ *	  get information about all default ACL information in the system catalogs
  */
-DefaultACLInfo *
-getDefaultACLs(Archive *fout, int *numDefaultACLs)
+void
+getDefaultACLs(Archive *fout)
 {
 	DumpOptions *dopt = fout->dopt;
 	DefaultACLInfo *daclinfo;
@@ -9756,7 +9611,6 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
 	ntups = PQntuples(res);
-	*numDefaultACLs = ntups;
 
 	daclinfo = (DefaultACLInfo *) pg_malloc(ntups * sizeof(DefaultACLInfo));
 
@@ -9801,8 +9655,6 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
 	PQclear(res);
 
 	destroyPQExpBuffer(query);
-
-	return daclinfo;
 }
 
 /*
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index 865823868f..4b2e5870a9 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -731,17 +731,17 @@ extern void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs);
 /*
  * version specific routines
  */
-extern NamespaceInfo *getNamespaces(Archive *fout, int *numNamespaces);
+extern void getNamespaces(Archive *fout);
 extern ExtensionInfo *getExtensions(Archive *fout, int *numExtensions);
-extern TypeInfo *getTypes(Archive *fout, int *numTypes);
-extern FuncInfo *getFuncs(Archive *fout, int *numFuncs);
-extern AggInfo *getAggregates(Archive *fout, int *numAggs);
-extern OprInfo *getOperators(Archive *fout, int *numOprs);
-extern AccessMethodInfo *getAccessMethods(Archive *fout, int *numAccessMethods);
-extern OpclassInfo *getOpclasses(Archive *fout, int *numOpclasses);
-extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies);
-extern CollInfo *getCollations(Archive *fout, int *numCollations);
-extern ConvInfo *getConversions(Archive *fout, int *numConversions);
+extern void getTypes(Archive *fout);
+extern void getFuncs(Archive *fout);
+extern void getAggregates(Archive *fout);
+extern void getOperators(Archive *fout);
+extern void getAccessMethods(Archive *fout);
+extern void getOpclasses(Archive *fout);
+extern void getOpfamilies(Archive *fout);
+extern void getCollations(Archive *fout);
+extern void getConversions(Archive *fout);
 extern TableInfo *getTables(Archive *fout, int *numTables);
 extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
 extern InhInfo *getInherits(Archive *fout, int *numInherits);
@@ -749,30 +749,27 @@ extern void getPartitioningInfo(Archive *fout);
 extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
 extern void getExtendedStatistics(Archive *fout);
 extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
-extern RuleInfo *getRules(Archive *fout, int *numRules);
+extern void getRules(Archive *fout);
 extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
-extern ProcLangInfo *getProcLangs(Archive *fout, int *numProcLangs);
-extern CastInfo *getCasts(Archive *fout, int *numCasts);
-extern TransformInfo *getTransforms(Archive *fout, int *numTransforms);
+extern void getProcLangs(Archive *fout);
+extern void getCasts(Archive *fout);
+extern void getTransforms(Archive *fout);
 extern void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables);
 extern bool shouldPrintColumn(const DumpOptions *dopt, const TableInfo *tbinfo, int colno);
-extern TSParserInfo *getTSParsers(Archive *fout, int *numTSParsers);
-extern TSDictInfo *getTSDictionaries(Archive *fout, int *numTSDicts);
-extern TSTemplateInfo *getTSTemplates(Archive *fout, int *numTSTemplates);
-extern TSConfigInfo *getTSConfigurations(Archive *fout, int *numTSConfigs);
-extern FdwInfo *getForeignDataWrappers(Archive *fout,
-									   int *numForeignDataWrappers);
-extern ForeignServerInfo *getForeignServers(Archive *fout,
-											int *numForeignServers);
-extern DefaultACLInfo *getDefaultACLs(Archive *fout, int *numDefaultACLs);
+extern void getTSParsers(Archive *fout);
+extern void getTSDictionaries(Archive *fout);
+extern void getTSTemplates(Archive *fout);
+extern void getTSConfigurations(Archive *fout);
+extern void getForeignDataWrappers(Archive *fout);
+extern void getForeignServers(Archive *fout);
+extern void getDefaultACLs(Archive *fout);
 extern void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
 								   int numExtensions);
 extern void processExtensionTables(Archive *fout, ExtensionInfo extinfo[],
 								   int numExtensions);
-extern EventTriggerInfo *getEventTriggers(Archive *fout, int *numEventTriggers);
+extern void getEventTriggers(Archive *fout);
 extern void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables);
-extern PublicationInfo *getPublications(Archive *fout,
-										int *numPublications);
+extern void getPublications(Archive *fout);
 extern void getPublicationNamespaces(Archive *fout);
 extern void getPublicationTables(Archive *fout, TableInfo tblinfo[],
 								 int numTables);
-- 
2.39.3 (Apple Git-146)

---

From: Neil Conway <[email-masked]>
Date: Wed, 5 Jun 2024 12:22:03 -0400

On Wed, Jun 5, 2024 at 11:14 AM Nathan Bossart <[email-masked]>
wrote:

>  In fact, many of the functions in this area don't actually need to

> bit.  Patch attached.

Nice cleanup! Two minor comments:

(1) Names like `getXXX` for these functions suggest to me that they return
a value, rather than side-effecting. I realize some variants continue to
return a value, but the majority no longer do. Perhaps a name like
lookupXXX() or readXXX() would be clearer?

(2) These functions malloc() a single ntups * sizeof(struct) allocation and
then index into it to fill-in each struct before entering it into the hash
table. It might be more straightforward to just malloc each individual
struct.

Neil

---

From: Nathan Bossart <[email-masked]>
Date: Wed, 5 Jun 2024 11:37:54 -0500

> Nice cleanup! Two minor comments:

Thanks for taking a look.

> lookupXXX() or readXXX() would be clearer?

What about collectXXX() to match similar functions in pg_dump.c (e.g.,
collectRoleNames(), collectComments(), collectSecLabels())?

> table. It might be more straightforward to just malloc each individual

That'd increase the number of allocations quite significantly, but I'd be
surprised if that was noticeable outside of extreme scenarios.  At the
moment, I'm inclined to leave these as-is for this reason and because I
doubt it'd result in much cleanup, but I'll yield to the majority opinion
here.

-- 
nathan

---

From: Neil Conway <[email-masked]>
Date: Wed, 5 Jun 2024 13:51:08 -0400

> collectRoleNames(), collectComments(), collectSecLabels())?

sgtm.

> doubt it'd result in much cleanup, but I'll yield to the majority opinion

As you say, I'd be surprised if the performance difference is noticeable.
Personally I don't think the marginal performance win justifies the hit to
readability, but I don't feel strongly about it.

Neil

---

From: Tom Lane <[email-masked]>
Date: Wed, 05 Jun 2024 13:58:54 -0400

> collectRoleNames(), collectComments(), collectSecLabels())?

Personally I see nothing much wrong with leaving them as getXXX.

> doubt it'd result in much cleanup, but I'll yield to the majority opinion

I think that would be quite an invasive change; it would require
many hundreds of edits like

-		finfo[i].dobj.objType = DO_FUNC;
+		finfo->dobj.objType = DO_FUNC;

which aside from being tedious would create a back-patching hazard.
So I'm kind of -0.1 or so.

Another angle to this is that Coverity and possibly other tools tend
to report that these functions leak these allocations, apparently
because they don't notice that pointers into the allocations get
stored in hash tables by a subroutine.  I'm not sure if making this
change would make that worse or better.  If we really want to change
it, that might be worth checking somehow before we jump.

			regards, tom lane

---

From: Nathan Bossart <[email-masked]>
Date: Tue, 11 Jun 2024 15:30:14 -0500

> it, that might be worth checking somehow before we jump.

At the moment, I'm inclined to commit v1 once v18 development opens up.  We
can consider any additional adjustments separately.

-- 
nathan