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

$avg with Infinity can incorrectly return NaN

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • None
    • 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

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              backlog-query-optimization Backlog - Query Optimization
              nicholas.zolnierz@mongodb.com Nicholas Zolnierz
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: