Skip to content

Commit c460316

Browse files
Honor @pending_task_threshold in sp_HealthParser scheduler shreds
@pending_task_threshold documents the minimum pending-task count the caller wants to see, but two shreds silently ignored it: 1. #scheduler_details WHERE clause (line ~2954): AND (... pendingTasks[.>= sql:variable("@pending_task_threshold")] ... OR @warnings_only = 0) The `OR @warnings_only = 0` short-circuit meant that whenever the user ran in the default @warnings_only = 0 mode, the threshold predicate evaluated to TRUE regardless of the pending-task value. Setting @pending_task_threshold = 100 returned rows with 2 pending tasks just the same. 2. #pending_task_details CROSS APPLY (line ~3179): ... queryProcessing[@pendingTasks > 1] ... Hardcoded literal 1, again with no reference to the parameter. Both now use sql:variable("@pending_task_threshold") unconditionally. @warnings_only still independently controls the WARNING-state filter. Verified the sproc installs clean and @what_to_check = 'scheduler' with @pending_task_threshold = 100 runs without errors against the system_health session on SQL Server 2022. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7a9919f commit c460316

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

sp_HealthParser/sp_HealthParser.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,11 @@ AND ca.utc_timestamp < @end_date';
29512951
CROSS APPLY wi.sp_server_diagnostics_component_result.nodes('/event') AS w(x)
29522952
WHERE w.x.exist('(data[@name="component"]/text[.= "QUERY_PROCESSING"])') = 1
29532953
AND (w.x.exist('(data[@name="state"]/text[.= "WARNING"])') = @warnings_only OR @warnings_only = 0)
2954-
AND (w.x.exist('(/event/data[@name="data"]/value/queryProcessing/@pendingTasks[.>= sql:variable("@pending_task_threshold")])') = 1 OR @warnings_only = 0)
2954+
/* Threshold is honored whether or not @warnings_only is set — the
2955+
parameter documents "minimum pending tasks to display" and the
2956+
previous `OR @warnings_only = 0` short-circuit silently ignored
2957+
the user-supplied value whenever warnings-only was off. */
2958+
AND w.x.exist('(/event/data[@name="data"]/value/queryProcessing/@pendingTasks[.>= sql:variable("@pending_task_threshold")])') = 1
29552959
OPTION(RECOMPILE, MAXDOP 1);
29562960

29572961
IF @debug = 1
@@ -3176,7 +3180,10 @@ AND ca.utc_timestamp < @end_date';
31763180
INTO #pending_task_details
31773181
FROM #sp_server_diagnostics_component_result AS wi
31783182
CROSS APPLY wi.sp_server_diagnostics_component_result.nodes('/event') AS w(x)
3179-
CROSS APPLY w.x.nodes('/event/data[@name="data"]/value/queryProcessing[@pendingTasks > 1]/pendingTasks/entryPoint') AS ep(e)
3183+
/* Hardcoded threshold > 1 ignored the @pending_task_threshold
3184+
parameter. Replaced with sql:variable() binding so the user's
3185+
value actually takes effect here too. */
3186+
CROSS APPLY w.x.nodes('/event/data[@name="data"]/value/queryProcessing[@pendingTasks >= sql:variable("@pending_task_threshold")]/pendingTasks/entryPoint') AS ep(e)
31803187
WHERE w.x.exist('(data[@name="component"]/text[.= "QUERY_PROCESSING"])') = 1
31813188
AND (w.x.exist('(data[@name="state"]/text[.= "WARNING"])') = @warnings_only OR @warnings_only = 0)
31823189
OPTION(RECOMPILE, MAXDOP 1);

0 commit comments

Comments
 (0)