Skip to content

Commit 5f1a0ca

Browse files
author
Commitfest Bot
committed
[CF 5680] Improve coments on structures in trigger.c
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5680 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/[email protected] Author(s): Yugo Nagata
2 parents 80b727e + 96c5141 commit 5f1a0ca

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

src/backend/commands/trigger.c

+47-40
Original file line numberDiff line numberDiff line change
@@ -3771,55 +3771,15 @@ typedef struct AfterTriggerEventList
37713771
*
37723772
* query_stack[query_depth] is the per-query-level data, including these fields:
37733773
*
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-
*
37883774
* maxquerydepth is just the allocated length of query_stack.
37893775
*
37903776
* trans_stack holds per-subtransaction data, including these fields:
37913777
*
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-
*
38063778
* We use GetCurrentTransactionNestLevel() to determine the correct array
38073779
* index in trans_stack. maxtransdepth is the number of allocated entries in
38083780
* trans_stack. (By not keeping our own stack pointer, we can avoid trouble
38093781
* in cases where errors during subxact abort cause multiple invocations
38103782
* 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.
38233783
*/
38243784
typedef struct AfterTriggersQueryData AfterTriggersQueryData;
38253785
typedef struct AfterTriggersTransData AfterTriggersTransData;
@@ -3842,13 +3802,47 @@ typedef struct AfterTriggersData
38423802
int maxtransdepth; /* allocated len of above array */
38433803
} AfterTriggersData;
38443804

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+
*/
38453822
struct AfterTriggersQueryData
38463823
{
38473824
AfterTriggerEventList events; /* events pending from this query */
38483825
Tuplestorestate *fdw_tuplestore; /* foreign tuples for said events */
38493826
List *tables; /* list of AfterTriggersTableData, see below */
38503827
};
38513828

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+
*/
38523846
struct AfterTriggersTransData
38533847
{
38543848
/* these fields are just for resetting at subtrans abort: */
@@ -3858,6 +3852,19 @@ struct AfterTriggersTransData
38583852
CommandId firing_counter; /* saved firing_counter */
38593853
};
38603854

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+
*/
38613868
struct AfterTriggersTableData
38623869
{
38633870
/* relid + cmdType form the lookup key for these structs: */

0 commit comments

Comments
 (0)