From de19ba885126c63980970007fa789d266c0fa7e3 Mon Sep 17 00:00:00 2001 From: Hari Babu Date: Thu, 29 Mar 2018 16:17:54 +1100 Subject: [PATCH 14/14] ExecARUpdateTriggers is updated to accept slot instead of tuple The After record update trigger function is changed to accept slot instead of newtuple, thus is reduces the need of TableTuple variable in the callers. --- src/backend/commands/trigger.c | 4 ++-- src/backend/executor/execReplication.c | 5 +---- src/backend/executor/nodeModifyTable.c | 22 ++++++---------------- src/include/commands/trigger.h | 2 +- src/pl/tcl/pltcl.c | 2 +- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 9a3f19a79a..33e1712bbd 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -3072,7 +3072,7 @@ void ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple fdw_trigtuple, - HeapTuple newtuple, + TupleTableSlot *slot, List *recheckIndexes, TransitionCaptureState *transition_capture) { @@ -3084,7 +3084,7 @@ ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo, transition_capture->tcs_update_new_table))) { HeapTuple trigtuple; - + HeapTuple newtuple = slot ? ExecHeapifySlot(slot) : NULL; /* * Note: if the UPDATE is converted into a DELETE+INSERT as part of * update-partition-key operation, then this function is also called diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index 3ab6db5902..48661eb2d6 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -391,7 +391,6 @@ ExecSimpleRelationUpdate(EState *estate, EPQState *epqstate, TupleTableSlot *searchslot, TupleTableSlot *slot) { bool skip_tuple = false; - TableTuple tuple; ResultRelInfo *resultRelInfo = estate->es_result_relation_info; Relation rel = resultRelInfo->ri_RelationDesc; ItemPointer tid = &(searchslot->tts_tid); @@ -427,12 +426,10 @@ ExecSimpleRelationUpdate(EState *estate, EPQState *epqstate, table_update(rel, tid, slot, estate, GetCurrentCommandId(true), InvalidSnapshot, true, &hufd, &lockmode, IndexFunc, &recheckIndexes); - tuple = ExecHeapifySlot(slot); - /* AFTER ROW UPDATE Triggers */ ExecARUpdateTriggers(estate, resultRelInfo, tid, - NULL, tuple, recheckIndexes, NULL); + NULL, slot, recheckIndexes, NULL); list_free(recheckIndexes); } diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 2b84654248..880b7ad6a1 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -272,7 +272,6 @@ ExecInsert(ModifyTableState *mtstate, EState *estate, bool canSetTag) { - TableTuple tuple; ResultRelInfo *resultRelInfo; Relation resultRelationDesc; Oid newId; @@ -547,10 +546,9 @@ ExecInsert(ModifyTableState *mtstate, if (mtstate->operation == CMD_UPDATE && mtstate->mt_transition_capture && mtstate->mt_transition_capture->tcs_update_new_table) { - tuple = ExecHeapifySlot(slot); ExecARUpdateTriggers(estate, resultRelInfo, NULL, NULL, - tuple, + slot, NULL, mtstate->mt_transition_capture); @@ -934,7 +932,6 @@ ExecUpdate(ModifyTableState *mtstate, EState *estate, bool canSetTag) { - TableTuple tuple; ResultRelInfo *resultRelInfo; Relation resultRelationDesc; HTSU_Result result; @@ -952,7 +949,7 @@ ExecUpdate(ModifyTableState *mtstate, * get the heap tuple out of the tuple table slot, making sure we have a * writable copy */ - tuple = ExecHeapifySlot(slot); + ExecMaterializeSlot(slot); /* * get information on the (current) result relation @@ -969,9 +966,6 @@ ExecUpdate(ModifyTableState *mtstate, if (slot == NULL) /* "do nothing" */ return NULL; - - /* trigger might have changed tuple */ - tuple = ExecHeapifySlot(slot); } /* INSTEAD OF ROW UPDATE Triggers */ @@ -983,9 +977,6 @@ ExecUpdate(ModifyTableState *mtstate, if (slot == NULL) /* "do nothing" */ return NULL; - - /* trigger might have changed tuple */ - tuple = ExecHeapifySlot(slot); } else if (resultRelInfo->ri_FdwRoutine) { @@ -1005,9 +996,6 @@ ExecUpdate(ModifyTableState *mtstate, * tableoid column, so initialize t_tableOid before evaluating them. */ ExecSlotUpdateTupleTableoid(slot, RelationGetRelid(resultRelationDesc)); - - /* FDW might have changed tuple */ - tuple = ExecHeapifySlot(slot); } else { @@ -1064,6 +1052,7 @@ lreplace:; PartitionTupleRouting *proute = mtstate->mt_partition_tuple_routing; int map_index; TupleConversionMap *tupconv_map; + HeapTuple tuple = ExecHeapifySlot(slot); /* * Disallow an INSERT ON CONFLICT DO UPDATE that causes the @@ -1195,6 +1184,8 @@ lreplace:; if (result == HeapTupleUpdated && !IsolationUsesXactSnapshot()) { + TableTuple tuple; + result = table_lock_tuple(resultRelationDesc, tupleid, estate->es_snapshot, &tuple, estate->es_output_cid, @@ -1218,7 +1209,6 @@ lreplace:; return NULL; } slot = ExecFilterJunk(resultRelInfo->ri_junkFilter, epqslot); - tuple = ExecHeapifySlot(slot); goto lreplace; } } @@ -1290,7 +1280,7 @@ lreplace:; (estate->es_processed)++; /* AFTER ROW UPDATE Triggers */ - ExecARUpdateTriggers(estate, resultRelInfo, tupleid, oldtuple, tuple, + ExecARUpdateTriggers(estate, resultRelInfo, tupleid, oldtuple, slot, recheckIndexes, mtstate->operation == CMD_INSERT ? mtstate->mt_oc_transition_capture : diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index 2fe7ed33a5..7cac03d469 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -230,7 +230,7 @@ extern void ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple fdw_trigtuple, - HeapTuple newtuple, + TupleTableSlot *slot, List *recheckIndexes, TransitionCaptureState *transition_capture); extern TupleTableSlot *ExecIRUpdateTriggers(EState *estate, diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c index 558cabc949..0d9a40f711 100644 --- a/src/pl/tcl/pltcl.c +++ b/src/pl/tcl/pltcl.c @@ -2432,7 +2432,7 @@ pltcl_process_SPI_result(Tcl_Interp *interp, { int my_rc = TCL_OK; int loop_rc; - HeapTuple *tuples; + TableTuple *tuples; TupleDesc tupdesc; switch (spi_rc) -- 2.16.1.windows.4