Home > Functions and DMVs, Joins, SQL Queries, SQL Server, T-SQL > An easier way to translate query stats and plan/SQL handle information

An easier way to translate query stats and plan/SQL handle information

September 29, 2009 Leave a comment Go to comments

Usually we capture the SQl/plan handles for the query stats or from cached plan DMVs and supply these as the inputs to the DMFs to translate everything into human-readable format, there is a better / easier way to arrive at this translation. The queries below shows the approach that can serve as an alternative.

SELECT * 
FROM 
        sys.dm_exec_cached_plans 
CROSS APPLY 
      sys.dm_exec_query_plan(plan_handle)
SELECT * 
FROM 
        sys.dm_exec_query_stats 
CROSS APPLY 
       sys.dm_exec_sql_text(sql_handle)
SELECT * 
FROM 
        sys.dm_exec_query_stats 
CROSS APPLY 
       sys.dm_exec_query_plan(plan_handle)

The CROSS APPLY operator invokes a table-valued function for each row within a table.  and As usual, do not forget to add the WHERE clause to restrict the number of records.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: