Need to quickly spot failed query’s in Query Store?

When I work with Query Store, I often need to find the executions that didn’t finish successfully, queries that were aborted or ended with an exceptionIn the SSMS interface, you’d normally look for a square icon (client-abort) or a triangle icon (runtime error) . Trying to find those by clicking through the dashboard is slow.

  • An aborted execution can come from exceeding the client execution timeout.

  • An exception might occur when, for example, a 5-character string is inserted into a CHAR(2) column.

Retrieve failed executions with T-SQL

The T‑SQL query provided below lets you filter for these failed executions. It retrieves time window, together with the plan_id/query_id, execution count, Query plan, and SQL text.

 

Retrieve wait stats for aborted queries

When a query got aborted, it can be useful to get information about the wait statistics related to that query. The wait-stats can point you into the right direction. To retrieve the wait-stats you can use this query.

 

 

 

Note: sys.query_store_wait_stats is only available in SQL Server 2017+ or Azure SQL Database, and requires WAIT_STATS_CAPTURE_MODE to be enabled (default on new databases)

Leave a Comment

Scroll to Top