Going from Performance Store to QueryStore

How can we help?
< All Topics
Print

Going from Performance Store to QueryStore

By using the statement_sql_handle and the statement_context_id from dbo.v_activity, we can use the following query to get the query_id to be used in Query Store:

use [database containing QueryStore]
go

select qsq.query_id
from sys.dm_exec_query_stats qs
inner join sys.query_store_query qsq on qsq.query_hash = qs.query_hash
where qs.statement_sql_handle = [statement_sql_handle]
and qs.statement_context_id = [statement_context_id]

It is also possible to get the query_id from the sql_handle, offset_start and offset_end from dbo.v_errors and dbo.v_top_completed:

use [database containing QueryStore]
go

select qsq.query_id
from sys.query_store_query qsq
where qsq.last_compile_batch_sql_handle = [sql_handle]
and qsq.last_compile_batch_offset_start = [offset_start]
and qsq.last_compile_batch_offset_end = [offset_end]

The values of offset_start and offset_end will always be -1 if the statement has been successfully executed. In that case, comment out the last two lines.

Note, here we can not filter on the statement_context_id, as this information is not available in the module_end Extended Event.

Table of Contents