SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Execution Plan Reuse


Execution Plan Reuse

Author
Message
jhager
jhager
SSC Veteran
SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)

Group: General Forum Members
Points: 220 Visits: 331
We have SPs that take several parameters; when I check the plan cache using

... FROM
sys.dm_exec_cached_plans AS ECP
CROSS APPLY
sys.dm_exec_sql_text(ECP.plan_handle) AS ESQL
...
I see lots of reuse for "Compiled Plan", "Proc", SQL Text like "Create Proc xyz..."

but for "Compiled Plan","Prepared", SQL text like "EXEC xyz 'A','B','C'..." has no reuse.

Is there a not complicated method to EXECute the SPs with plan reuse?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91879 Visits: 45285
Huh?

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

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


jhager
jhager
SSC Veteran
SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)

Group: General Forum Members
Points: 220 Visits: 331
Sorry if I was too cryptic/concise...

1) Here's the query I run to check exec plan reuse:

SELECT ECP.usecounts,ECP.refcounts,ECP.cacheobjtype,ECP.objtype,EST.[text]
FROM
sys.dm_exec_cached_plans AS ECP
CROSS APPLY
sys.dm_exec_sql_text(ECP.plan_handle) AS EST
ORDER BY
ECP.usecounts DESC,EST.[text]
;

One row of output:

usecounts refcounts cacheobjtype objtype text
540253 2 Compiled Plan Proc Create Proc mt_amstas30 @SourceID varchar(3),TaskID int,....

Other rows of output (there are thousands of these, just the parameters different):

usecounts refcounts cacheobjtype objtype text
1 2 Compiled Plan Prepared exec mt_amstas30 'AMS','77985984',...
1 2 Compiled Plan Prepared exec mt_amstas30 'AMS','77985995',...

My goal is to reuse query plans whenever possible. If I'm interpreting the results of the query correctly, the exec plan for the SP mt_amstas30 is being reused, but the EXEC statements that "start" the SP are not. If this is true, is there a simple way to "start" the SP that does not create a new exec plan when the parameter strings change? My research on MSDN turns up RCP and ODBC calls that are far too complex...

Thanks in advance for any guidance / help you can provide.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91879 Visits: 45285
The batch EXEC ProcA has no execution plan, there's nothing in there, there's nothing to reuse. The plan for the actual execution of the procedure will be reused as per the normal reuse rules.

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

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


jhager
jhager
SSC Veteran
SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)

Group: General Forum Members
Points: 220 Visits: 331
Thanks for responding..perhaps one more question. I'm curious what the query is returning, then: I've got several thousand of these "EXEC mt_" rows returned that differ only by the value(s) of the variable(s). If these are not exec plans, what are they?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91879 Visits: 45285
If there's a select in the batch (which I've seen friom some apps), then the select portion gets a plan, but the EXEC portion has no plan, the plan for the procedure is separate and is the one you see with the text of 'CREATE PROCEDURE', and is reused.

Has a select in, as in has a form kinda, something like

EXEC SomeProc @Param1, @Param2 OUTPUT; select @Param2

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

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


jhager
jhager
SSC Veteran
SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)SSC Veteran (220 reputation)

Group: General Forum Members
Points: 220 Visits: 331
Here's a few rows in their entirety:

exec mt_amstas47 'AMS','78350438','19','4086','0','20121114 08:33','U'

exec mt_amstas47 'AMS','78350438','18','4198','0','20121114 08:33','U'

exec mt_amstas47 'AMS','78350438','22','16','0','20121114 08:33','U'

(There are over 32K rows just calling this one sp; there are hundreds of these similar sp's). I'll have to find out "how" these sp's are called; I think from within an application.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91879 Visits: 45285
Offhand no idea then. I'd have to look at the plan cache myself to figure it out.

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

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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search