From 1511877eb2b0eb3cc70cbe616f3652583daff8f9 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Wed, 8 May 2024 19:41:08 +0200
Subject: [PATCH 4/6] Take PQfnumber() calls out of the routine

---
 src/bin/pg_dump/pg_dump.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 739b16516f..8af9127ba2 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -293,7 +293,9 @@ static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo);
 static void buildMatViewRefreshDependencies(Archive *fout);
 static void getTableDataFKConstraints(void);
 static void determineNotNullFlags(Archive *fout, PGresult *res, int r,
-								  TableInfo *tbinfo, int j, int *notnullcount);
+								  TableInfo *tbinfo, int j, int *notnullcount,
+								  int i_notnull_name, int i_notnull_noinherit,
+								  int i_notnull_is_pk, int i_notnull_inh);
 static char *format_function_arguments(const FuncInfo *finfo, const char *funcargs,
 									   bool is_agg);
 static char *format_function_signature(Archive *fout,
@@ -8704,6 +8706,10 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
 	int			i_attlen;
 	int			i_attalign;
 	int			i_attislocal;
+	int			i_notnull_name;
+	int			i_notnull_noinherit;
+	int			i_notnull_is_pk;
+	int			i_notnull_inh;
 	int			i_attoptions;
 	int			i_attcollation;
 	int			i_attcompression;
@@ -8898,6 +8904,10 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
 	i_attlen = PQfnumber(res, "attlen");
 	i_attalign = PQfnumber(res, "attalign");
 	i_attislocal = PQfnumber(res, "attislocal");
+	i_notnull_name = PQfnumber(res, "notnull_name");
+	i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
+	i_notnull_is_pk = PQfnumber(res, "notnull_is_pk");
+	i_notnull_inh = PQfnumber(res, "notnull_inh");
 	i_attoptions = PQfnumber(res, "attoptions");
 	i_attcollation = PQfnumber(res, "attcollation");
 	i_attcompression = PQfnumber(res, "attcompression");
@@ -8995,7 +9005,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
 
 			/* Handle not-null constraint name flags separately */
 			determineNotNullFlags(fout, res, r,
-								  tbinfo, j, &notnullcount);
+								  tbinfo, j, &notnullcount,
+								  i_notnull_name, i_notnull_noinherit,
+								  i_notnull_is_pk, i_notnull_inh);
 
 			tbinfo->attoptions[j] = pg_strdup(PQgetvalue(res, r, i_attoptions));
 			tbinfo->attcollation[j] = atooid(PQgetvalue(res, r, i_attcollation));
@@ -9293,22 +9305,15 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
  */
 static void
 determineNotNullFlags(Archive *fout, PGresult *res, int r,
-					  TableInfo *tbinfo, int j, int *notnullcount)
+					  TableInfo *tbinfo, int j, int *notnullcount,
+					  int i_notnull_name, int i_notnull_noinherit,
+					  int i_notnull_is_pk, int i_notnull_inh)
 {
 	DumpOptions *dopt = fout->dopt;
-	int			i_notnull_name;
-	int			i_notnull_noinherit;
-	int			i_notnull_is_pk;
-	int			i_notnull_inh;
 	bool		use_named_notnull = false;
 	bool		use_unnamed_notnull = false;
 	bool		use_throwaway_notnull = false;
 
-	i_notnull_name = PQfnumber(res, "notnull_name");
-	i_notnull_noinherit = PQfnumber(res, "notnull_noinherit");
-	i_notnull_is_pk = PQfnumber(res, "notnull_is_pk");
-	i_notnull_inh = PQfnumber(res, "notnull_inh");
-
 	/*
 	 * Not-null constraints require a jumping through a few hoops. First, if
 	 * the user has specified a constraint name that's not the system-assigned
-- 
2.39.2

