Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 629f861

Browse files
committed
Rethink function argument sorting in pg_dump.
Commit 7b583b2 created an unnecessary dump failure hazard by applying pg_get_function_identity_arguments() to every function in the database, even those that won't get dumped. This could result in snapshot-related problems if concurrent sessions are, for example, creating and dropping temporary functions, as noted by Marko Tiikkaja in bug #12832. While this is by no means pg_dump's only such issue with concurrent DDL, it's unfortunate that we added a new failure mode for cases that used to work, and even more so that the failure was created for basically cosmetic reasons (ie, to sort overloaded functions more deterministically). To fix, revert that patch and instead sort function arguments using information that pg_dump has available anyway, namely the names of the argument types. This will produce a slightly different sort ordering for overloaded functions than the previous coding; but applying strcmp directly to the output of pg_get_function_identity_arguments really was a bit odd anyway. The sorting will still be name-based and hence independent of possibly-installation-specific OID assignments. A small additional benefit is that sorting now works regardless of server version. Back-patch to 9.3, where the previous commit appeared.
1 parent 0deecc2 commit 629f861

File tree

3 files changed

+22
-49
lines changed

3 files changed

+22
-49
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,6 @@ getAggregates(Archive *fout, int *numAggs)
39513951
int i_proargtypes;
39523952
int i_rolname;
39533953
int i_aggacl;
3954-
int i_proiargs;
39553954

39563955
/* Make sure we are in proper schema */
39573956
selectSourceSchema(fout, "pg_catalog");
@@ -3961,12 +3960,11 @@ getAggregates(Archive *fout, int *numAggs)
39613960
* rationale behind the filtering logic.
39623961
*/
39633962

