|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 11:38 AM
Points: 389,
Visits: 912
|
|
Hi, I've been running the following script to capture plan usage stats.
SELECT DB_NAME(st.dbid) DBName ,OBJECT_SCHEMA_NAME(st.objectid, dbid) SchemaName ,OBJECT_NAME(st.objectid, dbid) StoredProcedure ,MAX(cp.usecounts) Execution_count ,cp.plan_handle FROM sys.dm_exec_cached_plans cp CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st WHERE DB_NAME(st.dbid) IS NOT NULL AND cp.objtype = 'proc' GROUP BY cp.plan_handle ,DB_NAME(st.dbid) ,OBJECT_SCHEMA_NAME(objectid, st.dbid) ,OBJECT_NAME(objectid, st.dbid) In my results I see the same stored procedure using 2 different plans, I'm curious as to why. Initially I figured the plan was updated and now it's using the new but I see execution counts increasing for both.
I'm not trying to solve any issues here i'm running this script to determine what sprocs are still in use, mostly just curious if anyone knows why a sproc would use 2 different plans?
thanks
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 6,826,
Visits: 11,951
|
|
That can be caused by two sessions executing the proc with different SET options, e.g. ARITHABORT. Each execution plan has within it the set of server options that are set. Since those server options can affect behavior SQL Server must generate a new plan and both are cached and re-used where possible.
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 11:38 AM
Points: 389,
Visits: 912
|
|
Ok that makes sense, I figured it was something along those lines but just wasnt sure.
thanks for the reply
|
|
|
|