@@ -47,7 +47,62 @@ abstract class Optimizer(sessionCatalog: SessionCatalog)
47
47
protected def fixedPoint = FixedPoint (SQLConf .get.optimizerMaxIterations)
48
48
49
49
def batches : Seq [Batch ] = {
50
- Batch (" Eliminate Distinct" , Once , EliminateDistinct ) ::
50
+ val operatorOptimizationRuleSet =
51
+ Seq (
52
+ // Operator push down
53
+ PushProjectionThroughUnion ,
54
+ ReorderJoin ,
55
+ EliminateOuterJoin ,
56
+ PushPredicateThroughJoin ,
57
+ PushDownPredicate ,
58
+ LimitPushDown ,
59
+ ColumnPruning ,
60
+ InferFiltersFromConstraints ,
61
+ // Operator combine
62
+ CollapseRepartition ,
63
+ CollapseProject ,
64
+ CollapseWindow ,
65
+ CombineFilters ,
66
+ CombineLimits ,
67
+ CombineUnions ,
68
+ // Constant folding and strength reduction
69
+ NullPropagation ,
70
+ ConstantPropagation ,
71
+ FoldablePropagation ,
72
+ OptimizeIn ,
73
+ ConstantFolding ,
74
+ ReorderAssociativeOperator ,
75
+ LikeSimplification ,
76
+ BooleanSimplification ,
77
+ SimplifyConditionals ,
78
+ RemoveDispensableExpressions ,
79
+ SimplifyBinaryComparison ,
80
+ PruneFilters ,
81
+ EliminateSorts ,
82
+ SimplifyCasts ,
83
+ SimplifyCaseConversionExpressions ,
84
+ RewriteCorrelatedScalarSubquery ,
85
+ EliminateSerialization ,
86
+ RemoveRedundantAliases ,
87
+ RemoveRedundantProject ,
88
+ SimplifyCreateStructOps ,
89
+ SimplifyCreateArrayOps ,
90
+ SimplifyCreateMapOps ,
91
+ CombineConcats ) ++
92
+ extendedOperatorOptimizationRules
93
+
94
+ val operatorOptimizationBatch : Seq [Batch ] = {
95
+ val rulesWithoutInferFiltersFromConstraints =
96
+ operatorOptimizationRuleSet.filterNot(_ == InferFiltersFromConstraints )
97
+ Batch (" Operator Optimization before Inferring Filters" , fixedPoint,
98
+ rulesWithoutInferFiltersFromConstraints : _* ) ::
99
+ Batch (" Infer Filters" , Once ,
100
+ InferFiltersFromConstraints ) ::
101
+ Batch (" Operator Optimization after Inferring Filters" , fixedPoint,
102
+ rulesWithoutInferFiltersFromConstraints : _* ) :: Nil
103
+ }
104
+
105
+ (Batch (" Eliminate Distinct" , Once , EliminateDistinct ) ::
51
106
// Technically some of the rules in Finish Analysis are not optimizer rules and belong more
52
107
// in the analyzer, because they are needed for correctness (e.g. ComputeCurrentTime).
53
108
// However, because we also use the analyzer to canonicalized queries (for view definition),
@@ -81,68 +136,26 @@ abstract class Optimizer(sessionCatalog: SessionCatalog)
81
136
ReplaceDistinctWithAggregate ) ::
82
137
Batch (" Aggregate" , fixedPoint,
83
138
RemoveLiteralFromGroupExpressions ,
84
- RemoveRepetitionFromGroupExpressions ) ::
85
- Batch (" Operator Optimizations" , fixedPoint, Seq (
86
- // Operator push down
87
- PushProjectionThroughUnion ,
88
- ReorderJoin ,
89
- EliminateOuterJoin ,
90
- InferFiltersFromConstraints ,
91
- BooleanSimplification ,
92
- PushPredicateThroughJoin ,
93
- PushDownPredicate ,
94
- LimitPushDown ,
95
- ColumnPruning ,
96
- // Operator combine
97
- CollapseRepartition ,
98
- CollapseProject ,
99
- CollapseWindow ,
100
- CombineFilters ,
101
- CombineLimits ,
102
- CombineUnions ,
103
- // Constant folding and strength reduction
104
- NullPropagation ,
105
- ConstantPropagation ,
106
- FoldablePropagation ,
107
- OptimizeIn ,
108
- ConstantFolding ,
109
- ReorderAssociativeOperator ,
110
- LikeSimplification ,
111
- BooleanSimplification ,
112
- SimplifyConditionals ,
113
- RemoveDispensableExpressions ,
114
- SimplifyBinaryComparison ,
115
- PruneFilters ,
116
- EliminateSorts ,
117
- SimplifyCasts ,
118
- SimplifyCaseConversionExpressions ,
119
- RewriteCorrelatedScalarSubquery ,
120
- EliminateSerialization ,
121
- RemoveRedundantAliases ,
122
- RemoveRedundantProject ,
123
- SimplifyCreateStructOps ,
124
- SimplifyCreateArrayOps ,
125
- SimplifyCreateMapOps ,
126
- CombineConcats ) ++
127
- extendedOperatorOptimizationRules : _* ) ::
139
+ RemoveRepetitionFromGroupExpressions ) :: Nil ++
140
+ operatorOptimizationBatch) :+
128
141
Batch (" Join Reorder" , Once ,
129
- CostBasedJoinReorder ) ::
142
+ CostBasedJoinReorder ) :+
130
143
Batch (" Decimal Optimizations" , fixedPoint,
131
- DecimalAggregates ) ::
144
+ DecimalAggregates ) :+
132
145
Batch (" Object Expressions Optimization" , fixedPoint,
133
146
EliminateMapObjects ,
134
- CombineTypedFilters ) ::
147
+ CombineTypedFilters ) :+
135
148
Batch (" LocalRelation" , fixedPoint,
136
149
ConvertToLocalRelation ,
137
- PropagateEmptyRelation ) ::
150
+ PropagateEmptyRelation ) :+
138
151
// The following batch should be executed after batch "Join Reorder" and "LocalRelation".
139
152
Batch (" Check Cartesian Products" , Once ,
140
- CheckCartesianProducts ) ::
153
+ CheckCartesianProducts ) :+
141
154
Batch (" RewriteSubquery" , Once ,
142
155
RewritePredicateSubquery ,
143
156
ColumnPruning ,
144
157
CollapseProject ,
145
- RemoveRedundantProject ) :: Nil
158
+ RemoveRedundantProject )
146
159
}
147
160
148
161
/**
0 commit comments