From 7b14e20b12cc8358cad9bdd05dd6b7de7f73c431 Mon Sep 17 00:00:00 2001 From: Dean Rasheed Date: Mon, 13 Mar 2023 11:09:39 +0000 Subject: Fix MERGE command tag for actions blocked by BEFORE ROW triggers. This ensures that the row count in the command tag for a MERGE is correctly computed in the case where UPDATEs or DELETEs are skipped due to a BEFORE ROW trigger returning NULL (the INSERT case was already handled correctly by ExecMergeNotMatched() calling ExecInsert()). Back-patch to v15, where MERGE was introduced. Discussion: https://postgr.es/m/CAEZATCU8XEmR0JWKDtyb7iZ%3DqCffxS9uyJt0iOZ4TV4RT%2Bow1w%40mail.gmail.com --- src/backend/executor/nodeModifyTable.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/backend/executor/nodeModifyTable.c') diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index e8d655868ae..3fa2b930a52 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -2883,8 +2883,9 @@ lmerge_matched: if (!ExecUpdatePrologue(context, resultRelInfo, tupleid, NULL, newslot, &result)) { - /* Blocked by trigger, or concurrent update/delete */ - break; + if (result == TM_Ok) + return true; /* "do nothing" */ + break; /* concurrent update/delete */ } result = ExecUpdateAct(context, resultRelInfo, tupleid, NULL, newslot, false, &updateCxt); @@ -2901,8 +2902,9 @@ lmerge_matched: if (!ExecDeletePrologue(context, resultRelInfo, tupleid, NULL, NULL, &result)) { - /* Blocked by trigger, or concurrent update/delete */ - break; + if (result == TM_Ok) + return true; /* "do nothing" */ + break; /* concurrent update/delete */ } result = ExecDeleteAct(context, resultRelInfo, tupleid, false); if (result == TM_Ok) -- cgit v1.2.3