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

Compound index not providing sort if equality predicate given on sort field

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.11, 2.8.0-rc3
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Fully Compatible

      Queries that can use a compound index to provide a sort on a subset of fields in the key pattern are sometimes given an unnecessary in-memory sort if an equality predicate is given on the sort field.

      Reproduce with:

      > db.foo.ensureIndex({a:1,b:1})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.foo.find({a:1}).sort({b:1}).explain().scanAndOrder
      false // CORRECT
      > db.foo.find({a:1,b:{$gt:0}}).sort({b:1}).explain().scanAndOrder
      false // CORRECT
      > db.foo.find({a:1,b:/hello/}).sort({b:1}).explain().scanAndOrder
      false // CORRECT
      > db.foo.find({a:1,b:1}).sort({b:1}).explain().scanAndOrder
      true // INCORRECT
      

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: