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

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

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 2.6.11, 2.8.0-rc3
    • Querying
    • None
    • Fully Compatible

    Description

      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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: