-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.2.7, 2.4.14, 2.6.10, 3.1.5
-
Component/s: Index Maintenance, Querying
-
Minor Change
-
ALL
-
The $mod operator in find queries currently casts values to long long when matching, using the unsafe BSONElement.numberLong(...). This means NaN, -Infinity, and Infinity are all converted to the minimum long long, although the behavior is undefined. Behavior for doubles out of range of long long is also undefined, although I haven't checked precisely what does occur.
If $mod is going to convert to long long, it might be appropriate to not match any values outside the range of long long, as all of them will have undefined value.
This would solve the indexing problem, and we could scan the interval of NumberLong s instead of NumberDouble.
This issue was introduced because BSONElement.appendMinForType and BSONElement.appendMaxForType appends the maximum and minimum double value, not Infinity. Elsewhere in src/mongo/db/query/index_bounds_builder.cpp, appendMin/MaxForType is not used, in favor of explicitly using Infinity. In practice the only time this function is called is for the $mod and $type match expressions.
- related to
-
SERVER-19349 $type results are inconsistent with indexing enable on Infinity, -Infinity, NaN
- Closed