[SERVER-28980] aggregation can subsume $sort into $group when $first/$last are present Created: 26/Apr/17  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Asya Kamsky Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: asya, optimization, performance
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-23732 Aggregation should optimize an irrele... Backlog
is related to SERVER-9507 Optimize $sort+$group+$first pipeline... Closed
Assigned Teams:
Query Optimization
Participants:
Case:

 Description   

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)



 Comments   
Comment by Asya Kamsky [ 21/Sep/22 ]

I think with addition of $topN operators this ticket may not be relevant anymore (unless we take it to mean "automatically execute sort+group with $first as $topN?)

Generated at Thu Feb 08 04:19:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.