[SERVER-1017] Does the $ne operator skip the index? Created: 13/Apr/10  Updated: 26/Apr/10  Resolved: 13/Apr/10

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 1.4.0
Fix Version/s: None

Type: Question Priority: Minor - P4
Reporter: Ben Wyrosdick Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

When you use the $ne operator it seems to skip the index (unless I am reading the explain wrong) is that intentional?

> db.quotations.find({noteworthy: {"$ne": false}}).limit(25).explain()
{
"cursor" : "BasicCursor",
"indexBounds" : [ ],
"nscanned" : 25,
"nscannedObjects" : 25,
"n" : 25,
"millis" : 0,
"oldPlan" :

{ "cursor" : "BasicCursor", "indexBounds" : [ ] }

,
"allPlans" : [

{ "cursor" : "BasicCursor", "indexBounds" : [ ] }

]
}

versus me changing out {$ne: false} to true (I know it isn't equivalent)

> db.quotations.find(

{noteworthy: true}

).limit(25).explain()
{
"cursor" : "BtreeCursor noteworthy_1",
"indexBounds" : [
[

{ "noteworthy" : true }

,

{ "noteworthy" : true }

]
],
"nscanned" : 5,
"nscannedObjects" : 5,
"n" : 5,
"millis" : 0,
"allPlans" : [
{
"cursor" : "BtreeCursor noteworthy_1",
"indexBounds" : [
[

{ "noteworthy" : true }

,

{ "noteworthy" : true }

]
]
}
]
}



 Comments   
Comment by Eliot Horowitz (Inactive) [ 13/Apr/10 ]

it tries both and figures out which one is generally faster.
often with $ne, not using the index is faster

Generated at Thu Feb 08 02:55:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.