Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Stored Procuders which has multiple execution plans Expand / Collapse
Author
Message
Posted Tuesday, November 16, 2010 2:41 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, February 16, 2011 10:51 PM
Points: 83, Visits: 53
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
Post #1021318
Posted Tuesday, November 16, 2010 3:29 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, November 10, 2014 2:21 AM
Points: 2,223, Visits: 3,652
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.







Pradeep Singh
Post #1021332
Posted Tuesday, November 16, 2010 3:45 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:32 AM
Points: 40,448, Visits: 36,903
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1021340
Posted Tuesday, November 16, 2010 4:34 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, February 16, 2011 10:51 PM
Points: 83, Visits: 53
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
Post #1021363
Posted Tuesday, November 16, 2010 4:39 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, November 10, 2014 2:21 AM
Points: 2,223, Visits: 3,652
what query are you running to see that?




Pradeep Singh
Post #1021368
Posted Tuesday, November 16, 2010 4:42 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, February 16, 2011 10:51 PM
Points: 83, Visits: 53
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
Post #1021370
Posted Tuesday, November 16, 2010 4:55 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, November 10, 2014 2:21 AM
Points: 2,223, Visits: 3,652
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.





Pradeep Singh
Post #1021377
Posted Tuesday, November 16, 2010 6:29 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:32 AM
Points: 40,448, Visits: 36,903
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1021441
Posted Tuesday, November 16, 2010 8:35 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, November 10, 2014 2:21 AM
Points: 2,223, Visits: 3,652
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





Pradeep Singh
Post #1021539
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse