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

Optimize a $group after a $unionWith

    • Query Optimization

      Consider the following pipeline:

      db.example.aggregate([
        {$unionWith: "unionColl"},
        {$match: {example: {$eq: "predicate"}}},
        {$group: {_id: "$groupKey", total: {$sum: "$price"}}}
      ])
      

      Unfortunately we are missing an optimization to duplicate the $group for each branch of the union and keep only a merge of pre-grouped data after the $unionWith. We should implement this optimization.

      This could help in cases where part of either pipeline is happening on another shard in the cluster, or when an index could be used to speed up the group like in SERVER-9507.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: