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

Commita4e871c

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 parent672abc4 commita4e871c

File tree

1 file changed

+26
-50
lines changed

1 file changed

+26
-50
lines changed

‎src/bin/pg_dump/pg_dump.c‎

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,24 @@ selectDumpableDefaultACL(DefaultACLInfo *dinfo)
13321332
dinfo->dobj.dump=include_everything;
13331333
}
13341334

1335+
/*
1336+
* selectDumpableCast: policy-setting subroutine
1337+
*Mark a cast as to be dumped or not
1338+
*
1339+
* Casts do not belong to any particular namespace (since they haven't got
1340+
* names), nor do they have identifiable owners. To distinguish user-defined
1341+
* casts from built-in ones, we must resort to checking whether the cast's
1342+
* OID is in the range reserved for initdb.
1343+
*/
1344+
staticvoid
1345+
selectDumpableCast(CastInfo*cast)
1346+
{
1347+
if (cast->dobj.catId.oid< (Oid)FirstNormalObjectId)
1348+
cast->dobj.dump= false;
1349+
else
1350+
cast->dobj.dump=include_everything;
1351+
}
1352+
13351353
/*
13361354
* selectDumpableExtension: policy-setting subroutine
13371355
*Mark an extension as to be dumped or not
@@ -6134,12 +6152,13 @@ getCasts(Archive *fout, int *numCasts)
61346152
sTypeInfo->dobj.name,tTypeInfo->dobj.name);
61356153
castinfo[i].dobj.name=namebuf.data;
61366154

6137-
if (OidIsValid(castinfo[i].castfunc))
6155+
if (fout->remoteVersion<70300&&
6156+
OidIsValid(castinfo[i].castfunc))
61386157
{
61396158
/*
61406159
* We need to make a dependency to ensure the function will be
61416160
* dumped first. (In 7.3 and later the regular dependency
6142-
* mechanismwill handle this for us.)
6161+
* mechanismhandles this for us.)
61436162
*/
61446163
FuncInfo*funcInfo;
61456164

@@ -6148,6 +6167,9 @@ getCasts(Archive *fout, int *numCasts)
61486167
addObjectDependency(&castinfo[i].dobj,
61496168
funcInfo->dobj.dumpId);
61506169
}
6170+
6171+
/* Decide whether we want to dump it */
6172+
selectDumpableCast(&(castinfo[i]));
61516173
}
61526174

61536175
PQclear(res);
@@ -10028,55 +10050,9 @@ dumpCast(Archive *fout, CastInfo *cast)
1002810050
}
1002910051

1003010052
/*
10031-
* As per discussion we dump casts if one or more of the underlying
10032-
* objects (the conversion function and the two data types) are not
10033-
* builtin AND if all of the non-builtin objects are included in the dump.
10034-
* Builtin meaning, the namespace name does not start with "pg_".
10035-
*
10036-
* However, for a cast that belongs to an extension, we must not use this
10037-
* heuristic, but just dump the cast iff we're told to (via dobj.dump).
10053+
* Make sure we are in proper schema (needed for getFormattedTypeName).
10054+
* Casts don't have a schema of their own, so use pg_catalog.
1003810055
*/
10039-
if (!cast->dobj.ext_member)
10040-
{
10041-
TypeInfo*sourceInfo=findTypeByOid(cast->castsource);
10042-
TypeInfo*targetInfo=findTypeByOid(cast->casttarget);
10043-
10044-
if (sourceInfo==NULL||targetInfo==NULL)
10045-
return;
10046-
10047-
/*
10048-
* Skip this cast if all objects are from pg_
10049-
*/
10050-
if ((funcInfo==NULL||
10051-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)==0)&&
10052-
strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)==0&&
10053-
strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)==0)
10054-
return;
10055-
10056-
/*
10057-
* Skip cast if function isn't from pg_ and is not to be dumped.
10058-
*/
10059-
if (funcInfo&&
10060-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
10061-
!funcInfo->dobj.dump)
10062-
return;
10063-
10064-
/*
10065-
* Same for the source type
10066-
*/
10067-
if (strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
10068-
!sourceInfo->dobj.dump)
10069-
return;
10070-
10071-
/*
10072-
* and the target type.
10073-
*/
10074-
if (strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
10075-
!targetInfo->dobj.dump)
10076-
return;
10077-
}
10078-
10079-
/* Make sure we are in proper schema (needed for getFormattedTypeName) */
1008010056
selectSourceSchema(fout,"pg_catalog");
1008110057

1008210058
defqry=createPQExpBuffer();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp