Skip to content

Commit 109d606

Browse files
authored
Merge pull request #1391 from BrentOzarULTD/issue_1380
Fix spill math
2 parents 4bc6e73 + fc06b53 commit 109d606

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

sp_BlitzCache.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ SELECT @body += N' ORDER BY ' +
17301730
WHEN N'avg writes' THEN N'total_logical_writes / execution_count'
17311731
WHEN N'avg duration' THEN N'total_elapsed_time / execution_count'
17321732
WHEN N'avg memory grant' THEN N'CASE WHEN max_grant_kb = 0 THEN 0 ELSE max_grant_kb / execution_count END'
1733-
WHEN N'avg spills' THEN N'CASE WHEN max_spills = 0 THEN 0 ELSE max_spills / total_spills END'
1733+
WHEN N'avg spills' THEN N'CASE WHEN total_spills = 0 THEN 0 ELSE total_spills / execution_count END'
17341734
WHEN N'avg executions' THEN 'CASE WHEN execution_count = 0 THEN 0
17351735
WHEN COALESCE(CAST((CASE WHEN DATEDIFF(mi, cached_time, GETDATE()) > 0 AND execution_count > 1
17361736
THEN DATEDIFF(mi, cached_time, GETDATE())
@@ -1829,7 +1829,7 @@ SELECT TOP (@Top)
18291829
min_spills AS MinSpills,
18301830
max_spills AS MaxSpills,
18311831
total_spills AS TotalSpills,
1832-
CAST(ISNULL(NULLIF(( max_spills * 1. ), 0) / NULLIF(total_spills, 0), 0) AS MONEY) AS AvgSpills, ';
1832+
CAST(ISNULL(NULLIF(( total_spills * 1. ), 0) / NULLIF(execution_count, 0), 0) AS MONEY) AS AvgSpills, ';
18331833
END;
18341834
ELSE
18351835
BEGIN
@@ -1962,7 +1962,7 @@ BEGIN
19621962
min_spills AS MinSpills,
19631963
max_spills AS MaxSpills,
19641964
total_spills AS TotalSpills,
1965-
CAST(ISNULL(NULLIF(( max_spills * 1. ), 0) / NULLIF(total_spills, 0), 0) AS MONEY) AS AvgSpills, ';
1965+
CAST(ISNULL(NULLIF(( total_spills * 1. ), 0) / NULLIF(execution_count, 0), 0) AS MONEY) AS AvgSpills,';
19661966
END;
19671967
ELSE
19681968
BEGIN
@@ -2043,7 +2043,7 @@ BEGIN
20432043
min_spills AS MinSpills,
20442044
max_spills AS MaxSpills,
20452045
total_spills AS TotalSpills,
2046-
CAST(ISNULL(NULLIF(( max_spills * 1. ), 0) / NULLIF(total_spills, 0), 0) AS MONEY) AS AvgSpills, ',
2046+
CAST(ISNULL(NULLIF(( total_spills * 1. ), 0) / NULLIF(execution_count, 0), 0) AS MONEY) AS AvgSpills, ',
20472047
N'
20482048
NULL AS MinSpills,
20492049
NULL AS MaxSpills,
@@ -2110,7 +2110,7 @@ SELECT @sort = CASE @SortOrder WHEN N'cpu' THEN N'total_worker_time'
21102110
WHEN N'avg writes' THEN N'total_logical_writes / execution_count'
21112111
WHEN N'avg duration' THEN N'total_elapsed_time / execution_count'
21122112
WHEN N'avg memory grant' THEN N'CASE WHEN max_grant_kb = 0 THEN 0 ELSE max_grant_kb / execution_count END'
2113-
WHEN N'avg spills' THEN N'CASE WHEN max_spills = 0 THEN 0 ELSE max_spills / total_spills END'
2113+
WHEN N'avg spills' THEN N'CASE WHEN total_spills = 0 THEN 0 ELSE total_spills / execution_count END'
21142114
WHEN N'avg executions' THEN N'CASE WHEN execution_count = 0 THEN 0
21152115
WHEN COALESCE(age_minutes, age_minutes_lifetime, 0) = 0 THEN 0
21162116
ELSE CAST((1.00 * execution_count / COALESCE(age_minutes, age_minutes_lifetime)) AS money)

0 commit comments

Comments
 (0)