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

Sparse indexes should not be assigned to {$in: [null, ...]} predicates

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.1.5
    • Querying
    • None
    • Minor Change
    • ALL
    • Quint Iteration 5

    Description

      Sparse indexes are incorrectly assigned to {$in: [null, ...]} predicates. As a consequence, {$in: [null, ...]} queries can omit documents from the result set that are missing the value of the given field, if a sparse index is assigned to the $in predicate.

      Reproduce as follows:

      > db.foo.drop()
      true
      > db.foo.ensureIndex({a: 1}, {sparse: true})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.foo.insert({})
      WriteResult({ "nInserted" : 1 })
      > db.foo.find({a: {$in: [null]}}) // No results: unexpected.
      > db.foo.find({a: {$in: [null]}}).hint({$natural: 1}) // 1 result: expected.
      { "_id" : ObjectId("55477a258aa4f4cc73af71a5") }
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: