Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references - Mailing list pgsql-bugs

From Alexander Lakhin
Subject Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references
Date
Msg-id afb7be67-cc8a-42b9-952a-0bd7e8c9f925@gmail.com
Whole thread Raw
In response to Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references
List 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

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5
Next
From: PG Bug reporting form
Date:
Subject: BUG #18966: Invalid SQL queries hang indefinitely until server restart