Re: wrong results: merge when not matched by source

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Jeff Davis <pgsql(at)j-davis(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: wrong results: merge when not matched by source
Date: 2026-09-18 12:51:57
Message-ID: CAHewXNn0m_-puA6NMydF7ku3tRL-J_wn1MM_Wf2KmBiya1zXog@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> 于2026年9月18日周五 20:22写道:
>
> On Fri, 18 Sept 2026, 12:03 Dean Rasheed, <dean(dot)a(dot)rasheed(at)gmail(dot)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?

--
Thanks,
Tender Wang

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Dean Rasheed 2026-09-18 13:08:37 Re: wrong results: merge when not matched by source
Previous Message Dean Rasheed 2026-09-18 12:21:53 Re: wrong results: merge when not matched by source