Re: ERROR: too late to create a new PlaceHolderInfo

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: ERROR: too late to create a new PlaceHolderInfo
Date: 2026-11-05 02:25:30
Message-ID: CAMbWs4874sZ3prYDx0ZEEWJRAO0OrT0OV0D19oMBjE=mAO5EOw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I found that v2 still has a loose end at the pull_up_simple_subquery
boundary. When a subquery is pulled up, its targetlist, and its
jointree quals if it is LATERAL, are flattened using the subroot,
while the rest of it is flattened later using the parent root. Since
each root has its own join_alias_phvs, an alias Var that appears in
both places still gets two different PHVs:

select *
from (select v.k
from t t1 left join (t t2 join t t3 on true) j on true
left join lateral (select j as k from t t4) v on true
where v.k is not null) ss;
ERROR: too late to create a new PlaceHolderInfo

Here the PHV that pullup makes for v.k ends up in both the targetlist
and the WHERE clause of ss. The j inside it is expanded by ss's
subroot in one copy and by the parent root in the other.

To fix, attached v3 makes pull_up_simple_subquery handle the subroot's
join_alias_phvs the same way as its append_rel_list: adjust it with
OffsetVarNodes and IncrementVarSublevelsUp, then append it to the
parent's list, so that the parent's flattening reuses the subroot's
PHVs.

I'd like to push this to master and v19, and leave v18 and older
alone due to ABI concerns.

I plan to push it soon, after going over the code a bit more, so that
I have at least some time to react to any bugs found by the automated
LLM-based tools that now scan new commits.

- Richard

Attachment Content-Type Size
v3-0001-Fix-mismatched-PHVs-for-join-alias-Vars-flattened.patch application/octet-stream 19.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo Nagata 2026-11-05 02:25:58 Re: Track skipped tables during autovacuum and autoanalyze
Previous Message Manu 2026-11-05 02:16:43 Re: Add a hint to the "WAL summaries are required" errors