Posted in

How to Diagnose and Resolve Query Performance Regressions in Azure SQL Using Query Data Store and DMVs

Discover how Azure SQL’s Query Data Store and DMVs help diagnose query performance regressions caused by multiple execution plans. Learn how automatic statistics updates can trigger new plans, impacting query speed, and explore TSQL scripts to analyze and resolve these issues effectively. Unique :

Lesson Learned #521: Tackling Query Performance Regression in Azure SQL

Recently, a customer reached out with a puzzling question: why did their query slow down unexpectedly? After digging in, the culprit turned out to be multiple execution plans for the same query. This is a common but tricky issue in Azure SQL that can cause performance regressions.

What’s New: Multiple Execution Plans Identified

Using Query Data Store (QDS) and Dynamic Management Views (DMVs), the team ran a T-SQL script to spot queries with more than one plan_id. This is often a sign that the optimizer created multiple execution strategies for a single query.

“One possible issue could be that more than one execution plan is being used for a specific query.”

They found the exact query causing trouble: a simple aggregate with a parameter filtering records, which surprisingly had two execution plans.

Major Updates: Analyzing Execution Plans and Performance

Next, they examined runtime stats for each plan. One plan executed fewer times but took longer on average. This discrepancy hinted at something deeper.

By inspecting the execution plan XML, the team discovered an automatic statistics update triggered a new plan. This update can cause the optimizer to switch strategies, sometimes hurting performance.

Diving Deeper: Querying Execution Plan XML

To better understand when statistics were updated, they crafted a T-SQL query that extracts this info directly from the execution plan XML. This approach provides granular insights into optimizer behavior and stats freshness.

“We found another way to query directly the execution plan and include other information from Query Data Store.”

Why This Matters for Azure SQL Users

Performance regressions due to multiple execution plans can be subtle and hard to diagnose. Leveraging QDS and DMVs to analyze plan usage and statistics updates is a powerful method.

Understanding when and why the optimizer switches plans helps DBAs and developers maintain consistent query performance.

Final Thoughts

If you notice unexpected query slowdowns in Azure SQL, check for multiple execution plans first. Use the provided T-SQL scripts and XML queries to pinpoint causes. This lesson from Microsoft’s Azure Database Support team is a handy reminder: sometimes, the optimizer’s best intentions can backfire.

Stay tuned for more tips on mastering Azure SQL performance!

  • Identifying queries with multiple execution plans using Query Data Store and DMVs.
  • Analyzing execution statistics to compare plan performance and execution frequency.
  • Detecting automatic statistics updates within execution plan XML that affect query optimization.
  • Using TSQL with XML namespaces to extract detailed statistics update information from execution plans.
  • Practical troubleshooting steps for resolving query performance regressions in Azure SQL Database.
  • From the New blog articles in Microsoft Community Hub