fn build_join_top(
query_info: &SubqueryInfo,
left: &LogicalPlan,
alias: &Arc<AliasGenerator>,
) -> Result<Option<LogicalPlan>>Expand description
Optimize the subquery to left-anti/left-semi join. If the subquery is a correlated subquery, we need extract the join predicate from the subquery.
For example, given a query like:
select t1.a, t1.b from t1 where t1 in (select t2.a from t2 where t1.b = t2.b and t1.c > t2.c)
The optimized plan will be:
Projection: t1.a, t1.b
LeftSemi Join: Filter: t1.a = __correlated_sq_1.a AND t1.b = __correlated_sq_1.b AND t1.c > __correlated_sq_1.c
TableScan: t1
SubqueryAlias: __correlated_sq_1
Projection: t2.a, t2.b, t2.c
TableScan: t2Given another query like:
select t1.id from t1 where exists(SELECT t2.id FROM t2 WHERE t1.id = t2.id)
The optimized plan will be:
Projection: t1.id
LeftSemi Join: Filter: t1.id = __correlated_sq_1.id
TableScan: t1
SubqueryAlias: __correlated_sq_1
Projection: t2.id
TableScan: t2