Hello Geeks and welcome to the Day 42 of the long series of One DMV a day. In this series of blogs I will be exploring and explaining the most useful DMVs in SQL Server. As we go ahead in this series we will also talk about the usage, linking between DMVs and some scenarios where these DMVs will be helpful while you are using SQL Server. For the complete list in the series please click here.

Yesterday I have covered sys.dm_exec_cached_plans. Also I have mentioned that in this post I will write about sys.dm_exec_plan_attributes. We have seen one use case of sys.dm_exec_plan_attributes yesterday. As this DMV gives the attributes of a cached plan, we can use it to filter on results from cached plans.

Sys.dm_exec_plan_attributes provides properties about the cached plans. They include different set options, execution context details, cursor details, date and language settings, and database and object id. There are three columns returned as output. The first one is the attribute. Second is value of the attribute which is of type sql_variant and a bit column is_cache_use to indicate if the column is used for cache lookup for the plan.

More specific detail on the set option value is covered in MSDN. I will talk about a specific example where sys.dm_exec_plan_attributes is useful. Have you ever seen two plans in the cache for a single procedure? Yes, it is possible and quiet frequent in heavily used SQL instances. There are multiple reasons why SQL Optimizer generates a new plan when there is already one in the cache. One of them is due to different SET options.

Let us understand this by using a simple demo. I will run the same procedure which I ran yesterday on AdventureWorks2014 twice. By default SSMS has ARITHABORT set to ON. So I will first run it by default and then OFF the setting and run again.

Now run the below query which we used yesterday and you will observe there are two plans for the single object.


Now run select on sys.dm_exec_plan_attributes with two plan_handles and you will observe the below results.


The SET option is the only difference between these two. In real troubleshooting scenarios we listen to customers telling procedure timeout from application. When we run the procedure in SSMS you will see the results come out pretty fast. In those cases make sure you are checking the right plan used by the application. Different applications have different default SET options. The options which will lead to not reusing cached plans are listed below.


You can read more about the plan cache in this whitepaper written by Greg Low. Now you know how to check the plan attributes using sys.dm_exec_plan_attributes. Tomorrow I will be covering another execution related DMV. Stay tuned. Till then

Happy Learning,

Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook |
Follow me on Twitter | Follow me on FaceBook