From ff823e22a17296b1c9219d432332cd73921c861c Mon Sep 17 00:00:00 2001 From: Hari Babu Date: Thu, 29 Mar 2018 16:17:54 +1100 Subject: [PATCH 14/15] 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 65fd58f35f..ff475f8fa4 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -3073,7 +3073,7 @@ void ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple fdw_trigtuple, - HeapTuple newtuple, + TupleTableSlot *slot, List *recheckIndexes, TransitionCaptureState *transition_capture) { @@ -3085,7 +3085,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 8480044cd2..5146791b6a 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -401,7 +401,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); @@ -437,12 +436,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 0633a27d78..28bccde00c 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); @@ -936,7 +934,6 @@ ExecUpdate(ModifyTableState *mtstate, EState *estate, bool canSetTag) { - TableTuple tuple; ResultRelInfo *resultRelInfo; Relation resultRelationDesc; HTSU_Result result; @@ -954,7 +951,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 @@ -971,9 +968,6 @@ ExecUpdate(ModifyTableState *mtstate, if (slot == NULL) /* "do nothing" */ return NULL; - - /* trigger might have changed tuple */ - tuple = ExecHeapifySlot(slot); } /* INSTEAD OF ROW UPDATE Triggers */ @@ -985,9 +979,6 @@ ExecUpdate(ModifyTableState *mtstate, if (slot == NULL) /* "do nothing" */ return NULL; - - /* trigger might have changed tuple */ - tuple = ExecHeapifySlot(slot); } else if (resultRelInfo->ri_FdwRoutine) { @@ -1007,9 +998,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 { @@ -1066,6 +1054,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 @@ -1198,6 +1187,8 @@ lreplace:; if (result == HeapTupleUpdated && !IsolationUsesXactSnapshot()) { + TableTuple tuple; + result = table_lock_tuple(resultRelationDesc, tupleid, estate->es_snapshot, &tuple, estate->es_output_cid, @@ -1221,7 +1212,6 @@ lreplace:; return NULL; } slot = ExecFilterJunk(resultRelInfo->ri_junkFilter, epqslot); - tuple = ExecHeapifySlot(slot); goto lreplace; } } @@ -1293,7 +1283,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