if (!bms_is_subset(ljinfo->lateral_lhs, rel1->relids))
return false; /* rel1 can't compute the required parameter */
if (match_sjinfo &&
- (reversed || match_sjinfo->jointype == JOIN_FULL))
+ (reversed ||
+ unique_ified ||
+ match_sjinfo->jointype == JOIN_FULL))
return false; /* not implementable as nestloop */
}
if (bms_is_subset(ljinfo->lateral_rhs, rel1->relids) &&
if (!bms_is_subset(ljinfo->lateral_lhs, rel2->relids))
return false; /* rel2 can't compute the required parameter */
if (match_sjinfo &&
- (!reversed || match_sjinfo->jointype == JOIN_FULL))
+ (!reversed ||
+ unique_ified ||
+ match_sjinfo->jointype == JOIN_FULL))
return false; /* not implementable as nestloop */
}
}
Output: 3
(11 rows)
+-- check we don't try to do a unique-ified semijoin with LATERAL
+explain (verbose, costs off)
+select * from
+ (values (0,9998), (1,1000)) v(id,x),
+ lateral (select f1 from int4_tbl
+ where f1 = any (select unique1 from tenk1
+ where unique2 = v.x offset 0)) ss;
+ QUERY PLAN
+----------------------------------------------------------------------
+ Nested Loop
+ Output: "*VALUES*".column1, "*VALUES*".column2, int4_tbl.f1
+ -> Values Scan on "*VALUES*"
+ Output: "*VALUES*".column1, "*VALUES*".column2
+ -> Nested Loop Semi Join
+ Output: int4_tbl.f1
+ Join Filter: (int4_tbl.f1 = tenk1.unique1)
+ -> Seq Scan on public.int4_tbl
+ Output: int4_tbl.f1
+ -> Materialize
+ Output: tenk1.unique1
+ -> Index Scan using tenk1_unique2 on public.tenk1
+ Output: tenk1.unique1
+ Index Cond: (tenk1.unique2 = "*VALUES*".column2)
+(14 rows)
+
+select * from
+ (values (0,9998), (1,1000)) v(id,x),
+ lateral (select f1 from int4_tbl
+ where f1 = any (select unique1 from tenk1
+ where unique2 = v.x offset 0)) ss;
+ id | x | f1
+----+------+----
+ 0 | 9998 | 0
+(1 row)
+
-- test some error cases where LATERAL should have been used but wasn't
select f1,g from int4_tbl a, (select f1 as g) ss;
ERROR: column "f1" does not exist
select * from (select 3 as z offset 0) z where z.z = x.x
) zz on zz.z = y.y;
+-- check we don't try to do a unique-ified semijoin with LATERAL
+explain (verbose, costs off)
+select * from
+ (values (0,9998), (1,1000)) v(id,x),
+ lateral (select f1 from int4_tbl
+ where f1 = any (select unique1 from tenk1
+ where unique2 = v.x offset 0)) ss;
+select * from
+ (values (0,9998), (1,1000)) v(id,x),
+ lateral (select f1 from int4_tbl
+ where f1 = any (select unique1 from tenk1
+ where unique2 = v.x offset 0)) ss;
+
-- test some error cases where LATERAL should have been used but wasn't
select f1,g from int4_tbl a, (select f1 as g) ss;
select f1,g from int4_tbl a, (select a.f1 as g) ss;