-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
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.
- is related to
-
SERVER-26442 Push $sort before $project and $addFields
- Open
-
SERVER-54822 Push $sort before $unwind when possible
- Closed
-
SERVER-54823 $sort should be pushed before $lookup when is possible
- Closed