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

XMLWordPrintableJSON

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

      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 Stearn
              Reporter:
              Daniel Pasette (Inactive)
              Votes:
              4 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: