[SERVER-55417] Conditionally reorder $sort and $lookup depending on whether the query planner allows for an index-provided sort Created: 22/Mar/21  Updated: 06/Dec/22

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

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

Issue Links:
Related
is related to SERVER-26442 Push $sort before $project and $addFi... Open
is related to SERVER-54822 Push $sort before $unwind when possible Closed
is related to SERVER-54823 $sort should be pushed before $lookup... Closed
Assigned Teams:
Query Optimization
Participants:

 Description   

With the pipeline of [$lookup, $unwind, $sort, $limit], the current implementation will not push $sort before $lookup since $unwind will block $limit from being pushed before $lookup and then combined with $sort. Although letting $sort take advantages of the indexes benefits more than absorbing $limit into $sort to run a top-k sort, there is no way in the current system to learn if there are indexes on the sorting fields.

Instead of depending on the presence of $unwind, the optimization should reorder $lookup and $sort depending on if an index-provided sort is allowed. The other condition of not sorting on fields introduced or modified by $lookup and $unwind remains the same.


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