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

From Dean Rasheed
Subject Re: wrong results: merge when not matched by source
Date
Msg-id CAEZATCV7-8tKUo0siqmnAYZ2WUGt1=ZEi5zWJcjqAfL0J_dWBg@mail.gmail.com
Whole thread
In response to Re: wrong results: merge when not matched by source  (Tender Wang <tndrwang@gmail.com>)
List pgsql-bugs
On Fri, 18 Sept 2026, 13:52 Tender Wang, <tndrwang@gmail.com> wrote:
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, it will 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?

Sure. I'm AFK at the moment, so if you want to have a crack at that, I'll take a look when I get back.

Regards,
Dean

pgsql-bugs by date:

Previous
From: Tender Wang
Date:
Subject: Re: wrong results: merge when not matched by source
Next
From: Peter Eisentraut
Date:
Subject: Re: BUG #19545: Integer truncation of `GinTuple.keylen` causes out-of-bounds read in parallel GIN index build