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

Too many documents examined when using an index and $first/$last in $group stage

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • Aggregation Framework
    • None

    Description

      Let's say I have two documents in a collection:
      {_id: 0, a: 1, b: 1} and {_id: 1, a: 1, b: 2}
      and index on {a: 1}.
      Aggregation pipeline [{$sort: {a: 1}}, {$group: {_id: '$a'}] will be covered by the index, however pipeline [{$sort: {a: 1}}, {$group: {_id: '$a', b: {$first: '$b'}}}], according to execution stats, will examine both 2 documents despite only needing 1 value for $first operator.
      So this seems like a place for aggregation optimization.

      Attachments

        Activity

          People

            david.storch@mongodb.com David Storch
            angly Angly Cat
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: