[SERVER-47466] Optimize $push in $group to limit array size if followed by $slice of same field Created: 10/Apr/20  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: optimization, qopt-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

If I have a pipeline

{$group:{_id:"any", a:{$push:"$x"}}}, {$project:{a:{$slice:["$a",0,5]}}}

We can pull in knowledge that only first 5 elements are needed from "a" in $group and stop pushing more elements after we have that many.



 Comments   
Comment by keshav garg [ 28/Sep/21 ]

Is there any workaround, to satisfy this use case?
wanted to restrict the size of group member elements in each group.
the current solution required me to bring every group member in memory which might cross the hard limit of 100 MB.

Comment by Asya Kamsky [ 10/Apr/20 ]

if there are no other accumulators in $group we can even shortcircuit processing the stage once we have enough to satisfy slice.

Generated at Thu Feb 08 05:14:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.