-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
Let's say I have two documents in a collection:
{_id: 0, a: 1, b: 1} and {_id: 1, a: 1, b: 2}
and index on {a: 1}.
Aggregation pipeline [{$sort: {a: 1}}, {$group: {_id: '$a'}] will be covered by the index, however pipeline [{$sort: {a: 1}}, {$group: {_id: '$a', b: {$first: '$b'}}}], according to execution stats, will examine both 2 documents despite only needing 1 value for $first operator.
So this seems like a place for aggregation optimization.
- duplicates
-
SERVER-9507 Optimize $sort+$group+$first pipeline to avoid full index scan
- Closed