@@ -3805,10 +3805,14 @@ AfterTriggerEndQuery(EState *estate)
3805
3805
* IMMEDIATE: all events we have decided to defer will be available for it
3806
3806
* to fire.
3807
3807
*
3808
- * We loop in case a trigger queues more events at the same query level
3809
- * (is that even possible?). Be careful here: firing a trigger could
3810
- * result in query_stack being repalloc'd, so we can't save its address
3811
- * across afterTriggerInvokeEvents calls.
3808
+ * We loop in case a trigger queues more events at the same query level.
3809
+ * Ordinary trigger functions, including all PL/pgSQL trigger functions,
3810
+ * will instead fire any triggers in a dedicated query level. Foreign key
3811
+ * enforcement triggers do add to the current query level, thanks to their
3812
+ * passing fire_triggers = false to SPI_execute_snapshot(). Other
3813
+ * C-language triggers might do likewise. Be careful here: firing a
3814
+ * trigger could result in query_stack being repalloc'd, so we can't save
3815
+ * its address across afterTriggerInvokeEvents calls.
3812
3816
*
3813
3817
* If we find no firable events, we don't have to increment
3814
3818
* firing_counter.
@@ -4046,7 +4050,9 @@ AfterTriggerEndSubXact(bool isCommit)
4046
4050
4047
4051
/*
4048
4052
* Release any event lists from queries being aborted, and restore
4049
- * query_depth to its pre-subxact value.
4053
+ * query_depth to its pre-subxact value. This assumes that a
4054
+ * subtransaction will not add events to query levels started in a
4055
+ * earlier transaction state.
4050
4056
*/
4051
4057
while (afterTriggers -> query_depth > afterTriggers -> depth_stack [my_level ])
4052
4058
{
0 commit comments