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

Computed projection should not be pushed down past sort+limit

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.0-rc4, 5.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • ALL
    • v5.0
    • Query Optimization 2021-06-14, Query Optimization 2021-06-28
    • 136

      In PipelineD::prepareExecutor, we are sometimes pushing down a computed projection past a sort+limit. This is incorrect because the projection can raise an error when it sees documents that the sort+limit would not return.

      We should change buildProjectionForPushdown so that it never returns a computed projection:

      /**
       * Given a dependency set and a pipeline, builds a projection BSON object to push down into the
       * PlanStage layer. The rules to push down the projection are as follows:
       *    1. If there is an inclusion projection at the front of the pipeline, it will be pushed down
       *       as is.
       *    2. If there is no inclusion projection at the front of the pipeline, but there is a finite
       *       dependency set, a projection representing this dependency set will be pushed down.
       *    3. Otherwise, an empty projection is returned and no projection push down will happen.
       */
      auto buildProjectionForPushdown(const DepsTracker& deps, Pipeline* pipeline) {
      

      https://github.com/mongodb/mongo/blob/0d6199bb52dcae5978551816c6ac4ad98bda165b/src/mongo/db/pipeline/pipeline_d.cpp#L480-L489

      Computed projections should be ineligible for case 1. For example, if the pipeline starts with {$project: {b: {$round: "$a"}}}, we'll fall through to case 2 and push down {a: 1}, based on the dependencies.

            Assignee:
            david.percy@mongodb.com David Percy
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: