[SERVER-82368] Match top/bottom N accumulators in SBE and Classic Created: 23/Oct/23  Updated: 20/Nov/23  Resolved: 31/Oct/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.2.0-rc0, 7.0.5, 6.0.13

Type: Bug Priority: Major - P3
Reporter: Ivan Fefer Assignee: Ivan Fefer
Resolution: Fixed Votes: 0
Labels: bkp
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File data.js    
Issue Links:
Backports
Depends
Duplicate
Problem/Incident
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0, v6.0
Sprint: QE 2023-10-30, QE 2023-11-13
Participants:
Linked BF Score: 130

 Description   

Currently in Classic, $bottom accumulator will compare arrays element-by-element, which is natural, but contradicts our documentation: https://www.mongodb.com/docs/manual/reference/bson-type-comparison-order/#arrays

A less-than comparison, or an ascending sort, compares the smallest elements of the array according to the BSON type sort order.
 
A greater-than comparison, or a descending sort, compares the largest elements of the array according to the reverse BSON type sort order. 

SBE will follow the docs.

This is because in Classic, accumulator wraps sort keys in array and sort key generator considers the array being nested, so it returns it fully in a sort key. SBE accepts document fully as-is, so the array is not nested, so only one element is returned as a sort key.

Reproduction script is attached.



 Comments   
Comment by Githook User [ 20/Nov/23 ]

Author:

{'name': 'Ivan Fefer', 'email': 'ivan.fefer@mongodb.com', 'username': 'Fefer-Ivan'}

Message: SERVER-82368 In top/bottom accumulator map sort fields to object fields not array
Branch: v6.0
https://github.com/mongodb/mongo/commit/5218a9a6d9058b8966bee1ed19d8397e50126e21

Comment by Githook User [ 20/Nov/23 ]

Author:

{'name': 'Ivan Fefer', 'email': 'ivan.fefer@mongodb.com', 'username': 'Fefer-Ivan'}

Message: SERVER-82368 In top/bottom accumulator map sort fields to object fields not array
Branch: v7.0
https://github.com/mongodb/mongo/commit/afe533061125ca6deb824884acb55cc8fd3c8349

Comment by Githook User [ 31/Oct/23 ]

Author:

{'name': 'Ivan Fefer', 'email': 'ivan.fefer@mongodb.com', 'username': 'Fefer-Ivan'}

Message: SERVER-82368 In top/bottom accumulator map sort fields to object fields not array
Branch: master
https://github.com/mongodb/mongo/commit/704ef3193b571c71455f00ef26bfa4ebc00a6d36

Comment by Ivan Fefer [ 27/Oct/23 ]

The classic implementation affected array comparison by mistake, so we are going to match SBE and Classic and documentation altogether.

Generated at Thu Feb 08 06:49:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.