Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, Richard Guo <guofenglinux(at)gmail(dot)com>
Subject: Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references
Date: 2025-06-24 07:00:00
Message-ID: afb7be67-cc8a-42b9-952a-0bd7e8c9f925@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello Tom and Richard,

23.06.2025 21:24, Tom Lane wrote:
> Anyway, with one eye on the possibility that we'll need to back-patch
> this in some form, I went for the localized fix of ensuring that
> we use a copy of the PHV that's been through the normal processing.
> I do want to look into restructuring the handling of these PHVs
> to make this less messy, but that's not a job to undertake for v18
> (much less if we have to back-patch).

I've managed to discover one more anomaly introduced by a16ef313f, that is
not fixed by fix-bug-18953-some-more:
CREATE TABLE t(i int PRIMARY KEY);

MERGE INTO t
USING
  (SELECT 1 AS j FROM generate_series(1, 1))
  RIGHT JOIN (SELECT 1) ON true
  LEFT JOIN (SELECT 1 FROM (SELECT 1 FROM generate_series(1, 1))) ON false
ON i = j
WHEN NOT MATCHED THEN INSERT VALUES (1);
ERROR:  XX000: wrong phnullingrels (b) (expected (b 4)) for PlaceHolderVar 1
LOCATION:  search_indexed_tlist_for_phv, setrefs.c:2958

Thank you for spending your time on this!

Best regards,
Alexander

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-06-24 14:10:08 BUG #18966: Invalid SQL queries hang indefinitely until server restart
Previous Message Masahiko Sawada 2025-06-24 05:14:41 Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5