Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
97 changes: 47 additions & 50 deletions sp_QuickieCache/sp_QuickieCache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -451,27 +451,27 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
DB_NAME(CONVERT(integer, MAX(pa.value))),
qs.query_hash,
plan_count =
COUNT_BIG(DISTINCT qs.plan_handle),
FORMAT(COUNT_BIG(DISTINCT qs.plan_handle), N'N0'),
total_executions =
SUM(qs.execution_count),
FORMAT(SUM(qs.execution_count), N'N0'),
total_cpu_ms =
SUM(qs.total_worker_time) / 1000.0,
FORMAT(SUM(qs.total_worker_time) / 1000.0, N'N3'),
total_duration_ms =
SUM(qs.total_elapsed_time) / 1000.0,
FORMAT(SUM(qs.total_elapsed_time) / 1000.0, N'N3'),
total_logical_reads =
SUM(qs.total_logical_reads),
FORMAT(SUM(qs.total_logical_reads), N'N0'),
total_logical_writes =
SUM(qs.total_logical_writes),
FORMAT(SUM(qs.total_logical_writes), N'N0'),
total_physical_reads =
SUM(qs.total_physical_reads),
FORMAT(SUM(qs.total_physical_reads), N'N0'),
total_rows =
SUM(qs.total_rows),
FORMAT(SUM(qs.total_rows), N'N0'),
min_rows =
MIN(qs.min_rows),
FORMAT(MIN(qs.min_rows), N'N0'),
max_rows =
MAX(qs.max_rows),
total_cached_size_kb =
SUM(cp.size_in_bytes) / 1024,
FORMAT(MAX(qs.max_rows), N'N0'),
total_cached_size_mb =
FORMAT(SUM(cp.size_in_bytes) / 1048576.0, N'N2'),
oldest_plan =
MIN(qs.creation_time),
newest_plan =
Expand Down Expand Up @@ -958,8 +958,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
max_rows bigint NULL,
min_cpu_ms decimal(38, 2) NULL,
max_cpu_ms decimal(38, 2) NULL,
min_logical_reads bigint NULL,
max_logical_reads bigint NULL,
min_physical_reads bigint NULL,
max_physical_reads bigint NULL,
min_duration_ms decimal(38, 2) NULL,
max_duration_ms decimal(38, 2) NULL,
oldest_plan_creation datetime NULL,
Expand Down Expand Up @@ -1019,8 +1019,8 @@ WITH
max_rows,
min_cpu_ms,
max_cpu_ms,
min_logical_reads,
max_logical_reads,
min_physical_reads,
max_physical_reads,
min_duration_ms,
max_duration_ms,
oldest_plan_creation,
Expand Down Expand Up @@ -1068,8 +1068,8 @@ SELECT
max_rows = MAX(qs.max_rows),
min_cpu_ms = MIN(qs.min_worker_time) / 1000.0,
max_cpu_ms = MAX(qs.max_worker_time) / 1000.0,
min_logical_reads = MIN(qs.min_logical_reads),
max_logical_reads = MAX(qs.max_logical_reads),
min_physical_reads = MIN(qs.min_physical_reads),
max_physical_reads = MAX(qs.max_physical_reads),
min_duration_ms = MIN(qs.min_elapsed_time) / 1000.0,
max_duration_ms = MAX(qs.max_elapsed_time) / 1000.0,
oldest_plan_creation = MIN(qs.creation_time),
Expand Down Expand Up @@ -1445,7 +1445,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
DECLARE
@total_cpu_ms decimal(38, 2) = 0,
@total_duration_ms decimal(38, 2) = 0,
@total_logical_reads bigint = 0,
@total_physical_reads bigint = 0,
@total_logical_writes bigint = 0,
@total_grant_mb decimal(38, 2) = 0,
@total_spills bigint = 0,
Expand All @@ -1455,7 +1455,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
SELECT
@total_cpu_ms = SUM(qs.total_cpu_ms),
@total_duration_ms = SUM(qs.total_duration_ms),
@total_logical_reads = SUM(qs.total_logical_reads),
@total_physical_reads = SUM(qs.total_physical_reads),
@total_logical_writes = SUM(qs.total_logical_writes),
@total_grant_mb = SUM(qs.total_grant_mb),
@total_spills = SUM(qs.total_spills),
Expand All @@ -1469,7 +1469,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
SELECT
@debug_msg =
N'Workload totals — CPU: ' + CONVERT(nvarchar(20), @total_cpu_ms) +
N' ms, Reads: ' + CONVERT(nvarchar(20), @total_logical_reads) +
N' ms, Physical Reads: ' + CONVERT(nvarchar(20), @total_physical_reads) +
N', Executions: ' + CONVERT(nvarchar(20), @total_executions) +
N', Entries: ' + CONVERT(nvarchar(20), @total_entries);
RAISERROR(N'%s', 0, 1, @debug_msg) WITH NOWAIT;
Expand Down Expand Up @@ -1521,7 +1521,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
qs.id
FROM #query_stats AS qs
ORDER BY
qs.total_logical_reads DESC
qs.total_physical_reads DESC

UNION

Expand Down Expand Up @@ -1589,9 +1589,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
total_executions bigint NOT NULL,
total_cpu_ms decimal(38, 2) NOT NULL,
total_duration_ms decimal(38, 2) NOT NULL,
total_logical_reads bigint NOT NULL,
total_logical_writes bigint NOT NULL,
total_physical_reads bigint NOT NULL,
total_logical_writes bigint NOT NULL,
total_rows bigint NOT NULL,
total_grant_mb decimal(38, 2) NOT NULL,
total_used_grant_mb decimal(38, 2) NOT NULL,
Expand All @@ -1604,8 +1603,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
max_rows bigint NULL,
min_cpu_ms decimal(38, 2) NULL,
max_cpu_ms decimal(38, 2) NULL,
min_logical_reads bigint NULL,
max_logical_reads bigint NULL,
min_physical_reads bigint NULL,
max_physical_reads bigint NULL,
min_duration_ms decimal(38, 2) NULL,
max_duration_ms decimal(38, 2) NULL,

Expand Down Expand Up @@ -1656,9 +1655,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
total_executions,
total_cpu_ms,
total_duration_ms,
total_logical_reads,
total_logical_writes,
total_physical_reads,
total_logical_writes,
total_rows,
total_grant_mb,
total_used_grant_mb,
Expand All @@ -1671,8 +1669,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
max_rows,
min_cpu_ms,
max_cpu_ms,
min_logical_reads,
max_logical_reads,
min_physical_reads,
max_physical_reads,
min_duration_ms,
max_duration_ms,
cpu_share,
Expand Down Expand Up @@ -1707,9 +1705,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
total_executions = qs.total_executions,
total_cpu_ms = qs.total_cpu_ms,
total_duration_ms = qs.total_duration_ms,
total_logical_reads = qs.total_logical_reads,
total_logical_writes = qs.total_logical_writes,
total_physical_reads = qs.total_physical_reads,
total_logical_writes = qs.total_logical_writes,
total_rows = qs.total_rows,
total_grant_mb = qs.total_grant_mb,
total_used_grant_mb = qs.total_used_grant_mb,
Expand All @@ -1722,8 +1719,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
max_rows = qs.max_rows,
min_cpu_ms = qs.min_cpu_ms,
max_cpu_ms = qs.max_cpu_ms,
min_logical_reads = qs.min_logical_reads,
max_logical_reads = qs.max_logical_reads,
min_physical_reads = qs.min_physical_reads,
max_physical_reads = qs.max_physical_reads,
min_duration_ms = qs.min_duration_ms,
max_duration_ms = qs.max_duration_ms,

Expand All @@ -1742,8 +1739,8 @@ OPTION(RECOMPILE, MAXDOP 1);';
END,
reads_share =
CASE
WHEN @total_logical_reads > 0
THEN CONVERT(decimal(5, 2), qs.total_logical_reads * 100.0 / @total_logical_reads)
WHEN @total_physical_reads > 0
THEN CONVERT(decimal(5, 2), qs.total_physical_reads * 100.0 / @total_physical_reads)
ELSE 0
END,
writes_share =
Expand Down Expand Up @@ -1799,12 +1796,12 @@ OPTION(RECOMPILE, MAXDOP 1);';
END,
reads_pctl =
CASE
WHEN @total_logical_reads > 0
AND qs.total_logical_reads * 1.0 / @total_logical_reads >= 0.001
WHEN @total_physical_reads > 0
AND qs.total_physical_reads * 1.0 / @total_physical_reads >= 0.001
THEN PERCENT_RANK() OVER
(
ORDER BY
qs.total_logical_reads
qs.total_physical_reads
)
ELSE NULL
END,
Expand Down Expand Up @@ -1909,7 +1906,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
s.high_signals =
CASE WHEN s.cpu_pctl >= 0.80 THEN N'cpu, ' ELSE N'' END +
CASE WHEN s.duration_pctl >= 0.80 THEN N'duration, ' ELSE N'' END +
CASE WHEN s.reads_pctl >= 0.80 THEN N'reads, ' ELSE N'' END +
CASE WHEN s.reads_pctl >= 0.80 THEN N'physical reads, ' ELSE N'' END +
CASE WHEN s.writes_pctl >= 0.80 THEN N'writes, ' ELSE N'' END +
CASE WHEN s.grant_pctl >= 0.80 THEN N'memory, ' ELSE N'' END +
CASE WHEN s.spills_pctl >= 0.80 THEN N'spills, ' ELSE N'' END +
Expand Down Expand Up @@ -2005,20 +2002,20 @@ OPTION(RECOMPILE, MAXDOP 1);';
FORMAT(CONVERT(bigint, s.total_cpu_ms / s.total_executions), N'N0') +
N' ms); '
WHEN s.total_executions > 3
AND s.min_logical_reads IS NOT NULL
AND s.max_logical_reads IS NOT NULL
AND s.total_logical_reads / s.total_executions > 100000
AND s.min_physical_reads IS NOT NULL
AND s.max_physical_reads IS NOT NULL
AND s.total_physical_reads / s.total_executions > 1000
AND
(
s.min_logical_reads < (s.total_logical_reads / s.total_executions) * 0.70
OR s.max_logical_reads > (s.total_logical_reads / s.total_executions) * 1.30
s.min_physical_reads < (s.total_physical_reads / s.total_executions) * 0.70
OR s.max_physical_reads > (s.total_physical_reads / s.total_executions) * 1.30
)
THEN N'Parameter sniffing (reads ' +
FORMAT(s.min_logical_reads, N'N0') +
THEN N'Parameter sniffing (physical reads ' +
FORMAT(s.min_physical_reads, N'N0') +
N'-' +
FORMAT(s.max_logical_reads, N'N0') +
FORMAT(s.max_physical_reads, N'N0') +
N', avg ' +
FORMAT(s.total_logical_reads / s.total_executions, N'N0') +
FORMAT(s.total_physical_reads / s.total_executions, N'N0') +
N'); '
ELSE N''
END +
Expand Down Expand Up @@ -2238,7 +2235,7 @@ OPTION(RECOMPILE, MAXDOP 1);';
s.diagnostics,
s.total_cpu_ms,
s.total_duration_ms,
s.total_logical_reads,
s.total_physical_reads,
s.total_logical_writes,
s.total_grant_mb,
s.total_spills,
Expand Down
Loading
Loading