Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31776

$avg pipeline accumulator may overflow

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
    • 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;
      

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            Uyttendaele Simon
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated: