Skip to content

Commit df4e6cc

Browse files
authored
[Minor] Short circuit ApplyFunctionRewrites if there are no function rewrites (#11765)
* Short circuit ApplyFunctionRewrites if there are no function rewrites * Short circuit ApplyFunctionRewrites in the Analyzer itself
1 parent d010ce9 commit df4e6cc

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

datafusion/optimizer/src/analyzer/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,15 @@ impl Analyzer {
136136
// Note this is run before all other rules since it rewrites based on
137137
// the argument types (List or Scalar), and TypeCoercion may cast the
138138
// argument types from Scalar to List.
139-
let expr_to_function: Arc<dyn AnalyzerRule + Send + Sync> =
140-
Arc::new(ApplyFunctionRewrites::new(self.function_rewrites.clone()));
141-
let rules = std::iter::once(&expr_to_function).chain(self.rules.iter());
139+
let expr_to_function: Option<Arc<dyn AnalyzerRule + Send + Sync>> =
140+
if self.function_rewrites.is_empty() {
141+
None
142+
} else {
143+
Some(Arc::new(ApplyFunctionRewrites::new(
144+
self.function_rewrites.clone(),
145+
)))
146+
};
147+
let rules = expr_to_function.iter().chain(self.rules.iter());
142148

143149
// TODO add common rule executor for Analyzer and Optimizer
144150
for rule in rules {

datafusion/sqllogictest/test_files/explain.slt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ EXPLAIN VERBOSE SELECT a, b, c FROM simple_explain_test
176176
initial_logical_plan
177177
01)Projection: simple_explain_test.a, simple_explain_test.b, simple_explain_test.c
178178
02)--TableScan: simple_explain_test
179-
logical_plan after apply_function_rewrites SAME TEXT AS ABOVE
180179
logical_plan after inline_table_scan SAME TEXT AS ABOVE
181180
logical_plan after type_coercion SAME TEXT AS ABOVE
182181
logical_plan after count_wildcard_rule SAME TEXT AS ABOVE

0 commit comments

Comments
 (0)