From 9f9d78e02a474402ee37ebcbed8390f4f3470743 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 16 Mar 2018 14:29:28 -0300 Subject: [PATCH v4 1/3] Simplify ExecInsert API re. ON CONFLICT data Instead of passing the ON CONFLICT-related members of ModifyTableState into ExecInsert(), we can have that routine obtain them from the node, since that is already an argument into the function. While at it, remove arbiterIndexes from ModifyTableState, since that's just a copy of the list already in the ModifyTable node, to which the state node already has access. --- src/backend/executor/nodeModifyTable.c | 18 +++++++++--------- src/include/nodes/execnodes.h | 2 -- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 3332ae4bf3..a9a48e914f 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -258,8 +258,6 @@ static TupleTableSlot * ExecInsert(ModifyTableState *mtstate, TupleTableSlot *slot, TupleTableSlot *planSlot, - List *arbiterIndexes, - OnConflictAction onconflict, EState *estate, bool canSetTag) { @@ -271,6 +269,7 @@ ExecInsert(ModifyTableState *mtstate, List *recheckIndexes = NIL; TupleTableSlot *result = NULL; TransitionCaptureState *ar_insert_trig_tcs; + OnConflictAction onconflict = mtstate->mt_onconflict; /* * get the heap tuple out of the tuple table slot, making sure we have a @@ -455,6 +454,7 @@ ExecInsert(ModifyTableState *mtstate, else { WCOKind wco_kind; + bool check_partition_constr; /* * We always check the partition constraint, including when the tuple @@ -463,8 +463,7 @@ ExecInsert(ModifyTableState *mtstate, * trigger might modify the tuple such that the partition constraint * is no longer satisfied, so we need to check in that case. */ - bool check_partition_constr = - (resultRelInfo->ri_PartitionCheck != NIL); + check_partition_constr = (resultRelInfo->ri_PartitionCheck != NIL); /* * Constraints might reference the tableoid column, so initialize @@ -510,6 +509,9 @@ ExecInsert(ModifyTableState *mtstate, uint32 specToken; ItemPointerData conflictTid; bool specConflict; + List *arbiterIndexes; + + arbiterIndexes = ((ModifyTable *) mtstate->ps.plan)->arbiterIndexes; /* * Do a non-conclusive check for conflicts first. @@ -627,7 +629,7 @@ ExecInsert(ModifyTableState *mtstate, if (resultRelInfo->ri_NumIndices > 0) recheckIndexes = ExecInsertIndexTuples(slot, &(tuple->t_self), estate, false, NULL, - arbiterIndexes); + NIL); } } @@ -1217,8 +1219,8 @@ lreplace:; Assert(mtstate->rootResultRelInfo != NULL); estate->es_result_relation_info = mtstate->rootResultRelInfo; - ret_slot = ExecInsert(mtstate, slot, planSlot, NULL, - ONCONFLICT_NONE, estate, canSetTag); + ret_slot = ExecInsert(mtstate, slot, planSlot, + estate, canSetTag); /* * Revert back the active result relation and the active @@ -2052,7 +2054,6 @@ ExecModifyTable(PlanState *pstate) { case CMD_INSERT: slot = ExecInsert(node, slot, planSlot, - node->mt_arbiterindexes, node->mt_onconflict, estate, node->canSetTag); break; case CMD_UPDATE: @@ -2137,7 +2138,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) mtstate->mt_arowmarks = (List **) palloc0(sizeof(List *) * nplans); mtstate->mt_nplans = nplans; mtstate->mt_onconflict = node->onConflictAction; - mtstate->mt_arbiterindexes = node->arbiterIndexes; /* set up epqstate with dummy subplan data for the moment */ EvalPlanQualInit(&mtstate->mt_epqstate, estate, NULL, NIL, node->epqParam); diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index a953820f43..1bee5ccbeb 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -990,8 +990,6 @@ typedef struct ModifyTableState EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ bool fireBSTriggers; /* do we need to fire stmt triggers? */ OnConflictAction mt_onconflict; /* ON CONFLICT type */ - List *mt_arbiterindexes; /* unique index OIDs to arbitrate taking - * alt path */ TupleTableSlot *mt_existing; /* slot to store existing target tuple in */ List *mt_excludedtlist; /* the excluded pseudo relation's tlist */ TupleTableSlot *mt_conflproj; /* CONFLICT ... SET ... projection target */ -- 2.11.0