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

MergeSort stage should be limit-aware, rather than adding an explicit limit stage after the sort completes

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.6.0-rc2
    • Affects Version/s: 2.5.5
    • Component/s: Querying
    • None
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      The new query system does not implement the optimization described in SERVER-5063. We should reimplement it for the new query system.

      For example, if you have an $in query and you specify a limit, then the limit can be applied to each element of the $in. Let's say that you have index {a: 1, b: 1}. The query

      db.collection.find({a: {$in: [1, 2]}}).sort({b: 1}).limit(5)
      

      can be executed by limiting the results from a==1 to 5 and the results from a==2 to 5, sorting on "b" with a merge sort, then reapplying a limit of 5. Currently this query is executed with a mergeSort, but the limits are not applied to the children of the mergeSort.

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: