mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Add tg_updatedcols to TriggerData
This allows a trigger function to determine for an UPDATE trigger which columns were actually updated. This allows some optimizations in generic trigger functions such as lo_manage and tsvector_update_trigger. Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://www.postgresql.org/message-id/flat/11c5f156-67a9-0fb5-8200-2a8018eb2e0c@2ndquadrant.com
This commit is contained in:
@ -2591,6 +2591,7 @@ ExecBSUpdateTriggers(EState *estate, ResultRelInfo *relinfo)
|
||||
LocTriggerData.tg_event = TRIGGER_EVENT_UPDATE |
|
||||
TRIGGER_EVENT_BEFORE;
|
||||
LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
|
||||
LocTriggerData.tg_updatedcols = updatedCols;
|
||||
for (i = 0; i < trigdesc->numtriggers; i++)
|
||||
{
|
||||
Trigger *trigger = &trigdesc->triggers[i];
|
||||
@ -2699,6 +2700,7 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate,
|
||||
TRIGGER_EVENT_BEFORE;
|
||||
LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
|
||||
updatedCols = GetAllUpdatedColumns(relinfo, estate);
|
||||
LocTriggerData.tg_updatedcols = updatedCols;
|
||||
for (i = 0; i < trigdesc->numtriggers; i++)
|
||||
{
|
||||
Trigger *trigger = &trigdesc->triggers[i];
|
||||
@ -3255,6 +3257,7 @@ typedef struct AfterTriggerSharedData
|
||||
Oid ats_relid; /* the relation it's on */
|
||||
CommandId ats_firing_id; /* ID for firing cycle */
|
||||
struct AfterTriggersTableData *ats_table; /* transition table access */
|
||||
Bitmapset *ats_modifiedcols; /* modified columns */
|
||||
} AfterTriggerSharedData;
|
||||
|
||||
typedef struct AfterTriggerEventData *AfterTriggerEvent;
|
||||
@ -3954,6 +3957,8 @@ AfterTriggerExecute(EState *estate,
|
||||
LocTriggerData.tg_event =
|
||||
evtshared->ats_event & (TRIGGER_EVENT_OPMASK | TRIGGER_EVENT_ROW);
|
||||
LocTriggerData.tg_relation = rel;
|
||||
if (TRIGGER_FOR_UPDATE(LocTriggerData.tg_trigger->tgtype))
|
||||
LocTriggerData.tg_updatedcols = evtshared->ats_modifiedcols;
|
||||
|
||||
MemoryContextReset(per_tuple_context);
|
||||
|
||||
@ -5641,6 +5646,7 @@ AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
|
||||
new_shared.ats_table = transition_capture->tcs_private;
|
||||
else
|
||||
new_shared.ats_table = NULL;
|
||||
new_shared.ats_modifiedcols = modifiedCols;
|
||||
|
||||
afterTriggerAddEvent(&afterTriggers.query_stack[afterTriggers.query_depth].events,
|
||||
&new_event, &new_shared);
|
||||
|
Reference in New Issue
Block a user