[SERVER-61868] $max accumulator with collation might produce incorrect result for NaN Created: 02/Dec/21  Updated: 29/Oct/23  Resolved: 07/Dec/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.3.0, 5.2.0-rc2

Type: Bug Priority: Major - P3
Reporter: Irina Yatsenko (Inactive) Assignee: Irina Yatsenko (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.2
Steps To Reproduce:

Into a collection insert two documents: {n: NumberLong(98618)}, {n: NaN}, then run aggregate([\{$group: {_id: null, max: {$max:"$n}}}],{collation:{locale:"en"}}).

In classic engine the result is "NumberLong(98618)" and in SBE it's NaN. The classic result is correct, because we consider NaN to be less than any long.

 

Sprint: QE 2021-12-13
Participants:
Linked BF Score: 165

 Comments   
Comment by Githook User [ 15/Dec/21 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-61868 Switch aggColl(Min|Max) to use comparison that is aware of MQL semantics for NaN

(cherry picked from commit 560421e00c89080b410469550618536897e4cabf)
Branch: v5.2
https://github.com/mongodb/mongo/commit/f1d0f5a615182cb4b51de8f2c5d0541e26008213

Comment by Githook User [ 07/Dec/21 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-61868 Switch aggColl(Min|Max) to use comparison that is aware of MQL semantics for NaN
Branch: master
https://github.com/mongodb/mongo/commit/560421e00c89080b410469550618536897e4cabf

Comment by Irina Yatsenko (Inactive) [ 03/Dec/21 ]

The original title of this ticket was: "Inconsistent comparison of number types between 'genericCompare' and 'compare3way'". However, the inconsistency between how 'genericCompare()' and 'compare3way()' treats NaN is by design because 'genericCompare' implements SBE's semantics for NaN and 'compare3way' implements MQL's semantics. The proper fix for $max (and $min) with collation to use compare3way rather than genericCompare. Updated the title to "$max with collation might produce incorrect result for NaN"

Generated at Thu Feb 08 05:53:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.