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

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.6.11, 2.8.0-rc3
    • Component/s: Querying
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Backport Completed:

      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

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: