Re: BUG #19653: "variable not found in subplan target list" during planning with parallel parameterized nested loop,

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: 10215501441(at)stu(dot)ecnu(dot)edu(dot)cn, Robert Haas <robertmhaas(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19653: "variable not found in subplan target list" during planning with parallel parameterized nested loop,
Date: 2026-09-07 02:00:49
Message-ID: CAMbWs49tzZzriJGqZ+1y7njh0=4sMGm3vOvAUmBo8r_Yqp=1SQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Sep 7, 2026 at 2:51 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Right. (For anyone following along at home, the new test case fails
> with "variable not found in subplan target list" if you run it against
> HEAD. You need to apply the first part of Richard's patch to get to
> "failed to assign all NestLoopParams to plan nodes".)

Yes. The second problem is masked until the first one is fixed.
Without the first change, the whole-PHV NestLoopParam never gets
created.

> Hmm, I'm not enamored of just union'ing the top_parent_relids with the
> regular relids. I don't see us doing that anywhere else, so it smells
> like a shortcut. Shouldn't we remove the child relids while adding
> the parent relids?

Yeah, we don't union child relids and parent relids anywhere else, and
I'm not entirely happy with it either. But I'm not sure we can simply
remove the child relids here, because the same set is used for two
different membership tests. For Vars, we check whether var->varno is
a member of the set, and within a child join the Vars carry child
relids. For PlaceHolderVars, we check whether ph_eval_at is a subset
of the set, and ph_eval_at always carries parent relids. So, AFAICS,
the set needs the child relids for the Var test and the parent relids
for the PHV test, and dropping the child relids would break the Var
test.

Maybe an alternative is to keep the set in top-parent terms and
translate each Var's varno to its top parent before the membership
test, or to leave the set alone and instead translate ph_eval_at into
child relids before the subset test. But AFAICS we need to update
quite a few places to make either way work, such as
replace_nestloop_params_mutator(), identify_current_nestloop_params(),
process_subquery_nestloop_params(), and maybe more. Not sure if this
is a better option.

Also, it just occured to me that a child join directly under an Append
that is parameterized by a parent rel keeps the parent relid in its
required-outer set, while its outer relids are child rels. That is to
say, the allleftrelids in identify_current_nestloop_params() is
already a mix of parent relids and child relids.

- Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-09-07 03:13:21 Re: REPACK (CONCURRENTLY) doesn't handle invalid indexes
Previous Message Tom Lane 2026-09-06 17:51:50 Re: BUG #19653: "variable not found in subplan target list" during planning with parallel parameterized nested loop,