-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
The following query:
db.foo.find({$expr: {$eq: [ "$a" , 2 ]}}).explain();
Does not use an index even though an apparently suitable predicate with $_internalExprEq }}has appeared in the {{parsedQuery representation :
parsedQuery: { '$and': [ { '$expr': { '$eq': [ '$a', { '$const': 2 } ] } }, { a: { '$_internalExprEq': 2 } } ] },
From my reading of https://github.com/10gen/mongo/blob/e73bcfb2ba365dced85566219e49e9ff2e4092b8/src/mongo/db/matcher/expression_internal_expr_comparison.h#L50-L70 it appears that it would be safe to use this predicate for indexing, provided that the complete original filter is then applied on top of the results returned by the index.
- duplicates
-
SERVER-41252 cannot get covered query with $expr with $eq only
- In Progress
- related to
-
SERVER-36818 $expr does not use multi-key index
- Closed
-
SERVER-41252 cannot get covered query with $expr with $eq only
- In Progress