Commit 181f55e5 authored by Tom Lane's avatar Tom Lane

Fix up pg_dump to emit shell-type definitions at the proper time, to

make use of the recently added ability to create a shell type explicitly.

I also put in place some infrastructure to allow dump/no dump decisions
to be made separately for each database object, rather than the former
hardwired 'dump if in a dumpable schema' policy.  This was needed anyway
for shell types so now seemed a convenient time to do it.  The flexibility
isn't exposed to the user yet, but is ready for future extensions.
parent 305fcb7a
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.87 2005/10/15 02:49:38 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.88 2006/03/02 01:18:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -201,7 +201,7 @@ flagInhTables(TableInfo *tblinfo, int numTables,
continue;
/* Don't bother computing anything for non-target tables, either */
if (!tblinfo[i].dump)
if (!tblinfo[i].dobj.dump)
continue;
/* Find all the immediate parent tables */
......@@ -242,7 +242,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
continue;
/* Don't bother computing anything for non-target tables, either */
if (!tbinfo->dump)
if (!tbinfo->dobj.dump)
continue;
numParents = tbinfo->numParents;
......@@ -388,7 +388,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
* Given a newly-created dumpable object, assign a dump ID,
* and enter the object into the lookup table.
*
* The caller is expected to have filled in objType and catalogId,
* The caller is expected to have filled in objType and catId,
* but not any of the other standard fields of a DumpableObject.
*/
void
......@@ -397,6 +397,7 @@ AssignDumpId(DumpableObject *dobj)
dobj->dumpId = ++lastDumpId;
dobj->name = NULL; /* must be set later */
dobj->namespace = NULL; /* may be set later */
dobj->dump = true; /* default assumption */
dobj->dependencies = NULL;
dobj->nDeps = 0;
dobj->allocDeps = 0;
......
This diff is collapsed.
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.123 2005/12/03 21:06:18 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.124 2006/03/02 01:18:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -62,6 +62,7 @@ typedef enum
/* When modifying this enum, update priority tables in pg_dump_sort.c! */
DO_NAMESPACE,
DO_TYPE,
DO_SHELL_TYPE,
DO_FUNC,
DO_AGG,
DO_OPERATOR,
......@@ -89,6 +90,7 @@ typedef struct _dumpableObject
DumpId dumpId; /* assigned by AssignDumpId() */
char *name; /* object name (should never be NULL) */
struct _namespaceInfo *namespace; /* containing namespace, or NULL */
bool dump; /* true if we want to dump this object */
DumpId *dependencies; /* dumpIds of objects this one depends on */
int nDeps; /* number of valid dependencies */
int allocDeps; /* allocated size of dependencies[] */
......@@ -99,7 +101,6 @@ typedef struct _namespaceInfo
DumpableObject dobj;
char *rolname; /* name of owner, or empty string */
char *nspacl;
bool dump; /* true if need to dump definition */
} NamespaceInfo;
typedef struct _typeInfo
......@@ -111,18 +112,26 @@ typedef struct _typeInfo
* produce something different than typname
*/
char *rolname; /* name of owner, or empty string */
Oid typinput;
Oid typelem;
Oid typrelid;
char typrelkind; /* 'r', 'v', 'c', etc */
char typtype; /* 'b', 'c', etc */
bool isArray; /* true if user-defined array type */
bool isDefined; /* true if typisdefined */
/* If it's a dumpable base type, we create a "shell type" entry for it */
struct _shellTypeInfo *shellType; /* shell-type entry, or NULL */
/* If it's a domain, we store links to its constraints here: */
int nDomChecks;
struct _constraintInfo *domChecks;
} TypeInfo;
typedef struct _shellTypeInfo
{
DumpableObject dobj;
TypeInfo *baseType; /* back link to associated base type */
} ShellTypeInfo;
typedef struct _funcInfo
{
DumpableObject dobj;
......@@ -181,7 +190,6 @@ typedef struct _tableInfo
int owning_col; /* attr # of column owning sequence */
bool interesting; /* true if need to collect more data */
bool dump; /* true if we want to dump it */
/*
* These fields are computed only if we decide the table is interesting
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump_sort.c,v 1.12 2005/11/22 18:17:29 momjian Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump_sort.c,v 1.13 2006/03/02 01:18:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -29,6 +29,7 @@ static const int oldObjectTypePriority[] =
{
1, /* DO_NAMESPACE */
2, /* DO_TYPE */
2, /* DO_SHELL_TYPE */
2, /* DO_FUNC */
3, /* DO_AGG */
3, /* DO_OPERATOR */
......@@ -57,6 +58,7 @@ static const int newObjectTypePriority[] =
{
1, /* DO_NAMESPACE */
3, /* DO_TYPE */
3, /* DO_SHELL_TYPE */
4, /* DO_FUNC */
5, /* DO_AGG */
6, /* DO_OPERATOR */
......@@ -602,35 +604,25 @@ findLoop(DumpableObject *obj,
/*
* A user-defined datatype will have a dependency loop with each of its
* I/O functions (since those have the datatype as input or output).
* We want the dump ordering to be the input function, then any other
* I/O functions, then the datatype. So we break the circularity in
* favor of the functions, and add a dependency from any non-input
* function to the input function.
* Break the loop and make the I/O function depend on the associated
* shell type, instead.
*/
static void
repairTypeFuncLoop(DumpableObject *typeobj, DumpableObject *funcobj)
{
TypeInfo *typeInfo = (TypeInfo *) typeobj;
FuncInfo *inputFuncInfo;
/* remove function's dependency on type */
removeObjectDependency(funcobj, typeobj->dumpId);
/* if this isn't the input function, make it depend on same */
if (funcobj->catId.oid == typeInfo->typinput)
return; /* it is the input function */
inputFuncInfo = findFuncByOid(typeInfo->typinput);
if (inputFuncInfo == NULL)
return;
addObjectDependency(funcobj, inputFuncInfo->dobj.dumpId);
/*
* Make sure the input function's dependency on type gets removed too; if
* it hasn't been done yet, we'd end up with loops involving the type and
* two or more functions, which repairDependencyLoop() is not smart enough
* to handle.
*/
removeObjectDependency(&inputFuncInfo->dobj, typeobj->dumpId);
/* add function's dependency on shell type, instead */
if (typeInfo->shellType)
{
addObjectDependency(funcobj, typeInfo->shellType->dobj.dumpId);
/* Mark shell type as to be dumped if any I/O function is */
if (funcobj->dump)
typeInfo->shellType->dobj.dump = true;
}
}
/*
......@@ -980,6 +972,11 @@ describeDumpableObject(DumpableObject *obj, char *buf, int bufsize)
"TYPE %s (ID %d OID %u)",
obj->name, obj->dumpId, obj->catId.oid);
return;
case DO_SHELL_TYPE:
snprintf(buf, bufsize,
"SHELL TYPE %s (ID %d OID %u)",
obj->name, obj->dumpId, obj->catId.oid);
return;
case DO_FUNC:
snprintf(buf, bufsize,
"FUNCTION %s (ID %d OID %u)",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment