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

Commit9feefed

Browse files
committed
Fix pg_dump's heuristic for deciding which casts to dump.
Back in 2003 we had a discussion about how to decide which casts to dump.At the time pg_dump really only considered an object's containing schemato decide what to dump (ie, dump whatever's not in pg_catalog), and sowe chose a complicated idea involving whether the underlying types were tobe dumped (cf commita6790ce). But usersare allowed to create casts between built-in types, and we failed to dumpsuch casts. Let's get rid of that heuristic, which has accreted even moreugliness since then, in favor of just looking at the cast's OID to decideif it's a built-in cast or not.In passing, also fix some really ancient code that supposed that it had tomanufacture a dependency for the cast on its cast function; that's onlytrue when dumping from a pre-7.3 server. This just resulted in some wastedcycles and duplicate dependency-list entries with newer servers, but wemight as well improve it.Per gripes from a number of people, most recently Greg Sabino Mullane.Back-patch to all supported branches.
1 parent1a179f3 commit9feefed

File tree

3 files changed

+29
-53
lines changed

3 files changed

+29
-53
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
199199

200200
if (g_verbose)
201201
write_msg(NULL,"reading type casts\n");
202-
getCasts(fout,&numCasts);
202+
getCasts(fout,dopt,&numCasts);
203203

204204
if (g_verbose)
205205
write_msg(NULL,"reading table inheritance information\n");

‎src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,24 @@ selectDumpableDefaultACL(DumpOptions *dopt, DefaultACLInfo *dinfo)
13501350
dinfo->dobj.dump=dopt->include_everything;
13511351
}
13521352

1353+
/*
1354+
* selectDumpableCast: policy-setting subroutine
1355+
*Mark a cast as to be dumped or not
1356+
*
1357+
* Casts do not belong to any particular namespace (since they haven't got
1358+
* names), nor do they have identifiable owners. To distinguish user-defined
1359+
* casts from built-in ones, we must resort to checking whether the cast's
1360+
* OID is in the range reserved for initdb.
1361+
*/
1362+
staticvoid
1363+
selectDumpableCast(DumpOptions*dopt,CastInfo*cast)
1364+
{
1365+
if (cast->dobj.catId.oid< (Oid)FirstNormalObjectId)
1366+
cast->dobj.dump= false;
1367+
else
1368+
cast->dobj.dump=dopt->include_everything;
1369+
}
1370+
13531371
/*
13541372
* selectDumpableExtension: policy-setting subroutine
13551373
*Mark an extension as to be dumped or not
@@ -6471,7 +6489,7 @@ getProcLangs(Archive *fout, int *numProcLangs)
64716489
* numCasts is set to the number of casts read in
64726490
*/
64736491
CastInfo*
6474-
getCasts(Archive*fout,int*numCasts)
6492+
getCasts(Archive*fout,DumpOptions*dopt,int*numCasts)
64756493
{
64766494
PGresult*res;
64776495
intntups;
@@ -6561,12 +6579,13 @@ getCasts(Archive *fout, int *numCasts)
65616579
sTypeInfo->dobj.name,tTypeInfo->dobj.name);
65626580
castinfo[i].dobj.name=namebuf.data;
65636581

6564-
if (OidIsValid(castinfo[i].castfunc))
6582+
if (fout->remoteVersion<70300&&
6583+
OidIsValid(castinfo[i].castfunc))
65656584
{
65666585
/*
65676586
* We need to make a dependency to ensure the function will be
65686587
* dumped first. (In 7.3 and later the regular dependency
6569-
* mechanismwill handle this for us.)
6588+
* mechanismhandles this for us.)
65706589
*/
65716590
FuncInfo*funcInfo;
65726591

@@ -6575,6 +6594,9 @@ getCasts(Archive *fout, int *numCasts)
65756594
addObjectDependency(&castinfo[i].dobj,
65766595
funcInfo->dobj.dumpId);
65776596
}
6597+
6598+
/* Decide whether we want to dump it */
6599+
selectDumpableCast(dopt,&(castinfo[i]));
65786600
}
65796601

65806602
PQclear(res);
@@ -10480,55 +10502,9 @@ dumpCast(Archive *fout, DumpOptions *dopt, CastInfo *cast)
1048010502
}
1048110503

1048210504
/*
10483-
* As per discussion we dump casts if one or more of the underlying
10484-
* objects (the conversion function and the two data types) are not
10485-
* builtin AND if all of the non-builtin objects are included in the dump.
10486-
* Builtin meaning, the namespace name does not start with "pg_".
10487-
*
10488-
* However, for a cast that belongs to an extension, we must not use this
10489-
* heuristic, but just dump the cast iff we're told to (via dobj.dump).
10505+
* Make sure we are in proper schema (needed for getFormattedTypeName).
10506+
* Casts don't have a schema of their own, so use pg_catalog.
1049010507
*/
10491-
if (!cast->dobj.ext_member)
10492-
{
10493-
TypeInfo*sourceInfo=findTypeByOid(cast->castsource);
10494-
TypeInfo*targetInfo=findTypeByOid(cast->casttarget);
10495-
10496-
if (sourceInfo==NULL||targetInfo==NULL)
10497-
return;
10498-
10499-
/*
10500-
* Skip this cast if all objects are from pg_
10501-
*/
10502-
if ((funcInfo==NULL||
10503-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)==0)&&
10504-
strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)==0&&
10505-
strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)==0)
10506-
return;
10507-
10508-
/*
10509-
* Skip cast if function isn't from pg_ and is not to be dumped.
10510-
*/
10511-
if (funcInfo&&
10512-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
10513-
!funcInfo->dobj.dump)
10514-
return;
10515-
10516-
/*
10517-
* Same for the source type
10518-
*/
10519-
if (strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
10520-
!sourceInfo->dobj.dump)
10521-
return;
10522-
10523-
/*
10524-
* and the target type.
10525-
*/
10526-
if (strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
10527-
!targetInfo->dobj.dump)
10528-
return;
10529-
}
10530-
10531-
/* Make sure we are in proper schema (needed for getFormattedTypeName) */
1053210508
selectSourceSchema(fout,"pg_catalog");
1053310509

1053410510
defqry=createPQExpBuffer();

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
534534
externRuleInfo*getRules(Archive*fout,int*numRules);
535535
externvoidgetTriggers(Archive*fout,TableInfotblinfo[],intnumTables);
536536
externProcLangInfo*getProcLangs(Archive*fout,int*numProcLangs);
537-
externCastInfo*getCasts(Archive*fout,int*numCasts);
537+
externCastInfo*getCasts(Archive*fout,DumpOptions*dopt,int*numCasts);
538538
externvoidgetTableAttrs(Archive*fout,DumpOptions*dopt,TableInfo*tbinfo,intnumTables);
539539
externboolshouldPrintColumn(DumpOptions*dopt,TableInfo*tbinfo,intcolno);
540540
externTSParserInfo*getTSParsers(Archive*fout,int*numTSParsers);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp