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

Coalesce $group and $limit in aggregation pipeline

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Won't Fix
    • 2.6.11
    • None
    • Aggregation Framework
    • Fully Compatible
    • Query 10 (02/22/16), Query 11 (03/14/16), Query 12 (04/04/16)

    Description

      I wonder is it possible to add coalescing optimization to a sequence of $group and $limit in aggregation pipeline?
      For example, I have a pipeline like this:

      db.messages.aggregate([
          {$match: {"company_id" : ObjectId("4c2118ad54397f271b000000")}},
          {$sort: {"ct": -1}},
          {$group: {_id: "$ti", ts: {$first: "$ct"}}},
          {$limit: 10}
      ])
      

      My goal is to get small subset of $ti ("thread id") that have latest $ct ("conversation timestamp"). Execution time for this request is prohibitively high and I guess it's because $group stage process all input documents and apply limit afterwards.

      It seems that incorporating $limit into $group processing would benefit this query by avoiding computations that will be thrown away in any case.

      Attachments

        Issue Links

          Activity

            People

              benjamin.murphy Benjamin Murphy
              rmihael@gmail.com Michael Korbakov
              Votes:
              0 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: