|
The new query planner added in version 2.6 plans the example $or query by constructing a plan that is an OR of two index scans:
> t.drop()
|
true
|
> t.ensureIndex({a: 1})
|
{
|
"createdCollectionAutomatically" : true,
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"ok" : 1
|
}
|
> t.find({$or: [{a: {$gte: 5, $lte: 10}}, {a: {$gte: 100}}]}).explain()
|
{
|
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "test.t",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
"$or" : [
|
{
|
"$and" : [
|
{
|
"a" : {
|
"$lte" : 10
|
}
|
},
|
{
|
"a" : {
|
"$gte" : 5
|
}
|
}
|
]
|
},
|
{
|
"a" : {
|
"$gte" : 100
|
}
|
}
|
]
|
},
|
"winningPlan" : {
|
"stage" : "SUBPLAN",
|
"inputStage" : {
|
"stage" : "FETCH",
|
"inputStage" : {
|
"stage" : "OR",
|
"inputStages" : [
|
{
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"a" : 1
|
},
|
"indexName" : "a_1",
|
"isMultiKey" : false,
|
"direction" : "forward",
|
"indexBounds" : {
|
"a" : [
|
"[5.0, 10.0]"
|
]
|
}
|
},
|
{
|
"stage" : "IXSCAN",
|
"keyPattern" : {
|
"a" : 1
|
},
|
"indexName" : "a_1",
|
"isMultiKey" : false,
|
"direction" : "forward",
|
"indexBounds" : {
|
"a" : [
|
"[100.0, inf.0]"
|
]
|
}
|
}
|
]
|
}
|
}
|
},
|
"rejectedPlans" : [ ]
|
},
|
"serverInfo" : {
|
"host" : "dstorch-desktop",
|
"port" : 27017,
|
"version" : "3.1.0-pre-",
|
"gitVersion" : "d8628625507b7a6927f21b1f1f91d68201fe4030"
|
},
|
"ok" : 1
|
}
|
The planner could collapse this into a single index scan with the following index bounds:
{a: [[5, 10], [100, Infinity]]}
|
An improvement request for this kind of collapsing of plans into a single index scan stage is already being tracked by SERVER-12594. Resolving as a duplicate of SERVER-12594.
|