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

Support group with distinct scan optimization with mixture of $first and $last accumulators

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

      Currently the group distinct scan optimization works if all the accumulators are $first or $last. However, if the index spec directions correspond to the $first/$last accumulators, then we should be able to use a distinct scan as well.

      For example:

      db.c.createIndex({b: 1, c: -1, a: 1}) 
      [
      { '$sort': { b: 1, c: -1, a: 1 } },
      { '$group': {
           _id: '$b',
           c_accum: { '$last': '$c' },
           a_accum: { '$first': '$a' }
         }
      }
      ]
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            ben.shteinfeld@mongodb.com Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: