From 16007feb14d14c8f1eeb3b33892372ddc7d3d87b Mon Sep 17 00:00:00 2001 From: surendravishnoi Date: Fri, 17 Jun 2022 23:13:00 +0530 Subject: [PATCH] BABEL: Add reverse dependency between TSQL trigger and trigger function during restore (#22) TSQL triggers needs reverse dependency from trigger function to trigger. It helps in dropping function when trigger itself is dropped as trigger functions are internal to TSQL triggers. This dependency is added specifically for TSQL triggers only. During restore, TSQL triggers are restored using two parts, first function restore followed by trigger restore using PG semantics. This code path does not execute TSQL logic to add reverse dependency. As a fix, we have moved reverse dependency addition to a place which executes during both normal trigger creation and restore. Task: BABEL-3249 Signed-off-by: Surendra Vishnoi (cherry picked from commit 86cb849947ddb702a5f21e0f637fd97f3e10be63) --- src/postgres/src/backend/commands/trigger.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/postgres/src/backend/commands/trigger.c b/src/postgres/src/backend/commands/trigger.c index a3ee6b70469e..89b14164ce3d 100644 --- a/src/postgres/src/backend/commands/trigger.c +++ b/src/postgres/src/backend/commands/trigger.c @@ -1183,6 +1183,15 @@ CreateTriggerFiringOn(CreateTrigStmt *stmt, const char *queryString, referenced.objectSubId = 0; recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); + /* + * For composite triggers, add dependency from trigger function + * to trigger so that a drop trigger will result in cascade drop + * for function as well. Trigger functions are created as part of + * create trigger for composite triggers. + */ + if (is_composite_trigger) + recordDependencyOn(&referenced, &myself, DEPENDENCY_NORMAL); + if (isInternal && OidIsValid(constraintOid)) { /*