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

aggregation can subsume $sort into $group when $first/$last are present

    • Query Optimization

      When the following is the pattern of pipeline:

      {$sort:{foo:1}},{$group:{_id:x, bar:{$first:"$a"},baz:{$last:"$z"}}}
      

      We can subsume the sort into group and get rid of the stage otherwise - have the logic of first/last by certain order in the $group itself. This would allow merging on the $group (SERVER-28942) rather than $sort - in fact, for all sorts, since sort does not impact later (post-group) stages.

      This optimization may not need to happen if sort can be subsumed into query pushdown (when index is available) or when another index optimization is being used (i.e. SERVER-9507)

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: