Commit ee0a1fc8 authored by Alvaro Herrera's avatar Alvaro Herrera

Remove unnecessary members from ModifyTableState and ExecInsert

These values can be obtained from the ModifyTable node which is already
a part of both the ModifyTableState and ExecInsert.

Author: Álvaro Herrera, Amit Langote
Reviewed-by: Peter Geoghegan
Discussion: https://postgr.es/m/20180316151303.rml2p5wffn3o6qy6@alvherre.pgsql
parent 839a8eb2
...@@ -363,8 +363,8 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -363,8 +363,8 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
if (partrel->rd_rel->relhasindex && if (partrel->rd_rel->relhasindex &&
leaf_part_rri->ri_IndexRelationDescs == NULL) leaf_part_rri->ri_IndexRelationDescs == NULL)
ExecOpenIndices(leaf_part_rri, ExecOpenIndices(leaf_part_rri,
(mtstate != NULL && (node != NULL &&
mtstate->mt_onconflict != ONCONFLICT_NONE)); node->onConflictAction != ONCONFLICT_NONE));
/* /*
* Build WITH CHECK OPTION constraints for the partition. Note that we * Build WITH CHECK OPTION constraints for the partition. Note that we
......
...@@ -263,8 +263,6 @@ static TupleTableSlot * ...@@ -263,8 +263,6 @@ static TupleTableSlot *
ExecInsert(ModifyTableState *mtstate, ExecInsert(ModifyTableState *mtstate,
TupleTableSlot *slot, TupleTableSlot *slot,
TupleTableSlot *planSlot, TupleTableSlot *planSlot,
List *arbiterIndexes,
OnConflictAction onconflict,
EState *estate, EState *estate,
bool canSetTag) bool canSetTag)
{ {
...@@ -275,6 +273,8 @@ ExecInsert(ModifyTableState *mtstate, ...@@ -275,6 +273,8 @@ ExecInsert(ModifyTableState *mtstate,
List *recheckIndexes = NIL; List *recheckIndexes = NIL;
TupleTableSlot *result = NULL; TupleTableSlot *result = NULL;
TransitionCaptureState *ar_insert_trig_tcs; TransitionCaptureState *ar_insert_trig_tcs;
ModifyTable *node = (ModifyTable *) mtstate->ps.plan;
OnConflictAction onconflict = node->onConflictAction;
/* /*
* get the heap tuple out of the tuple table slot, making sure we have a * get the heap tuple out of the tuple table slot, making sure we have a
...@@ -365,6 +365,7 @@ ExecInsert(ModifyTableState *mtstate, ...@@ -365,6 +365,7 @@ ExecInsert(ModifyTableState *mtstate,
else else
{ {
WCOKind wco_kind; WCOKind wco_kind;
bool check_partition_constr;
/* /*
* We always check the partition constraint, including when the tuple * We always check the partition constraint, including when the tuple
...@@ -373,8 +374,7 @@ ExecInsert(ModifyTableState *mtstate, ...@@ -373,8 +374,7 @@ ExecInsert(ModifyTableState *mtstate,
* trigger might modify the tuple such that the partition constraint * trigger might modify the tuple such that the partition constraint
* is no longer satisfied, so we need to check in that case. * is no longer satisfied, so we need to check in that case.
*/ */
bool check_partition_constr = check_partition_constr = (resultRelInfo->ri_PartitionCheck != NIL);
(resultRelInfo->ri_PartitionCheck != NIL);
/* /*
* Constraints might reference the tableoid column, so initialize * Constraints might reference the tableoid column, so initialize
...@@ -420,6 +420,9 @@ ExecInsert(ModifyTableState *mtstate, ...@@ -420,6 +420,9 @@ ExecInsert(ModifyTableState *mtstate,
uint32 specToken; uint32 specToken;
ItemPointerData conflictTid; ItemPointerData conflictTid;
bool specConflict; bool specConflict;
List *arbiterIndexes;
arbiterIndexes = node->arbiterIndexes;
/* /*
* Do a non-conclusive check for conflicts first. * Do a non-conclusive check for conflicts first.
...@@ -537,7 +540,7 @@ ExecInsert(ModifyTableState *mtstate, ...@@ -537,7 +540,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0) if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(slot, &(tuple->t_self), recheckIndexes = ExecInsertIndexTuples(slot, &(tuple->t_self),
estate, false, NULL, estate, false, NULL,
arbiterIndexes); NIL);
} }
} }
...@@ -1124,8 +1127,8 @@ lreplace:; ...@@ -1124,8 +1127,8 @@ lreplace:;
slot = ExecPrepareTupleRouting(mtstate, estate, proute, slot = ExecPrepareTupleRouting(mtstate, estate, proute,
mtstate->rootResultRelInfo, slot); mtstate->rootResultRelInfo, slot);
ret_slot = ExecInsert(mtstate, slot, planSlot, NULL, ret_slot = ExecInsert(mtstate, slot, planSlot,
ONCONFLICT_NONE, estate, canSetTag); estate, canSetTag);
/* Revert ExecPrepareTupleRouting's node change. */ /* Revert ExecPrepareTupleRouting's node change. */
estate->es_result_relation_info = resultRelInfo; estate->es_result_relation_info = resultRelInfo;
...@@ -1487,6 +1490,7 @@ ExecOnConflictUpdate(ModifyTableState *mtstate, ...@@ -1487,6 +1490,7 @@ ExecOnConflictUpdate(ModifyTableState *mtstate,
static void static void
fireBSTriggers(ModifyTableState *node) fireBSTriggers(ModifyTableState *node)
{ {
ModifyTable *plan = (ModifyTable *) node->ps.plan;
ResultRelInfo *resultRelInfo = node->resultRelInfo; ResultRelInfo *resultRelInfo = node->resultRelInfo;
/* /*
...@@ -1501,7 +1505,7 @@ fireBSTriggers(ModifyTableState *node) ...@@ -1501,7 +1505,7 @@ fireBSTriggers(ModifyTableState *node)
{ {
case CMD_INSERT: case CMD_INSERT:
ExecBSInsertTriggers(node->ps.state, resultRelInfo); ExecBSInsertTriggers(node->ps.state, resultRelInfo);
if (node->mt_onconflict == ONCONFLICT_UPDATE) if (plan->onConflictAction == ONCONFLICT_UPDATE)
ExecBSUpdateTriggers(node->ps.state, ExecBSUpdateTriggers(node->ps.state,
resultRelInfo); resultRelInfo);
break; break;
...@@ -1545,12 +1549,13 @@ getTargetResultRelInfo(ModifyTableState *node) ...@@ -1545,12 +1549,13 @@ getTargetResultRelInfo(ModifyTableState *node)
static void static void
fireASTriggers(ModifyTableState *node) fireASTriggers(ModifyTableState *node)
{ {
ModifyTable *plan = (ModifyTable *) node->ps.plan;
ResultRelInfo *resultRelInfo = getTargetResultRelInfo(node); ResultRelInfo *resultRelInfo = getTargetResultRelInfo(node);
switch (node->operation) switch (node->operation)
{ {
case CMD_INSERT: case CMD_INSERT:
if (node->mt_onconflict == ONCONFLICT_UPDATE) if (plan->onConflictAction == ONCONFLICT_UPDATE)
ExecASUpdateTriggers(node->ps.state, ExecASUpdateTriggers(node->ps.state,
resultRelInfo, resultRelInfo,
node->mt_oc_transition_capture); node->mt_oc_transition_capture);
...@@ -1578,6 +1583,7 @@ fireASTriggers(ModifyTableState *node) ...@@ -1578,6 +1583,7 @@ fireASTriggers(ModifyTableState *node)
static void static void
ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate) ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate)
{ {
ModifyTable *plan = (ModifyTable *) mtstate->ps.plan;
ResultRelInfo *targetRelInfo = getTargetResultRelInfo(mtstate); ResultRelInfo *targetRelInfo = getTargetResultRelInfo(mtstate);
/* Check for transition tables on the directly targeted relation. */ /* Check for transition tables on the directly targeted relation. */
...@@ -1585,8 +1591,8 @@ ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate) ...@@ -1585,8 +1591,8 @@ ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate)
MakeTransitionCaptureState(targetRelInfo->ri_TrigDesc, MakeTransitionCaptureState(targetRelInfo->ri_TrigDesc,
RelationGetRelid(targetRelInfo->ri_RelationDesc), RelationGetRelid(targetRelInfo->ri_RelationDesc),
mtstate->operation); mtstate->operation);
if (mtstate->operation == CMD_INSERT && if (plan->operation == CMD_INSERT &&
mtstate->mt_onconflict == ONCONFLICT_UPDATE) plan->onConflictAction == ONCONFLICT_UPDATE)
mtstate->mt_oc_transition_capture = mtstate->mt_oc_transition_capture =
MakeTransitionCaptureState(targetRelInfo->ri_TrigDesc, MakeTransitionCaptureState(targetRelInfo->ri_TrigDesc,
RelationGetRelid(targetRelInfo->ri_RelationDesc), RelationGetRelid(targetRelInfo->ri_RelationDesc),
...@@ -2064,7 +2070,6 @@ ExecModifyTable(PlanState *pstate) ...@@ -2064,7 +2070,6 @@ ExecModifyTable(PlanState *pstate)
slot = ExecPrepareTupleRouting(node, estate, proute, slot = ExecPrepareTupleRouting(node, estate, proute,
resultRelInfo, slot); resultRelInfo, slot);
slot = ExecInsert(node, slot, planSlot, slot = ExecInsert(node, slot, planSlot,
node->mt_arbiterindexes, node->mt_onconflict,
estate, node->canSetTag); estate, node->canSetTag);
/* Revert ExecPrepareTupleRouting's state change. */ /* Revert ExecPrepareTupleRouting's state change. */
if (proute) if (proute)
...@@ -2151,8 +2156,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) ...@@ -2151,8 +2156,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
mtstate->mt_arowmarks = (List **) palloc0(sizeof(List *) * nplans); mtstate->mt_arowmarks = (List **) palloc0(sizeof(List *) * nplans);
mtstate->mt_nplans = 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 */ /* set up epqstate with dummy subplan data for the moment */
EvalPlanQualInit(&mtstate->mt_epqstate, estate, NULL, NIL, node->epqParam); EvalPlanQualInit(&mtstate->mt_epqstate, estate, NULL, NIL, node->epqParam);
...@@ -2195,7 +2198,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags) ...@@ -2195,7 +2198,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
if (resultRelInfo->ri_RelationDesc->rd_rel->relhasindex && if (resultRelInfo->ri_RelationDesc->rd_rel->relhasindex &&
operation != CMD_DELETE && operation != CMD_DELETE &&
resultRelInfo->ri_IndexRelationDescs == NULL) resultRelInfo->ri_IndexRelationDescs == NULL)
ExecOpenIndices(resultRelInfo, mtstate->mt_onconflict != ONCONFLICT_NONE); ExecOpenIndices(resultRelInfo,
node->onConflictAction != ONCONFLICT_NONE);
/* /*
* If this is an UPDATE and a BEFORE UPDATE trigger is present, the * If this is an UPDATE and a BEFORE UPDATE trigger is present, the
......
...@@ -989,9 +989,6 @@ typedef struct ModifyTableState ...@@ -989,9 +989,6 @@ typedef struct ModifyTableState
List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */ List **mt_arowmarks; /* per-subplan ExecAuxRowMark lists */
EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */ EPQState mt_epqstate; /* for evaluating EvalPlanQual rechecks */
bool fireBSTriggers; /* do we need to fire stmt triggers? */ 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 */ TupleTableSlot *mt_existing; /* slot to store existing target tuple in */
List *mt_excludedtlist; /* the excluded pseudo relation's tlist */ List *mt_excludedtlist; /* the excluded pseudo relation's tlist */
TupleTableSlot *mt_conflproj; /* CONFLICT ... SET ... projection target */ TupleTableSlot *mt_conflproj; /* CONFLICT ... SET ... projection target */
......
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