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

Execution Plan Reuse Expand / Collapse
Author
Message
Posted Friday, November 9, 2012 2:56 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, August 8, 2014 6:54 AM
Points: 58, Visits: 239
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?
Post #1383262
Posted Friday, November 9, 2012 4:36 PM


SSC-Forever

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

Group: General Forum Members
Last Login: Yesterday @ 3:52 PM
Points: 42,849, Visits: 35,978
Huh?


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 #1383296
Posted Saturday, November 10, 2012 5:08 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, August 8, 2014 6:54 AM
Points: 58, Visits: 239
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.
Post #1383359
Posted Monday, November 12, 2012 11:03 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: Yesterday @ 3:52 PM
Points: 42,849, Visits: 35,978
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 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 #1383788
Posted Wednesday, November 14, 2012 7:36 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, August 8, 2014 6:54 AM
Points: 58, Visits: 239
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?
Post #1384625
Posted Wednesday, November 14, 2012 7:47 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: Yesterday @ 3:52 PM
Points: 42,849, Visits: 35,978
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 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 #1384638
Posted Wednesday, November 14, 2012 8:05 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, August 8, 2014 6:54 AM
Points: 58, Visits: 239
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.
Post #1384647
Posted Wednesday, November 14, 2012 8:17 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: Yesterday @ 3:52 PM
Points: 42,849, Visits: 35,978
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 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 #1384663
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse