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

$avg with Infinity can incorrectly return NaN

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide

      *On a debug build, to ensure we always spill to disk*

      db.test.insert({_id: 0, value: Infinity});
      db.test.insert({_id: 0, value: 5});
      db.test.aggregate([{ $group: {
                      _id: null,
                      'num': { 
                          $avg: '$value'
                      }
      } }]);
      
      Show
      * On a debug build, to ensure we always spill to disk * db.test.insert({_id: 0, value: Infinity}); db.test.insert({_id: 0, value: 5}); db.test.aggregate([{ $group: { _id: null , 'num' : { $avg: '$value' } } }]);
    • 50

      When adding Infinity to any value using the DoubleDoubleSummation class, the _addend double is calculated to be NaN. This is probably fine, however getting the result of the summation here results in a value of Infinity with an error of NaN.

      If this happens when the $avg accumulator spills to disk, we will attempt to process the NaN error as if its a finite value and as a result the accumulator evaluates to NaN.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            nicholas.zolnierz@mongodb.com Nicholas Zolnierz
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: