[SERVER-65199] replanReason is incorrectly omitted from logs when replanning a query with $group/$lookup pushed down to SBE Created: 01/Apr/22  Updated: 29/Oct/23  Resolved: 14/Apr/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: Yoon Soo Kim
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-65197 Query with $lookup pushed down to SBE... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QE 2022-04-18
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 14/Apr/22 ]

Author:

{'name': 'Yoonsoo Kim', 'email': 'yoonsoo.kim@mongodb.com', 'username': 'yun-soo'}

Message: SERVER-65199 Pass through `replanReason` when lowered stages are replanned
Branch: master
https://github.com/mongodb/mongo/commit/297809252f48064534ae90189652855bcdda8d3f

Generated at Thu Feb 08 06:02:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.