Skip to content

Commit 5d8ec1b

Browse files
committed
Don't rely on uninitialized value in MERGE / DELETE
On MERGE / WHEN MATCHED DELETE it's not possible to get cross-partition updates, so we don't initialize cpUpdateRetrySlot; however, the code was not careful to ignore the value in that case. Make it do so. Backpatch to 15. Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://postgr.es/m/17792-0f89452029662c36@postgresql.org
1 parent 5fd6105 commit 5d8ec1b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,21 +2975,20 @@ lmerge_matched:;
29752975
*/
29762976

29772977
/*
2978-
* If cpUpdateRetrySlot is set, ExecCrossPartitionUpdate()
2979-
* must have detected that the tuple was concurrently
2980-
* updated, so we restart the search for an appropriate
2981-
* WHEN MATCHED clause to process the updated tuple.
2978+
* During an UPDATE, if cpUpdateRetrySlot is set, then
2979+
* ExecCrossPartitionUpdate() must have detected that the
2980+
* tuple was concurrently updated, so we restart the search
2981+
* for an appropriate WHEN MATCHED clause to process the
2982+
* updated tuple.
29822983
*
29832984
* In this case, ExecDelete() would already have performed
29842985
* EvalPlanQual() on the latest version of the tuple,
29852986
* which in turn would already have been loaded into
29862987
* ri_oldTupleSlot, so no need to do either of those
29872988
* things.
2988-
*
2989-
* XXX why do we not check the WHEN NOT MATCHED list in
2990-
* this case?
29912989
*/
2992-
if (!TupIsNull(context->cpUpdateRetrySlot))
2990+
if (commandType == CMD_UPDATE &&
2991+
!TupIsNull(context->cpUpdateRetrySlot))
29932992
goto lmerge_matched;
29942993

29952994
/*

0 commit comments

Comments
 (0)