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

Commit14794f9

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 parent52579d5 commit14794f9

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

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

5580-
if (OidIsValid(castinfo[i].castfunc))
5598+
if (g_fout->remoteVersion<70300&&
5599+
OidIsValid(castinfo[i].castfunc))
55815600
{
55825601
/*
55835602
* We need to make a dependency to ensure the function will be
55845603
* dumped first. (In 7.3 and later the regular dependency
5585-
* mechanismwill handle this for us.)
5604+
* mechanismhandles this for us.)
55865605
*/
55875606
FuncInfo*funcInfo;
55885607

@@ -5591,6 +5610,9 @@ getCasts(int *numCasts)
55915610
addObjectDependency(&castinfo[i].dobj,
55925611
funcInfo->dobj.dumpId);
55935612
}
5613+
5614+
/* Decide whether we want to dump it */
5615+
selectDumpableCast(&(castinfo[i]));
55945616
}
55955617

55965618
PQclear(res);
@@ -9225,55 +9247,9 @@ dumpCast(Archive *fout, CastInfo *cast)
92259247
}
92269248

92279249
/*
9228-
* As per discussion we dump casts if one or more of the underlying
9229-
* objects (the conversion function and the two data types) are not
9230-
* builtin AND if all of the non-builtin objects are included in the dump.
9231-
* Builtin meaning, the namespace name does not start with "pg_".
9232-
*
9233-
* However, for a cast that belongs to an extension, we must not use this
9234-
* heuristic, but just dump the cast iff we're told to (via dobj.dump).
9250+
* Make sure we are in proper schema (needed for getFormattedTypeName).
9251+
* Casts don't have a schema of their own, so use pg_catalog.
92359252
*/
9236-
if (!cast->dobj.ext_member)
9237-
{
9238-
TypeInfo*sourceInfo=findTypeByOid(cast->castsource);
9239-
TypeInfo*targetInfo=findTypeByOid(cast->casttarget);
9240-
9241-
if (sourceInfo==NULL||targetInfo==NULL)
9242-
return;
9243-
9244-
/*
9245-
* Skip this cast if all objects are from pg_
9246-
*/
9247-
if ((funcInfo==NULL||
9248-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)==0)&&
9249-
strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)==0&&
9250-
strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)==0)
9251-
return;
9252-
9253-
/*
9254-
* Skip cast if function isn't from pg_ and is not to be dumped.
9255-
*/
9256-
if (funcInfo&&
9257-
strncmp(funcInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
9258-
!funcInfo->dobj.dump)
9259-
return;
9260-
9261-
/*
9262-
* Same for the source type
9263-
*/
9264-
if (strncmp(sourceInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
9265-
!sourceInfo->dobj.dump)
9266-
return;
9267-
9268-
/*
9269-
* and the target type.
9270-
*/
9271-
if (strncmp(targetInfo->dobj.namespace->dobj.name,"pg_",3)!=0&&
9272-
!targetInfo->dobj.dump)
9273-
return;
9274-
}
9275-
9276-
/* Make sure we are in proper schema (needed for getFormattedTypeName) */
92779253
selectSourceSchema("pg_catalog");
92789254

92799255
defqry=createPQExpBuffer();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp