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

incorrect result and index not used for $ne with sparse index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.5.5
    • Component/s: None
    • Labels:
      None
    • Major Change
    • ALL

      The way indexed queries against sparse index work changed from 2.4.x to 2.5.5 - in pre-2.5 the results of $eq and $ne of same value would add up to the number of entries in the index, in 2.5.5+ it's the total number of documents (same as with non-sparse index).

      Not that this only impacts $ne - $gt shows the same behavior as before.

      db.test.insert({a:1})
      db.test.insert({a:1,b:1})
      db.test.insert({b:1})
      db.test.ensureIndex({a:1},{sparse:true})
      

      Results in 2..5.5

      > db.test.find().count()
      3
      > db.test.find({a:1}).count()
      2
      > db.test.find({a:{$ne:1}}).count()
      1
      > db.test.find({a:{$gt:1}}).count()
      0
      

      And in 2.4.8

      > db.test.find().count()
      3
      > db.test.find({a:1}).count()
      2
      > db.test.find({a:{$ne:1}}).count()
      0
      > db.test.find({a:{$gt:1}}).count()
      0
      

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: