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

Commit2593c70

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 parent0d08310 commit2593c70

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
@@ -1207,6 +1207,24 @@ selectDumpableDefaultACL(DefaultACLInfo *dinfo)
12071207
dinfo->dobj.dump=include_everything;
12081208
}
12091209

1210+
/*
1211+
* selectDumpableCast: policy-setting subroutine
1212+
*Mark a cast as to be dumped or not
1213+
*
1214+
* Casts do not belong to any particular namespace (since they haven't got
1215+
* names), nor do they have identifiable owners. To distinguish user-defined
1216+
* casts from built-in ones, we must resort to checking whether the cast's
1217+
* OID is in the range reserved for initdb.
1218+
*/
1219+
staticvoid
1220+
selectDumpableCast(CastInfo*cast)
1221+
{
1222+
if (cast->dobj.catId.oid< (Oid)FirstNormalObjectId)
1223+
cast->dobj.dump= false;
1224+
else
1225+
cast->dobj.dump=include_everything;
1226+
}
1227+
12101228
/*
12111229
* selectDumpableExtension: policy-setting subroutine
12121230
*Mark an extension as to be dumped or not
@@ -5605,12 +5623,13 @@ getCasts(Archive *fout, int *numCasts)
56055623
sTypeInfo->dobj.name,tTypeInfo->dobj.name);
56065624
castinfo[i].dobj.name=namebuf.data;
56075625

5608-
if (OidIsValid(castinfo[i].castfunc))
5626+
if (fout->remoteVersion<70300&&
5627+
OidIsValid(castinfo[i].castfunc))
56095628
{
56105629
/*
56115630
* We need to make a dependency to ensure the function will be
56125631
* dumped first. (In 7.3 and later the regular dependency
5613-
* mechanismwill handle this for us.)
5632+
* mechanismhandles this for us.)
56145633
*/
56155634
FuncInfo*funcInfo;
56165635

@@ -5619,6 +5638,9 @@ getCasts(Archive *fout, int *numCasts)
56195638
addObjectDependency(&castinfo[i].dobj,
56205639
funcInfo->dobj.dumpId);
56215640
}
5641+
5642+
/* Decide whether we want to dump it */
5643+
selectDumpableCast(&(castinfo[i]));
56225644
}
56235645

56245646
PQclear(res);
@@ -9493,55 +9515,9 @@ dumpCast(Archive *fout, CastInfo *cast)
94939515
}
94949516

94959517
/*
9496-
* As per discussion we dump casts if one or more of the underlying
9497-
* objects (the conversion function and the two data types) are not
9498-
* builtin AND if all of the non-builtin objects are included in the dump.
9499-
* Builtin meaning, the namespace name does not start with "pg_".
9500-
*
9501-
* However, for a cast that belongs to an extension, we must not use this
9502-
* heuristic, but just dump the cast iff we're told to (via dobj.dump).
9518+
* Make sure we are in proper schema (needed for getFormattedTypeName).
9519+
* Casts don't have a schema of their own, so use pg_catalog.
95039520
*/
9504-
if (!cast->dobj.ext_member)
9505-
{
9506-
TypeInfo*sourceInfo=findTypeByOid(cast->castsource);
9507-
TypeInfo*targetInfo=findTypeByOid(cast->casttarget);
9508-
9509-
if (sourceInfo==NULL||targetInfo==NULL)
9510-
return;
9511-
9512-
/*
9513-
* Skip this cast if all objects are from pg_
9514-
*/
9515-
if ((funcInfo==NULL||
9516-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)==0)&&
9517-
strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)==0&&
9518-
strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)==0)
9519-
return;
9520-
9521-
/*
9522-
* Skip cast if function isn't from pg_ and is not to be dumped.
9523-
*/
9524-
if (funcInfo&&
9525-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
9526-
!funcInfo->dobj.dump)
9527-
return;
9528-
9529-
/*
9530-
* Same for the source type
9531-
*/
9532-
if (strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
9533-
!sourceInfo->dobj.dump)
9534-
return;
9535-
9536-
/*
9537-
* and the target type.
9538-
*/
9539-
if (strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
9540-
!targetInfo->dobj.dump)
9541-
return;
9542-
}
9543-
9544-
/* Make sure we are in proper schema (needed for getFormattedTypeName) */
95459521
selectSourceSchema(fout,"pg_catalog");
95469522

95479523
defqry=createPQExpBuffer();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp