Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Crash when Instead of View Trigger calls itself #245

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/backend/commands/trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN;

/* How many levels deep into trigger execution are we? */
static int MyTriggerDepth = 0;
List *triggerOids = NIL; /* To store all trigger calls information */
deepakshi-mittal marked this conversation as resolved.
Show resolved Hide resolved

/* Local function prototypes */
static void renametrig_internal(Relation tgrel, Relation targetrel,
Expand Down Expand Up @@ -2571,11 +2572,13 @@ ExecCallTriggerFunc(TriggerData *trigdata,
MyTriggerDepth++;
PG_TRY();
{
triggerOids = lappend_oid(triggerOids, trigdata->tg_trigger->tgoid);
result = FunctionCallInvoke(fcinfo);
}
PG_FINALLY();
{
MyTriggerDepth--;
triggerOids = list_delete_oid(triggerOids, trigdata->tg_trigger->tgoid);
}
PG_END_TRY();

Expand Down
3 changes: 2 additions & 1 deletion src/backend/rewrite/rewriteHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3736,7 +3736,8 @@ RewriteQuery(Query *parsetree, List *rewrite_events, int orig_rt_length)
result_relation = parsetree->resultRelation;
Assert(result_relation != 0);
rt_entry = rt_fetch(result_relation, parsetree->rtable);
Assert(rt_entry->rtekind == RTE_RELATION);
/** allow transition table in TSQL inside trigger body, rtekind can be RTE_NAMEDTUPLESTORE, eg inserted and deleted*/
Assert(rt_entry->rtekind == RTE_RELATION || (sql_dialect == SQL_DIALECT_TSQL && rt_entry->rtekind == RTE_NAMEDTUPLESTORE));

/*
* We can use NoLock here since either the parser or
Expand Down
1 change: 1 addition & 0 deletions src/include/commands/trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ extern void AfterTriggerEndSubXact(bool isCommit);
extern void AfterTriggerSetState(ConstraintsSetStmt *stmt);
extern bool AfterTriggerPendingOnRel(Oid relid);

extern List *triggerOids; /* To store all trigger calls information */

/*
* in utils/adt/ri_triggers.c
Expand Down
Loading