Skip to content

Apache DataFusion SQL Query Engine

[pruning] Add shortcut when all units have been pruned (#8675)

Yang Jiang7f440e18f22a
diff --git a/datafusion/core/src/physical_optimizer/pruning.rs b/datafusion/core/src/physical_optimizer/pruning.rs
index 79e084d7b7..fecbffdbb0 100644
--- a/datafusion/core/src/physical_optimizer/pruning.rs
+++ b/datafusion/core/src/physical_optimizer/pruning.rs
@@ -258,6 +258,11 @@ impl PruningPredicate {
builder.combine_array(&arrow::compute::not(&results)?)
}
}
+ // if all containers are pruned (has rows that DEFINITELY DO NOT pass the predicate)
+ // can return early without evaluating the rest of predicates.
+ if builder.check_all_pruned() {
+ return Ok(builder.build());
+ }
}
}
@@ -380,6 +385,11 @@ impl BoolVecBuilder {
fn build(self) -> Vec<bool> {
self.inner
}
+
+ /// Check all containers has rows that DEFINITELY DO NOT pass the predicate
+ fn check_all_pruned(&self) -> bool {
+ self.inner.iter().all(|&x| !x)
+ }
}
fn is_always_true(expr: &Arc<dyn PhysicalExpr>) -> bool {