Skip to content

Commit dc6e56d

Browse files
Use AND between @Dbid and @database_name filter groups in sp_HealthParser
The deadlock process-list filter combined two "pass-through if NULL" predicate pairs with OR between them: WHERE (x.database_id = @Dbid OR @Dbid = NULL) OR (x.current_database_name = @db OR @db = NULL) which means "match if either pair's parameter is NULL" — so whenever one of the two was unsupplied (or both), the whole filter short- circuited to TRUE, and every row passed regardless of the other parameter's value. The intent is AND: both filters apply independently when their parameter is supplied, and each individually passes through when NULL. Currently masked in practice because an earlier validation block aborts the proc when @database_name is set but @Dbid couldn't be resolved, keeping the two parameters in lockstep. But the shape was broken and would surface the moment that validation relaxed or another caller supplied mismatched inputs. Verified sp_HealthParser installs clean and @what_to_check = 'deadlocks' @database_name = N'PerformanceMonitor' runs against system_health without errors on SQL Server 2022. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 731c746 commit dc6e56d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

sp_HealthParser/sp_HealthParser.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5728,9 +5728,16 @@ AND ca.utc_timestamp < @end_date';
57285728
FROM #deadlocks AS d
57295729
CROSS APPLY d.xml_deadlock_report.nodes('//deadlock/process-list/process') AS e(x)
57305730
) AS x
5731+
/* Standard "filter if supplied, pass-through if NULL" predicate
5732+
pairs must be combined with AND between the groups — OR let
5733+
rows through whenever either parameter was NULL, which makes
5734+
the @database_name/@dbid filter loose whenever only one side
5735+
was supplied. Currently masked because the validation block
5736+
above aborts when the two disagree, but the shape was
5737+
wrong and would break if that validation ever relaxed. */
57315738
WHERE (x.database_id = @dbid
57325739
OR @dbid IS NULL)
5733-
OR (x.current_database_name = @database_name
5740+
AND (x.current_database_name = @database_name
57345741
OR @database_name IS NULL)
57355742
OPTION(RECOMPILE, MAXDOP 1);
57365743

0 commit comments

Comments
 (0)