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 6072cd36-8d7b-457a-a7c6-7cf41c05fe6c@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>)
List pgsql-bugs
Hello Tom and Richard,

28.06.2025 00:37, Tom Lane wrote:
... BTW, looking at these two patches again, I wonder if it'd be
better to put the hackery for SubLink conversion into
identify_current_nestloop_params?  That'd remove the need to argue
that we don't have to fix both copies of a nestloop-parameter PHV.
The responsibility doesn't clearly belong to
identify_current_nestloop_params, but it doesn't clearly belong
to create_nestloop_plan either, so neither choice seems superior
from a modularity standpoint.

I've discovered a query which fails with an error after a16ef313f with
both v2 patches applied:
create temp table t(i int primary key);
select * from
    (select k from
        (select i, coalesce(i, j) as k from
            (select i from t union all select 1)
            join (select 1 as j limit 1) on i = j)
        right join (select 1) on true
        join (select 1) on i is not null
    ),
    lateral (select k offset 1);
ERROR:  XX000: variable not found in subplan target list
LOCATION:  fix_upper_expr_mutator, setrefs.c:3310

Thank you for working on this!

Best regards,
Alexander

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references
Next
From: PG Bug reporting form
Date:
Subject: BUG #18970: Atempt to alter type of table column used in row type with check leads to assertion failure