Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55417

Conditionally reorder $sort and $lookup depending on whether the query planner allows for an index-provided sort

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            yuhong.zhang@mongodb.com Yuhong Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: