From ce1eff3f395c5abaa6725b227dc7baff98cf1497 Mon Sep 17 00:00:00 2001 From: Deepakshi Mittal Date: Thu, 9 Nov 2023 15:53:19 +0000 Subject: [PATCH] Added function to fix crash with indirect recursion happening previously The query plan might be cached and cant rely on erroring out iin analyzer phase. Task: BABEL-2170 Signed-off-by: Deepakshi Mittal --- contrib/babelfishpg_tsql/src/hooks.c | 18 ++++-------------- test/JDBC/expected/BABEL-2170-vu-verify.out | 8 ++++++-- .../input/triggers/BABEL-2170-vu-verify.sql | 4 ++-- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index 48fb081281d..674c0ccdbc0 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -722,26 +722,16 @@ static bool pltsql_bbfViewHasInsteadofTrigger(Relation view, CmdType event) { TriggerDesc *trigDesc = view->trigdesc; - if (triggerOids) + if (triggerOids && trigDesc) { int i; for (i = 0; i < trigDesc->numtriggers; i++) { Trigger *trigger = &trigDesc->triggers[i]; Oid current_tgoid = trigger->tgoid; - Oid prev_tgoid = InvalidOid; - prev_tgoid = lfirst_oid(list_tail(triggerOids)); - if (prev_tgoid == current_tgoid) - { - return false; /** Direct recursive trigger case*/ - } - else if (list_member_oid(triggerOids, current_tgoid)) - { - /** Indirect recursive trigger case*/ - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)"))); - } + Oid prev_tgoid = lfirst_oid(list_tail(triggerOids)); + if(prev_tgoid == current_tgoid) + return false; // Trigger calls itself } } diff --git a/test/JDBC/expected/BABEL-2170-vu-verify.out b/test/JDBC/expected/BABEL-2170-vu-verify.out index 98b41239d90..4c17a01a80e 100644 --- a/test/JDBC/expected/BABEL-2170-vu-verify.out +++ b/test/JDBC/expected/BABEL-2170-vu-verify.out @@ -593,9 +593,13 @@ GO ~~ERROR (Message: Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32))~~ +UPDATE babel_2170_vu_employees_view_rec SET MonthSalary = MonthSalary +100 WHERE EmployeeID = 2; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32))~~ + --- UPDATE babel_2170_vu_employees_view_rec SET MonthSalary = MonthSalary +100 WHERE EmployeeID = 2; --- GO DROP TRIGGER IF EXISTS babel_2170_vu_employees_view_iot_rec; GO diff --git a/test/JDBC/input/triggers/BABEL-2170-vu-verify.sql b/test/JDBC/input/triggers/BABEL-2170-vu-verify.sql index de4fd6e234c..18f42242938 100644 --- a/test/JDBC/input/triggers/BABEL-2170-vu-verify.sql +++ b/test/JDBC/input/triggers/BABEL-2170-vu-verify.sql @@ -337,8 +337,8 @@ GO UPDATE babel_2170_vu_employees_view SET MonthSalary = MonthSalary +100 WHERE EmployeeID = 2; GO --- UPDATE babel_2170_vu_employees_view_rec SET MonthSalary = MonthSalary +100 WHERE EmployeeID = 2; --- GO +UPDATE babel_2170_vu_employees_view_rec SET MonthSalary = MonthSalary +100 WHERE EmployeeID = 2; +GO DROP TRIGGER IF EXISTS babel_2170_vu_employees_view_iot_rec; GO