Commit 44956c52 authored by Tom Lane's avatar Tom Lane

Fix AfterTriggerSaveEvent to use a test and elog, not just Assert, to check

that it's called within an AfterTriggerBeginQuery/AfterTriggerEndQuery pair.
The RI cascade triggers suppress that overhead on the assumption that they
are always run non-deferred, so it's possible to violate the condition if
someone mistakenly changes pg_trigger to mark such a trigger deferred.
We don't really care about supporting that, but throwing an error instead
of crashing seems desirable.  Per report from Marcelo Costa.
parent 61e53282
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.255 2009/10/26 02:26:28 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.256 2009/10/27 20:14:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -3895,9 +3895,15 @@ AfterTriggerSaveEvent(ResultRelInfo *relinfo, int event, bool row_trigger, ...@@ -3895,9 +3895,15 @@ AfterTriggerSaveEvent(ResultRelInfo *relinfo, int event, bool row_trigger,
int ntriggers; int ntriggers;
int *tgindx; int *tgindx;
/*
* Check state. We use normal tests not Asserts because it is possible
* to reach here in the wrong state given misconfigured RI triggers,
* in particular deferring a cascade action trigger.
*/
if (afterTriggers == NULL) if (afterTriggers == NULL)
elog(ERROR, "AfterTriggerSaveEvent() called outside of transaction"); elog(ERROR, "AfterTriggerSaveEvent() called outside of transaction");
Assert(afterTriggers->query_depth >= 0); if (afterTriggers->query_depth < 0)
elog(ERROR, "AfterTriggerSaveEvent() called outside of query");
/* /*
* Validate the event code and collect the associated tuple CTIDs. * Validate the event code and collect the associated tuple CTIDs.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment