Assert failure in get_baserel_parampathinfo with lateral UNION ALL - Mailing list pgsql-hackers

From Richard Guo
Subject Assert failure in get_baserel_parampathinfo with lateral UNION ALL
Date
Msg-id CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com
Whole thread
Responses Re: Assert failure in get_baserel_parampathinfo with lateral UNION ALL
List 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

pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: psql: avoid over-reading unterminated prompt escapes
Next
From: "ZizhuanLiu X-MAN"
Date:
Subject: Re: Optimize MCV stats for sortable types and utilize sorted-order properties