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

$exists and sparse index

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.2
    • Component/s: None
    • Labels:
    • ALL

      You can see that c_1 index is used for {$exists:false} and not used for ${exists:true}. I believe it should be other way round.

      > db.tmp.find()
      { "_id" : ObjectId("4efc37bb80f98024da20613f"), "a" : 10, "c" : 2 }
      { "_id" : ObjectId("4efc37c180f98024da206140"), "a" : 11, "c" : 23 }
      { "_id" : ObjectId("4efc37c480f98024da206141"), "a" : 11 }
      { "_id" : ObjectId("4efc37cd80f98024da206142"), "a" : "Test" }
      { "_id" : ObjectId("4efc38c880f98024da206143"), "a" : "Test", "c" : 1231 }
      >db.tmp.ensureIndex({c:1},{sparse:true})
      >db.tmp.find({c:{$exists:true}}).explain()
      {
      	"cursor" : "BasicCursor",
      	"nscanned" : 5,
      	"nscannedObjects" : 5,
      	"n" : 3,
      	"millis" : 0,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"isMultiKey" : false,
      	"indexOnly" : false,
      	"indexBounds" : {
      		
      	}
      }
      > db.tmp.find({c:{$exists:false}}).explain()
      {
      	"cursor" : "BtreeCursor c_1",
      	"nscanned" : 0,
      	"nscannedObjects" : 0,
      	"n" : 0,
      	"millis" : 0,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"isMultiKey" : false,
      	"indexOnly" : false,
      	"indexBounds" : {
      		"c" : [
      			[
      				null,
      				null
      			]
      		]
      	}
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            uladzimir_mihura@epam.com Uladzimir Mihura
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: