forked from mtikoian/SQLDBA-SSMS-Solution
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path04) ClearTrace-Top-15-Statements-By-IO.sql
42 lines (40 loc) · 1.17 KB
/
04) ClearTrace-Top-15-Statements-By-IO.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Top 15 Statements Group by SQL Text Order by IO */
;WITH CTE AS (
SELECT
TextDataHashCode, NormalizedTextData AS Item,
SUM(ExecutionCount) AS [#],
SUM(CPU) AS CPU,
CAST(CAST(SUM(CPU) AS DECIMAL(22,2))/ SUM(ExecutionCount) AS DECIMAL(22,2)) AS AvgCPU,
SUM(Reads) AS Reads,
CAST(CAST(SUM(Reads) AS DECIMAL(22,2))/ SUM(ExecutionCount) AS DECIMAL(22,2)) AS AvgReads,
SUM(Writes) AS Writes,
CAST(CAST(SUM(Writes) AS DECIMAL(22,2))/ SUM(ExecutionCount) AS DECIMAL(22,2)) AS AvgWrites,
SUM(Duration) AS Duration,
CAST(CAST(SUM(Duration) AS DECIMAL(22,2))/ SUM(ExecutionCount) AS DECIMAL(22,2)) AS AvgDuration
,ROW_NUMBER() OVER (ORDER BY SUM(CPU) DESC ) AS CpuRank
,ROW_NUMBER() OVER (ORDER BY SUM(Reads) DESC ) AS ReadsRank
FROM
[dbo].[CTTraceSummaryView] TD
WHERE
EventClass IN (41, 45)
AND
NormalizedTextData IS NOT NULL
AND
NormalizedTextData <> ''
GROUP BY
TextDataHashCode, NormalizedTextData )
SELECT TOP (15) WITH TIES
[TextDataHashCode]
,
[Item]
,[#]
,[CPU]
,[AvgCPU]
,[Reads]
,[AvgReads]
,[Writes]
,[AvgWrites]
,[Duration]
,[AvgDuration]
FROM [CTE]
ORDER BY ([Reads]+[Writes]) DESC, ([AvgReads]+[AvgWrites]) DESC