Skip to content

Commit 656092e

Browse files
committed
Add fast path for optimize_projection (apache#15746)
1 parent dfb339d commit 656092e

File tree

1 file changed

+11
-0
lines changed
  • datafusion/optimizer/src/optimize_projections

1 file changed

+11
-0
lines changed

datafusion/optimizer/src/optimize_projections/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,17 @@ fn merge_consecutive_projections(proj: Projection) -> Result<Transformed<Project
455455
return Projection::try_new_with_schema(expr, input, schema).map(Transformed::no);
456456
};
457457

458+
// A fast path: if the previous projection is same as the current projection
459+
// we can directly remove the current projection and return child projection.
460+
if prev_projection.expr == expr {
461+
return Projection::try_new_with_schema(
462+
expr,
463+
Arc::clone(&prev_projection.input),
464+
schema,
465+
)
466+
.map(Transformed::yes);
467+
}
468+
458469
// Count usages (referrals) of each projection expression in its input fields:
459470
let mut column_referral_map = HashMap::<&Column, usize>::new();
460471
expr.iter()

0 commit comments

Comments
 (0)