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

Non deterministic Infinity vs NumberDecimal(Infinity) comparisons

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • ALL
    • 0

      BF-35282 shows that the output of `$max(Infinity, NumberDecimal(Infinity))` is not deterministic.

      The reasons are:

      1. We consider both Infinity and NumberDecimal(Infinity) numerically identical.
      2. [Current accumulator logic favours the first argument if both are identical|the code.

      This behaviour, in itself seems harmless, but causes discrepancies and could cause customer impact since Infinity and NumberDecimal(Infinity) are not the same, for example, in terms of precision.

      My proposal is to make it deterministic, preferring NumberDecimal since it has larger precision. However it needs careful consideration since that would also impact other operators such as $addToSet or $setUnion since they also are order-affected.

      MongoDB Enterprise > db.test.find()
      { "_id" : ObjectId("673373c182450e56da9acd6c"), "a" : [ Infinity ], "b" : [ NumberDecimal("Infinity") ] }
      
      MongoDB Enterprise > db.test.aggregate({$project: {all: {$setUnion: [ "$a", "$b" ]}}})
      { "_id" : ObjectId("673373c182450e56da9acd6c"), "all" : [ Infinity ] }
      
      MongoDB Enterprise > db.test.aggregate({$project: {all: {$setUnion: [ "$b", "$a" ]}}})
      { "_id" : ObjectId("673373c182450e56da9acd6c"), "all" : [ NumberDecimal("Infinity") ] } 

      Kudos militsa.sotirova@mongodb.com for her help here.

            Assignee:
            Unassigned Unassigned
            Reporter:
            c.alonso@mongodb.com Carlos Alonso Pérez
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: