Skip to content

Commit 715346f

Browse files
Merge pull request #758 from erikdarlingdata/dev
Align scoring dimensions between sp_QuickieCache and sp_QuickieStore
2 parents f807476 + 228cd42 commit 715346f

3 files changed

Lines changed: 231 additions & 67 deletions

File tree

Install-All/DarlingData.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43646,7 +43646,7 @@ OPTION(RECOMPILE);' + @nc10;
4364643646
N', ' +
4364743647
ws2.wait_category_desc +
4364843648
N' (' +
43649-
CONVERT(nvarchar(20), CONVERT(integer, ws2.total_wait_ms)) +
43649+
CONVERT(nvarchar(20), CONVERT(bigint, ws2.total_wait_ms)) +
4365043650
N' ms)'
4365143651
FROM #hi_wait_staging AS ws2
4365243652
WHERE ws2.query_hash = ws.query_hash

sp_QuickieCache/sp_QuickieCache.sql

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -451,27 +451,27 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
451451
DB_NAME(CONVERT(integer, MAX(pa.value))),
452452
qs.query_hash,
453453
plan_count =
454-
COUNT_BIG(DISTINCT qs.plan_handle),
454+
FORMAT(COUNT_BIG(DISTINCT qs.plan_handle), N'N0'),
455455
total_executions =
456-
SUM(qs.execution_count),
456+
FORMAT(SUM(qs.execution_count), N'N0'),
457457
total_cpu_ms =
458-
SUM(qs.total_worker_time) / 1000.0,
458+
FORMAT(SUM(qs.total_worker_time) / 1000.0, N'N3'),
459459
total_duration_ms =
460-
SUM(qs.total_elapsed_time) / 1000.0,
460+
FORMAT(SUM(qs.total_elapsed_time) / 1000.0, N'N3'),
461461
total_logical_reads =
462-
SUM(qs.total_logical_reads),
462+
FORMAT(SUM(qs.total_logical_reads), N'N0'),
463463
total_logical_writes =
464-
SUM(qs.total_logical_writes),
464+
FORMAT(SUM(qs.total_logical_writes), N'N0'),
465465
total_physical_reads =
466-
SUM(qs.total_physical_reads),
466+
FORMAT(SUM(qs.total_physical_reads), N'N0'),
467467
total_rows =
468-
SUM(qs.total_rows),
468+
FORMAT(SUM(qs.total_rows), N'N0'),
469469
min_rows =
470-
MIN(qs.min_rows),
470+
FORMAT(MIN(qs.min_rows), N'N0'),
471471
max_rows =
472-
MAX(qs.max_rows),
473-
total_cached_size_kb =
474-
SUM(cp.size_in_bytes) / 1024,
472+
FORMAT(MAX(qs.max_rows), N'N0'),
473+
total_cached_size_mb =
474+
FORMAT(SUM(cp.size_in_bytes) / 1048576.0, N'N2'),
475475
oldest_plan =
476476
MIN(qs.creation_time),
477477
newest_plan =
@@ -958,8 +958,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
958958
max_rows bigint NULL,
959959
min_cpu_ms decimal(38, 2) NULL,
960960
max_cpu_ms decimal(38, 2) NULL,
961-
min_logical_reads bigint NULL,
962-
max_logical_reads bigint NULL,
961+
min_physical_reads bigint NULL,
962+
max_physical_reads bigint NULL,
963963
min_duration_ms decimal(38, 2) NULL,
964964
max_duration_ms decimal(38, 2) NULL,
965965
oldest_plan_creation datetime NULL,
@@ -1019,8 +1019,8 @@ WITH
10191019
max_rows,
10201020
min_cpu_ms,
10211021
max_cpu_ms,
1022-
min_logical_reads,
1023-
max_logical_reads,
1022+
min_physical_reads,
1023+
max_physical_reads,
10241024
min_duration_ms,
10251025
max_duration_ms,
10261026
oldest_plan_creation,
@@ -1068,8 +1068,8 @@ SELECT
10681068
max_rows = MAX(qs.max_rows),
10691069
min_cpu_ms = MIN(qs.min_worker_time) / 1000.0,
10701070
max_cpu_ms = MAX(qs.max_worker_time) / 1000.0,
1071-
min_logical_reads = MIN(qs.min_logical_reads),
1072-
max_logical_reads = MAX(qs.max_logical_reads),
1071+
min_physical_reads = MIN(qs.min_physical_reads),
1072+
max_physical_reads = MAX(qs.max_physical_reads),
10731073
min_duration_ms = MIN(qs.min_elapsed_time) / 1000.0,
10741074
max_duration_ms = MAX(qs.max_elapsed_time) / 1000.0,
10751075
oldest_plan_creation = MIN(qs.creation_time),
@@ -1445,7 +1445,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
14451445
DECLARE
14461446
@total_cpu_ms decimal(38, 2) = 0,
14471447
@total_duration_ms decimal(38, 2) = 0,
1448-
@total_logical_reads bigint = 0,
1448+
@total_physical_reads bigint = 0,
14491449
@total_logical_writes bigint = 0,
14501450
@total_grant_mb decimal(38, 2) = 0,
14511451
@total_spills bigint = 0,
@@ -1455,7 +1455,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
14551455
SELECT
14561456
@total_cpu_ms = SUM(qs.total_cpu_ms),
14571457
@total_duration_ms = SUM(qs.total_duration_ms),
1458-
@total_logical_reads = SUM(qs.total_logical_reads),
1458+
@total_physical_reads = SUM(qs.total_physical_reads),
14591459
@total_logical_writes = SUM(qs.total_logical_writes),
14601460
@total_grant_mb = SUM(qs.total_grant_mb),
14611461
@total_spills = SUM(qs.total_spills),
@@ -1469,7 +1469,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
14691469
SELECT
14701470
@debug_msg =
14711471
N'Workload totals — CPU: ' + CONVERT(nvarchar(20), @total_cpu_ms) +
1472-
N' ms, Reads: ' + CONVERT(nvarchar(20), @total_logical_reads) +
1472+
N' ms, Physical Reads: ' + CONVERT(nvarchar(20), @total_physical_reads) +
14731473
N', Executions: ' + CONVERT(nvarchar(20), @total_executions) +
14741474
N', Entries: ' + CONVERT(nvarchar(20), @total_entries);
14751475
RAISERROR(N'%s', 0, 1, @debug_msg) WITH NOWAIT;
@@ -1521,7 +1521,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
15211521
qs.id
15221522
FROM #query_stats AS qs
15231523
ORDER BY
1524-
qs.total_logical_reads DESC
1524+
qs.total_physical_reads DESC
15251525

15261526
UNION
15271527

@@ -1589,9 +1589,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
15891589
total_executions bigint NOT NULL,
15901590
total_cpu_ms decimal(38, 2) NOT NULL,
15911591
total_duration_ms decimal(38, 2) NOT NULL,
1592-
total_logical_reads bigint NOT NULL,
1593-
total_logical_writes bigint NOT NULL,
15941592
total_physical_reads bigint NOT NULL,
1593+
total_logical_writes bigint NOT NULL,
15951594
total_rows bigint NOT NULL,
15961595
total_grant_mb decimal(38, 2) NOT NULL,
15971596
total_used_grant_mb decimal(38, 2) NOT NULL,
@@ -1604,8 +1603,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
16041603
max_rows bigint NULL,
16051604
min_cpu_ms decimal(38, 2) NULL,
16061605
max_cpu_ms decimal(38, 2) NULL,
1607-
min_logical_reads bigint NULL,
1608-
max_logical_reads bigint NULL,
1606+
min_physical_reads bigint NULL,
1607+
max_physical_reads bigint NULL,
16091608
min_duration_ms decimal(38, 2) NULL,
16101609
max_duration_ms decimal(38, 2) NULL,
16111610

@@ -1656,9 +1655,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
16561655
total_executions,
16571656
total_cpu_ms,
16581657
total_duration_ms,
1659-
total_logical_reads,
1660-
total_logical_writes,
16611658
total_physical_reads,
1659+
total_logical_writes,
16621660
total_rows,
16631661
total_grant_mb,
16641662
total_used_grant_mb,
@@ -1671,8 +1669,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
16711669
max_rows,
16721670
min_cpu_ms,
16731671
max_cpu_ms,
1674-
min_logical_reads,
1675-
max_logical_reads,
1672+
min_physical_reads,
1673+
max_physical_reads,
16761674
min_duration_ms,
16771675
max_duration_ms,
16781676
cpu_share,
@@ -1707,9 +1705,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
17071705
total_executions = qs.total_executions,
17081706
total_cpu_ms = qs.total_cpu_ms,
17091707
total_duration_ms = qs.total_duration_ms,
1710-
total_logical_reads = qs.total_logical_reads,
1711-
total_logical_writes = qs.total_logical_writes,
17121708
total_physical_reads = qs.total_physical_reads,
1709+
total_logical_writes = qs.total_logical_writes,
17131710
total_rows = qs.total_rows,
17141711
total_grant_mb = qs.total_grant_mb,
17151712
total_used_grant_mb = qs.total_used_grant_mb,
@@ -1722,8 +1719,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
17221719
max_rows = qs.max_rows,
17231720
min_cpu_ms = qs.min_cpu_ms,
17241721
max_cpu_ms = qs.max_cpu_ms,
1725-
min_logical_reads = qs.min_logical_reads,
1726-
max_logical_reads = qs.max_logical_reads,
1722+
min_physical_reads = qs.min_physical_reads,
1723+
max_physical_reads = qs.max_physical_reads,
17271724
min_duration_ms = qs.min_duration_ms,
17281725
max_duration_ms = qs.max_duration_ms,
17291726

@@ -1742,8 +1739,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
17421739
END,
17431740
reads_share =
17441741
CASE
1745-
WHEN @total_logical_reads > 0
1746-
THEN CONVERT(decimal(5, 2), qs.total_logical_reads * 100.0 / @total_logical_reads)
1742+
WHEN @total_physical_reads > 0
1743+
THEN CONVERT(decimal(5, 2), qs.total_physical_reads * 100.0 / @total_physical_reads)
17471744
ELSE 0
17481745
END,
17491746
writes_share =
@@ -1799,12 +1796,12 @@ OPTION(RECOMPILE, MAXDOP 1);';
17991796
END,
18001797
reads_pctl =
18011798
CASE
1802-
WHEN @total_logical_reads > 0
1803-
AND qs.total_logical_reads * 1.0 / @total_logical_reads >= 0.001
1799+
WHEN @total_physical_reads > 0
1800+
AND qs.total_physical_reads * 1.0 / @total_physical_reads >= 0.001
18041801
THEN PERCENT_RANK() OVER
18051802
(
18061803
ORDER BY
1807-
qs.total_logical_reads
1804+
qs.total_physical_reads
18081805
)
18091806
ELSE NULL
18101807
END,
@@ -1909,7 +1906,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
19091906
s.high_signals =
19101907
CASE WHEN s.cpu_pctl >= 0.80 THEN N'cpu, ' ELSE N'' END +
19111908
CASE WHEN s.duration_pctl >= 0.80 THEN N'duration, ' ELSE N'' END +
1912-
CASE WHEN s.reads_pctl >= 0.80 THEN N'reads, ' ELSE N'' END +
1909+
CASE WHEN s.reads_pctl >= 0.80 THEN N'physical reads, ' ELSE N'' END +
19131910
CASE WHEN s.writes_pctl >= 0.80 THEN N'writes, ' ELSE N'' END +
19141911
CASE WHEN s.grant_pctl >= 0.80 THEN N'memory, ' ELSE N'' END +
19151912
CASE WHEN s.spills_pctl >= 0.80 THEN N'spills, ' ELSE N'' END +
@@ -2005,20 +2002,20 @@ OPTION(RECOMPILE, MAXDOP 1);';
20052002
FORMAT(CONVERT(bigint, s.total_cpu_ms / s.total_executions), N'N0') +
20062003
N' ms); '
20072004
WHEN s.total_executions > 3
2008-
AND s.min_logical_reads IS NOT NULL
2009-
AND s.max_logical_reads IS NOT NULL
2010-
AND s.total_logical_reads / s.total_executions > 100000
2005+
AND s.min_physical_reads IS NOT NULL
2006+
AND s.max_physical_reads IS NOT NULL
2007+
AND s.total_physical_reads / s.total_executions > 1000
20112008
AND
20122009
(
2013-
s.min_logical_reads < (s.total_logical_reads / s.total_executions) * 0.70
2014-
OR s.max_logical_reads > (s.total_logical_reads / s.total_executions) * 1.30
2010+
s.min_physical_reads < (s.total_physical_reads / s.total_executions) * 0.70
2011+
OR s.max_physical_reads > (s.total_physical_reads / s.total_executions) * 1.30
20152012
)
2016-
THEN N'Parameter sniffing (reads ' +
2017-
FORMAT(s.min_logical_reads, N'N0') +
2013+
THEN N'Parameter sniffing (physical reads ' +
2014+
FORMAT(s.min_physical_reads, N'N0') +
20182015
N'-' +
2019-
FORMAT(s.max_logical_reads, N'N0') +
2016+
FORMAT(s.max_physical_reads, N'N0') +
20202017
N', avg ' +
2021-
FORMAT(s.total_logical_reads / s.total_executions, N'N0') +
2018+
FORMAT(s.total_physical_reads / s.total_executions, N'N0') +
20222019
N'); '
20232020
ELSE N''
20242021
END +
@@ -2238,7 +2235,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
22382235
s.diagnostics,
22392236
s.total_cpu_ms,
22402237
s.total_duration_ms,
2241-
s.total_logical_reads,
2238+
s.total_physical_reads,
22422239
s.total_logical_writes,
22432240
s.total_grant_mb,
22442241
s.total_spills,

0 commit comments

Comments
 (0)