Skip to content

Plan analysis: mark which warnings are SQL Server's and key duplicate index suggestions on the database (#4520, #4523) - #4543

Merged
erikdarlingdata merged 1 commit into
devfrom
plan-sync/4520-4523
Sep 28, 2026
Merged

erikdarlingdata merged 1 commit into
devfrom
plan-sync/4520-4523

Conversation

@erikdarlingdata

@erikdarlingdata erikdarlingdata commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Fixes #4520
Fixes #4523
Part of #4511

Why

Two small syncs from PerformanceStudio's plan analyzer.

PlanWarning carried nothing but type, severity and message, so a reader could not tell a warning SQL Server itself wrote into the plan (a spill, an implicit conversion, no statistics — a record of what the engine did) apart from one the analyzer inferred from plan shape (which can be wrong about a particular plan in a way the engine's own record cannot be).

Rule 30's duplicate-index-suggestion check grouped missing index suggestions by schema and table only. A plan touching a same-named table (e.g. dbo.t) in two different databases had its suggestions merged and reported as duplicates of each other, even though they target unrelated tables.

What changes

  • PlanWarning.Source (new enum PlanWarningSource: Analyzer default, SqlServer). ShowPlanParser.ParseWarningsFromElement stamps every warning it returns as SqlServer in one place — the only place parser warnings are built — so a new engine warning is attributed correctly without anyone needing to remember it at each construction site.
  • The MCP plan-analysis JSON now carries a source field on every warning (additive; existing fields unchanged).
  • The plan viewer tags the engine's own warnings with [SQL Server] next to the warning type, in both the statement-level and node-level warnings panels. Only the engine's are tagged, since they are the minority and a badge on every line would carry no information.
  • Rule 30's duplicate-index grouping key and the per-suggestion lookup key now include the database (MissingIndex.Database, which already existed on the model), not just schema and table.

Test plan

New Darling.Tests classes with synthetic plan XML (dbo.t, [db1]/[db2]):

  • PlanSync4520Tests: an engine PlanAffectingConvert warning is stamped SqlServer; an analyzer non-SARGable-predicate warning keeps the default Analyzer; the MCP formatter's JSON carries both source values on the product's own formatting call path (McpPlanAnalysisFormatter.BuildAnalysisResult).

  • PlanSync4523Tests: two missing-index suggestions for the same table name in two different databases are NOT reported as duplicates; two suggestions for the same table in the same database still are.

  • Findings do not say whether SQL Server or the analyzer produced them (PlanWarning.Source) #4520: PlanWarning.Source and PlanWarningSource are new, so PlanSync4520Tests is a compile-only RED on dev. Mutation: removing the parser's Source = SqlServer stamping fails EngineWarning_IsStampedSqlServer (Expected: SqlServer, Actual: Analyzer) and McpFormatter_CarriesSourceOnEachWarning ("source":"SqlServer" not found).

  • Duplicate index suggestions (rule 30) treat same-named tables in different databases as one table #4523: SameTableName_DifferentDatabases_AreNotReportedAsDuplicates is a runtime RED on dev (Assert.DoesNotContain() Failure: Filter matched in collection). Mutation: dropping the database from both rule-30 keys fails it again.

  • Run: the new classes plus the plan-analysis classes (ShowPlanParserCondAndMultiplePlanTests, the ActualPlan* classes, QueryModificationDetectorTests, ReproScriptBuilderHardeningTests, DarlingAnalysisPipelineTests, DarlingMcpPlanToolsSurfaceAndSqlTests, McpPlanAnalysisEnvelopeTests, SerialLoopStoreSizeSourceTests, TsqlConventionGuardTests, DocCommentHygieneTests): Total: 234, Failed: 0. McpPlanAnalysisEnvelopeTests needed no change: the source field is additive. The live-Postgres plan-tool class runs in CI. Lite.Tests builds; its plan classes run on Windows only.

  • Consumers checked: PlanAdvisoryAggregator reads severity and counts only; McpPlanAnalysisFormatter gains source; the plan viewer tags the engine's own warnings [SQL Server] in both warning panels, as PerformanceStudio does. PerformanceStudio's CLI text formatter has no PM counterpart.

CHANGELOG

SECTION: Added
ENTRY: - Plan analysis now marks which findings are SQL Server's own warnings and which are inferences, and duplicate missing-index suggestions are no longer merged across different databases ([#4543]) - PlanWarning.Source says whether a plan warning came from the engine's own <Warnings> element or from the analyzer; the plan viewer tags the engine's with [SQL Server] and the MCP plan tools carry it as a source field. Rule 30's duplicate-index-suggestion check now keys on database as well as schema and table, so same-named tables in different databases are no longer reported as duplicates of each other.
REF: [#4543]: #4543

…, and key duplicate index suggestions on the database (#4520) (#4523)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant