|
The code only checks whether an AND-expression filter is satisfied if the query is also an AND-expression. This means that querying for an explicit value of a will not be able to use the partial index.
> db.foo.find({a:6}).explain().queryPlanner
|
{
|
"plannerVersion" : 1,
|
"namespace" : "test.foo",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
"a" : {
|
"$eq" : 6
|
}
|
},
|
"winningPlan" : {
|
"stage" : "COLLSCAN",
|
"filter" : {
|
"a" : {
|
"$eq" : 6
|
}
|
},
|
"direction" : "forward"
|
},
|
"rejectedPlans" : [ ]
|
}
|
But specifying a fake AND-expression in the query will allow the partial index to be used.
> db.foo.find({$and: [{a:6}, {a:6}]}).explain().queryPlanner
|
{
|
"plannerVersion" : 1,
|
"namespace" : "test.foo",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
"$and" : [
|
{
|
"a" : {
|
"$eq" : 6
|
}
|
},
|
{
|
"a" : {
|
"$eq" : 6
|
}
|
}
|
]
|
},
|
"winningPlan" : {
|
"stage" : "FETCH",
|
"inputStage" : {
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"a" : 1
|
},
|
"indexName" : "a_1",
|
"isMultiKey" : false,
|
"indexVersion" : 1,
|
"direction" : "forward",
|
"indexBounds" : {
|
"a" : [
|
"[6.0, 6.0]"
|
]
|
}
|
}
|
},
|
"rejectedPlans" : [ ]
|
}
|
|