aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-02-10 22:38:17 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2015-02-10 22:38:17 -0500
commita592e5883529b7a73188d1b325c30a5a4eee65e4 (patch)
tree70ce5152558aaea55582abe2b6d92b9801935054 /src
parent433c79d2c88009e4f4a053bc4e32a18719136611 (diff)
downloadpostgresql-a592e5883529b7a73188d1b325c30a5a4eee65e4.tar.gz
postgresql-a592e5883529b7a73188d1b325c30a5a4eee65e4.zip
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 schema to decide what to dump (ie, dump whatever's not in pg_catalog), and so we chose a complicated idea involving whether the underlying types were to be dumped (cf commit a6790ce85752b67ad994f55fdf1a450262ccc32e). But users are allowed to create casts between built-in types, and we failed to dump such casts. Let's get rid of that heuristic, which has accreted even more ugliness since then, in favor of just looking at the cast's OID to decide if it's a built-in cast or not. In passing, also fix some really ancient code that supposed that it had to manufacture a dependency for the cast on its cast function; that's only true when dumping from a pre-7.3 server. This just resulted in some wasted cycles and duplicate dependency-list entries with newer servers, but we might as well improve it. Per gripes from a number of people, most recently Greg Sabino Mullane. Back-patch to all supported branches.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_dump.c76
1 files changed, 26 insertions, 50 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2991f2415a1..0b26864d7dd 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -1343,6 +1343,24 @@ selectDumpableDefaultACL(DefaultACLInfo *dinfo)
}
/*
+ * selectDumpableCast: policy-setting subroutine
+ * Mark a cast as to be dumped or not
+ *
+ * Casts do not belong to any particular namespace (since they haven't got
+ * names), nor do they have identifiable owners. To distinguish user-defined
+ * casts from built-in ones, we must resort to checking whether the cast's
+ * OID is in the range reserved for initdb.
+ */
+static void
+selectDumpableCast(CastInfo *cast)
+{
+ if (cast->dobj.catId.oid < (Oid) FirstNormalObjectId)
+ cast->dobj.dump = false;
+ else
+ cast->dobj.dump = include_everything;
+}
+
+/*
* selectDumpableExtension: policy-setting subroutine
* Mark an extension as to be dumped or not
*
@@ -6258,12 +6276,13 @@ getCasts(Archive *fout, int *numCasts)
sTypeInfo->dobj.name, tTypeInfo->dobj.name);
castinfo[i].dobj.name = namebuf.data;
- if (OidIsValid(castinfo[i].castfunc))
+ if (fout->remoteVersion < 70300 &&
+ OidIsValid(castinfo[i].castfunc))
{
/*
* We need to make a dependency to ensure the function will be
* dumped first. (In 7.3 and later the regular dependency
- * mechanism will handle this for us.)
+ * mechanism handles this for us.)
*/
FuncInfo *funcInfo;
@@ -6272,6 +6291,9 @@ getCasts(Archive *fout, int *numCasts)
addObjectDependency(&castinfo[i].dobj,
funcInfo->dobj.dumpId);
}
+
+ /* Decide whether we want to dump it */
+ selectDumpableCast(&(castinfo[i]));
}
PQclear(res);
@@ -10154,55 +10176,9 @@ dumpCast(Archive *fout, CastInfo *cast)
}
/*
- * As per discussion we dump casts if one or more of the underlying
- * objects (the conversion function and the two data types) are not
- * builtin AND if all of the non-builtin objects are included in the dump.
- * Builtin meaning, the namespace name does not start with "pg_".
- *
- * However, for a cast that belongs to an extension, we must not use this
- * heuristic, but just dump the cast iff we're told to (via dobj.dump).
+ * Make sure we are in proper schema (needed for getFormattedTypeName).
+ * Casts don't have a schema of their own, so use pg_catalog.
*/
- if (!cast->dobj.ext_member)
- {
- TypeInfo *sourceInfo = findTypeByOid(cast->castsource);
- TypeInfo *targetInfo = findTypeByOid(cast->casttarget);
-
- if (sourceInfo == NULL || targetInfo == NULL)
- return;
-
- /*
- * Skip this cast if all objects are from pg_
- */
- if ((funcInfo == NULL ||
- strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) == 0) &&
- strncmp(sourceInfo->dobj.namespace->dobj.name, "pg_", 3) == 0 &&
- strncmp(targetInfo->dobj.namespace->dobj.name, "pg_", 3) == 0)
- return;
-
- /*
- * Skip cast if function isn't from pg_ and is not to be dumped.
- */
- if (funcInfo &&
- strncmp(funcInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
- !funcInfo->dobj.dump)
- return;
-
- /*
- * Same for the source type
- */
- if (strncmp(sourceInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
- !sourceInfo->dobj.dump)
- return;
-
- /*
- * and the target type.
- */
- if (strncmp(targetInfo->dobj.namespace->dobj.name, "pg_", 3) != 0 &&
- !targetInfo->dobj.dump)
- return;
- }
-
- /* Make sure we are in proper schema (needed for getFormattedTypeName) */
selectSourceSchema(fout, "pg_catalog");
defqry = createPQExpBuffer();