subquery pullup misses lateral refs in join alias Vars
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253854psql -h localhost -U postgresBuilt from patchset v1 (message #1), September 20, 2026 at 07:28 AM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t253854_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t253854_1 && git checkout t253854_1Patchset v1 (message #1) is on t253854_1
is_simple_subquery() refuses to pull up a LATERAL subquery whose
targetlist or quals reference rels outside the lowest outer join above
it. But pull_up_simple_subquery() rechecks this before flattening
join alias Vars in the subquery, so a lateral reference hidden in a
join Var goes unnoticed. Both queries below hit Assert("sjinfo ==
NULL") in distribute_qual_to_rels():
create table t (a int);
-- hidden in the subquery's targetlist
select 1 from t t1,
lateral (select (j is null)::int
from ((select t1.a) s left join (select 1) v on false) j) ss(x)
left join t t2 on ss.x = t2.a;
-- hidden in the subquery's quals
select 1 from t t1,
t t2 left join
lateral (select 1 from ((select t1.a) s left join (select 1) v on false) j
where length(j::text) > 3) ss on true;
Without asserts, the second fails with "wrong phnullingrels".
I think we should flatten join alias Vars in the subquery's targetlist
and quals before the recheck. Attached is a WIP patch doing that.
- Richard