Class IntersectToSemiJoinRule

All Implemented Interfaces:
TransformationRule

@Enclosing public class IntersectToSemiJoinRule extends RelRule<IntersectToSemiJoinRule.Config> implements TransformationRule
Planner rule that translates a Intersect to a series of Join that type is JoinRelType.SEMI. This rule supports n-way Intersect conversion, as this rule can be repeatedly applied during query optimization to refine the plan.

Example

Original sql:


 select ename from emp where deptno = 10
 intersect
 select deptno from emp where ename in ('a', 'b')
 intersect
 select ename from empnullables
 

Original plan:


 LogicalIntersect(all=[false])
   LogicalProject(ENAME=[$1])
     LogicalFilter(condition=[=($7, 10)])
       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
   LogicalProject(DEPTNO=[CAST($7):VARCHAR NOT NULL])
     LogicalFilter(condition=[OR(=($1, 'a'), =($1, 'b'))])
       LogicalTableScan(table=[[CATALOG, SALES, EMP]])
   LogicalProject(ENAME=[$1])
     LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])
 

Plan after conversion:


 LogicalProject(ENAME=[CAST($0):VARCHAR])
   LogicalAggregate(group=[{0}])
     LogicalJoin(condition=[<=>(CAST($0):VARCHAR, CAST($1):VARCHAR)], joinType=[semi])
       LogicalJoin(condition=[=(CAST($0):VARCHAR, $1)], joinType=[semi])
         LogicalProject(ENAME=[$1])
           LogicalFilter(condition=[=($7, 10)])
             LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalProject(DEPTNO=[CAST($7):VARCHAR NOT NULL])
           LogicalFilter(condition=[OR(=($1, 'a'), =($1, 'b'))])
             LogicalTableScan(table=[[CATALOG, SALES, EMP]])
       LogicalProject(ENAME=[$1])
         LogicalTableScan(table=[[CATALOG, SALES, EMPNULLABLES]])