gpg: Firmado el mar 14 feb 2023 20:17:10 CET
gpg:                usando RSA clave E2C96E4A9BCA7E92A8E3DA551C20ACB9D5C564AE
gpg: Firma correcta de "Álvaro Herrera <alvherre@alvh.no-ip.org>" [absoluta]
gpg:                 alias "Álvaro Herrera (PostgreSQL Global Development Group) <alvherre@postgresql.org>" [absoluta]
gpg:                 alias "Álvaro Herrera (2ndQuadrant) <alvherre@2ndQuadrant.com>" [absoluta]
commit 14242c4f5bebb21f945c3f8f43b02d34bb060807
Author:     Alvaro Herrera <alvherre@alvh.no-ip.org> [Álvaro Herrera <alvherre@alvh.no-ip.org>]
AuthorDate: Tue Feb 14 19:26:51 2023 +0100
CommitDate: Tue Feb 14 20:17:10 2023 +0100

    fix crash on mis-set cpUpdateRetrySlot

diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 1ac65172e4..c4b845160d 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -2967,21 +2967,20 @@ lmerge_matched:
 					 */
 
 					/*
-					 * If cpUpdateRetrySlot is set, ExecCrossPartitionUpdate()
-					 * must have detected that the tuple was concurrently
-					 * updated, so we restart the search for an appropriate
-					 * WHEN MATCHED clause to process the updated tuple.
+					 * During an UPDATE, if cpUpdateRetrySlot is set, then
+					 * ExecCrossPartitionUpdate() must have detected that the
+					 * tuple was concurrently updated, so we restart the search
+					 * for an appropriate WHEN MATCHED clause to process the
+					 * updated tuple.
 					 *
 					 * In this case, ExecDelete() would already have performed
 					 * EvalPlanQual() on the latest version of the tuple,
 					 * which in turn would already have been loaded into
 					 * ri_oldTupleSlot, so no need to do either of those
 					 * things.
-					 *
-					 * XXX why do we not check the WHEN NOT MATCHED list in
-					 * this case?
 					 */
-					if (!TupIsNull(context->cpUpdateRetrySlot))
+					if (commandType == CMD_UPDATE &&
+						!TupIsNull(context->cpUpdateRetrySlot))
 						goto lmerge_matched;
 
 					/*
