-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query Execution
-
Query 2020-08-24
The $avg pipeline group accumulator computes the average by summing all elements then divide by the count.
src/mongo/db/pipeline/accumulator_avg.cpp :
return Value(_nonDecimalTotal.getDouble() / static_cast<double>(_count));
This may lead to an overflow in the sum for large number of records or large numbers.
To be evaluated for performance reasons : using a stream-average to compute the average.
count++ avg += (x - avg) / count;