Refactor creation of normal dependency records when creating extension
authorMichael Paquier <michael@paquier.xyz>
Wed, 1 Jul 2020 02:12:33 +0000 (11:12 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 1 Jul 2020 02:12:33 +0000 (11:12 +0900)
When creating an extension, the same type of dependency is used when
registering a dependency to a schema and required extensions.  This
improves the code so as those dependencies are not recorded one-by-one,
but grouped together.  Note that this has as side effect to remove
duplicate dependency entries, even if it should not happen in practice
as extensions listed as required in a control file should be listed only
once.

Extracted from a larger patch by the same author.

Author: Daniel Dustafsson
Discussion: https://postgr.es/m/20200629065535.GA183079@paquier.xyz

src/backend/commands/extension.c

index 472e69fdaf97b5fdcff9d61c604d8df064f02191..3b69ab7ed5c4f5a209e9e80ecc4d41c17c9d08f4 100644 (file)
@@ -1783,6 +1783,7 @@ InsertExtensionTuple(const char *extName, Oid extOwner,
        HeapTuple       tuple;
        ObjectAddress myself;
        ObjectAddress nsp;
+       ObjectAddresses *refobjs;
        ListCell   *lc;
 
        /*
@@ -1825,27 +1826,26 @@ InsertExtensionTuple(const char *extName, Oid extOwner,
         */
        recordDependencyOnOwner(ExtensionRelationId, extensionOid, extOwner);
 
-       myself.classId = ExtensionRelationId;
-       myself.objectId = extensionOid;
-       myself.objectSubId = 0;
+       refobjs = new_object_addresses();
 
-       nsp.classId = NamespaceRelationId;
-       nsp.objectId = schemaOid;
-       nsp.objectSubId = 0;
+       ObjectAddressSet(myself, ExtensionRelationId, extensionOid);
 
-       recordDependencyOn(&myself, &nsp, DEPENDENCY_NORMAL);
+       ObjectAddressSet(nsp, NamespaceRelationId, schemaOid);
+       add_exact_object_address(&nsp, refobjs);
 
        foreach(lc, requiredExtensions)
        {
                Oid                     reqext = lfirst_oid(lc);
                ObjectAddress otherext;
 
-               otherext.classId = ExtensionRelationId;
-               otherext.objectId = reqext;
-               otherext.objectSubId = 0;
-
-               recordDependencyOn(&myself, &otherext, DEPENDENCY_NORMAL);
+               ObjectAddressSet(otherext, ExtensionRelationId, reqext);
+               add_exact_object_address(&otherext, refobjs);
        }
+
+       /* Record all of them (this includes duplicate elimination) */
+       record_object_address_dependencies(&myself, refobjs, DEPENDENCY_NORMAL);
+       free_object_addresses(refobjs);
+
        /* Post creation hook for new extension */
        InvokeObjectPostCreateHook(ExtensionRelationId, extensionOid, 0);