Re: BUG #19942: SIGSEGV crash (and wrong results) in MERGE ... RETURNING WITH (OLD/NEW) with VIRTUAL generated colum

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: Kirill Reshke <reshkekirill(at)gmail(dot)com>, 798604270(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19942: SIGSEGV crash (and wrong results) in MERGE ... RETURNING WITH (OLD/NEW) with VIRTUAL generated colum
Date: 2026-12-03 21:50:48
Message-ID: CAEZATCXf2KdrKDiUtwMWn_3okyNMSLXecrib7cbZh97wQ7-16w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 27 Nov 2026 at 09:51, Tender Wang <tndrwang(at)gmail(dot)com> wrote:
>
> Tender Wang <tndrwang(at)gmail(dot)com> 于2026年11月27日周五 14:10写道:
> >
> > One small wording suggestion for the comment: could we change “outer
> > side of the join” to “nullable side of the join”? I initially read
> > “outer side” as referring to the outer input.
>
> One follow-up on v2. When I read the code that builds nullable_relids,
> my first thought was that the set would follow directly from the join
> type.
> In v2, it also reflects which relation references in the expressions
> above the join actually read from the join output.
>
> The part I found less obvious was why the same set works for the
> action quals and RETURNING on a trigger-updatable view.
> ApplyRetrieveRule() leaves the action quals referring to
> mergeTargetRelation and redirects the target Vars in RETURNING to
> resultRelation.
> So adding mergeTargetRelation to the set marks the action quals as
> intended and leaves the RETURNING target Vars alone.
>
> Could we mention that rewrite step in the comment? I think it would
> make the shared marking in transform_MERGE_to_join() easier to follow.

OK, that makes sense. Committed with updated comments and regression tests.

This bug doesn't actually apply to v17, because virtual generated
columns and support for OLD/NEW in RETURNING weren't added until v18.
However, I back-patched it to v17, because 17550c8a had been, and it
helps maintainability to keep transform_MERGE_to_join() the same in
all branches (at least all branches that need to worry about
varnullingrels).

Regards,
Dean

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander Shpilkin 2026-12-03 23:48:08 Package size mismatch for pgdg-redhat-repo-42.0-71 in RHEL 9.8
Previous Message Tom Lane 2026-12-03 21:50:29 Re: btree_gist: <-> fails on same-sign infinite intervals