In pg_dump, split "dump" into "dump" and "dump_contains"
authorStephen Frost <sfrost@snowman.net>
Thu, 7 Apr 2016 01:45:32 +0000 (21:45 -0400)
committerStephen Frost <sfrost@snowman.net>
Thu, 7 Apr 2016 01:45:32 +0000 (21:45 -0400)
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
src/bin/pg_dump/pg_dump.h

index cfd53f1838bae988d3478a44bcd2a2dfd5f337be..e3360bc4d56d754b890cf07f67468eea5960bb10 100644 (file)
@@ -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;
index f479c06d26ceee62559c1739ed0feb579b48d398..85f9f480ba5046eac1e65ae2db1e178fe25e8a34 100644 (file)
@@ -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 */