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

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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Query Optimization

    Description

      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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            christopher.harris@mongodb.com Chris Harris
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated: