Skip to content

Commit e2e7354

Browse files
authored
[Minor] Remove/reorder logical plan rules (#15421)
* Remove rules that execute twice * Move optimization rule around
1 parent de8bcc5 commit e2e7354

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

datafusion/optimizer/src/optimizer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ impl Optimizer {
230230
Arc::new(EliminateDuplicatedExpr::new()),
231231
Arc::new(EliminateFilter::new()),
232232
Arc::new(EliminateCrossJoin::new()),
233-
Arc::new(CommonSubexprEliminate::new()),
234233
Arc::new(EliminateLimit::new()),
235234
Arc::new(PropagateEmptyRelation::new()),
236235
// Must be after PropagateEmptyRelation
@@ -243,9 +242,8 @@ impl Optimizer {
243242
Arc::new(SingleDistinctToGroupBy::new()),
244243
// The previous optimizations added expressions and projections,
245244
// that might benefit from the following rules
246-
Arc::new(SimplifyExpressions::new()),
247-
Arc::new(CommonSubexprEliminate::new()),
248245
Arc::new(EliminateGroupByConstant::new()),
246+
Arc::new(CommonSubexprEliminate::new()),
249247
Arc::new(OptimizeProjections::new()),
250248
];
251249

datafusion/optimizer/tests/optimizer_integration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ fn subquery_filter_with_cast() -> Result<()> {
7878
\n SubqueryAlias: __scalar_sq_1\
7979
\n Aggregate: groupBy=[[]], aggr=[[avg(CAST(test.col_int32 AS Float64))]]\
8080
\n Projection: test.col_int32\
81-
\n Filter: __common_expr_5 >= Date32(\"2002-05-08\") AND __common_expr_5 <= Date32(\"2002-05-13\")\
82-
\n Projection: CAST(test.col_utf8 AS Date32) AS __common_expr_5, test.col_int32\
81+
\n Filter: __common_expr_4 >= Date32(\"2002-05-08\") AND __common_expr_4 <= Date32(\"2002-05-13\")\
82+
\n Projection: CAST(test.col_utf8 AS Date32) AS __common_expr_4, test.col_int32\
8383
\n TableScan: test projection=[col_int32, col_utf8]";
8484
assert_eq!(expected, format!("{plan}"));
8585
Ok(())

datafusion/sqllogictest/test_files/explain.slt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ logical_plan after extract_equijoin_predicate SAME TEXT AS ABOVE
187187
logical_plan after eliminate_duplicated_expr SAME TEXT AS ABOVE
188188
logical_plan after eliminate_filter SAME TEXT AS ABOVE
189189
logical_plan after eliminate_cross_join SAME TEXT AS ABOVE
190-
logical_plan after common_sub_expression_eliminate SAME TEXT AS ABOVE
191190
logical_plan after eliminate_limit SAME TEXT AS ABOVE
192191
logical_plan after propagate_empty_relation SAME TEXT AS ABOVE
193192
logical_plan after eliminate_one_union SAME TEXT AS ABOVE
@@ -196,9 +195,8 @@ logical_plan after eliminate_outer_join SAME TEXT AS ABOVE
196195
logical_plan after push_down_limit SAME TEXT AS ABOVE
197196
logical_plan after push_down_filter SAME TEXT AS ABOVE
198197
logical_plan after single_distinct_aggregation_to_group_by SAME TEXT AS ABOVE
199-
logical_plan after simplify_expressions SAME TEXT AS ABOVE
200-
logical_plan after common_sub_expression_eliminate SAME TEXT AS ABOVE
201198
logical_plan after eliminate_group_by_constant SAME TEXT AS ABOVE
199+
logical_plan after common_sub_expression_eliminate SAME TEXT AS ABOVE
202200
logical_plan after optimize_projections TableScan: simple_explain_test projection=[a, b, c]
203201
logical_plan after eliminate_nested_union SAME TEXT AS ABOVE
204202
logical_plan after simplify_expressions SAME TEXT AS ABOVE
@@ -210,7 +208,6 @@ logical_plan after extract_equijoin_predicate SAME TEXT AS ABOVE
210208
logical_plan after eliminate_duplicated_expr SAME TEXT AS ABOVE
211209
logical_plan after eliminate_filter SAME TEXT AS ABOVE
212210
logical_plan after eliminate_cross_join SAME TEXT AS ABOVE
213-
logical_plan after common_sub_expression_eliminate SAME TEXT AS ABOVE
214211
logical_plan after eliminate_limit SAME TEXT AS ABOVE
215212
logical_plan after propagate_empty_relation SAME TEXT AS ABOVE
216213
logical_plan after eliminate_one_union SAME TEXT AS ABOVE
@@ -219,9 +216,8 @@ logical_plan after eliminate_outer_join SAME TEXT AS ABOVE
219216
logical_plan after push_down_limit SAME TEXT AS ABOVE
220217
logical_plan after push_down_filter SAME TEXT AS ABOVE
221218
logical_plan after single_distinct_aggregation_to_group_by SAME TEXT AS ABOVE
222-
logical_plan after simplify_expressions SAME TEXT AS ABOVE
223-
logical_plan after common_sub_expression_eliminate SAME TEXT AS ABOVE
224219
logical_plan after eliminate_group_by_constant SAME TEXT AS ABOVE
220+
logical_plan after common_sub_expression_eliminate SAME TEXT AS ABOVE
225221
logical_plan after optimize_projections SAME TEXT AS ABOVE
226222
logical_plan TableScan: simple_explain_test projection=[a, b, c]
227223
initial_physical_plan DataSourceExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/example.csv]]}, projection=[a, b, c], file_type=csv, has_header=true

datafusion/sqllogictest/test_files/group_by.slt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,9 +4188,8 @@ EXPLAIN SELECT SUM(DISTINCT CAST(x AS DOUBLE)), MAX(DISTINCT CAST(x AS DOUBLE))
41884188
logical_plan
41894189
01)Projection: sum(alias1) AS sum(DISTINCT t1.x), max(alias1) AS max(DISTINCT t1.x)
41904190
02)--Aggregate: groupBy=[[t1.y]], aggr=[[sum(alias1), max(alias1)]]
4191-
03)----Aggregate: groupBy=[[t1.y, __common_expr_1 AS t1.x AS alias1]], aggr=[[]]
4192-
04)------Projection: CAST(t1.x AS Float64) AS __common_expr_1, t1.y
4193-
05)--------TableScan: t1 projection=[x, y]
4191+
03)----Aggregate: groupBy=[[t1.y, CAST(t1.x AS Float64) AS alias1]], aggr=[[]]
4192+
04)------TableScan: t1 projection=[x, y]
41944193
physical_plan
41954194
01)ProjectionExec: expr=[sum(alias1)@1 as sum(DISTINCT t1.x), max(alias1)@2 as max(DISTINCT t1.x)]
41964195
02)--AggregateExec: mode=FinalPartitioned, gby=[y@0 as y], aggr=[sum(alias1), max(alias1)]
@@ -4201,9 +4200,8 @@ physical_plan
42014200
07)------------CoalesceBatchesExec: target_batch_size=2
42024201
08)--------------RepartitionExec: partitioning=Hash([y@0, alias1@1], 8), input_partitions=8
42034202
09)----------------RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1
4204-
10)------------------AggregateExec: mode=Partial, gby=[y@1 as y, __common_expr_1@0 as alias1], aggr=[]
4205-
11)--------------------ProjectionExec: expr=[CAST(x@0 AS Float64) as __common_expr_1, y@1 as y]
4206-
12)----------------------DataSourceExec: partitions=1, partition_sizes=[1]
4203+
10)------------------AggregateExec: mode=Partial, gby=[y@1 as y, CAST(x@0 AS Float64) as alias1], aggr=[]
4204+
11)--------------------DataSourceExec: partitions=1, partition_sizes=[1]
42074205

42084206
# create an unbounded table that contains ordered timestamp.
42094207
statement ok

0 commit comments

Comments
 (0)