[SERVER-4578] $exists and sparse index Created: 29/Dec/11  Updated: 29/Feb/12  Resolved: 29/Dec/11

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.0.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Uladzimir Mihura Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: epam
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3918 make sparse indexes error out on {$ex... Closed
duplicates SERVER-4187 automatically pick sparse indexes for... Closed
Related
Operating System: ALL
Participants:

 Description   

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
			]
		]
	}
}


Generated at Thu Feb 08 03:06:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.