ic4y commented on issue #956:
URL: 
https://github.com/apache/arrow-datafusion/issues/956#issuecomment-987649287


   @alamb In the count sql, I use pprof to count the time consumed by the 
following methods. The long time consumption is mainly in `make slice`, 
`hashbrown get_mut`, `create_hashes`. The time consumed by creating the final 
array and aggregate updates method is relatively small.
   
   | func | time |
   | ----  | ----|
   |arrow::array::array::Array::slice|26% of all
   |hashbrown::raw::inner::RawTable<T,A>::get_mut|22% of all
   |datafusion::physical_plan::hash_utils::create_hashes|6.5% of all
   |datafusion::physical_plan::AccumulatorFly>::update_batch|2.5% of all
   |datafusion::physical_plan::hash_aggregate_fly::create_batch_from_map|<0.1% 
of all
   
   Corresponding to the following code snippets
   1、array slice and update_batch
   ```rust
       groups_with_rows.iter()
           .zip(offsets.windows(2))
           .try_for_each(|(group_idx, offsets)| {
               accumulators.group_indices[*group_idx].clear();
               accumulators.accumulator_items.iter_mut()
                   .zip(values.iter())
                   .try_for_each(|(accumulator, aggr_array)| {
                       let values = aggr_array
                           .iter()
                           .map(|array| {
                               array.slice(offsets[0], offsets[1] - offsets[0])
                           })
                           .collect::<Vec<ArrayRef>>();
                       match mode {
                           AggregateMode::Partial => 
accumulator.update_batch(*group_idx, &values),
                           AggregateMode::FinalPartitioned | 
AggregateMode::Final => {
                               accumulator.merge_batch(*group_idx, &values)
                           }
                       }
               })
           });
   ```
   2、hashbrown get_mut
   ```rust
           let entry = map.get_mut(hash, |(_hash, group_idx)| {
               let group_state_c = &group_by_values[*group_idx];
               group_values
                   .iter()
                   .zip(group_state_c.iter())
                   .all(|(array, scalar)| scalar.eq_array(array, row)) // 
eq_array takes a long time
           });
   ```
   3、create_hashes
   ```rust
   create_hashes(&group_values, random_state, &mut batch_hashes)?;
   ```
   4、create_batch_from_map
   ```rust
   let batch = create_batch_from_map(&mode, &accumulators, group_expr.len(), 
&schema);
   ```
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to