组装SQL优化的类有org.apache.flink.table.planner.plan.optimize.program.FlinkStreamProgram
, org.apache.flink.table.planner.plan.optimize.program.FlinkBatchProgram
, 这两个类里面会组装一些用于SQL优化的Rule。在优化的时候会不断的遍历这些规则进行优化。
Rule
EnumerableToLogicalTableScan
�converts an EnumerableTableScan into a LogicalTableScan
SimplifyFilterConditionRule
Merges same expressions and then simplifies the result expression by [[RexSimplify]].
Examples for merging same expressions:
1. a = b AND b = a -> a = b
2. a = b OR b = a -> a = b
3. (a > b AND c < 10) AND b < a -> a > b AND c < 10
4. (a > b OR c < 10) OR b < a -> a > b OR c < 10
5. a = a, a >= a, a <= a -> true
6. a <> a, a > a, a < a -> false
FlinkRewriteSubQueryRule
select * from T1 where (select count(*) from T2) > 0
toselect * from T1 where exists (select * from T2)
,
which could be converted to SEMI join by [[FlinkSubQueryRemoveRule]]