-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
if we are using $expr, we don’t produce covered projections.
If index on a is present,
This will have fetch + projection simple
db.test.explain().aggregate([{$match: {$expr: {$eq: ["$a", 1]}}}, {$project: {_id: 0, a: 1}}])
But this will have projection covered:
db.test.explain().aggregate([\{$match: {a: 1}}, \{$project: {_id: 0, a: 1}}])
It looks like a problem with dependency analysis of $expr that can’t determine that we only need field “a” that can come from the index.
In some cases we have to use $expr syntax. For example, in $lookup with pipelines.
- duplicates
-
SERVER-41252 cannot get covered query with $expr with $eq only
- Open
- is depended on by
-
SERVER-84094 Implement initial drain policy for unsharded collections when the user specifies a destination shard
- Backlog