-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
Fully Compatible
Consider the following two aggregations:
db.foo.aggregate([ { '$group': { _id: '$city', data: { '$first': '$$ROOT' } } }, { '$match': { _id: { '$in': [ 'Austin', 'Dallas' ] } } } ])
db.foo.aggregate([ { '$group': { _id: '$city', data: { '$first': '$$ROOT' } } }, { '$match': { 'data.city': { '$in': [ 'Austin', 'Dallas' ] } } } ])
Logically they represent the same result set as data.city contains the same value as _id after the $group since both refer to the city field in the originating document and that field is being grouped on.
The former pipeline can participate in the $match / $group optimization implemented via SERVER-34741 while the latter currently cannot. This ticket will improve our dependency tracking and analysis to allow for pipelines such as the latter to participate in such an optimization.
This enhancement will apply to both single field groupings as shown as well as compound groupings where similar logic can be applied.
- is related to
-
SERVER-91102 Moving $match before $group is incorrect when predicate distinguishes equal values
- Closed