Use powershell to analyze a bunch of query plans.
2025TL; DR
In SQL Server, we can capture query plans using Extended Events—but then what? Analyzing a single query plan can be a complex task, but what if you have hundreds or even thousands of them?
To simplify this, I wrote PowerShell code that parses the query plan XML and stores the extracted data in a database. This approach makes it much easier to identify performance issues and gain insights in a large set of query plans.
Session Details
Analyzing a bunch of queries with PowerShell
In SQL Server, we can capture query plans using Extended Events—but then what? Analyzing a single query plan can be a complex task, but what if you have hundreds or even thousands of them?
To simplify this, I wrote PowerShell code that parses the query plan XML and stores the extracted data in a database. This approach makes it much easier to identify performance issues and gain insights in a large set of query plans.
Session content:
First, we'll take a closer look at the query optimization process. Then we’ll examine the XML structure of a query plan and identify key elements within the plan. Next, we'll walk through the PowerShell script that parses the XML and writes the extracted data to a database. Finally, I'll demonstrate how to retrieve and analyze valuable insights from the database.
Some use cases:
• Parameter sniffing
o Identify compiled vs. runtime parameter values.
o Detect parameters that contribute to poor performance.
• Warnings and issues
o Columns with no statistics.
o Spills to tempdb.
In SQL Server, we can capture query plans using Extended Events—but then what? Analyzing a single query plan can be a complex task, but what if you have hundreds or even thousands of them?
To simplify this, I wrote PowerShell code that parses the query plan XML and stores the extracted data in a database. This approach makes it much easier to identify performance issues and gain insights in a large set of query plans.
Session content:
First, we'll take a closer look at the query optimization process. Then we’ll examine the XML structure of a query plan and identify key elements within the plan. Next, we'll walk through the PowerShell script that parses the XML and writes the extracted data to a database. Finally, I'll demonstrate how to retrieve and analyze valuable insights from the database.
Some use cases:
• Parameter sniffing
o Identify compiled vs. runtime parameter values.
o Detect parameters that contribute to poor performance.
• Warnings and issues
o Columns with no statistics.
o Spills to tempdb.
3 things you'll get out of this session
Session goals:
• Understand the basic XML structure of a query plan.
• Execute the PowerShell script in your own environment.
• Use the extracted data to diagnose and resolve performance issues.