Re: wrong results: merge when not matched by source - Mailing list pgsql-bugs

From Tender Wang
Subject Re: wrong results: merge when not matched by source
Date
Msg-id CAHewXNn0m_-puA6NMydF7ku3tRL-J_wn1MM_Wf2KmBiya1zXog@mail.gmail.com
Whole thread
In response to Re: wrong results: merge when not matched by source  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: wrong results: merge when not matched by source
Re: wrong results: merge when not matched by source
List pgsql-bugs
Dean Rasheed <dean.a.rasheed@gmail.com> 于2026年9月18日周五 20:22写道:
>
> On Fri, 18 Sept 2026, 12:03 Dean Rasheed, <dean.a.rasheed@gmail.com> wrote:
>>
>>
>> That fix looks good to me. Nice and simple.
>
>
> Actually, the last part of the new comment is wrong/unnecessary. If it changes matched from true to false, retrying,
itwill have locked the target tuple, and it can't be concurrently deleted when it retries. It never retries more than
once.So the comment can be simplified a bit. 
>

Thanks for confirming.

I also noticed the following part of the comment at the beginning of
`ExecMerge()`:

...
If the target tuple gets deleted or a concurrent update causes the join
quals to fail, it returns a matched status of false and we call
ExecMergeNotMatched().
...

With this change, perhaps this part of the comment should also be
adjusted to distinguish an original `WHEN MATCHED` case from an
original `WHEN NOT MATCHED BY SOURCE` case.

For the former, a concurrent delete leaves the source tuple to be
processed by `WHEN NOT MATCHED [BY TARGET]` actions, whereas for the
latter, neither a source tuple nor a target tuple remains, so there is
no further action to execute.

Do you think it's worth updating this comment as part of the patch?


--
Thanks,
Tender Wang



pgsql-bugs by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: wrong results: merge when not matched by source
Next
From: Dean Rasheed
Date:
Subject: Re: wrong results: merge when not matched by source