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

Move $sample earlier in the aggregation pipeline

    • Fully Compatible
    • Query 2018-11-05, Query 2018-11-19
    • 0

      When $sample is the first stage of an aggregation pipeline, the executor optimizes it with storage-engine support. This optimization could be extended to more use cases by moving $sample prior to stages that don't alter the number of documents that pass through it, including

      • $project
      • $addFields
      • $lookup
      • $sort

      While most applications can ensure the $sample is first in the pipeline, there is one important use case where this is not possible: views. It's common for our own tools (mongodrdl, compass) to sample views, and often those views contain a pipeline consisting of only the above stages, and MongoDB will tack the $sample to the end of the view's pipeline. This optimization will improve the performance of that $sample by pushing it down to the storage engine.

            Assignee:
            jacob.evans@mongodb.com Jacob Evans
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            5 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved: