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

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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

            Assignee:
            [DO NOT USE] Backlog - Query Optimization
            Reporter:
            Jon Rangel (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: