Commit 8f152b6c authored by Peter Eisentraut's avatar Peter Eisentraut

Code simplification

Initialize TriggerData to 0 for the whole struct together, instead of
each field separately.
Reviewed-by: default avatarDaniel Gustafsson <daniel@yesql.se>
Discussion: https://www.postgresql.org/message-id/flat/11c5f156-67a9-0fb5-8200-2a8018eb2e0c@2ndquadrant.com
parent ef34ab42
...@@ -10264,7 +10264,7 @@ validateForeignKeyConstraint(char *conname, ...@@ -10264,7 +10264,7 @@ validateForeignKeyConstraint(char *conname,
while (table_scan_getnextslot(scan, ForwardScanDirection, slot)) while (table_scan_getnextslot(scan, ForwardScanDirection, slot))
{ {
LOCAL_FCINFO(fcinfo, 0); LOCAL_FCINFO(fcinfo, 0);
TriggerData trigdata; TriggerData trigdata = {0};
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
...@@ -10283,8 +10283,6 @@ validateForeignKeyConstraint(char *conname, ...@@ -10283,8 +10283,6 @@ validateForeignKeyConstraint(char *conname,
trigdata.tg_relation = rel; trigdata.tg_relation = rel;
trigdata.tg_trigtuple = ExecFetchSlotHeapTuple(slot, false, NULL); trigdata.tg_trigtuple = ExecFetchSlotHeapTuple(slot, false, NULL);
trigdata.tg_trigslot = slot; trigdata.tg_trigslot = slot;
trigdata.tg_newtuple = NULL;
trigdata.tg_newslot = NULL;
trigdata.tg_trigger = &trig; trigdata.tg_trigger = &trig;
fcinfo->context = (Node *) &trigdata; fcinfo->context = (Node *) &trigdata;
......
...@@ -2140,7 +2140,7 @@ ExecBSInsertTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2140,7 +2140,7 @@ ExecBSInsertTriggers(EState *estate, ResultRelInfo *relinfo)
{ {
TriggerDesc *trigdesc; TriggerDesc *trigdesc;
int i; int i;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
trigdesc = relinfo->ri_TrigDesc; trigdesc = relinfo->ri_TrigDesc;
...@@ -2158,12 +2158,6 @@ ExecBSInsertTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2158,12 +2158,6 @@ ExecBSInsertTriggers(EState *estate, ResultRelInfo *relinfo)
LocTriggerData.tg_event = TRIGGER_EVENT_INSERT | LocTriggerData.tg_event = TRIGGER_EVENT_INSERT |
TRIGGER_EVENT_BEFORE; TRIGGER_EVENT_BEFORE;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
Trigger *trigger = &trigdesc->triggers[i]; Trigger *trigger = &trigdesc->triggers[i];
...@@ -2210,7 +2204,7 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2210,7 +2204,7 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
TriggerDesc *trigdesc = relinfo->ri_TrigDesc; TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
HeapTuple newtuple = NULL; HeapTuple newtuple = NULL;
bool should_free; bool should_free;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
int i; int i;
LocTriggerData.type = T_TriggerData; LocTriggerData.type = T_TriggerData;
...@@ -2218,12 +2212,6 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2218,12 +2212,6 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
TRIGGER_EVENT_ROW | TRIGGER_EVENT_ROW |
TRIGGER_EVENT_BEFORE; TRIGGER_EVENT_BEFORE;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
Trigger *trigger = &trigdesc->triggers[i]; Trigger *trigger = &trigdesc->triggers[i];
...@@ -2292,7 +2280,7 @@ ExecIRInsertTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2292,7 +2280,7 @@ ExecIRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
TriggerDesc *trigdesc = relinfo->ri_TrigDesc; TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
HeapTuple newtuple = NULL; HeapTuple newtuple = NULL;
bool should_free; bool should_free;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
int i; int i;
LocTriggerData.type = T_TriggerData; LocTriggerData.type = T_TriggerData;
...@@ -2300,12 +2288,6 @@ ExecIRInsertTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2300,12 +2288,6 @@ ExecIRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
TRIGGER_EVENT_ROW | TRIGGER_EVENT_ROW |
TRIGGER_EVENT_INSTEAD; TRIGGER_EVENT_INSTEAD;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
Trigger *trigger = &trigdesc->triggers[i]; Trigger *trigger = &trigdesc->triggers[i];
...@@ -2357,7 +2339,7 @@ ExecBSDeleteTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2357,7 +2339,7 @@ ExecBSDeleteTriggers(EState *estate, ResultRelInfo *relinfo)
{ {
TriggerDesc *trigdesc; TriggerDesc *trigdesc;
int i; int i;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
trigdesc = relinfo->ri_TrigDesc; trigdesc = relinfo->ri_TrigDesc;
...@@ -2375,12 +2357,6 @@ ExecBSDeleteTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2375,12 +2357,6 @@ ExecBSDeleteTriggers(EState *estate, ResultRelInfo *relinfo)
LocTriggerData.tg_event = TRIGGER_EVENT_DELETE | LocTriggerData.tg_event = TRIGGER_EVENT_DELETE |
TRIGGER_EVENT_BEFORE; TRIGGER_EVENT_BEFORE;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
Trigger *trigger = &trigdesc->triggers[i]; Trigger *trigger = &trigdesc->triggers[i];
...@@ -2437,7 +2413,7 @@ ExecBRDeleteTriggers(EState *estate, EPQState *epqstate, ...@@ -2437,7 +2413,7 @@ ExecBRDeleteTriggers(EState *estate, EPQState *epqstate,
TupleTableSlot *slot = ExecGetTriggerOldSlot(estate, relinfo); TupleTableSlot *slot = ExecGetTriggerOldSlot(estate, relinfo);
TriggerDesc *trigdesc = relinfo->ri_TrigDesc; TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
bool result = true; bool result = true;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
HeapTuple trigtuple; HeapTuple trigtuple;
bool should_free = false; bool should_free = false;
int i; int i;
...@@ -2476,12 +2452,6 @@ ExecBRDeleteTriggers(EState *estate, EPQState *epqstate, ...@@ -2476,12 +2452,6 @@ ExecBRDeleteTriggers(EState *estate, EPQState *epqstate,
TRIGGER_EVENT_ROW | TRIGGER_EVENT_ROW |
TRIGGER_EVENT_BEFORE; TRIGGER_EVENT_BEFORE;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
HeapTuple newtuple; HeapTuple newtuple;
...@@ -2554,7 +2524,7 @@ ExecIRDeleteTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2554,7 +2524,7 @@ ExecIRDeleteTriggers(EState *estate, ResultRelInfo *relinfo,
{ {
TriggerDesc *trigdesc = relinfo->ri_TrigDesc; TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
TupleTableSlot *slot = ExecGetTriggerOldSlot(estate, relinfo); TupleTableSlot *slot = ExecGetTriggerOldSlot(estate, relinfo);
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
int i; int i;
LocTriggerData.type = T_TriggerData; LocTriggerData.type = T_TriggerData;
...@@ -2562,12 +2532,6 @@ ExecIRDeleteTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2562,12 +2532,6 @@ ExecIRDeleteTriggers(EState *estate, ResultRelInfo *relinfo,
TRIGGER_EVENT_ROW | TRIGGER_EVENT_ROW |
TRIGGER_EVENT_INSTEAD; TRIGGER_EVENT_INSTEAD;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
ExecForceStoreHeapTuple(trigtuple, slot, false); ExecForceStoreHeapTuple(trigtuple, slot, false);
...@@ -2606,7 +2570,7 @@ ExecBSUpdateTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2606,7 +2570,7 @@ ExecBSUpdateTriggers(EState *estate, ResultRelInfo *relinfo)
{ {
TriggerDesc *trigdesc; TriggerDesc *trigdesc;
int i; int i;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
Bitmapset *updatedCols; Bitmapset *updatedCols;
trigdesc = relinfo->ri_TrigDesc; trigdesc = relinfo->ri_TrigDesc;
...@@ -2627,12 +2591,6 @@ ExecBSUpdateTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2627,12 +2591,6 @@ ExecBSUpdateTriggers(EState *estate, ResultRelInfo *relinfo)
LocTriggerData.tg_event = TRIGGER_EVENT_UPDATE | LocTriggerData.tg_event = TRIGGER_EVENT_UPDATE |
TRIGGER_EVENT_BEFORE; TRIGGER_EVENT_BEFORE;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
Trigger *trigger = &trigdesc->triggers[i]; Trigger *trigger = &trigdesc->triggers[i];
...@@ -2687,7 +2645,7 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate, ...@@ -2687,7 +2645,7 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate,
HeapTuple trigtuple; HeapTuple trigtuple;
bool should_free_trig = false; bool should_free_trig = false;
bool should_free_new = false; bool should_free_new = false;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
int i; int i;
Bitmapset *updatedCols; Bitmapset *updatedCols;
LockTupleMode lockmode; LockTupleMode lockmode;
...@@ -2740,8 +2698,6 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate, ...@@ -2740,8 +2698,6 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate,
TRIGGER_EVENT_ROW | TRIGGER_EVENT_ROW |
TRIGGER_EVENT_BEFORE; TRIGGER_EVENT_BEFORE;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
updatedCols = GetAllUpdatedColumns(relinfo, estate); updatedCols = GetAllUpdatedColumns(relinfo, estate);
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
...@@ -2855,7 +2811,7 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2855,7 +2811,7 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
TupleTableSlot *oldslot = ExecGetTriggerOldSlot(estate, relinfo); TupleTableSlot *oldslot = ExecGetTriggerOldSlot(estate, relinfo);
HeapTuple newtuple = NULL; HeapTuple newtuple = NULL;
bool should_free; bool should_free;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
int i; int i;
LocTriggerData.type = T_TriggerData; LocTriggerData.type = T_TriggerData;
...@@ -2863,8 +2819,6 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo, ...@@ -2863,8 +2819,6 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
TRIGGER_EVENT_ROW | TRIGGER_EVENT_ROW |
TRIGGER_EVENT_INSTEAD; TRIGGER_EVENT_INSTEAD;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
ExecForceStoreHeapTuple(trigtuple, oldslot, false); ExecForceStoreHeapTuple(trigtuple, oldslot, false);
...@@ -2920,7 +2874,7 @@ ExecBSTruncateTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2920,7 +2874,7 @@ ExecBSTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
{ {
TriggerDesc *trigdesc; TriggerDesc *trigdesc;
int i; int i;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
trigdesc = relinfo->ri_TrigDesc; trigdesc = relinfo->ri_TrigDesc;
...@@ -2933,12 +2887,6 @@ ExecBSTruncateTriggers(EState *estate, ResultRelInfo *relinfo) ...@@ -2933,12 +2887,6 @@ ExecBSTruncateTriggers(EState *estate, ResultRelInfo *relinfo)
LocTriggerData.tg_event = TRIGGER_EVENT_TRUNCATE | LocTriggerData.tg_event = TRIGGER_EVENT_TRUNCATE |
TRIGGER_EVENT_BEFORE; TRIGGER_EVENT_BEFORE;
LocTriggerData.tg_relation = relinfo->ri_RelationDesc; LocTriggerData.tg_relation = relinfo->ri_RelationDesc;
LocTriggerData.tg_trigtuple = NULL;
LocTriggerData.tg_newtuple = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
LocTriggerData.tg_oldtable = NULL;
LocTriggerData.tg_newtable = NULL;
for (i = 0; i < trigdesc->numtriggers; i++) for (i = 0; i < trigdesc->numtriggers; i++)
{ {
...@@ -3864,7 +3812,7 @@ AfterTriggerExecute(EState *estate, ...@@ -3864,7 +3812,7 @@ AfterTriggerExecute(EState *estate,
Relation rel = relInfo->ri_RelationDesc; Relation rel = relInfo->ri_RelationDesc;
AfterTriggerShared evtshared = GetTriggerSharedData(event); AfterTriggerShared evtshared = GetTriggerSharedData(event);
Oid tgoid = evtshared->ats_tgoid; Oid tgoid = evtshared->ats_tgoid;
TriggerData LocTriggerData; TriggerData LocTriggerData = {0};
HeapTuple rettuple; HeapTuple rettuple;
int tgindx; int tgindx;
bool should_free_trig = false; bool should_free_trig = false;
...@@ -3873,10 +3821,6 @@ AfterTriggerExecute(EState *estate, ...@@ -3873,10 +3821,6 @@ AfterTriggerExecute(EState *estate,
/* /*
* Locate trigger in trigdesc. * Locate trigger in trigdesc.
*/ */
LocTriggerData.tg_trigger = NULL;
LocTriggerData.tg_trigslot = NULL;
LocTriggerData.tg_newslot = NULL;
for (tgindx = 0; tgindx < trigdesc->numtriggers; tgindx++) for (tgindx = 0; tgindx < trigdesc->numtriggers; tgindx++)
{ {
if (trigdesc->triggers[tgindx].tgoid == tgoid) if (trigdesc->triggers[tgindx].tgoid == tgoid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment