Parses SQL Server ShowPlan XML (.sqlplan / .xml) and acts as an automated query-tuning consultant: cardinality-estimate mismatches, tempdb spills, SARGability violations, implicit conversions, parameter-sniffing risk, and missing-index suggestions — with a runtime-evidence severity model instead of the optimizer's own (page-weighted) cost estimates. Optionally connects live to cross-reference indexes/statistics and Query Store, and can emit a JSON bundle for the offline Plan Visualizer.
Execution Flow
Synopsis
Two operating modes: offline file parsing of a saved .sqlplan/.xml plan, or telemetry & regression mode that additionally connects to the source database (via dbatools) to cross-reference existing indexes and statistics staleness, append Query Store metrics for the matching query/plan hash, and auto-generate plan-forcing/OPTIMIZE FOR mitigation scripts when a regression is found. Cardinality-estimate severity is computed entirely from runtime evidence (log-scaled CE mismatch ratio, actual rows touched, and rows-read-vs-rows-returned waste) rather than the optimizer's own page-weighted cost model — the same evidence a DBA would look for manually, just automated.
Path to the .sqlplan or .xml execution plan file to analyze. Positional (0).
-TopOperators
Int
15
How many operators to list in the cost/CPU-volume grids.
-CEMismatchRatio
Double
10
Cardinality estimate mismatch ratio threshold (estimated vs. actual rows) before flagging.
-CEMinRows
Double
10
Minimum row count before a CE mismatch is considered significant.
-LookupCallsThreshold
Double
10000
Call-volume heuristic threshold for flagging expensive key/RID lookups.
-ServerInstance
String
—
Target SQL Server instance for optional Query Store telemetry / database inspection.
-Database
String
—
Target database. Required together with -ServerInstance / -InspectDatabase.
-InspectDatabase
Switch
false
Connect to the database to inspect existing indexes, statistics staleness, and missing-index coverage. Requires -ServerInstance and -Database, and dbatools.
-SqlCredential
PSCredential
—
SQL Server authentication credential, passed through to dbatools.
-Statement
String
(auto-chosen)
Analyze a specific statement in a multi-statement plan instead of the automatically chosen one — use the batch-qualified key printed in the report (e.g. "1.1"). Falls back to auto-selection if not found.
-OutFile
String
—
Emit a self-contained sqlplan-insights JSON bundle (plan XML + analysis + live-inspection data) for the HTML Plan Visualizer. Stamped with the run date/time.
-ShowAllHeuristicMatches
Switch
false
List every matching operator for heuristic sections instead of deduplicated/grouped findings.
-IncludeOperatorRows
Switch
false
Diagnostics: include raw per-operator row data in the result.
-SanityCheck
Switch
false
Diagnostics: run internal consistency checks against the parsed plan.
-DebugSargability
Switch
false
Verbose tracing of the SARGability regex detection for troubleshooting false positives/negatives.
Return Value
Property
Description
File / DegreeOfParallelism
Source file analyzed and the chosen statement's observed DOP.
TopOperators
Most expensive operators by estimated subtree cost and true CPU volume.
CardinalityIssues
CE mismatches with the runtime-evidence severity score and likely contributors.
SargabilityIssues
Non-SARGable predicates: implicit conversions, functions on columns, leading-wildcard LIKE.
SpillSignals / ParallelSkewSignals
TempDB spill markers and parallelism skew detected in the plan XML.
MissingIndexes
Missing-index suggestions harvested from the plan XML, merged to avoid duplicates.
KeyLookups / SortOps / JoinChecks / HintSignals
Expensive key/RID lookups, large sorts, join-strategy sanity checks, and query/table hint signals.
Suggestions
Actionable rewrite/design recommendations distilled from all of the above.
DbInspection / QueryStoreRegressions
Live index/statistics coverage and Query Store regression data (only with -InspectDatabase).
*Count properties
Convenience counts (CEIssuesCount, SargIssuesCount, SpillOpsCount, MissingIndexesCount, …) added for the compact default display view.
Examples
Example 1 — Offline analysis of a saved plan
Get-sqmPlanInsights-Path".\Execution plan.xml"
Example 2 — With live index coverage and Query Store telemetry