Details
-
Improvement
-
Resolution: Unresolved
-
Major - P3
-
None
-
None
-
None
-
Query Optimization
Description
When a partial filter expression uses $or, we sometimes don't recognize that it can satisfy a query using $or. For example:
> db.c.createIndex({a: 1}, {partialFilterExpression: {$or: [ {a: {$lt: 0}}, {a: {$gt: 10}} ]}})
|
{
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"createdCollectionAutomatically" : true,
|
"ok" : 1
|
}
|
> for (a=-2; a<15; ++a) db.c.insert({a})
|
WriteResult({ "nInserted" : 1 })
|
> db.c.find({$or: [ {a: -1}, {a: 12} ]}).explain()
|
{
|
...
|
"winningPlan" : {
|
"stage" : "COLLSCAN",
|
...
|
}
|
This query should use the index, because any document matching {a: -1} will be indexed, and any document matching {a: 12} will be indexed.