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

XMLWordPrintableJSON

    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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:
            [DO NOT USE] Backlog - Query Optimization
            Reporter:
            Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: