From 8febfd1855450f50f17419def41c2ea9bcf994d5 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Sat, 5 Sep 2020 21:33:53 +0900 Subject: Switch to multi-inserts when registering dependencies for many code paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit improves the dependency registrations by taking advantage of the preliminary work done in 63110c62, to group together the insertion of dependencies of the same type to pg_depend. With the current layer of routines available, and as only dependencies of the same type can be grouped, there are code paths still doing more than one multi-insert when it is necessary to register dependencies of multiple types (constraint and index creation are two cases doing that). While on it, this refactors some of the code to use ObjectAddressSet() when manipulating object addresses. Author: Daniel Gustafsson, Michael Paquier Reviewed-by: Andres Freund, Álvaro Herrera Discussion: https://postgr.es/m/20200807061619.GA23955@paquier.xyz --- src/backend/commands/functioncmds.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/backend/commands/functioncmds.c') diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 1b5bdcec8b8..e236581a8e0 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -1696,6 +1696,7 @@ CreateTransform(CreateTransformStmt *stmt) Relation relation; ObjectAddress myself, referenced; + ObjectAddresses *addrs; bool is_replace; /* @@ -1836,39 +1837,34 @@ CreateTransform(CreateTransformStmt *stmt) if (is_replace) deleteDependencyRecordsFor(TransformRelationId, transformid, true); + addrs = new_object_addresses(); + /* make dependency entries */ - myself.classId = TransformRelationId; - myself.objectId = transformid; - myself.objectSubId = 0; + ObjectAddressSet(myself, TransformRelationId, transformid); /* dependency on language */ - referenced.classId = LanguageRelationId; - referenced.objectId = langid; - referenced.objectSubId = 0; - recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); + ObjectAddressSet(referenced, LanguageRelationId, langid); + add_exact_object_address(&referenced, addrs); /* dependency on type */ - referenced.classId = TypeRelationId; - referenced.objectId = typeid; - referenced.objectSubId = 0; - recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); + ObjectAddressSet(referenced, TypeRelationId, typeid); + add_exact_object_address(&referenced, addrs); /* dependencies on functions */ if (OidIsValid(fromsqlfuncid)) { - referenced.classId = ProcedureRelationId; - referenced.objectId = fromsqlfuncid; - referenced.objectSubId = 0; - recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); + ObjectAddressSet(referenced, ProcedureRelationId, fromsqlfuncid); + add_exact_object_address(&referenced, addrs); } if (OidIsValid(tosqlfuncid)) { - referenced.classId = ProcedureRelationId; - referenced.objectId = tosqlfuncid; - referenced.objectSubId = 0; - recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); + ObjectAddressSet(referenced, ProcedureRelationId, tosqlfuncid); + add_exact_object_address(&referenced, addrs); } + record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL); + free_object_addresses(addrs); + /* dependency on extension */ recordDependencyOnCurrentExtension(&myself, is_replace); -- cgit v1.2.3