@@ -3771,55 +3771,15 @@ typedef struct AfterTriggerEventList
3771
3771
*
3772
3772
* query_stack[query_depth] is the per-query-level data, including these fields:
3773
3773
*
3774
- * events is a list of AFTER trigger events queued by the current query.
3775
- * None of these are valid until the matching AfterTriggerEndQuery call
3776
- * occurs. At that point we fire immediate-mode triggers, and append any
3777
- * deferred events to the main events list.
3778
- *
3779
- * fdw_tuplestore is a tuplestore containing the foreign-table tuples
3780
- * needed by events queued by the current query. (Note: we use just one
3781
- * tuplestore even though more than one foreign table might be involved.
3782
- * This is okay because tuplestores don't really care what's in the tuples
3783
- * they store; but it's possible that someday it'd break.)
3784
- *
3785
- * tables is a List of AfterTriggersTableData structs for target tables
3786
- * of the current query (see below).
3787
- *
3788
3774
* maxquerydepth is just the allocated length of query_stack.
3789
3775
*
3790
3776
* trans_stack holds per-subtransaction data, including these fields:
3791
3777
*
3792
- * state is NULL or a pointer to a saved copy of the SET CONSTRAINTS
3793
- * state data. Each subtransaction level that modifies that state first
3794
- * saves a copy, which we use to restore the state if we abort.
3795
- *
3796
- * events is a copy of the events head/tail pointers,
3797
- * which we use to restore those values during subtransaction abort.
3798
- *
3799
- * query_depth is the subtransaction-start-time value of query_depth,
3800
- * which we similarly use to clean up at subtransaction abort.
3801
- *
3802
- * firing_counter is the subtransaction-start-time value of firing_counter.
3803
- * We use this to recognize which deferred triggers were fired (or marked
3804
- * for firing) within an aborted subtransaction.
3805
- *
3806
3778
* We use GetCurrentTransactionNestLevel() to determine the correct array
3807
3779
* index in trans_stack. maxtransdepth is the number of allocated entries in
3808
3780
* trans_stack. (By not keeping our own stack pointer, we can avoid trouble
3809
3781
* in cases where errors during subxact abort cause multiple invocations
3810
3782
* of AfterTriggerEndSubXact() at the same nesting depth.)
3811
- *
3812
- * We create an AfterTriggersTableData struct for each target table of the
3813
- * current query, and each operation mode (INSERT/UPDATE/DELETE), that has
3814
- * either transition tables or statement-level triggers. This is used to
3815
- * hold the relevant transition tables, as well as info tracking whether
3816
- * we already queued the statement triggers. (We use that info to prevent
3817
- * firing the same statement triggers more than once per statement, or really
3818
- * once per transition table set.) These structs, along with the transition
3819
- * table tuplestores, live in the (sub)transaction's CurTransactionContext.
3820
- * That's sufficient lifespan because we don't allow transition tables to be
3821
- * used by deferrable triggers, so they only need to survive until
3822
- * AfterTriggerEndQuery.
3823
3783
*/
3824
3784
typedef struct AfterTriggersQueryData AfterTriggersQueryData ;
3825
3785
typedef struct AfterTriggersTransData AfterTriggersTransData ;
@@ -3842,13 +3802,47 @@ typedef struct AfterTriggersData
3842
3802
int maxtransdepth ; /* allocated len of above array */
3843
3803
} AfterTriggersData ;
3844
3804
3805
+ /*
3806
+ * AfterTriggersQueryData has the following fields:
3807
+ *
3808
+ * events is a list of AFTER trigger events queued by the current query.
3809
+ * None of these are valid until the matching AfterTriggerEndQuery call
3810
+ * occurs. At that point we fire immediate-mode triggers, and append any
3811
+ * deferred events to the main events list.
3812
+ *
3813
+ * fdw_tuplestore is a tuplestore containing the foreign-table tuples
3814
+ * needed by events queued by the current query. (Note: we use just one
3815
+ * tuplestore even though more than one foreign table might be involved.
3816
+ * This is okay because tuplestores don't really care what's in the tuples
3817
+ * they store; but it's possible that someday it'd break.)
3818
+ *
3819
+ * tables is a List of AfterTriggersTableData structs for target tables
3820
+ * of the current query (see below).
3821
+ */
3845
3822
struct AfterTriggersQueryData
3846
3823
{
3847
3824
AfterTriggerEventList events ; /* events pending from this query */
3848
3825
Tuplestorestate * fdw_tuplestore ; /* foreign tuples for said events */
3849
3826
List * tables ; /* list of AfterTriggersTableData, see below */
3850
3827
};
3851
3828
3829
+ /*
3830
+ * AfterTriggersTransData has the following fields:
3831
+ *
3832
+ * state is NULL or a pointer to a saved copy of the SET CONSTRAINTS
3833
+ * state data. Each subtransaction level that modifies that state first
3834
+ * saves a copy, which we use to restore the state if we abort.
3835
+ *
3836
+ * events is a copy of the events head/tail pointers,
3837
+ * which we use to restore those values during subtransaction abort.
3838
+ *
3839
+ * query_depth is the subtransaction-start-time value of query_depth,
3840
+ * which we similarly use to clean up at subtransaction abort.
3841
+ *
3842
+ * firing_counter is the subtransaction-start-time value of firing_counter.
3843
+ * We use this to recognize which deferred triggers were fired (or marked
3844
+ * for firing) within an aborted subtransaction.
3845
+ */
3852
3846
struct AfterTriggersTransData
3853
3847
{
3854
3848
/* these fields are just for resetting at subtrans abort: */
@@ -3858,6 +3852,19 @@ struct AfterTriggersTransData
3858
3852
CommandId firing_counter ; /* saved firing_counter */
3859
3853
};
3860
3854
3855
+ /*
3856
+ * We create an AfterTriggersTableData struct for each target table of the
3857
+ * current query, and each operation mode (INSERT/UPDATE/DELETE), that has
3858
+ * either transition tables or statement-level triggers. This is used to
3859
+ * hold the relevant transition tables, as well as info tracking whether
3860
+ * we already queued the statement triggers. (We use that info to prevent
3861
+ * firing the same statement triggers more than once per statement, or really
3862
+ * once per transition table set.) These structs, along with the transition
3863
+ * table tuplestores, live in the (sub)transaction's CurTransactionContext.
3864
+ * That's sufficient lifespan because we don't allow transition tables to be
3865
+ * used by deferrable triggers, so they only need to survive until
3866
+ * AfterTriggerEndQuery.
3867
+ */
3861
3868
struct AfterTriggersTableData
3862
3869
{
3863
3870
/* relid + cmdType form the lookup key for these structs: */
0 commit comments