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

aggregation: optimize sort/limit combination to only sort top-n items

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.2
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible

      If a limit follows a sort, then we can optimize the sort by only retaining the top-n items required to satisfy the request.

      This may use one of http://www.cplusplus.com/reference/algorithm/partial_sort/ or
      https://github.com/mongodb/mongo/blob/master/src/mongo/db/scanandorder.cpp#L40-85 , or if those don't fit, maintain a priority queue, and always discard elements after the top-n.

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            dan@mongodb.com Daniel Pasette (Inactive)
            Votes:
            4 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: