Skip to content

Instantly share code, notes, and snippets.

@SteGriff
Created June 10, 2021 13:48
Show Gist options
  • Save SteGriff/cde40af5704e128b752b9170f95268d6 to your computer and use it in GitHub Desktop.
Save SteGriff/cde40af5704e128b752b9170f95268d6 to your computer and use it in GitHub Desktop.
Visualise execution plans of running queries
-- QUERY TO GET RUNNING PLAN HANDLES
SELECT d.name, t.text,PLAN_HANDLE, r.total_elapsed_time/1000 RunningSeconds
FROM sys.dm_exec_requests r
JOIN sys.databases d on d.database_id = r.database_id
CROSS APPLY sys.dm_exec_sql_text(sql_handle) t
ORDER BY 4 DESC
-- VISUALISE A PLAN HANDLE
SELECT CAST(query_plan AS XML)
FROM sys.dm_exec_text_query_plan (0x06001200CF2D13354032C1F38501000001000000000000000000000000000000000000000000000000000000,0,-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment