Re: [BUG] Remove self joins causes 'variable not found in subplan target lists' error

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Sergey Soloviev <sergey.soloviev@tantorlabs.ru>, pgsql-hackers@lists.postgresql.org
Date: 2025-08-26T09:50:26Z
Lists: pgsql-hackers

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 semijoin unique-ification for child relations

  2. Fix "variable not found in subplan target lists" in semijoin de-duplication.

  3. Recalculate where-needed data accurately after a join removal.

On Tue, Aug 26, 2025 at 4:16 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I wrote:
> > Yeah.  I think this is an oversight in create_unique_paths(): it's
> > building an ORDER BY list without consideration for the possibility
> > that some of the entries are known to be constant.  In fact, because
> > make_pathkeys_for_sortclauses will get rid of redundancies, this
> > example actually ends up with a unique_rel whose unique_pathkeys
> > are shorter than the unique_groupclause, which is pretty bogus.
>
> Here is a patch that fixes it that way.  I like this better than
> Sergey's approach because it is making the plans better not worse.

Another question we need to consider is how to fix this error in v18,
where it seems we'll need to remove redundant expressions during
createplan.c.

Thanks
Richard