I have this problem where I want to see how a newly released query is performing, but it may not be bad enough to make any of the canned reports that SQL Server provides in QueryStore. I was able to look up the plan handle, but always struggled to get to the query id for QueryStore, until now.
Here I am using a small and unique section from the query I want to find in the WHERE clause between two percent signs to work with my LIKE:
SELECT plan_handle, text
FROM sys.dm_exec_cached_plans
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st
WHERE text LIKE N'%SELECT S.SuperHeroName, S.SuperHeroDescription,%'
AND text NOT LIKE N'%DBCC%'
I use the text that was returned to verify that I have the right query that I want to find in QueryStore. Then I take that plan_handle and put it in this query:
SELECT qsp.query_id, qsp.plan_id
FROM sys.dm_exec_query_stats eqs INNER JOIN sys.query_store_plan qsp
ON eqs.query_plan_hash = qsp.query_plan_hash
WHERE eqs.plan_handle = 0x05000900EBC0B12E005DDEC92402000001000000000000000000000000000000000000000000000000000000 --plan handle here
Finally, I can take that query id and plug it into the Tracked Queries report in QueryStore:
Then I can see my query and even force the plan that I want to use moving forward (as you can see I have done above).
The song for this post is Everything Turns Around by Dogstar.
[…] Andrea Allred does a search: […]