| From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
|---|---|
| To: | Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Subject: | Re: ERROR: unsupported join alias expression |
| Date: | 2026-09-19 05:38:36 |
| Message-ID: | CAMbWs4-c6bOzULdVduPaReK4s0Pui1=iJshStjNF5GG-h+wuSQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, Sep 17, 2026 at 3:45 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> Fuzzing with Claude on add_nullingrels_if_needed() found two cases
> that fail with $subject.
>
> create table t (a int);
>
> -- 1
> select count(j) from t x left join (t b cross join t c) j on true;
> ERROR: unsupported join alias expression
>
> -- 2
> select (select j) from t x
> left join ((select from t) b cross join (select from t) c) j on x.a = 1;
> ERROR: unsupported join alias expression
Some more bugs exist in add_nullingrels_if_needed().
-- 3
select j from t t1 left join
(lateral (values (t1.a)) as v(a) cross join t t2) as j on true, t t3;
ERROR: wrong phnullingrels (b 5) (expected (b)) for PlaceHolderVar 2
-- 4 Wrong result
insert into t values (1);
select (j is null) from t t1
left join (t t2 join lateral (select t1.a from (values (3)) v) ss(x)
on true) as j
on false;
?column?
----------
f
(1 row)
-- 5
select 1 from (unnest(array[1, (select sum(a) from t t1)]) as u(b)
right join (values (1)) as v(b) using (b)
full join t t2 on true) as j,
length(j::text) f;
ERROR: wrong phnullingrels (b 3 5) (expected (b 5)) for PlaceHolderVar 1
For 3 and 4, the problem is that if a LATERAL subquery under an inner
join has been pulled up, the join's alias list can contain a bare
lateral reference to a rel outside the join. That rel then ends up in
phrels, so the PHV is evaluated above the outer join that is supposed
to null it.
For 5, the problem is that for a variable-free expression we fall back
to the join's relids but remove the join's own outer-join relid. That
leaves a set spanning both sides of the outer join without the join
itself.
I've updated 0002 to fix all of these bugs in one go. 0001 is
unchanged.
- Richard
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-parser-failure-with-whole-row-join-alias-Vars.patch | application/octet-stream | 5.2 KB |
| v2-0002-Fix-PlaceHolderVar-placement-for-join-alias-expre.patch | application/octet-stream | 16.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Corey Huinker | 2026-09-19 05:00:26 | Re: [PG19][PATCH] Make postgres_fdw statistics import atomic |