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

Better path tracking when $$ROOT is used in a $group accumulator

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • Fully Compatible

      Consider the following two aggregations:

      db.foo.aggregate([
            { '$group': { _id: '$city', data: { '$first': '$$ROOT' } } },
            {
              '$match': { _id: { '$in': [ 'Austin', 'Dallas' ] } }
            }
      ])
      
      db.foo.aggregate([
            { '$group': { _id: '$city', data: { '$first': '$$ROOT' } } },
            {
              '$match': { 'data.city': { '$in': [ 'Austin', 'Dallas' ] } }
            }
      ])
      

      Logically they represent the same result set as data.city contains the same value as _id after the $group since both refer to the city field in the originating document and that field is being grouped on.

      The former pipeline can participate in the $match$group optimization implemented via SERVER-34741 while the latter currently cannot. This ticket will improve our dependency tracking and analysis to allow for pipelines such as the latter to participate in such an optimization.

      This enhancement will apply to both single field groupings as shown as well as compound groupings where similar logic can be applied.

            Assignee:
            samuel.mercier@mongodb.com Sam Mercier
            Reporter:
            christopher.harris@mongodb.com Chris Harris
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: