sys.dm_exec_query_plan
The sys.dm_exec_query_plan DMF is another helper function like sys.dm_exec_sql_text that retrieves the estimated execution plan based on plan_handle. You can call sys.dm_exec_query_plan on its own with a valid plan_handle, or you can leverage CROSS APPLY with views like sys.dm_exec_query_stats that contain a plan_handle column.
The value that is returned in the query_plan column is in XML format but querying this view in SSMS will show the XML as a link. When clicked, the link will open as a graphical plan in a new tab.
We can use the plan_handle we found earlier in the sys.dm_exec_procedure_stats section to retrieve the estimated plan for the uspGetEmployeeByDepartment stored procedure, as in the following example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access