Class SortJoinTransposeRule

All Implemented Interfaces:
TransformationRule

@Enclosing public class SortJoinTransposeRule extends RelRule<SortJoinTransposeRule.Config> implements TransformationRule
Planner rule that pushes a Sort past a Join.

This rule applies to left/right outer joins, and only pushes the sort if its keys are entirely from one input. It will not fire if the sort uses dynamic parameters or the input is already sorted and limited. However, an extension for full outer joins for this rule could be envisioned.

For example, given the SQL:

   select d.deptno, empno from sales.dept d
   right join sales.emp e using (deptno) limit 10 offset 2
 
The initial plan:
   LogicalProject(DEPTNO=[$0], EMPNO=[$2])
     LogicalSort(offset=[2], fetch=[10])
       LogicalJoin(condition=[=($0, $9)], joinType=[right])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 
After applying this rule:
   LogicalProject(DEPTNO=[$0], EMPNO=[$2])
     LogicalSort(offset=[2], fetch=[10])
       LogicalJoin(condition=[=($0, $9)], joinType=[right])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
         LogicalSort(fetch=[12])
           LogicalTableScan(table=[[CATALOG, SALES, EMP]])
 
See Also: