| From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
|---|---|
| To: | Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Assert failure in get_baserel_parampathinfo with lateral UNION ALL |
| Date: | 2026-09-21 03:39:48 |
| Message-ID: | CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
The following query trips the Assert(join_clause_is_movable_into(...))
in get_baserel_parampathinfo():
create table t (a int, b int);
select * from t t1 left join t t2 on t1.a = t2.a,
lateral (select 1 as x union all select t1.a + t2.b) s
where t1.b = s.x;
What happens is that after the UNION ALL subquery is flattened, the
child EC member for the second branch is the expression "t1.a + t2.b",
where t2.b is nulled by the left join. create_join_clause() builds
the child clause "t1.b = t1.a + t2.b" with make_restrictinfo(), so its
clause_relids are computed from the expression: t1, t2 and the outer
join, plus the child's relid added by commit 03107b4ed. But the child
is parameterized by its lateral_relids, which list only baserels, so
the outer join's relid is never available and the Assert fails.
I think we should set a child clause's clause_relids to the union of
its members' em_relids instead. The lateral references need not be
represented there, since every path for the child is parameterized by
at least its lateral_relids. It is also what a child's non-EC join
clauses already get: for "t1.b < s.x", adjust_appendrel_attrs()
translates the parent clause's relids {t1, s} to {t1, child} rather
than recomputing them from the translated expression, so the lateral
references do not appear there either. For child clauses without
lateral references the resulting relids are the same as before.
Thoughts?
- Richard
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-relids-of-EC-derived-join-clauses-for-lateral.patch | application/octet-stream | 10.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | ZizhuanLiu X-MAN | 2026-09-21 03:40:34 | Re: Optimize MCV stats for sortable types and utilize sorted-order properties |
| Previous Message | Chao Li | 2026-09-21 03:30:16 | psql: avoid over-reading unterminated prompt escapes |