@@ -3805,10 +3805,14 @@ AfterTriggerEndQuery(EState *estate)
38053805 * IMMEDIATE: all events we have decided to defer will be available for it
38063806 * to fire.
38073807 *
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.
38123816 *
38133817 * If we find no firable events, we don't have to increment
38143818 * firing_counter.
@@ -4046,7 +4050,9 @@ AfterTriggerEndSubXact(bool isCommit)
40464050
40474051 /*
40484052 * 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.
40504056 */
40514057 while (afterTriggers -> query_depth > afterTriggers -> depth_stack [my_level ])
40524058 {
0 commit comments