November 16, 2010 at 2:41 am
Hi All,
I have few doubts on execution plans.
1) How to find the Stored Procuders which has/Generates multiple execution plans?
2) How to avoid the generation of multiple execution plans by SP's.
Please help me on this guys..:-)
Thanks in advance.
Regards,
Vijay Singh
November 16, 2010 at 3:29 am
by default query processor generates multiple execution plan for any query that you submit and chooses one of them based on least cost. This is by design and you cannot control it. There are some cases where in if query processor determines that choosing amongst various execution plan is going to take more time, it generates one plan and executes the query as per that plan.
you can click on include actual execution plan to see what is the plan selected by the query processor.
November 16, 2010 at 3:45 am
The only way you'll have multiple plans per procedure is if the procedure has been run with different SET options. Certain set options (see BoL for details) change the way the query must be executed and hence get a different plan.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 16, 2010 at 4:34 am
Thanks for the updates..:-)
When i saw the Cache i got SPs with multiple cache plan even after not changing the SET options.
Is there any other way to avoid this?
Thanks,
Vijay Singh
November 16, 2010 at 4:39 am
what query are you running to see that?
November 16, 2010 at 4:42 am
Hi Pradeep,
Below is the query :
SELECT db_name(st.dbid) DBName,
object_schema_name(st.objectid, dbid) SchemaName,
object_name(st.objectid, dbid) StoredProcedure,
MAX(cp.usecounts) Execution_count,
st.text [Plan_Text]
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),
st.text
ORDER BY MAX(cp.usecounts) DESC
Thanks,
Vijay Singh
November 16, 2010 at 4:55 am
In some cases, query processor may keep two plans, 1) without using parallelism, 2) using parallism and use either of them.
beyond that, i cant think why you are seeing several plans for one sp.
November 16, 2010 at 6:29 am
ps. (11/16/2010)
In some cases, query processor may keep two plans, 1) without using parallelism, 2) using parallism and use either of them.
Nope. Recently debunked by Paul White (I'll leave it to him to come up with url, I'm working on a freshly installed machine)
If there are multiple plans (ie with different plan handles) then either set options are different or (user is different and query is not safe for reuse between different users)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 16, 2010 at 8:35 am
Yes i have that URL. He explained that a parallel plan can also be executed by a single processor.
http://sqlblog.com/blogs/paul_white/default.aspx%5B/url%5D
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply