-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
Currently the group distinct scan optimization works if all the accumulators are $first or $last. However, if the index spec directions correspond to the $first/$last accumulators, then we should be able to use a distinct scan as well.
For example:
db.c.createIndex({b: 1, c: -1, a: 1})
[ { '$sort': { b: 1, c: -1, a: 1 } }, { '$group': { _id: '$b', c_accum: { '$last': '$c' }, a_accum: { '$first': '$a' } } } ]