[SERVER-54822] Push $sort before $unwind when possible Created: 26/Feb/21  Updated: 29/Oct/23  Resolved: 14/Jun/21

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

Type: Improvement Priority: Major - P3
Reporter: Renato Riccio Assignee: Militsa Sotirova
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-55417 Conditionally reorder $sort and $look... Backlog
is related to SERVER-26442 Push $sort before $project and $addFi... Open
Backwards Compatibility: Fully Compatible
Sprint: Query Optimization 2021-05-17, Query Optimization 2021-05-31, Query Optimization 2021-06-14, Query Optimization 2021-06-28
Participants:

 Description   

$sort should be pushed automatically before $unwind if sort is happening on a different field.
E.g.

db.foo.aggregation([{$unwind: "fieldA"},{$sort: { fieldB: 1}}])



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 16/Jun/21 ]

Author:

{'name': 'Militsa Sotirova', 'email': 'militsa.sotirova@mongodb.com', 'username': 'militsasotirova'}

Message: SERVER-54822: sort should be pushed automatically before unwind if sort is happening on a different field.
Branch: SERVER-34632
https://github.com/mongodb/mongo/commit/fd808e64b2a34bedfeeef012c2ef9314bec08e8f

Comment by Githook User [ 14/Jun/21 ]

Author:

{'name': 'Militsa Sotirova', 'email': 'militsa.sotirova@mongodb.com', 'username': 'militsasotirova'}

Message: SERVER-54822: sort should be pushed automatically before unwind if sort is happening on a different field.
Branch: master
https://github.com/mongodb/mongo/commit/fd808e64b2a34bedfeeef012c2ef9314bec08e8f

Comment by David Percy [ 30/Apr/21 ]

We should make sure this doesn't inhibit the $lookup + $unwind optimization.  If you have $lookup, $unwind, $sort, and the $lookup can absorb the $unwind, it would be bad if the $sort stage somehow got stuck in between.

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