Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sp_BlitzLock.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3618,7 +3618,7 @@ BEGIN
en =
DENSE_RANK() OVER (ORDER BY dp.event_date),
qn =
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date),
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date) - 1,
dn =
Comment on lines 3618 to 3622
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qn is now 0-based (ROW_NUMBER() - 1), but downstream formatting later builds deadlock_group with CASE WHEN d.qn = 0 THEN '1' ELSE CONVERT(..., d.qn) END, which will label both qn=0 and qn=1 as "Query #1". Update the consumer to display d.qn + 1 (or otherwise adjust) so query numbering remains correct, especially for parallel deadlocks where only qn<2 rows are kept.

Copilot uses AI. Check for mistakes.
ROW_NUMBER() OVER (PARTITION BY dp.event_date, dp.id ORDER BY dp.event_date),
Comment on lines +3621 to 3623
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ROW_NUMBER() uses ORDER BY dp.event_date inside PARTITION BY dp.event_date, which is non-deterministic because all rows in the partition have the same ordering key. Since qn is used to filter parallel deadlocks to the first 2 rows, consider ordering by a stable discriminator (e.g., dp.id and/or dp.spid) to ensure consistent row selection.

Suggested change
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date) - 1,
dn =
ROW_NUMBER() OVER (PARTITION BY dp.event_date, dp.id ORDER BY dp.event_date),
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.id, dp.spid) - 1,
dn =
ROW_NUMBER() OVER (PARTITION BY dp.event_date, dp.id ORDER BY dp.spid, dp.id),

Copilot uses AI. Check for mistakes.
dp.is_victim,
Expand Down Expand Up @@ -3703,7 +3703,7 @@ BEGIN
en =
DENSE_RANK() OVER (ORDER BY dp.event_date),
qn =
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date),
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date) - 1,
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as earlier: with qn now 0-based, the later deadlock_group label logic (WHEN d.qn = 0 THEN '1' ELSE CONVERT(..., d.qn)) will mislabel qn=1 as "Query #1". Adjust the label computation to use d.qn + 1 (or equivalent) so output query numbering stays correct.

Suggested change
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date) - 1,
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date),

Copilot uses AI. Check for mistakes.
dn =
ROW_NUMBER() OVER (PARTITION BY dp.event_date, dp.id ORDER BY dp.event_date),
Comment on lines +3706 to 3708
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same non-determinism here: ROW_NUMBER() orders by dp.event_date while partitioning by dp.event_date, so qn assignment can change between runs/plans. Because later logic filters qn < 2 for parallel deadlocks, order by a stable column (e.g., dp.id, dp.spid) to make the filter deterministic.

Suggested change
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.event_date) - 1,
dn =
ROW_NUMBER() OVER (PARTITION BY dp.event_date, dp.id ORDER BY dp.event_date),
ROW_NUMBER() OVER (PARTITION BY dp.event_date ORDER BY dp.id, dp.spid) - 1,
dn =
ROW_NUMBER() OVER (PARTITION BY dp.event_date, dp.id ORDER BY dp.spid),

Copilot uses AI. Check for mistakes.
is_victim = 1,
Expand Down