Skip to content

Apache DataFusion SQL Query Engine

ARROW-6803: [Rust] [DataFusion] Performance optimization for single partition aggregate queries

Andy Grove8d61ba4e8e77
diff --git a/rust/datafusion/src/execution/physical_plan/hash_aggregate.rs b/rust/datafusion/src/execution/physical_plan/hash_aggregate.rs
index 0f59361644..c0718c44b7 100644
--- a/rust/datafusion/src/execution/physical_plan/hash_aggregate.rs
+++ b/rust/datafusion/src/execution/physical_plan/hash_aggregate.rs
@@ -91,6 +91,12 @@ impl ExecutionPlan for HashAggregateExec {
})
.collect();
+ if partitions.len() == 1 {
+ // if there is only a single partition then it isn't necessary to perform any
+ // additional logic
+ return Ok(partitions);
+ }
+
// create partition to combine and aggregate the results
let final_group: Vec<Arc<dyn PhysicalExpr>> = (0..self.group_expr.len())
.map(|i| Arc::new(Column::new(i)) as Arc<dyn PhysicalExpr>)