[SERVER-4506] aggregation: optimize by pushing matches to earlier in a pipeline Created: 15/Dec/11 Updated: 11/Nov/19 Resolved: 01/Apr/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Daniel Pasette (Inactive) | Assignee: | Benjamin Murphy |
| Resolution: | Duplicate | Votes: | 5 |
| Labels: | bi-performance, optimization, performance | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||||||||||||||
| Sprint: | Query 10 (02/22/16), Query 11 (03/14/16), Query 12 (04/04/16) | ||||||||||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||||||||||
| Description |
|
An aggregation pipeline using $match should be optimized so that the $match is moved as close as possible to the front of the pipeline, reducing the number of documents passing through each subsequent stage. Work is planned for the following optimizations, and is tracked in these tickets:
Old Description Applying matches before other operations allows less work to be done in the pipeline because documents will have been filtered out. Matches can't be pushed earlier than just anything. For example, a $match can't be pushed ahead of a $skip or $limit, because it will change the results. On the other hand, a $match can be pushed ahead of a $project when it doesn't depend on a computed value in the project – field renames don't alter anything except the references in the $match. Being able to push matches earlier will allow us to use indexes for the underlying query. |