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

XMLWordPrintableJSON

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

      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
            Reporter:
            Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: