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

Alexander Lakhin <exclusion@gmail.com>

From: Alexander Lakhin <exclusion@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>, Richard Guo <guofenglinux@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-06-28T06:00:01Z
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

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix some new issues with planning of PlaceHolderVars.

  2. Remove planner's have_dangerous_phv() join-order restriction.