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

find(a).sort(b,_id) doesn't use index(a,b) to minimize scans

    • Query Optimization

      I have a collection of documents with keys _id, a, and b. I have an index {a:1,b:1}.

      When I do find(a).sort(b).limit(5) the index is used, and only 5 documents are scanned.

      When I do find(a).sort(b,_id).limit(5) (with or without a hint) it appears the index is only used to match a - as all documents with the matching value for a are scanned (nscanned and nscannedObjects are high).

      The behavior I would expect is that it would scan through a and b values enough to get to the limit (5), and then it would stop scanning when it found the next unique b (or a). It would then sort on _id within the scanned records.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            timhaines Tim Haines
            Votes:
            3 Vote for this issue
            Watchers:
            29 Start watching this issue

              Created:
              Updated: