Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3bfe6d

Browse files
committed
Rethink function argument sorting in pg_dump.
Commit7b583b2 created an unnecessarydump 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 MarkoTiikkaja in bug #12832. While this is by no means pg_dump's only suchissue with concurrent DDL, it's unfortunate that we added a new failuremode for cases that used to work, and even more so that the failure wascreated for basically cosmetic reasons (ie, to sort overloaded functionsmore deterministically).To fix, revert that patch and instead sort function arguments usinginformation that pg_dump has available anyway, namely the names of theargument types. This will produce a slightly different sort ordering foroverloaded functions than the previous coding; but applying strcmpdirectly to the output of pg_get_function_identity_arguments really wasa bit odd anyway. The sorting will still be name-based and henceindependent of possibly-installation-specific OID assignments. A smalladditional benefit is that sorting now works regardless of server version.Back-patch to 9.3, where the previous commit appeared.
1 parentc6ee39b commite3bfe6d

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
@@ -4199,7 +4199,6 @@ getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
41994199
inti_proargtypes;
42004200
inti_rolname;
42014201
inti_aggacl;
4202-
inti_proiargs;
42034202

42044203
/* Make sure we are in proper schema */
42054204
selectSourceSchema(fout,"pg_catalog");
@@ -4209,12 +4208,11 @@ getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
42094208
* rationale behind the filtering logic.
42104209
*/
42114210

4212-
if (fout->remoteVersion >=80400)
4211+
if (fout->remoteVersion >=80200)
42134212
{
42144213
appendPQExpBuffer(query,"SELECT tableoid, oid, proname AS aggname, "
42154214
"pronamespace AS aggnamespace, "
42164215
"pronargs, proargtypes, "
4217-
"pg_catalog.pg_get_function_identity_arguments(oid) AS proiargs,"
42184216
"(%s proowner) AS rolname, "
42194217
"proacl AS aggacl "
42204218
"FROM pg_proc p "
@@ -4232,28 +4230,12 @@ getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
42324230
"deptype = 'e')");
42334231
appendPQExpBufferChar(query,')');
42344232
}
4235-
elseif (fout->remoteVersion >=80200)
4236-
{
4237-
appendPQExpBuffer(query,"SELECT tableoid, oid, proname AS aggname, "
4238-
"pronamespace AS aggnamespace, "
4239-
"pronargs, proargtypes, "
4240-
"NULL::text AS proiargs,"
4241-
"(%s proowner) AS rolname, "
4242-
"proacl AS aggacl "
4243-
"FROM pg_proc p "
4244-
"WHERE proisagg AND ("
4245-
"pronamespace != "
4246-
"(SELECT oid FROM pg_namespace "
4247-
"WHERE nspname = 'pg_catalog'))",
4248-
username_subquery);
4249-
}
42504233
elseif (fout->remoteVersion >=70300)
42514234
{
42524235
appendPQExpBuffer(query,"SELECT tableoid, oid, proname AS aggname, "
42534236
"pronamespace AS aggnamespace, "
42544237
"CASE WHEN proargtypes[0] = 'pg_catalog.\"any\"'::pg_catalog.regtype THEN 0 ELSE 1 END AS pronargs, "
42554238
"proargtypes, "
4256-
"NULL::text AS proiargs, "
42574239
"(%s proowner) AS rolname, "
42584240
"proacl AS aggacl "
42594241
"FROM pg_proc "
@@ -4268,7 +4250,6 @@ getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
42684250
"0::oid AS aggnamespace, "
42694251
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
42704252
"aggbasetype AS proargtypes, "
4271-
"NULL::text AS proiargs, "
42724253
"(%s aggowner) AS rolname, "
42734254
"'{=X}' AS aggacl "
42744255
"FROM pg_aggregate "
@@ -4284,7 +4265,6 @@ getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
42844265
"0::oid AS aggnamespace, "
42854266
"CASE WHEN aggbasetype = 0 THEN 0 ELSE 1 END AS pronargs, "
42864267
"aggbasetype AS proargtypes, "
4287-
"NULL::text AS proiargs, "
42884268
"(%s aggowner) AS rolname, "
42894269
"'{=X}' AS aggacl "
42904270
"FROM pg_aggregate "
@@ -4308,7 +4288,6 @@ getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
43084288
i_proargtypes=PQfnumber(res,"proargtypes");
43094289
i_rolname=PQfnumber(res,"rolname");
43104290
i_aggacl=PQfnumber(res,"aggacl");
4311-
i_proiargs=PQfnumber(res,"proiargs");
43124291

43134292
for (i=0;i<ntups;i++)
43144293
{
@@ -4328,7 +4307,6 @@ getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
43284307
agginfo[i].aggfn.lang=InvalidOid;/* not currently interesting */
43294308
agginfo[i].aggfn.prorettype=InvalidOid;/* not saved */
43304309
agginfo[i].aggfn.proacl=pg_strdup(PQgetvalue(res,i,i_aggacl));
4331-
agginfo[i].aggfn.proiargs=pg_strdup(PQgetvalue(res,i,i_proiargs));
43324310
agginfo[i].aggfn.nargs=atoi(PQgetvalue(res,i,i_pronargs));
43334311
if (agginfo[i].aggfn.nargs==0)
43344312
agginfo[i].aggfn.argtypes=NULL;
@@ -4380,7 +4358,6 @@ getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs)
43804358
inti_proargtypes;
43814359
inti_prorettype;
43824360
inti_proacl;
4383-
inti_proiargs;
43844361

43854362
/* Make sure we are in proper schema */
43864363
selectSourceSchema(fout,"pg_catalog");
@@ -4401,13 +4378,12 @@ getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs)
44014378
* doesn't have; otherwise we might not get creation ordering correct.
44024379
*/
44034380

4404-
if (fout->remoteVersion >=80400)
4381+
if (fout->remoteVersion >=70300)
44054382
{
44064383
appendPQExpBuffer(query,
44074384
"SELECT tableoid, oid, proname, prolang, "
44084385
"pronargs, proargtypes, prorettype, proacl, "
44094386
"pronamespace, "
4410-
"pg_catalog.pg_get_function_identity_arguments(oid) AS proiargs,"
44114387
"(%s proowner) AS rolname "
44124388
"FROM pg_proc p "
44134389
"WHERE NOT proisagg AND ("
@@ -4429,29 +4405,13 @@ getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs)
44294405
"deptype = 'e')");
44304406
appendPQExpBufferChar(query,')');
44314407
}
4432-
elseif (fout->remoteVersion >=70300)
4433-
{
4434-
appendPQExpBuffer(query,
4435-
"SELECT tableoid, oid, proname, prolang, "
4436-
"pronargs, proargtypes, prorettype, proacl, "
4437-
"pronamespace, "
4438-
"NULL::text AS proiargs,"
4439-
"(%s proowner) AS rolname "
4440-
"FROM pg_proc p "
4441-
"WHERE NOT proisagg AND ("
4442-
"pronamespace != "
4443-
"(SELECT oid FROM pg_namespace "
4444-
"WHERE nspname = 'pg_catalog'))",
4445-
username_subquery);
4446-
}
44474408
elseif (fout->remoteVersion >=70100)
44484409
{
44494410
appendPQExpBuffer(query,
44504411
"SELECT tableoid, oid, proname, prolang, "
44514412
"pronargs, proargtypes, prorettype, "
44524413
"'{=X}' AS proacl, "
44534414
"0::oid AS pronamespace, "
4454-
"NULL::text AS proiargs,"
44554415
"(%s proowner) AS rolname "
44564416
"FROM pg_proc "
44574417
"WHERE pg_proc.oid > '%u'::oid",
@@ -4468,7 +4428,6 @@ getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs)
44684428
"pronargs, proargtypes, prorettype, "
44694429
"'{=X}' AS proacl, "
44704430
"0::oid AS pronamespace, "
4471-
"NULL::text AS proiargs,"
44724431
"(%s proowner) AS rolname "
44734432
"FROM pg_proc "
44744433
"where pg_proc.oid > '%u'::oid",
@@ -4494,7 +4453,6 @@ getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs)
44944453
i_proargtypes=PQfnumber(res,"proargtypes");
44954454
i_prorettype=PQfnumber(res,"prorettype");
44964455
i_proacl=PQfnumber(res,"proacl");
4497-
i_proiargs=PQfnumber(res,"proiargs");
44984456

