[SERVER-83122] Optimize field projection in limit-sort pipeline in sbe Created: 10/Nov/23  Updated: 21/Dec/23  Resolved: 07/Dec/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc0

Type: Task Priority: Major - P3
Reporter: Projjal Chanda Assignee: Foteini Alvanaki
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Backwards Compatibility: Fully Compatible
Sprint: QE 2023-11-13, QE 2023-11-27, QE 2023-12-11
Participants:
Linked BF Score: 35

 Description   

With recent change SERVER-79862, some classic workloads had improved performance resulting in regression in some tests in sbe perf dashboard



 Comments   
Comment by Githook User [ 07/Dec/23 ]

Author:

{'name': 'Foteini Alvanaki', 'email': 'foteini.alvanaki@mongodb.com', 'username': ''}

Message: SERVER-83122 Retrieve fields after sorting when pipeline has limit

GitOrigin-RevId: 68358060ebc028af5c8b51cb1e26b0c74e0458f0
Branch: master
https://github.com/mongodb/mongo/commit/7eb9602a2f25422d3e075c01140aa4c6b9141fbd

Comment by Projjal Chanda [ 27/Nov/23 ]

There is regression in sbe in workloads where the window stage is followed by a (small) $limit, and preceded by a sort stage.

The sort stage desugared from $setWindowFields executes in sbe. When the window stage is in sbe, it pushes down its required fields through the sort stage in addition to result object, while when the window stage is in classic the sort stage in sbe only holds result object. So in fullsbe, there is higher allocations and cache pressure in the sort stage with these extra fields, resulting in slower sort. This is not an issue generally since the following stages will benefit from direct access to the required fields. But when we have a $limit (with a small limit) after the window stage, the sort stage still has to sort all the documents in the collection. So the sort stage completely dominates the execution time and the slower sort in case of fullSbe makes the overall query slower.

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