Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vsatya25
Starting Member
1 Post |
Posted - 2012-08-28 : 11:29:39
|
I see several entries of "UPDATE MSDB.DBO.SYSJOBSCHEDULES SET NEXT_RUN_DATE = ...." in cache.You can find those using this query:select * from sys.dm_exec_cached_plans across apply sys.dm_exec_sql_text (a.plan_handle)where text like '%update msdb.dbo.sysjobschedules%'Every time when it compiles, it is occupying 24kb and filling up the cache memory.Do you guys know how to parameterize it?Thanks,Venkat |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
komkrit
Yak Posting Veteran
60 Posts |
Posted - 2012-08-28 : 13:59:39
|
Dear Venkat,By default, SQL Server use Parameteriztion = Simple Mode.That is mean only simple statement will be enforced to use parameterization.In cache plan, it will be transform to be parameterized form.If your statement could not be choosed by optimizer to be parameterized,that is mean your statement is looking(for optimizer) not simple.You have choices.1. Enabling Forced Parameterizationexample--------------------------------------------------------ALTER DATABASE YOUR_DATABASE SET PARAMETERIZATION FORCED--------------------------------------------------------this does not recommend because it will enforce all statements to be parameterization, even though it make performance worse.2. Enabling Forced Parameterization for a single query using "Plan Guide"example--------------------------------------------------------DECLARE @stmt nvarchar(max);DECLARE @params nvarchar(max);EXEC sp_get_query_templateN'UPDATE MSDB.DBO.SYSJOBSCHEDULES SET NEXT_RUN_DATE = ....;',@stmt OUTPUT,@params OUTPUT;EXEC sp_create_plan_guideN'MyPlanGuide_JobResults',@stmt,N'TEMPLATE',NULL,@params,N'OPTION(PARAMETERIZATION FORCED)';--View all plans in your systemSELECT * FROM sys.plan_guides-- monitor cached planSELECT *FROM sys.dm_exec_query_stats qsCROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qtINNER JOIN sys.dm_exec_cached_plans as cp on qs.plan_handle=cp.plan_handleWHERE cp.plan_handle=qs.plan_handleAND (ObjType = 'Adhoc' OR ObjType='Prepared')-- clear cacheDBCC DROPCLEANBUFFERSDBCC FREEPROCCACHE- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Komkrit YensirikulWelcome for all questions. Let us know if our solution solved your problem. |
|
|
|
|
|
|
|