Skip to content

Commit c013a1a

Browse files
author
Commitfest Bot
committed
[PATCH]: ./improve_comments_on_trigger_structure.patch
1 parent da2052a commit c013a1a

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

src/backend/commands/trigger.c

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,55 +3822,15 @@ typedef struct AfterTriggerEventList
38223822
*
38233823
* query_stack[query_depth] is the per-query-level data, including these fields:
38243824
*
3825-
* events is a list of AFTER trigger events queued by the current query.
3826-
* None of these are valid until the matching AfterTriggerEndQuery call
3827-
* occurs. At that point we fire immediate-mode triggers, and append any
3828-
* deferred events to the main events list.
3829-
*
3830-
* fdw_tuplestore is a tuplestore containing the foreign-table tuples
3831-
* needed by events queued by the current query. (Note: we use just one
3832-
* tuplestore even though more than one foreign table might be involved.
3833-
* This is okay because tuplestores don't really care what's in the tuples
3834-
* they store; but it's possible that someday it'd break.)
3835-
*
3836-
* tables is a List of AfterTriggersTableData structs for target tables
3837-
* of the current query (see below).
3838-
*
38393825
* maxquerydepth is just the allocated length of query_stack.
38403826
*
38413827
* trans_stack holds per-subtransaction data, including these fields:
38423828
*
3843-
* state is NULL or a pointer to a saved copy of the SET CONSTRAINTS
3844-
* state data. Each subtransaction level that modifies that state first
3845-
* saves a copy, which we use to restore the state if we abort.
3846-
*
3847-
* events is a copy of the events head/tail pointers,
3848-
* which we use to restore those values during subtransaction abort.
3849-
*
3850-
* query_depth is the subtransaction-start-time value of query_depth,
3851-
* which we similarly use to clean up at subtransaction abort.
3852-
*
3853-
* firing_counter is the subtransaction-start-time value of firing_counter.
3854-
* We use this to recognize which deferred triggers were fired (or marked
3855-
* for firing) within an aborted subtransaction.
3856-
*
38573829
* We use GetCurrentTransactionNestLevel() to determine the correct array
38583830
* index in trans_stack. maxtransdepth is the number of allocated entries in
38593831
* trans_stack. (By not keeping our own stack pointer, we can avoid trouble
38603832
* in cases where errors during subxact abort cause multiple invocations
38613833
* of AfterTriggerEndSubXact() at the same nesting depth.)
3862-
*
3863-
* We create an AfterTriggersTableData struct for each target table of the
3864-
* current query, and each operation mode (INSERT/UPDATE/DELETE), that has
3865-
* either transition tables or statement-level triggers. This is used to
3866-
* hold the relevant transition tables, as well as info tracking whether
3867-
* we already queued the statement triggers. (We use that info to prevent
3868-
* firing the same statement triggers more than once per statement, or really
3869-
* once per transition table set.) These structs, along with the transition
3870-
* table tuplestores, live in the (sub)transaction's CurTransactionContext.
3871-
* That's sufficient lifespan because we don't allow transition tables to be
3872-
* used by deferrable triggers, so they only need to survive until
3873-
* AfterTriggerEndQuery.
38743834
*/
38753835
typedef struct AfterTriggersQueryData AfterTriggersQueryData;
38763836
typedef struct AfterTriggersTransData AfterTriggersTransData;
@@ -3893,13 +3853,47 @@ typedef struct AfterTriggersData
38933853
int maxtransdepth; /* allocated len of above array */
38943854
} AfterTriggersData;
38953855

3856+
/*
3857+
* AfterTriggersQueryData has the following fields:
3858+
*
3859+
* events is a list of AFTER trigger events queued by the current query.
3860+
* None of these are valid until the matching AfterTriggerEndQuery call
3861+
* occurs. At that point we fire immediate-mode triggers, and append any
3862+
* deferred events to the main events list.
3863+
*
3864+
* fdw_tuplestore is a tuplestore containing the foreign-table tuples
3865+
* needed by events queued by the current query. (Note: we use just one
3866+
* tuplestore even though more than one foreign table might be involved.
3867+
* This is okay because tuplestores don't really care what's in the tuples
3868+
* they store; but it's possible that someday it'd break.)
3869+
*
3870+
* tables is a List of AfterTriggersTableData structs for target tables
3871+
* of the current query (see below).
3872+
*/
38963873
struct AfterTriggersQueryData
38973874
{
38983875
AfterTriggerEventList events; /* events pending from this query */
38993876
Tuplestorestate *fdw_tuplestore; /* foreign tuples for said events */
39003877
List *tables; /* list of AfterTriggersTableData, see below */
39013878
};
39023879

3880+
/*
3881+
* AfterTriggersTransData has the following fields:
3882+
*
3883+
* state is NULL or a pointer to a saved copy of the SET CONSTRAINTS
3884+
* state data. Each subtransaction level that modifies that state first
3885+
* saves a copy, which we use to restore the state if we abort.
3886+
*
3887+
* events is a copy of the events head/tail pointers,
3888+
* which we use to restore those values during subtransaction abort.
3889+
*
3890+
* query_depth is the subtransaction-start-time value of query_depth,
3891+
* which we similarly use to clean up at subtransaction abort.
3892+
*
3893+
* firing_counter is the subtransaction-start-time value of firing_counter.
3894+
* We use this to recognize which deferred triggers were fired (or marked
3895+
* for firing) within an aborted subtransaction.
3896+
*/
39033897
struct AfterTriggersTransData
39043898
{
39053899
/* these fields are just for resetting at subtrans abort: */
@@ -3909,6 +3903,19 @@ struct AfterTriggersTransData
39093903
CommandId firing_counter; /* saved firing_counter */
39103904
};
39113905

3906+
/*
3907+
* We create an AfterTriggersTableData struct for each target table of the
3908+
* current query, and each operation mode (INSERT/UPDATE/DELETE), that has
3909+
* either transition tables or statement-level triggers. This is used to
3910+
* hold the relevant transition tables, as well as info tracking whether
3911+
* we already queued the statement triggers. (We use that info to prevent
3912+
* firing the same statement triggers more than once per statement, or really
3913+
* once per transition table set.) These structs, along with the transition
3914+
* table tuplestores, live in the (sub)transaction's CurTransactionContext.
3915+
* That's sufficient lifespan because we don't allow transition tables to be
3916+
* used by deferrable triggers, so they only need to survive until
3917+
* AfterTriggerEndQuery.
3918+
*/
39123919
struct AfterTriggersTableData
39133920
{
39143921
/* relid + cmdType form the lookup key for these structs: */

0 commit comments

Comments
 (0)