30.06.2013 Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: Query Plan Metadata<br />

• sys.dm_exec_procedure_stats – returns aggregated performance statistics<br />

for cached stored procedures (<strong>SQL</strong> <strong>Server</strong> 2008 only). Returns one row per<br />

stored procedure.<br />

• sys.dm_exec_cached_plans – provides detailed information about a cached plan,<br />

such as the number of times it has been used, its size, and so on. Returns a row for each<br />

cached plan.<br />

• sys.dm_exec_query_optimizer_info – returns statistics regarding the operation<br />

of the query optimizer, to identify any potential optimization problems. For example,<br />

you can find out how many queries have been optimized since the last time the server<br />

was restarted.<br />

In order to return the query plan for a given batch, as well as some interesting attributes<br />

of these plans, we can pass the identifier for that plan batch, the plan_handle, to one of<br />

the DMFs below.<br />

• sys.dm_exec_query_plan – returns in XML format the query plan, identified<br />

by a plan_handle, for a <strong>SQL</strong> batch.<br />

• sys.dm_exec_text_query_plan – returns in text format the query plan,<br />

identified by a plan_handle, for a <strong>SQL</strong> batch or, via the use of this DMF's offset<br />

columns, a specific statement <strong>with</strong>in that batch.<br />

• sys.dm_exec_plan_attributes – provides information about various attributes of<br />

a query plan, identified by a plan_handle, such as the number of queries currently<br />

using a given execution plan. It returns one row for each attribute.<br />

To the query optimizer, a query and a query plan are not synonymous. When a batch<br />

is executed, it gets a plan. This plan comprises one or more individual queries, each of<br />

which will have a query plan of its own. The DMVs for query plans, such as cached_<br />

plans, return one row per distinct batch or object. The DMVs for queries, such as<br />

query_stats, return one row per independent query that is embedded in that plan.<br />

If, in our queries, we "join" from query_stats to the query_plan DMF, in order to<br />

return the plan, each row returned by query_stats will contain a link to the plan for<br />

76

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!