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 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -201,7 +201,7 @@ flagInhTables(TableInfo *tblinfo, int numTables,
continue; continue;
/* Don't bother computing anything for non-target tables, either */ /* Don't bother computing anything for non-target tables, either */
if (!tblinfo[i].dump) if (!tblinfo[i].dobj.dump)
continue; continue;
/* Find all the immediate parent tables */ /* Find all the immediate parent tables */
...@@ -242,7 +242,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables, ...@@ -242,7 +242,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
continue; continue;
/* Don't bother computing anything for non-target tables, either */ /* Don't bother computing anything for non-target tables, either */
if (!tbinfo->dump) if (!tbinfo->dobj.dump)
continue; continue;
numParents = tbinfo->numParents; numParents = tbinfo->numParents;
...@@ -388,7 +388,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables, ...@@ -388,7 +388,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
* Given a newly-created dumpable object, assign a dump ID, * Given a newly-created dumpable object, assign a dump ID,
* and enter the object into the lookup table. * 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. * but not any of the other standard fields of a DumpableObject.
*/ */
void void
...@@ -397,6 +397,7 @@ AssignDumpId(DumpableObject *dobj) ...@@ -397,6 +397,7 @@ AssignDumpId(DumpableObject *dobj)
dobj->dumpId = ++lastDumpId; dobj->dumpId = ++lastDumpId;
dobj->name = NULL; /* must be set later */ dobj->name = NULL; /* must be set later */
dobj->namespace = NULL; /* may be set later */ dobj->namespace = NULL; /* may be set later */
dobj->dump = true; /* default assumption */
dobj->dependencies = NULL; dobj->dependencies = NULL;
dobj->nDeps = 0; dobj->nDeps = 0;
dobj->allocDeps = 0; dobj->allocDeps = 0;
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 ...@@ -62,6 +62,7 @@ typedef enum
/* When modifying this enum, update priority tables in pg_dump_sort.c! */ /* When modifying this enum, update priority tables in pg_dump_sort.c! */
DO_NAMESPACE, DO_NAMESPACE,
DO_TYPE, DO_TYPE,
DO_SHELL_TYPE,
DO_FUNC, DO_FUNC,
DO_AGG, DO_AGG,
DO_OPERATOR, DO_OPERATOR,
...@@ -89,6 +90,7 @@ typedef struct _dumpableObject ...@@ -89,6 +90,7 @@ typedef struct _dumpableObject
DumpId dumpId; /* assigned by AssignDumpId() */ DumpId dumpId; /* assigned by AssignDumpId() */
char *name; /* object name (should never be NULL) */ char *name; /* object name (should never be NULL) */
struct _namespaceInfo *namespace; /* containing namespace, or 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 */ DumpId *dependencies; /* dumpIds of objects this one depends on */
int nDeps; /* number of valid dependencies */ int nDeps; /* number of valid dependencies */
int allocDeps; /* allocated size of dependencies[] */ int allocDeps; /* allocated size of dependencies[] */
...@@ -99,7 +101,6 @@ typedef struct _namespaceInfo ...@@ -99,7 +101,6 @@ typedef struct _namespaceInfo
DumpableObject dobj; DumpableObject dobj;
char *rolname; /* name of owner, or empty string */ char *rolname; /* name of owner, or empty string */
char *nspacl; char *nspacl;
bool dump; /* true if need to dump definition */
} NamespaceInfo; } NamespaceInfo;
typedef struct _typeInfo typedef struct _typeInfo
...@@ -111,18 +112,26 @@ typedef struct _typeInfo ...@@ -111,18 +112,26 @@ typedef struct _typeInfo
* produce something different than typname * produce something different than typname
*/ */
char *rolname; /* name of owner, or empty string */ char *rolname; /* name of owner, or empty string */
Oid typinput;
Oid typelem; Oid typelem;
Oid typrelid; Oid typrelid;
char typrelkind; /* 'r', 'v', 'c', etc */ char typrelkind; /* 'r', 'v', 'c', etc */
char typtype; /* 'b', 'c', etc */ char typtype; /* 'b', 'c', etc */
bool isArray; /* true if user-defined array type */ bool isArray; /* true if user-defined array type */
bool isDefined; /* true if typisdefined */ 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: */ /* If it's a domain, we store links to its constraints here: */
int nDomChecks; int nDomChecks;
struct _constraintInfo *domChecks; struct _constraintInfo *domChecks;
} TypeInfo; } TypeInfo;
typedef struct _shellTypeInfo
{
DumpableObject dobj;
TypeInfo *baseType; /* back link to associated base type */
} ShellTypeInfo;
typedef struct _funcInfo typedef struct _funcInfo
{ {
DumpableObject dobj; DumpableObject dobj;
...@@ -181,7 +190,6 @@ typedef struct _tableInfo ...@@ -181,7 +190,6 @@ typedef struct _tableInfo
int owning_col; /* attr # of column owning sequence */ int owning_col; /* attr # of column owning sequence */
bool interesting; /* true if need to collect more data */ 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 * These fields are computed only if we decide the table is interesting
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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[] = ...@@ -29,6 +29,7 @@ static const int oldObjectTypePriority[] =
{ {
1, /* DO_NAMESPACE */ 1, /* DO_NAMESPACE */
2, /* DO_TYPE */ 2, /* DO_TYPE */
2, /* DO_SHELL_TYPE */
2, /* DO_FUNC */ 2, /* DO_FUNC */
3, /* DO_AGG */ 3, /* DO_AGG */
3, /* DO_OPERATOR */ 3, /* DO_OPERATOR */
...@@ -57,6 +58,7 @@ static const int newObjectTypePriority[] = ...@@ -57,6 +58,7 @@ static const int newObjectTypePriority[] =
{ {
1, /* DO_NAMESPACE */ 1, /* DO_NAMESPACE */
3, /* DO_TYPE */ 3, /* DO_TYPE */
3, /* DO_SHELL_TYPE */
4, /* DO_FUNC */ 4, /* DO_FUNC */
5, /* DO_AGG */ 5, /* DO_AGG */
6, /* DO_OPERATOR */ 6, /* DO_OPERATOR */
...@@ -602,35 +604,25 @@ findLoop(DumpableObject *obj, ...@@ -602,35 +604,25 @@ findLoop(DumpableObject *obj,
/* /*
* A user-defined datatype will have a dependency loop with each of its * 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). * 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 * Break the loop and make the I/O function depend on the associated
* I/O functions, then the datatype. So we break the circularity in * shell type, instead.
* favor of the functions, and add a dependency from any non-input
* function to the input function.
*/ */
static void static void
repairTypeFuncLoop(DumpableObject *typeobj, DumpableObject *funcobj) repairTypeFuncLoop(DumpableObject *typeobj, DumpableObject *funcobj)
{ {
TypeInfo *typeInfo = (TypeInfo *) typeobj; TypeInfo *typeInfo = (TypeInfo *) typeobj;
FuncInfo *inputFuncInfo;
/* remove function's dependency on type */ /* remove function's dependency on type */
removeObjectDependency(funcobj, typeobj->dumpId); removeObjectDependency(funcobj, typeobj->dumpId);
/* if this isn't the input function, make it depend on same */ /* add function's dependency on shell type, instead */
if (funcobj->catId.oid == typeInfo->typinput) if (typeInfo->shellType)
return; /* it is the input function */ {
inputFuncInfo = findFuncByOid(typeInfo->typinput); addObjectDependency(funcobj, typeInfo->shellType->dobj.dumpId);
if (inputFuncInfo == NULL) /* Mark shell type as to be dumped if any I/O function is */
return; if (funcobj->dump)
addObjectDependency(funcobj, inputFuncInfo->dobj.dumpId); typeInfo->shellType->dobj.dump = true;
}
/*
* 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);
} }
/* /*
...@@ -980,6 +972,11 @@ describeDumpableObject(DumpableObject *obj, char *buf, int bufsize) ...@@ -980,6 +972,11 @@ describeDumpableObject(DumpableObject *obj, char *buf, int bufsize)
"TYPE %s (ID %d OID %u)", "TYPE %s (ID %d OID %u)",
obj->name, obj->dumpId, obj->catId.oid); obj->name, obj->dumpId, obj->catId.oid);
return; 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: case DO_FUNC:
snprintf(buf, bufsize, snprintf(buf, bufsize,
"FUNCTION %s (ID %d OID %u)", "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