Re: [PG19] Wrong results from NOT NULL-based expression simplification

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Guofenglinux <guofenglinux(at)gmail(dot)com>
Subject: Re: [PG19] Wrong results from NOT NULL-based expression simplification
Date: 2026-11-12 09:58:28
Message-ID: CAEZATCU05Lyjw0jp0K3QZuCzQv1zwx6_vasmK79_4FCU_7zzJQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 6 Oct 2026 at 04:28, shihao zhong <zhong950419(at)gmail(dot)com> wrote:
>
> 2. With a join as the MERGE source, only Vars of the join RTE are
> marked nullable for NOT MATCHED BY SOURCE, not Vars of the tables
> under it.
> create table mt (id int);
> create table sa (id int not null);
> create table sb (id int);
> insert into mt values (1);
> merge into mt using (sa join sb on sa.id = sb.id) on mt.id = sa.id
> when not matched by source then delete
> returning sa.id is null;
> 18 returns t, 19 returns f. 0002 marks them all.
>
> The marking comes from 259a0a99fe3, the fix for bug #18634, which is
> also in 17 and 18. It covers a source that is one table, but not a
> join. On 18 that does not give wrong values, but planning can fail
> with "wrong varnullingrels", the error from that bug. So I think 0002
> should be back-patched to 17.

Thanks for the report. Your analysis and fix look correct.

I've pushed and back-patched the patch, with some cosmetic
adjustments, and I expanded the tests to cover both cases (wrong
results and "wrong varnullingrels" error).

Regards,
Dean

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-11-12 10:06:02 Re: Add a hook for handling logical decoding messages on subscribers.
Previous Message Nikhil Sontakke 2026-11-12 09:56:37 Fix CYCLE clause deparsing and dump/restore