-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query Optimization
-
(copied to CRM)
When the following is the pattern of pipeline:
{$sort:{foo:1}},{$group:{_id:x, bar:{$first:"$a"},baz:{$last:"$z"}}}
We can subsume the sort into group and get rid of the stage otherwise - have the logic of first/last by certain order in the $group itself. This would allow merging on the $group (SERVER-28942) rather than $sort - in fact, for all sorts, since sort does not impact later (post-group) stages.
This optimization may not need to happen if sort can be subsumed into query pushdown (when index is available) or when another index optimization is being used (i.e. SERVER-9507)
- is related to
-
SERVER-87590 Rewrite $sort + stages + $group with $first/$last to stages + $group with $top/$bottom
- Backlog
-
SERVER-9507 Optimize $sort+$group+$first pipeline to avoid full index scan
- Closed
- related to
-
SERVER-85213 Rewrite $sort+$group with $first/$last to use $top/$bottom
- Backlog
-
SERVER-23732 Aggregation should optimize an irrelevant $sort preceding a $group
- Backlog