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

replanReason is incorrectly omitted from logs when replanning a query with $group/$lookup pushed down to SBE

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • QE 2022-04-18

      When a replan occurs, a string field called "replanReason" is supposed to appear in the log and in system.profile. This is broken if there is a $group or $lookup pushed down to SBE. You can reproduce this with the same repro script that I wrote for related ticket SERVER-65197.

      After some digging, I was able to spot that the problem occurs here:

      https://github.com/mongodb/mongo/blob/e30ac62b20a58a26087b5eb3c5ebc55da7f15d17/src/mongo/db/query/sbe_multi_planner.cpp#L148-L153

      Imagine that a replan occurs, and the system uses the SBE multi-planner to select a new plan. The "replanReason" string is present in PlanStageData::replanReason, and each candidate plan has an associated PlanStageData object.

      When a $group or $lookup has been pushed down, the multi-planner selects a plan and then creates an entirely new SBE tree after calling extendWithAggPipeline(). This process currently drops the old PlanStageData object and creates a fresh one. As a result, we discard the value of "replanReason". When the downstream code responsible for displaying "replanReason" in the logs and profile executes, it finds no value and therefore displays nothing.

            Assignee:
            yoonsoo.kim@mongodb.com Yoon Soo Kim
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: