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

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(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-11-27 09:51:37
Message-ID: CAHewXNmQAQgbry1XFbyAWiGxvM4V6mFxwiF5wbbP-vX6SGH-PQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tender Wang <tndrwang(at)gmail(dot)com> 于2026年11月27日周五 14:10写道:
>
> Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> 于2026年11月26日周四 22:43写道:
> > So I was thinking of something more like the attached v2.
>
> Thanks for the v2 patch. I traced the rewrite through
> ApplyRetrieveRule(). For a trigger-updatable view,
> the action quals still reference the expanded view subquery via
> mergeTargetRelation, while the target Vars in RETURNING are redirected
> to resultRelation.
> That explains why the same nullable_relids set works for both. I’m
> happy to go with v2.
>
> 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.

--
Tender Wang

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Nitin Motiani 2026-11-27 12:09:52 Re: BUG #19931: postgres_fdw: FOR UPDATE over a pushed-down join ignores a pseudoconstant qual
Previous Message Kirill Reshke 2026-11-27 09:40:27 Re: PostgreSQL 17.11: SIGSEGV in dsa_free after "could not resize shared memory segment ... No space left on device"