44994457
for (i=0;i<ntups;i++)
45004458
{
@@ -4510,7 +4468,6 @@ getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs)
45104468
finfo[i].rolname=pg_strdup(PQgetvalue(res,i,i_rolname));
45114469
finfo[i].lang=atooid(PQgetvalue(res,i,i_prolang));
45124470
finfo[i].prorettype=atooid(PQgetvalue(res,i,i_prorettype));
4513-
finfo[i].proiargs=pg_strdup(PQgetvalue(res,i,i_proiargs));
45144471
finfo[i].proacl=pg_strdup(PQgetvalue(res,i,i_proacl));
45154472
finfo[i].nargs=atoi(PQgetvalue(res,i,i_pronargs));
45164473
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
@@ -149,7 +149,6 @@ typedef struct _funcInfo
149149
Oid*argtypes;
150150
Oidprorettype;
151151
char*proacl;
152-
char*proiargs;
153152
}FuncInfo;
154153

155154
/* 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
@@ -291,13 +291,30 @@ DOTypeNameCompare(const void *p1, const void *p2)
291291
{
292292
FuncInfo*fobj1=*(FuncInfo*const*)p1;
293293
FuncInfo*fobj2=*(FuncInfo*const*)p2;
294+
inti;
294295

295296
cmpval=fobj1->nargs-fobj2->nargs;
296297
if (cmpval!=0)
297298
returncmpval;
298-
cmpval=strcmp(fobj1->proiargs,fobj2->proiargs);
299-
if (cmpval!=0)
300-
returncmpval;
299+
for (i=0;i<fobj1->nargs;i++)
300+
{
301+
TypeInfo*argtype1=findTypeByOid(fobj1->argtypes[i]);
302+
TypeInfo*argtype2=findTypeByOid(fobj2->argtypes[i]);
303+
304+
if (argtype1&&argtype2)
305+
{
306+
if (argtype1->dobj.namespace&&argtype2->dobj.namespace)
307+
{
308+
cmpval=strcmp(argtype1->dobj.namespace->dobj.name,
309+
argtype2->dobj.namespace->dobj.name);
310+
if (cmpval!=0)
311+
returncmpval;
312+
}
313+
cmpval=strcmp(argtype1->dobj.name,argtype2->dobj.name);
314+
if (cmpval!=0)
315+
returncmpval;
316+
}
317+
}
301318
}
302319
elseif (obj1->objType==DO_OPERATOR)
303320
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp