Re: wrong results: merge when not matched by source

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tender Wang <tndrwang(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 13:08:37
Message-ID: CAEZATCV7-8tKUo0siqmnAYZ2WUGt1=ZEi5zWJcjqAfL0J_dWBg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 18 Sept 2026, 13:52 Tender Wang, <tndrwang(at)gmail(dot)com> wrote:

> 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?
>

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

>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2026-09-18 14:37:21 Re: BUG #19545: Integer truncation of `GinTuple.keylen` causes out-of-bounds read in parallel GIN index build
Previous Message Tender Wang 2026-09-18 12:51:57 Re: wrong results: merge when not matched by source