[SERVER-58809] Optimize $unwind + $group _id, to avoid blocking/spilling Created: 23/Jul/21 Updated: 12/Jan/23 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | David Percy | Assignee: | Backlog - Query Execution |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Query Execution
|
| Participants: |
| Description |
|
Currently this is an antipattern: {$unwind: "a"} because $group is a blocking stage, and can spill if the data is big enough. We recommend something like this instead: {$set: {a: {$filter ...}}} This performs better because it operates on one document at a time. But the first version is nicer in some ways:
We could make it perform better by doing a streaming group (in this narrow case).
|