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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, 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 18:26:58
Message-ID: 2329680.1751135218@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Alexander Lakhin <exclusion(at)gmail(dot)com> writes:
> 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.

> I've discovered a query which fails with an error after a16ef313f with
> both v2 patches applied:

Thank you! That demonstrates an unrelated oversight in a16ef313f:
we need to apply replace_nestloop_params() to the expression of a PHV
that is chosen to be a nestloop param. That's because it could
contain references to Vars/PHVs that will be supplied by some upper
nestloop.

In v3 attached, I moved the SubLink hacking into
identify_current_nestloop_params as suggested above. But
replace_nestloop_params is local to createplan.c, and anyway we can't
run it until all of the current nestloop's NLPs have been removed from
root->curOuterParams, else it might make invalid replacements. So
that has to be done in create_nestloop_plan.

I squashed everything into one patch, too.

regards, tom lane

Attachment Content-Type Size
v3-0001-fix-bug-18953-some-more.patch text/x-diff 20.1 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-06-28 19:13:25 Re: BUG #18971: Server passes an invalid (indirect) path in PGDATA to the external program
Previous Message PG Bug reporting form 2025-06-28 07:17:54 BUG #18971: Server passes an invalid (indirect) path in PGDATA to the external program