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>, Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references
Date: 2025-06-28 06:00:01
Message-ID: 6072cd36-8d7b-457a-a7c6-7cf41c05fe6c@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-06-28 07:00:02 BUG #18970: Atempt to alter type of table column used in row type with check leads to assertion failure
Previous Message Tom Lane 2025-06-27 21:37:19 Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references