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

    XMLWordPrintable

    Details

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-server-query Backlog - Query Team
              Reporter:
              timhaines Tim Haines
              Participants:
              Votes:
              2 Vote for this issue
              Watchers:
              15 Start watching this issue

                Dates

                Created:
                Updated: