Skip to content

Commit 6ffed55

Browse files
authored
Speed up optimize_projection by improving is_projection_unnecessary (#15761)
1 parent 66a7423 commit 6ffed55

File tree

1 file changed

+5
-1
lines changed
  • datafusion/optimizer/src/optimize_projections

1 file changed

+5
-1
lines changed

datafusion/optimizer/src/optimize_projections/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,12 @@ fn rewrite_projection_given_requirements(
786786
/// - input schema of the projection, output schema of the projection are same, and
787787
/// - all projection expressions are either Column or Literal
788788
fn is_projection_unnecessary(input: &LogicalPlan, proj_exprs: &[Expr]) -> Result<bool> {
789+
// First check if all expressions are trivial (cheaper operation than `projection_schema`)
790+
if !proj_exprs.iter().all(is_expr_trivial) {
791+
return Ok(false);
792+
}
789793
let proj_schema = projection_schema(input, proj_exprs)?;
790-
Ok(&proj_schema == input.schema() && proj_exprs.iter().all(is_expr_trivial))
794+
Ok(&proj_schema == input.schema())
791795
}
792796

793797
#[cfg(test)]

0 commit comments

Comments
 (0)