@@ -107,16 +107,16 @@ BEGIN
107107 END ;
108108
109109 /*
110- First run detection - collect last 1 hour of procedures if this is the first execution
110+ First run detection - collect all procedures if this is the first execution
111111 */
112112 IF NOT EXISTS (SELECT 1 / 0 FROM collect .procedure_stats )
113113 AND NOT EXISTS (SELECT 1 / 0 FROM config .collection_log WHERE collector_name = N ' procedure_stats_collector' )
114114 BEGIN
115- SET @cutoff_time = DATEADD (HOUR, - 1 , SYSDATETIME () );
115+ SET @cutoff_time = CONVERT ( datetime2 ( 7 ), ' 19000101' );
116116
117117 IF @debug = 1
118118 BEGIN
119- RAISERROR (N ' First run detected - collecting last 1 hour of procedure stats ' , 0 , 1 ) WITH NOWAIT ;
119+ RAISERROR (N ' First run detected - collecting all procedures from sys.dm_exec_procedure_stats ' , 0 , 1 ) WITH NOWAIT ;
120120 END ;
121121 END ;
122122 ELSE
@@ -153,17 +153,6 @@ BEGIN
153153 RAISERROR (N ' Collecting procedure stats with cutoff time: %s' , 0 , 1 , @cutoff_time_string) WITH NOWAIT ;
154154 END ;
155155
156- /*
157- Read collection flag for plans
158- */
159- DECLARE
160- @collect_plan bit = 1 ;
161-
162- SELECT
163- @collect_plan = cs .collect_plan
164- FROM config .collection_schedule AS cs
165- WHERE cs .collector_name = N ' procedure_stats_collector' ;
166-
167156 /*
168157 Collect procedure, trigger, and function statistics
169158 Single query with UNION ALL to collect from all three DMVs
@@ -234,12 +223,7 @@ BEGIN
234223 total_spills = ps .total_spills ,
235224 min_spills = ps .min_spills ,
236225 max_spills = ps .max_spills ,
237- query_plan_text =
238- CASE
239- WHEN @collect_plan = 1
240- THEN CONVERT (nvarchar (max ), tqp .query_plan )
241- ELSE NULL
242- END
226+ query_plan_text = CONVERT (nvarchar (max ), tqp .query_plan )
243227 FROM sys .dm_exec_procedure_stats AS ps
244228 OUTER APPLY
245229 sys .dm_exec_text_query_plan
@@ -402,12 +386,7 @@ BEGIN
402386 total_spills = ts .total_spills ,
403387 min_spills = ts .min_spills ,
404388 max_spills = ts .max_spills ,
405- query_plan_text =
406- CASE
407- WHEN @collect_plan = 1
408- THEN CONVERT (nvarchar (max ), tqp .query_plan )
409- ELSE NULL
410- END
389+ query_plan_text = CONVERT (nvarchar (max ), tqp .query_plan )
411390 FROM sys .dm_exec_trigger_stats AS ts
412391 CROSS APPLY sys .dm_exec_sql_text (ts .sql_handle ) AS st
413392 OUTER APPLY
@@ -467,12 +446,7 @@ BEGIN
467446 total_spills = NULL ,
468447 min_spills = NULL ,
469448 max_spills = NULL ,
470- query_plan_text =
471- CASE
472- WHEN @collect_plan = 1
473- THEN CONVERT (nvarchar (max ), tqp .query_plan )
474- ELSE NULL
475- END
449+ query_plan_text = CONVERT (nvarchar (max ), tqp .query_plan )
476450 FROM sys .dm_exec_function_stats AS fs
477451 OUTER APPLY
478452 sys .dm_exec_text_query_plan
0 commit comments