-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
(copied to CRM)
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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.