November 9, 2012 at 2:56 pm
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?
November 9, 2012 at 4:36 pm
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
November 10, 2012 at 5:08 am
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 PlanProc 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 PlanPrepared exec mt_amstas30 'AMS','77985984',...
1 2 Compiled PlanPrepared 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.
November 12, 2012 at 11:03 am
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
November 14, 2012 at 7:36 am
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?
November 14, 2012 at 7:47 am
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
November 14, 2012 at 8:05 am
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.
November 14, 2012 at 8:17 am
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
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply