diff options
Diffstat (limited to '')
-rw-r--r-- | src/backend/executor/nodeModifyTable.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 7f822ef..6fea82e 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -1404,6 +1404,7 @@ ExecDelete(ModifyTableContext *context, bool processReturning, bool changingPart, bool canSetTag, + TM_Result *tmresult, bool *tupleDeleted, TupleTableSlot **epqreturnslot) { @@ -1420,7 +1421,7 @@ ExecDelete(ModifyTableContext *context, * done if it says we are. */ if (!ExecDeletePrologue(context, resultRelInfo, tupleid, oldtuple, - epqreturnslot, NULL)) + epqreturnslot, tmresult)) return NULL; /* INSTEAD OF ROW DELETE Triggers */ @@ -1475,6 +1476,9 @@ ExecDelete(ModifyTableContext *context, ldelete:; result = ExecDeleteAct(context, resultRelInfo, tupleid, changingPart); + if (tmresult) + *tmresult = result; + switch (result) { case TM_SelfModified: @@ -1713,6 +1717,7 @@ ExecCrossPartitionUpdate(ModifyTableContext *context, TupleTableSlot *slot, bool canSetTag, UpdateContext *updateCxt, + TM_Result *tmresult, TupleTableSlot **retry_slot, TupleTableSlot **inserted_tuple, ResultRelInfo **insert_destrel) @@ -1776,7 +1781,7 @@ ExecCrossPartitionUpdate(ModifyTableContext *context, false, /* processReturning */ true, /* changingPart */ false, /* canSetTag */ - &tuple_deleted, &epqslot); + tmresult, &tuple_deleted, &epqslot); /* * For some reason if DELETE didn't happen (e.g. trigger prevented it, or @@ -1808,7 +1813,7 @@ ExecCrossPartitionUpdate(ModifyTableContext *context, * action entirely). */ if (context->relaction != NULL) - return false; + return *tmresult == TM_Ok; else if (TupIsNull(epqslot)) return true; else @@ -2013,6 +2018,7 @@ lreplace: if (ExecCrossPartitionUpdate(context, resultRelInfo, tupleid, oldtuple, slot, canSetTag, updateCxt, + &result, &retry_slot, &inserted_tuple, &insert_destrel)) @@ -2052,7 +2058,7 @@ lreplace: * here; instead let it handle that on its own rules. */ if (context->relaction != NULL) - return TM_Updated; + return result; /* * ExecCrossPartitionUpdate installed an updated version of the new @@ -2879,7 +2885,21 @@ lmerge_matched:; break; /* concurrent update/delete */ } result = ExecUpdateAct(context, resultRelInfo, tupleid, NULL, - newslot, false, &updateCxt); + newslot, canSetTag, &updateCxt); + + /* + * As in ExecUpdate(), if ExecUpdateAct() reports that a + * cross-partition update was done, then there's nothing else + * for us to do --- the UPDATE has been turned into a DELETE + * and an INSERT, and we must not perform any of the usual + * post-update tasks. + */ + if (updateCxt.crossPartUpdate) + { + mtstate->mt_merge_updated += 1; + return true; + } + if (result == TM_Ok && updateCxt.updated) { ExecUpdateEpilogue(context, &updateCxt, resultRelInfo, @@ -3808,7 +3828,7 @@ ExecModifyTable(PlanState *pstate) case CMD_DELETE: slot = ExecDelete(&context, resultRelInfo, tupleid, oldtuple, - true, false, node->canSetTag, NULL, NULL); + true, false, node->canSetTag, NULL, NULL, NULL); break; case CMD_MERGE: |