Skip to content

Commit 622f862

Browse files
committed
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.
1 parent c6d76d7 commit 622f862

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
12891289
* column ordering of COPY will not be what we want in certain corner
12901290
* cases involving ADD COLUMN and inheritance.)
12911291
*/
1292-
if (g_fout->remoteVersion >= 70300)
1292+
if (fout->remoteVersion >= 70300)
12931293
column_list = fmtCopyColumnList(tbinfo);
12941294
else
12951295
column_list = ""; /* can't select columns in COPY */
@@ -8157,7 +8157,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
81578157
selectSourceSchema(tyinfo->dobj.namespace->dobj.name);
81588158

81598159
/* Fetch domain specific details */
8160-
if (g_fout->remoteVersion >= 90100)
8160+
if (fout->remoteVersion >= 90100)
81618161
{
81628162
/* typcollation is new in 9.1 */
81638163
appendPQExpBuffer(query, "SELECT t.typnotnull, "
@@ -9040,7 +9040,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
90409040
selectSourceSchema(finfo->dobj.namespace->dobj.name);
90419041

90429042
/* Fetch function-specific details */
9043-
if (g_fout->remoteVersion >= 80400)
9043+
if (fout->remoteVersion >= 80400)
90449044
{
90459045
/*
90469046
* In 8.4 and up we rely on pg_get_function_arguments and
@@ -9058,7 +9058,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
90589058
"WHERE oid = '%u'::pg_catalog.oid",
90599059
finfo->dobj.catId.oid);
90609060
}
9061-
else if (g_fout->remoteVersion >= 80300)
9061+
else if (fout->remoteVersion >= 80300)
90629062
{
90639063
appendPQExpBuffer(query,
90649064
"SELECT proretset, prosrc, probin, "
@@ -9071,7 +9071,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
90719071
"WHERE oid = '%u'::pg_catalog.oid",
90729072
finfo->dobj.catId.oid);
90739073
}
9074-
else if (g_fout->remoteVersion >= 80100)
9074+
else if (fout->remoteVersion >= 80100)
90759075
{
90769076
appendPQExpBuffer(query,
90779077
"SELECT proretset, prosrc, probin, "
@@ -9084,7 +9084,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
90849084
"WHERE oid = '%u'::pg_catalog.oid",
90859085
finfo->dobj.catId.oid);
90869086
}
9087-
else if (g_fout->remoteVersion >= 80000)
9087+
else if (fout->remoteVersion >= 80000)
90889088
{
90899089
appendPQExpBuffer(query,
90909090
"SELECT proretset, prosrc, probin, "
@@ -9099,7 +9099,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
90999099
"WHERE oid = '%u'::pg_catalog.oid",
91009100
finfo->dobj.catId.oid);
91019101
}
9102-
else if (g_fout->remoteVersion >= 70300)
9102+
else if (fout->remoteVersion >= 70300)
91039103
{
91049104
appendPQExpBuffer(query,
91059105
"SELECT proretset, prosrc, probin, "
@@ -9641,7 +9641,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
96419641
/* Make sure we are in proper schema so regoperator works correctly */
96429642
selectSourceSchema(oprinfo->dobj.namespace->dobj.name);
96439643

9644-
if (g_fout->remoteVersion >= 80300)
9644+
if (fout->remoteVersion >= 80300)
96459645
{
96469646
appendPQExpBuffer(query, "SELECT oprkind, "
96479647
"oprcode::pg_catalog.regprocedure, "
@@ -9656,7 +9656,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
96569656
"WHERE oid = '%u'::pg_catalog.oid",
96579657
oprinfo->dobj.catId.oid);
96589658
}
9659-
else if (g_fout->remoteVersion >= 70300)
9659+
else if (fout->remoteVersion >= 70300)
96609660
{
96619661
appendPQExpBuffer(query, "SELECT oprkind, "
96629662
"oprcode::pg_catalog.regprocedure, "
@@ -9672,7 +9672,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
96729672
"WHERE oid = '%u'::pg_catalog.oid",
96739673
oprinfo->dobj.catId.oid);
96749674
}
9675-
else if (g_fout->remoteVersion >= 70100)
9675+
else if (fout->remoteVersion >= 70100)
96769676
{
96779677
appendPQExpBuffer(query, "SELECT oprkind, oprcode, "
96789678
"CASE WHEN oprleft = 0 THEN '-' "
@@ -9750,7 +9750,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
97509750
if (strcmp(oprkind, "r") == 0 ||
97519751
strcmp(oprkind, "b") == 0)
97529752
{
9753-
if (g_fout->remoteVersion >= 70100)
9753+
if (fout->remoteVersion >= 70100)
97549754
name = oprleft;
97559755
else
97569756
name = fmtId(oprleft);
@@ -9763,7 +9763,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
97639763
if (strcmp(oprkind, "l") == 0 ||
97649764
strcmp(oprkind, "b") == 0)
97659765
{
9766-
if (g_fout->remoteVersion >= 70100)
9766+
if (fout->remoteVersion >= 70100)
97679767
name = oprright;
97689768
else
97699769
name = fmtId(oprright);
@@ -10034,7 +10034,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1003410034
* pre-7.3 databases. This could be done but it seems not worth the
1003510035
* trouble.
1003610036
*/
10037-
if (g_fout->remoteVersion < 70300)
10037+
if (fout->remoteVersion < 70300)
1003810038
return;
1003910039

1004010040
query = createPQExpBuffer();
@@ -10046,7 +10046,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1004610046
selectSourceSchema(opcinfo->dobj.namespace->dobj.name);
1004710047

1004810048
/* Get additional fields from the pg_opclass row */
10049-
if (g_fout->remoteVersion >= 80300)
10049+
if (fout->remoteVersion >= 80300)
1005010050
{
1005110051
appendPQExpBuffer(query, "SELECT opcintype::pg_catalog.regtype, "
1005210052
"opckeytype::pg_catalog.regtype, "
@@ -10159,7 +10159,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1015910159
*/
1016010160
resetPQExpBuffer(query);
1016110161

10162-
if (g_fout->remoteVersion >= 90100)
10162+
if (fout->remoteVersion >= 90100)
1016310163
{
1016410164
appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
1016510165
"amopopr::pg_catalog.regoperator, "
@@ -10176,7 +10176,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1017610176
opcinfo->dobj.catId.oid,
1017710177
opcfamily);
1017810178
}
10179-
else if (g_fout->remoteVersion >= 80400)
10179+
else if (fout->remoteVersion >= 80400)
1018010180
{
1018110181
appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
1018210182
"amopopr::pg_catalog.regoperator, "
@@ -10190,7 +10190,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1019010190
"ORDER BY amopstrategy",
1019110191
opcinfo->dobj.catId.oid);
1019210192
}
10193-
else if (g_fout->remoteVersion >= 80300)
10193+
else if (fout->remoteVersion >= 80300)
1019410194
{
1019510195
appendPQExpBuffer(query, "SELECT amopstrategy, amopreqcheck, "
1019610196
"amopopr::pg_catalog.regoperator, "
@@ -10275,7 +10275,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1027510275
*/
1027610276
resetPQExpBuffer(query);
1027710277

10278-
if (g_fout->remoteVersion >= 80300)
10278+
if (fout->remoteVersion >= 80300)
1027910279
{
1028010280
appendPQExpBuffer(query, "SELECT amprocnum, "
1028110281
"amproc::pg_catalog.regprocedure, "
@@ -10437,7 +10437,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1043710437
* older server and then reload into that old version. This can go away
1043810438
* once 8.3 is so old as to not be of interest to anyone.
1043910439
*/
10440-
if (g_fout->remoteVersion >= 90100)
10440+
if (fout->remoteVersion >= 90100)
1044110441
{
1044210442
appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
1044310443
"amopopr::pg_catalog.regoperator, "
@@ -10454,7 +10454,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
1045410454
opfinfo->dobj.catId.oid,
1045510455
opfinfo->dobj.catId.oid);
1045610456
}
10457-
else if (g_fout->remoteVersion >= 80400)
10457+
else if (fout->remoteVersion >= 80400)
1045810458
{
1045910459
appendPQExpBuffer(query, "SELECT amopstrategy, false AS amopreqcheck, "
1046010460
"amopopr::pg_catalog.regoperator, "
@@ -10991,7 +10991,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
1099110991
selectSourceSchema(agginfo->aggfn.dobj.namespace->dobj.name);
1099210992

1099310993
/* Get aggregate-specific details */
10994-
if (g_fout->remoteVersion >= 80100)
10994+
if (fout->remoteVersion >= 80100)
1099510995
{
1099610996
appendPQExpBuffer(query, "SELECT aggtransfn, "
1099710997
"aggfinalfn, aggtranstype::pg_catalog.regtype, "
@@ -11003,7 +11003,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
1100311003
"AND p.oid = '%u'::pg_catalog.oid",
1100411004
agginfo->aggfn.dobj.catId.oid);
1100511005
}
11006-
else if (g_fout->remoteVersion >= 70300)
11006+
else if (fout->remoteVersion >= 70300)
1100711007
{
1100811008
appendPQExpBuffer(query, "SELECT aggtransfn, "
1100911009
"aggfinalfn, aggtranstype::pg_catalog.regtype, "
@@ -11015,7 +11015,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
1101511015
"AND p.oid = '%u'::pg_catalog.oid",
1101611016
agginfo->aggfn.dobj.catId.oid);
1101711017
}
11018-
else if (g_fout->remoteVersion >= 70100)
11018+
else if (fout->remoteVersion >= 70100)
1101911019
{
1102011020
appendPQExpBuffer(query, "SELECT aggtransfn, aggfinalfn, "
1102111021
"format_type(aggtranstype, NULL) AS aggtranstype, "
@@ -11077,14 +11077,14 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
1107711077
return;
1107811078
}
1107911079

11080-
if (g_fout->remoteVersion >= 70300)
11080+
if (fout->remoteVersion >= 70300)
1108111081
{
1108211082
/* If using 7.3's regproc or regtype, data is already quoted */
1108311083
appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
1108411084
aggtransfn,
1108511085
aggtranstype);
1108611086
}
11087-
else if (g_fout->remoteVersion >= 70100)
11087+
else if (fout->remoteVersion >= 70100)
1108811088
{
1108911089
/* format_type quotes, regproc does not */
1109011090
appendPQExpBuffer(details, " SFUNC = %s,\n STYPE = %s",
@@ -12300,7 +12300,7 @@ dumpTable(Archive *fout, TableInfo *tbinfo)
1230012300
* query rather than trying to fetch them during getTableAttrs, so
1230112301
* that we won't miss ACLs on system columns.
1230212302
*/
12303-
if (g_fout->remoteVersion >= 80400)
12303+
if (fout->remoteVersion >= 80400)
1230412304
{
1230512305
PQExpBuffer query = createPQExpBuffer();
1230612306
PGresult *res;
@@ -12377,7 +12377,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1237712377
reltypename = "VIEW";
1237812378

1237912379
/* Fetch the view definition */
12380-
if (g_fout->remoteVersion >= 70300)
12380+
if (fout->remoteVersion >= 70300)
1238112381
{
1238212382
/* Beginning in 7.3, viewname is not unique; rely on OID */
1238312383
appendPQExpBuffer(query,
@@ -12570,7 +12570,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1257012570
{
1257112571
appendPQExpBuffer(q, "WITH OPTIONS");
1257212572
}
12573-
else if (g_fout->remoteVersion >= 70100)
12573+
else if (fout->remoteVersion >= 70100)
1257412574
{
1257512575
appendPQExpBuffer(q, "%s",
1257612576
tbinfo->atttypnames[j]);
@@ -13444,7 +13444,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1344413444
snprintf(bufm, sizeof(bufm), INT64_FORMAT, SEQ_MINVALUE);
1344513445
snprintf(bufx, sizeof(bufx), INT64_FORMAT, SEQ_MAXVALUE);
1344613446

13447-
if (g_fout->remoteVersion >= 80400)
13447+
if (fout->remoteVersion >= 80400)
1344813448
{
1344913449
appendPQExpBuffer(query,
1345013450
"SELECT sequence_name, "
@@ -13545,7 +13545,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1354513545
"CREATE SEQUENCE %s\n",
1354613546
fmtId(tbinfo->dobj.name));
1354713547

13548-
if (g_fout->remoteVersion >= 80400)
13548+
if (fout->remoteVersion >= 80400)
1354913549
appendPQExpBuffer(query, " START WITH %s\n", startv);
1355013550
else
1355113551
{
@@ -13765,7 +13765,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
1376513765
if (OidIsValid(tginfo->tgconstrrelid))
1376613766
{
1376713767
/* If we are using regclass, name is already quoted */
13768-
if (g_fout->remoteVersion >= 70300)
13768+
if (fout->remoteVersion >= 70300)
1376913769
appendPQExpBuffer(query, " FROM %s\n ",
1377013770
tginfo->tgconstrrelname);
1377113771
else
@@ -13787,7 +13787,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
1378713787
appendPQExpBuffer(query, " FOR EACH STATEMENT\n ");
1378813788

1378913789
/* In 7.3, result of regproc is already quoted */
13790-
if (g_fout->remoteVersion >= 70300)
13790+
if (fout->remoteVersion >= 70300)
1379113791
appendPQExpBuffer(query, "EXECUTE PROCEDURE %s(",
1379213792
tginfo->tgfname);
1379313793
else
@@ -13904,7 +13904,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
1390413904
delcmd = createPQExpBuffer();
1390513905
labelq = createPQExpBuffer();
1390613906

13907-
if (g_fout->remoteVersion >= 70300)
13907+
if (fout->remoteVersion >= 70300)
1390813908
{
1390913909
appendPQExpBuffer(query,
1391013910
"SELECT pg_catalog.pg_get_ruledef('%u'::pg_catalog.oid) AS definition",

0 commit comments

Comments
 (0)