Commits

Anonymous committed 622f862

pg_dump: Reduce dependencies on global variables.

Change various places in the code that are referencing the global
Archive object g_fout to instead reference the Archive object fout
which is already being passed as a parameter. For parallel pg_dump to
work, we're going to need multiple Archive(Handle) objects, so the
real solution here is to pass down the Archive object to everywhere
that it needs to go, but we might as well pick the low-hanging fruit
first.

Comments (0)

Files changed (1)

src/bin/pg_dump/pg_dump.c

 	 * column ordering of COPY will not be what we want in certain corner
 	 * cases involving ADD COLUMN and inheritance.)
 	 */
-	if (g_fout->remoteVersion >= 70300)
+	if (fout->remoteVersion >= 70300)
 		column_list = fmtCopyColumnList(tbinfo);
 	else
 		column_list = "";		/* can't select columns in COPY */
 	selectSourceSchema(tyinfo->dobj.namespace->dobj.name);
 
 	/* Fetch domain specific details */
-	if (g_fout->remoteVersion >= 90100)
+	if (fout->remoteVersion >= 90100)
 	{
 		/* typcollation is new in 9.1 */
 		appendPQExpBuffer(query, "SELECT t.typnotnull, "
 	selectSourceSchema(finfo->dobj.namespace->dobj.name);
 
 	/* Fetch function-specific details */
-	if (g_fout->remoteVersion >= 80400)
+	if (fout->remoteVersion >= 80400)
 	{
 		/*
 		 * In 8.4 and up we rely on pg_get_function_arguments and
 						  "WHERE oid = '%u'::pg_catalog.oid",
 						  finfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 80300)
+	else if (fout->remoteVersion >= 80300)
 	{
 		appendPQExpBuffer(query,
 						  "SELECT proretset, prosrc, probin, "
 						  "WHERE oid = '%u'::pg_catalog.oid",
 						  finfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 80100)
+	else if (fout->remoteVersion >= 80100)
 	{
 		appendPQExpBuffer(query,
 						  "SELECT proretset, prosrc, probin, "
 						  "WHERE oid = '%u'::pg_catalog.oid",
 						  finfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 80000)
+	else if (fout->remoteVersion >= 80000)
 	{
 		appendPQExpBuffer(query,
 						  "SELECT proretset, prosrc, probin, "
 						  "WHERE oid = '%u'::pg_catalog.oid",
 						  finfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 70300)
+	else if (fout->remoteVersion >= 70300)
 	{
 		appendPQExpBuffer(query,
 						  "SELECT proretset, prosrc, probin, "
 	/* Make sure we are in proper schema so regoperator works correctly */
 	selectSourceSchema(oprinfo->dobj.namespace->dobj.name);
 
-	if (g_fout->remoteVersion >= 80300)
+	if (fout->remoteVersion >= 80300)
 	{
 		appendPQExpBuffer(query, "SELECT oprkind, "
 						  "oprcode::pg_catalog.regprocedure, "
 						  "WHERE oid = '%u'::pg_catalog.oid",
 						  oprinfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 70300)
+	else if (fout->remoteVersion >= 70300)
 	{
 		appendPQExpBuffer(query, "SELECT oprkind, "
 						  "oprcode::pg_catalog.regprocedure, "
 						  "WHERE oid = '%u'::pg_catalog.oid",
 						  oprinfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 70100)
+	else if (fout->remoteVersion >= 70100)
 	{
 		appendPQExpBuffer(query, "SELECT oprkind, oprcode, "
 						  "CASE WHEN oprleft = 0 THEN '-' "
 	if (strcmp(oprkind, "r") == 0 ||
 		strcmp(oprkind, "b") == 0)
 	{
-		if (g_fout->remoteVersion >= 70100)
+		if (fout->remoteVersion >= 70100)
 			name = oprleft;
 		else
 			name = fmtId(oprleft);
 	if (strcmp(oprkind, "l") == 0 ||
 		strcmp(oprkind, "b") == 0)
 	{
-		if (g_fout->remoteVersion >= 70100)
+		if (fout->remoteVersion >= 70100)
 			name = oprright;
 		else
 			name = fmtId(oprright);
 	 * pre-7.3 databases.  This could be done but it seems not worth the
 	 * trouble.
 	 */
-	if (g_fout->remoteVersion < 70300)
+	if (fout->remoteVersion < 70300)
 		return;
 
 	query = createPQExpBuffer();
 	selectSourceSchema(opcinfo->dobj.namespace->dobj.name);
 
 	/* Get additional fields from the pg_opclass row */
-	if (g_fout->remoteVersion >= 80300)
+	if (fout->remoteVersion >= 80300)
 	{
 		appendPQExpBuffer(query, "SELECT opcintype::pg_catalog.regtype, "
 						  "opckeytype::pg_catalog.regtype, "
 	 */
 	resetPQExpBuffer(query);
 
-	if (g_fout->remoteVersion >= 90100)
+	if (fout->remoteVersion >= 90100)
 	{
 		appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
 						  "amopopr::pg_catalog.regoperator, "
 						  opcinfo->dobj.catId.oid,
 						  opcfamily);
 	}
-	else if (g_fout->remoteVersion >= 80400)
+	else if (fout->remoteVersion >= 80400)
 	{
 		appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
 						  "amopopr::pg_catalog.regoperator, "
 						  "ORDER BY amopstrategy",
 						  opcinfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 80300)
+	else if (fout->remoteVersion >= 80300)
 	{
 		appendPQExpBuffer(query, "SELECT amopstrategy, amopreqcheck, "
 						  "amopopr::pg_catalog.regoperator, "
 	 */
 	resetPQExpBuffer(query);
 
-	if (g_fout->remoteVersion >= 80300)
+	if (fout->remoteVersion >= 80300)
 	{
 		appendPQExpBuffer(query, "SELECT amprocnum, "
 						  "amproc::pg_catalog.regprocedure, "
 	 * older server and then reload into that old version.	This can go away
 	 * once 8.3 is so old as to not be of interest to anyone.
 	 */
-	if (g_fout->remoteVersion >= 90100)
+	if (fout->remoteVersion >= 90100)
 	{
 		appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
 						  "amopopr::pg_catalog.regoperator, "
 						  opfinfo->dobj.catId.oid,
 						  opfinfo->dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 80400)
+	else if (fout->remoteVersion >= 80400)
 	{
 		appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
 						  "amopopr::pg_catalog.regoperator, "
 	selectSourceSchema(agginfo->aggfn.dobj.namespace->dobj.name);
 
 	/* Get aggregate-specific details */
-	if (g_fout->remoteVersion >= 80100)
+	if (fout->remoteVersion >= 80100)
 	{
 		appendPQExpBuffer(query, "SELECT aggtransfn, "
 						  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
 						  "AND p.oid = '%u'::pg_catalog.oid",
 						  agginfo->aggfn.dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 70300)
+	else if (fout->remoteVersion >= 70300)
 	{
 		appendPQExpBuffer(query, "SELECT aggtransfn, "
 						  "aggfinalfn, aggtranstype::pg_catalog.regtype, "
 						  "AND p.oid = '%u'::pg_catalog.oid",
 						  agginfo->aggfn.dobj.catId.oid);
 	}
-	else if (g_fout->remoteVersion >= 70100)
+	else if (fout->remoteVersion >= 70100)
 	{
 		appendPQExpBuffer(query, "SELECT aggtransfn, aggfinalfn, "
 						  "format_type(aggtranstype, NULL) AS aggtranstype, "
 		return;
 	}
 
-	if (g_fout->remoteVersion >= 70300)
+	if (fout->remoteVersion >= 70300)
 	{
 		/* If using 7.3's regproc or regtype, data is already quoted */
 		appendPQExpBuffer(details, "    SFUNC = %s,\n    STYPE = %s",
 						  aggtransfn,
 						  aggtranstype);
 	}
-	else if (g_fout->remoteVersion >= 70100)
+	else if (fout->remoteVersion >= 70100)
 	{
 		/* format_type quotes, regproc does not */
 		appendPQExpBuffer(details, "    SFUNC = %s,\n    STYPE = %s",
 		 * query rather than trying to fetch them during getTableAttrs, so
 		 * that we won't miss ACLs on system columns.
 		 */
-		if (g_fout->remoteVersion >= 80400)
+		if (fout->remoteVersion >= 80400)
 		{
 			PQExpBuffer query = createPQExpBuffer();
 			PGresult   *res;
 		reltypename = "VIEW";
 
 		/* Fetch the view definition */
-		if (g_fout->remoteVersion >= 70300)
+		if (fout->remoteVersion >= 70300)
 		{
 			/* Beginning in 7.3, viewname is not unique; rely on OID */
 			appendPQExpBuffer(query,
 				{
 					appendPQExpBuffer(q, "WITH OPTIONS");
 				}
-				else if (g_fout->remoteVersion >= 70100)
+				else if (fout->remoteVersion >= 70100)
 				{
 					appendPQExpBuffer(q, "%s",
 									  tbinfo->atttypnames[j]);
 	snprintf(bufm, sizeof(bufm), INT64_FORMAT, SEQ_MINVALUE);
 	snprintf(bufx, sizeof(bufx), INT64_FORMAT, SEQ_MAXVALUE);
 
-	if (g_fout->remoteVersion >= 80400)
+	if (fout->remoteVersion >= 80400)
 	{
 		appendPQExpBuffer(query,
 						  "SELECT sequence_name, "
 						  "CREATE SEQUENCE %s\n",
 						  fmtId(tbinfo->dobj.name));
 
-		if (g_fout->remoteVersion >= 80400)
+		if (fout->remoteVersion >= 80400)
 			appendPQExpBuffer(query, "    START WITH %s\n", startv);
 		else
 		{
 			if (OidIsValid(tginfo->tgconstrrelid))
 			{
 				/* If we are using regclass, name is already quoted */
-				if (g_fout->remoteVersion >= 70300)
+				if (fout->remoteVersion >= 70300)
 					appendPQExpBuffer(query, "    FROM %s\n    ",
 									  tginfo->tgconstrrelname);
 				else
 			appendPQExpBuffer(query, "    FOR EACH STATEMENT\n    ");
 
 		/* In 7.3, result of regproc is already quoted */
-		if (g_fout->remoteVersion >= 70300)
+		if (fout->remoteVersion >= 70300)
 			appendPQExpBuffer(query, "EXECUTE PROCEDURE %s(",
 							  tginfo->tgfname);
 		else
 	delcmd = createPQExpBuffer();
 	labelq = createPQExpBuffer();
 
-	if (g_fout->remoteVersion >= 70300)
+	if (fout->remoteVersion >= 70300)
 	{
 		appendPQExpBuffer(query,
 						  "SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid) AS definition",