Details
-
Improvement
-
Resolution: Unresolved
-
Major - P3
-
None
-
None
-
None
-
None
-
Query Optimization
Description
Consider the following:
> db.foo.find({z:1, $or:[{x:{$in:[1]}},{x:{ $nin:[1]}}]}).explain().queryPlanner.winningPlan
|
{
|
"stage" : "FETCH",
|
"filter" : {
|
"z" : {
|
"$eq" : 1
|
}
|
},
|
"inputStage" : {
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"x" : 1
|
},
|
"indexName" : "x_1",
|
"isMultiKey" : false,
|
"multiKeyPaths" : {
|
"x" : [ ]
|
},
|
"isUnique" : false,
|
"isSparse" : false,
|
"isPartial" : false,
|
"indexVersion" : 2,
|
"direction" : "forward",
|
"indexBounds" : {
|
"x" : [
|
"[MinKey, MaxKey]"
|
]
|
}
|
}
|
}
|
Here the database is performing a full index scan which is providing no value. Apart from the scan being unbounded, there is no filter being applied in the IXSCAN stage nor is the index supporting a sort order requested from a client. Such a plan does nothing but slow down the query and therefore should not be considered.