Skip to content

Commit

Permalink
Added function to fix crash with indirect recursion happening previously
Browse files Browse the repository at this point in the history
The query plan might be cached and cant rely on erroring out iin
analyzer phase.

Task: BABEL-2170

Signed-off-by: Deepakshi Mittal <[email protected]>
  • Loading branch information
deepakshi-mittal committed Nov 9, 2023
1 parent acee19f commit ce1eff3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
18 changes: 4 additions & 14 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
8 changes: 6 additions & 2 deletions test/JDBC/expected/BABEL-2170-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/input/triggers/BABEL-2170-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce1eff3

Please sign in to comment.