-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.0.2
-
Component/s: None
-
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 ] ] } }
- duplicates
-
SERVER-3918 make sparse indexes error out on {$exists: false} queries
- Closed
-
SERVER-4187 automatically pick sparse indexes for $exists:true queries
- Closed