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

Compound index not used for sort if sort spec doesn't match index spec, even with equality predicate on sort prefix

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Querying

      Description

      The query planner elects to use a blocking sort for queries where the sort spec doesn't match the index spec, even in the case where there is an equality match predicate on some prefix of the sort spec. In this special case a sort is only truly required on the remaining suffix of the sort spec, for which the index could possibly be used. For example, with an index on {a:1,b:1}:

      1. db.foo.find({a:2}).sort({a:1,b:1}) - sort uses the index
      2. db.foo.find({a:2}).sort({a:-1,b:1}) - blocking sort
      3. db.foo.find({a:2}).sort({a:-1,b:-1}) - sort uses the index
      4. db.foo.find({a:2}).sort({a:1,b:-1}) - blocking sort

      Logically, query 2 is the same as 1, and query 4 is the same as 3

        Attachments

          Activity

            People

            Assignee:
            backlog-server-query Backlog - Query Team
            Reporter:
            jon.rangel Jon Rangel
            Participants:
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Dates

              Created:
              Updated: