Re: Fix stale source values in MERGE RETURNING after a cross-partition update

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix stale source values in MERGE RETURNING after a cross-partition update
Date: 2026-11-23 12:32:08
Message-ID: CAEZATCVTXSiLO_sZGt471jYsq8jJXuMsbhbf9zX8aZ4aiGE3KA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 23 Nov 2026 at 09:11, Tender Wang <tndrwang(at)gmail(dot)com> wrote:
>
> Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> 于2026年11月22日周日 19:32写道:
> >
> > I think a better (more localised) solution is to have
> > ExecMergeMatched() swap out context->planSlot while it executes the
> > NOT MATCHED BY SOURCE action. That feels more robust, because it
> > removes any chance of any code called while executing the action
> > seeing the old stale source values. Something like v2, attached.
> >
> Yeah, I agree that temporarily replacing context->planSlot in
> ExecMergeMatched() is cleaner.
> It gives the entire NOT MATCHED BY SOURCE action a consistent view of
> the source row, including the cross-partition RETURNING path.
> Restoring the original slot before returning also makes it available
> to any subsequent NOT MATCHED BY TARGET action.
>
> > Also, I don't think merge-match-recheck is the right place to test
> > this, since it's not about rechecking AND conditions. I've added new
> > tests to merge-not-matched, based on the ones added before for bug
> > #19912, testing both left and full joins.
>
> +1

Pushed and back-patched to v17.

Regards,
Dean

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Rajesh Kumar Thandapani 2026-11-23 12:39:34 Re: Bug in logical decoding with DDL and subtransactions
Previous Message Shlok Kyal 2026-11-23 12:22:58 Re: Initial table sync copies the whole table when it is no longer published