-
Type: Bug
-
Resolution: Unresolved
-
Priority: 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:
- We consider both Infinity and NumberDecimal(Infinity) numerically identical.
- [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.