3964-
if (fout->remoteVersion >= 80400)
3963+
if (fout->remoteVersion >= 80200)
39653964
{
39663965
appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
39673966
"pronamespace AS aggnamespace, "
39683967
"pronargs, proargtypes, "
3969-
"pg_catalog.pg_get_function_identity_arguments(oid) AS proiargs,"
39703968
"(%s proowner) AS rolname, "
39713969
"proacl AS aggacl "
39723970
"FROM pg_proc p "
@@ -3984,28 +3982,12 @@ getAggregates(Archive *fout, int *numAggs)
39843982
"deptype = 'e')");
39853983
appendPQExpBufferChar(query, ')');
39863984
}
3987-
else if (fout->remoteVersion >= 80200)
3988-
{
3989-
appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
3990-
"pronamespace AS aggnamespace, "
3991-
"pronargs, proargtypes, "
3992-
"NULL::text AS proiargs,"
3993-
"(%s proowner) AS rolname, "
3994-
"proacl AS aggacl "
3995-
"FROM pg_proc p "
3996-
"WHERE proisagg AND ("
3997-
"pronamespace != "
3998-
"(SELECT oid FROM pg_namespace "
3999-
"WHERE nspname = 'pg_catalog'))",
4000-
username_subquery);
4001-
}
40023985
else if (fout->remoteVersion >= 70300)
40033986
{
40043987
appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
40053988
"pronamespace AS aggnamespace, "
40063989
"CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
40073990
"proargtypes, "
4008-
"NULL::text AS proiargs, "
40093991
"(%s proowner) AS rolname, "
40103992
"proacl AS aggacl "
40113993
"FROM pg_proc "
@@ -4020,7 +4002,6 @@ getAggregates(Archive *fout, int *numAggs)
40204002
"0::oid AS aggnamespace, "
40214003
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
40224004
"aggbasetype AS proargtypes, "
4023-
"NULL::text AS proiargs, "
40244005
"(%s aggowner) AS rolname, "
40254006
"'{=X}' AS aggacl "
40264007
"FROM pg_aggregate "
@@ -4036,7 +4017,6 @@ getAggregates(Archive *fout, int *numAggs)
40364017
"0::oid AS aggnamespace, "
40374018
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
40384019
"aggbasetype AS proargtypes, "
4039-
"NULL::text AS proiargs, "
40404020
"(%s aggowner) AS rolname, "
40414021
"'{=X}' AS aggacl "
40424022
"FROM pg_aggregate "
@@ -4060,7 +4040,6 @@ getAggregates(Archive *fout, int *numAggs)
40604040
i_proargtypes = PQfnumber(res, "proargtypes");
40614041
i_rolname = PQfnumber(res, "rolname");
40624042
i_aggacl = PQfnumber(res, "aggacl");
4063-
i_proiargs = PQfnumber(res, "proiargs");
40644043

40654044
for (i = 0; i < ntups; i++)
40664045
{
@@ -4080,7 +4059,6 @@ getAggregates(Archive *fout, int *numAggs)
40804059
agginfo[i].aggfn.lang = InvalidOid; /* not currently interesting */
40814060
agginfo[i].aggfn.prorettype = InvalidOid; /* not saved */
40824061
agginfo[i].aggfn.proacl = pg_strdup(PQgetvalue(res, i, i_aggacl));
4083-
agginfo[i].aggfn.proiargs = pg_strdup(PQgetvalue(res, i, i_proiargs));
40844062
agginfo[i].aggfn.nargs = atoi(PQgetvalue(res, i, i_pronargs));
40854063
if (agginfo[i].aggfn.nargs == 0)
40864064
agginfo[i].aggfn.argtypes = NULL;
@@ -4132,7 +4110,6 @@ getFuncs(Archive *fout, int *numFuncs)
41324110
int i_proargtypes;
41334111
int i_prorettype;
41344112
int i_proacl;
4135-
int i_proiargs;
41364113

41374114
/* Make sure we are in proper schema */
41384115
selectSourceSchema(fout, "pg_catalog");
@@ -4153,13 +4130,12 @@ getFuncs(Archive *fout, int *numFuncs)
41534130
* doesn't have; otherwise we might not get creation ordering correct.
41544131
*/
41554132

4156-
if (fout->remoteVersion >= 80400)
4133+
if (fout->remoteVersion >= 70300)
41574134
{
41584135
appendPQExpBuffer(query,
41594136
"SELECT tableoid, oid, proname, prolang, "
41604137
"pronargs, proargtypes, prorettype, proacl, "
41614138
"pronamespace, "
4162-
"pg_catalog.pg_get_function_identity_arguments(oid) AS proiargs,"
41634139
"(%s proowner) AS rolname "
41644140
"FROM pg_proc p "
41654141
"WHERE NOT proisagg AND ("
@@ -4181,29 +4157,13 @@ getFuncs(Archive *fout, int *numFuncs)
41814157
"deptype = 'e')");
41824158
appendPQExpBufferChar(query, ')');
41834159
}
4184-
else if (fout->remoteVersion >= 70300)
4185-
{
4186-
appendPQExpBuffer(query,
4187-
"SELECT tableoid, oid, proname, prolang, "
4188-
"pronargs, proargtypes, prorettype, proacl, "
4189-
"pronamespace, "
4190-
"NULL::text AS proiargs,"
4191-
"(%s proowner) AS rolname "
4192-
"FROM pg_proc p "
4193-
"WHERE NOT proisagg AND ("
4194-
"pronamespace != "
4195-
"(SELECT oid FROM pg_namespace "
4196-
"WHERE nspname = 'pg_catalog'))",
4197-
username_subquery);
4198-
}
41994160
else if (fout->remoteVersion >= 70100)
42004161
{
42014162
appendPQExpBuffer(query,
42024163
"SELECT tableoid, oid, proname, prolang, "
42034164
"pronargs, proargtypes, prorettype, "
42044165
"'{=X}' AS proacl, "
42054166
"0::oid AS pronamespace, "
4206-
"NULL::text AS proiargs,"
42074167
"(%s proowner) AS rolname "
42084168
"FROM pg_proc "
42094169
"WHERE pg_proc.oid > '%u'::oid",
@@ -4220,7 +4180,6 @@ getFuncs(Archive *fout, int *numFuncs)
42204180
"pronargs, proargtypes, prorettype, "
42214181
"'{=X}' AS proacl, "
42224182
"0::oid AS pronamespace, "
4223-
"NULL::text AS proiargs,"
42244183
"(%s proowner) AS rolname "
42254184
"FROM pg_proc "
42264185
"where pg_proc.oid > '%u'::oid",
@@ -4246,7 +4205,6 @@ getFuncs(Archive *fout, int *numFuncs)
42464205
i_proargtypes = PQfnumber(res, "proargtypes");
42474206
i_prorettype = PQfnumber(res, "prorettype");
42484207
i_proacl = PQfnumber(res, "proacl");
4249-
i_proiargs = PQfnumber(res, "proiargs");
42504208

42514209
for (i = 0; i < ntups; i++)
42524210
{
@@ -4262,7 +4220,6 @@ getFuncs(Archive *fout, int *numFuncs)
42624220
finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
42634221
finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
42644222
finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
4265-
finfo[i].proiargs = pg_strdup(PQgetvalue(res, i, i_proiargs));
42664223
finfo[i].proacl = pg_strdup(PQgetvalue(res, i, i_proacl));
42674224
finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
42684225
if (finfo[i].nargs == 0)

src/bin/pg_dump/pg_dump.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ typedef struct _funcInfo
184184
Oid *argtypes;
185185
Oid prorettype;
186186
char *proacl;
187-
char *proiargs;
188187
} FuncInfo;
189188

190189
/* AggInfo is a superset of FuncInfo */

src/bin/pg_dump/pg_dump_sort.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,30 @@ DOTypeNameCompare(const void *p1, const void *p2)
287287
{
288288
FuncInfo *fobj1 = *(FuncInfo *const *) p1;
289289
FuncInfo *fobj2 = *(FuncInfo *const *) p2;
290+
int i;
290291

291292
cmpval = fobj1->nargs - fobj2->nargs;
292293
if (cmpval != 0)
293294
return cmpval;
294-
cmpval = strcmp(fobj1->proiargs, fobj2->proiargs);
295-
if (cmpval != 0)
296-
return cmpval;
295+
for (i = 0; i < fobj1->nargs; i++)
296+
{
297+
TypeInfo *argtype1 = findTypeByOid(fobj1->argtypes[i]);
298+
TypeInfo *argtype2 = findTypeByOid(fobj2->argtypes[i]);
299+
300+
if (argtype1 && argtype2)
301+
{
302+
if (argtype1->dobj.namespace && argtype2->dobj.namespace)
303+
{
304+
cmpval = strcmp(argtype1->dobj.namespace->dobj.name,
305+
argtype2->dobj.namespace->dobj.name);
306+
if (cmpval != 0)
307+
return cmpval;
308+
}
309+
cmpval = strcmp(argtype1->dobj.name, argtype2->dobj.name);
310+
if (cmpval != 0)
311+
return cmpval;
312+
}
313+
}
297314
}
298315
else if (obj1->objType == DO_OPERATOR)
299316
{

0 commit comments

Comments
 (0)