Hi Tom,
v2 looks right to me. Here is a case that fails on v16 too, using
plain LATERAL. With Richard's tables it gives 18 rows on 16 to
master, and 6 with v2:
set from_collapse_limit = 1;
set enable_hashjoin = off;
set enable_mergejoin = off;
select t1.*, ss.a from t1, lateral
(select s.a from t1 t3,
(select a from t2 where t2.b > t1.b
union all
select a from t2 where t2.b > t1.b) s) ss
where t1.a = ss.a + t1.b
The original SQL not work for 16 because v16 keeps a correlated I
N sublink as a SubPlan and never makes the semijoin. So we can
use Plain LATERAL to repro it.
Thanks,
Shihao