From d217b2c360cb9a746b4ef122c568bdfedb6d726e Mon Sep 17 00:00:00 2001 From: Stephen Frost Date: Wed, 6 Apr 2016 21:45:32 -0400 Subject: [PATCH] In pg_dump, split "dump" into "dump" and "dump_contains" Historically, the "dump" component of the namespace has been used to decide if the objects inside of the namespace should be dumped also. Given that "dump" is now a bitmask and may be partial, and we may want to dump out all components of the namespace object but only some of the components of objects contained in the namespace, create a "dump_contains" bitmask which will represent what components of the objects inside of a namespace should be dumped out. No behavior change here, but in preparation for a change where we will dump out just the ACLs of objects in pg_catalog, but we might not dump out the ACL of the pg_catalog namespace itself (for instance, when it hasn't been changed from the value set at initdb time). Reviews by Alexander Korotkov, Jose Luis Tallon --- src/bin/pg_dump/pg_dump.c | 23 +++++++++++++---------- src/bin/pg_dump/pg_dump.h | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index cfd53f1838..e3360bc4d5 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1311,24 +1311,25 @@ selectDumpableNamespace(NamespaceInfo *nsinfo, DumpOptions *dopt) */ if (table_include_oids.head != NULL) - nsinfo->dobj.dump = DUMP_COMPONENT_NONE; + nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_NONE; else if (schema_include_oids.head != NULL) - nsinfo->dobj.dump = simple_oid_list_member(&schema_include_oids, - nsinfo->dobj.catId.oid) ? + nsinfo->dobj.dump_contains = nsinfo->dobj.dump = + simple_oid_list_member(&schema_include_oids, + nsinfo->dobj.catId.oid) ? DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE; else if (strncmp(nsinfo->dobj.name, "pg_", 3) == 0 || strcmp(nsinfo->dobj.name, "information_schema") == 0) - nsinfo->dobj.dump = DUMP_COMPONENT_NONE; + nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_NONE; else - nsinfo->dobj.dump = DUMP_COMPONENT_ALL; + nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_ALL; /* * In any case, a namespace can be excluded by an exclusion switch */ - if (nsinfo->dobj.dump && + if (nsinfo->dobj.dump_contains && simple_oid_list_member(&schema_exclude_oids, nsinfo->dobj.catId.oid)) - nsinfo->dobj.dump = DUMP_COMPONENT_NONE; + nsinfo->dobj.dump_contains = nsinfo->dobj.dump = DUMP_COMPONENT_NONE; } /* @@ -1350,7 +1351,7 @@ selectDumpableTable(TableInfo *tbinfo, DumpOptions *dopt) tbinfo->dobj.catId.oid) ? DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE; else - tbinfo->dobj.dump = tbinfo->dobj.namespace->dobj.dump; + tbinfo->dobj.dump = tbinfo->dobj.namespace->dobj.dump_contains; /* * In any case, a table can be excluded by an exclusion switch @@ -1407,7 +1408,8 @@ selectDumpableType(TypeInfo *tyinfo, DumpOptions *dopt) if (checkExtensionMembership(&tyinfo->dobj, dopt)) return; /* extension membership overrides all else */ - tyinfo->dobj.dump = tyinfo->dobj.namespace->dobj.dump; + /* Dump based on if the contents of the namespace are being dumped */ + tyinfo->dobj.dump = tyinfo->dobj.namespace->dobj.dump_contains; } /* @@ -1424,6 +1426,7 @@ selectDumpableDefaultACL(DefaultACLInfo *dinfo, DumpOptions *dopt) /* Default ACLs can't be extension members */ if (dinfo->dobj.namespace) + /* default ACLs are considered part of the namespace */ dinfo->dobj.dump = dinfo->dobj.namespace->dobj.dump; else dinfo->dobj.dump = dopt->include_everything ? @@ -1530,7 +1533,7 @@ selectDumpableObject(DumpableObject *dobj, DumpOptions *dopt) * non-namespace-associated items, dump if we're dumping "everything". */ if (dobj->namespace) - dobj->dump = dobj->namespace->dobj.dump; + dobj->dump = dobj->namespace->dobj.dump_contains; else dobj->dump = dopt->include_everything ? DUMP_COMPONENT_ALL : DUMP_COMPONENT_NONE; diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index f479c06d26..85f9f480ba 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -100,7 +100,8 @@ typedef struct _dumpableObject DumpId dumpId; /* assigned by AssignDumpId() */ char *name; /* object name (should never be NULL) */ struct _namespaceInfo *namespace; /* containing namespace, or NULL */ - DumpComponents dump; /* bitmask of components to dump */ + DumpComponents dump; /* bitmask of components to dump */ + DumpComponents dump_contains; /* as above, but for contained objects */ bool ext_member; /* true if object is member of extension */ DumpId *dependencies; /* dumpIds of objects this one depends on */ int nDeps; /* number of valid dependencies */