Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4506

aggregation: optimize by pushing matches to earlier in a pipeline

    • Fully Compatible
    • Query 10 (02/22/16), Query 11 (03/14/16), Query 12 (04/04/16)

      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
      This is an optimization we can apply in the future.

      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.

            Assignee:
            benjamin.murphy Benjamin Murphy
            Reporter:
            dan@mongodb.com Daniel Pasette (Inactive)
            Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: