[SERVER-48120] Optimize a $sort after a $unionWith Created: 12/May/20 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Aggregation Framework, Performance |
| Affects Version/s: | 4.4.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Charlie Swanson | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | optimization | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Assigned Teams: |
Query Optimization
|
||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
Consider the following pipeline:
Our optimization pass can recognize the $match stage can be duplicated and applied to both "example" and "unionColl" collections, which means the predicate could be answered using an index. Unfortunately we are missing an optimization to duplicate the $sort for each branch of the union and keep only a merge-sort instead of the union. We should implement this optimization. |