Parse IF-condition query plans and MULTIPLE PLAN hashes (#580) - #581
Merged
Merged
Conversation
A StmtCond keeps its condition's own QueryPlan (and any UDF sub-plans) under <Condition>. The parser fed each child of <Condition> back in as a statement, so the condition became an empty STATEMENT placeholder and its operator tree, hashes, missing indexes and warnings were lost. Parse the StmtCond itself as the statement and read its plan and sub-plans from <Condition> (new optional planContainerEl argument on ParseStatement). ParseStatement read the statement attributes only after the no-QueryPlan return, so a MULTIPLE PLAN statement lost the QueryHash and QueryPlanHash it carries. Read them before that return. Port of erikdarlingdata/PerformanceMonitor#4470. The two golden baselines change because eager_table_spool_plan.sqlplan has a WHILE (SELECT ...) condition that is now a real statement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G625JBNh45iTR1hpT4CxNR
|
Reviewed. This is a clean, well-scoped port of the PerformanceMonitor fix (#4470):
No correctness, untrusted-input, security, or repo-convention issues found (no |
This was referenced Sep 27, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #580. The plan parser dropped two statement shapes that carry their own plan or hashes. PerformanceMonitor fixed the same two gaps in its copy of the parser in erikdarlingdata/PerformanceMonitor#4470. This PR ports that fix to Studio's parser.
StmtCondwithStatementType="COND WITH QUERY"). The showplan schema puts the condition's ownQueryPlanunder<Condition>, next to optionalUDFsub-plans. The parser treated each child of<Condition>as a statement. The bareQueryPlanbecame an emptySTATEMENTplaceholder, and the condition's operator tree, hashes, missing indexes and warnings were lost. EachUDFchild became another empty placeholder, and the function body was lost.The parser now reads the
StmtCondas the statement, and it reads the plan and the sub-plans from<Condition>.ParseStatementhas a new optionalplanContainerElargument for this. A UDF body attaches to the condition statement throughParseSubPlans, as it does for every other statement. A plain IF with no query and no UDF still adds no statement.StmtSimplewithStatementType="MULTIPLE PLAN"). It carriesQueryHashandQueryPlanHashbut noQueryPlan.ParseStatementreturned at the no-plan branch before it read the statement attributes. It now reads them first. Every statement without a plan now getsStatementId, its hashes and the other statement attributes. Examples are DECLARE, ASSIGN and EXEC. The properties panel shows those hashes, and plan comparison can pair such statements by hash.One difference from #4470: PerformanceMonitor adds a condition's UDF statements to the top-level statement list. Studio attaches them to the condition statement, because Studio attaches every module body to its calling statement (#456, #486, #491).
Which component(s) does this affect?
The app, the CLI, the web viewer and the MCP tools all read the parser's output, so they all show the condition statement now. None of their code changed.
How was this tested?
ShowPlanParserCondAndMultiplePlanTests(7 tests). Five come from #4470, with its repro XML. Two are Studio's own: a UDF sub-plan under<Condition>attaches to the condition statement, and a plain IF adds no statement. Against the unfixed parser, 4 of the 7 fail. The other 3 cover behavior that was already correct: the statement count, the Then branch and the plain IF.ComparisonBaseline.txt:eager_table_spool_plan.sqlplanhas aWHILE (SELECT ...)loop. Its condition used to be an empty statement with no text, at the end of the list. Now it is a real statement with its text, cost and row estimate. The comparison pairs it by query hash, so it moves to Statement 1 and the other statements move down by one.WarningBaseline.txt: one new warning, on the same WHILE condition. Rule 23 (table-valued function) flags thesys.dm_db_index_physical_statscall (INDEXANALYSIS) in the condition's plan. The analyzer did not see that plan before, and rule 23 did not change. The rule's advice to rewrite as an inline function does not fit a system function. Whether rule 23 should skip built-in functions is a separate question, outside this fix.Checklist
dotnet test)dotnet test)🤖 Generated with Claude Code
https://claude.ai/code/session_01G625JBNh45iTR1hpT4CxNR