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

XMLWordPrintableJSON

    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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:
              [DO NOT USE] Backlog - Query Optimization
              Reporter:
              Tim Haines
              Votes:
              3 Vote for this issue
              Watchers:
              32 Start watching this issue

                Created:
                Updated: