Refactor creation of normal dependency records when creating extension

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
This commit is contained in:
Michael Paquier 2020-07-01 11:12:33 +09:00
parent c4342c932a
commit 684b4f29b7
1 changed files with 12 additions and 12 deletions

View 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);