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

(Optimisation) Scan index in reverse order if skip is large enough

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • ALL

      Would it be possible to increase performance for pagination with indexes for large collections ?

      Consider a collection with 200000 documents, paginated with $skip and $limit and indexed on the sort order.

      The first page takes a few milliseconds, but the last page can take a few seconds because the index is scanned from the start counting the $skip.

      What if, as an optimization, the query planner would check if $skip is greater than half the amount of indexed documents and if it is: go through the index in reverse and shift the results into the array instead of pushing them.

      This would result in never having to scan more than half the index.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jean-samuel.girard@kiwi.ca Jean-Samuel Girard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: