[SERVER-31775] NaN comparison not aligned between query and pipeline Created: 31/Oct/17  Updated: 24/Jul/23

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.4.10
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Simon Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: mql-semantics
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

The query comparison operators have a handled case for NaN

This behavior is not aligned with the Comparison Aggregation Operators and provides different result when used i.e. in $match pipeline stage or in a $project stage.

Query : src/mongo/db/matcher/expression_leaf.cpp

// Special case handling for NaN. NaN is equal to NaN but
// otherwise always compares to false.

Pipeline: src/mongo/db/pipeline/value.cpp

return compareInts(rL._storage.intValue, rR._storage.intValue);



 Comments   
Comment by Simon [ 31/Oct/17 ]

Test case:

> db.createCollection("SERVER_31775");
> db.SERVER_31775.insert([{value: -42},{value: 42},{value: NaN}]);
> db.SERVER_31775.aggregate([{$match: {value: {$lt: 0}}}]);
{ "_id" : ObjectId("59f8a0dbeeec12c698108231"), "value" : -42 }
> db.SERVER_31775.aggregate([{$match: {value: {$gt: 0}}}]);
{ "_id" : ObjectId("59f8a0dbeeec12c698108232"), "value" : 42 }
> db.SERVER_31775.aggregate([{$project: {check_lt: {$lt: ["$value", 0]}, check_gt: {$gt: ["$value", 0]}, value: "$value"}}]);
{ "_id" : ObjectId("59f8a0dbeeec12c698108231"), "check_lt" : true, "check_gt" : false, "value" : -42 }
{ "_id" : ObjectId("59f8a0dbeeec12c698108232"), "check_lt" : false, "check_gt" : true, "value" : 42 }
{ "_id" : ObjectId("59f8a0dbeeec12c698108233"), "check_lt" : true, "check_gt" : false, "value" : NaN }

Comment by Mark Agarunov [ 31/Oct/17 ]

Hello Uyttendaele,

Thank you for the detailed example. I've set the fixVersion to "Needs Triage" for this new feature to be scheduled against our currently planned work. Updates will be posted on this ticket as they happen.

Thanks,
Mark

Comment by Simon [ 31/Oct/17 ]

Relates somehow to #SERVER-18350

Generated at Thu Feb 08 04:28:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.