A SQL Server analysis script that extracts and evaluates cached execution plans to identify performance issues such as missing indexes, tempdb spills, key lookups, and implicit conversions.
Analyzes the SQL Server plan cache to surface potentially problematic queries.
Key features:
- Returns the top N queries by total CPU usage (configurable via
@TopN). - Shows both the full batch text and the specific statement text.
- Provides XML showplan for each query.
- Flags common performance issues:
HasMissingIndexWarningHasSpillToTempDb(hash/sort spills to tempdb)HasKeyLookupHasImplicitConversion(searches forCONVERT_IMPLICITin the plan)
Requirements:
VIEW SERVER STATEpermission.- Plan cache must contain relevant queries (cleared on restart or
DBCC FREEPROCCACHE).
Suggested usage:
- Filter or sort by the flag columns to focus on queries with specific issues.
- Export results to Excel for triage.
- Click the
QueryPlanXmlin SSMS to open the graphical execution plan and investigate further.