|
1 | 1 |
|
2 | 2 | -- SQL Server 2016 Diagnostic Information Queries
|
3 | 3 | -- Glenn Berry
|
4 |
| --- Last Modified: April 1, 2024 |
| 4 | +-- Last Modified: May 2, 2024 |
5 | 5 | -- https://glennsqlperformance.com/
|
6 | 6 | -- https://sqlserverperformance.wordpress.com/
|
7 | 7 | -- YouTube: https://bit.ly/2PkoAM1
|
@@ -1470,20 +1470,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);
|
1470 | 1470 |
|
1471 | 1471 | -- Get most frequently executed queries for this database (Query 54) (Query Execution Counts)
|
1472 | 1472 | SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
|
| 1473 | +ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute], |
1473 | 1474 | qs.total_logical_reads AS [Total Logical Reads],
|
1474 | 1475 | qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
|
1475 | 1476 | qs.total_worker_time AS [Total Worker Time],
|
1476 | 1477 | qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
|
1477 | 1478 | qs.total_elapsed_time AS [Total Elapsed Time],
|
1478 | 1479 | qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
|
1479 |
| -CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index], |
1480 |
| -FORMAT(qs.last_execution_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Last Execution Time], |
1481 |
| -FORMAT(qs.creation_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Plan Cached Time] |
| 1480 | +CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index], |
| 1481 | +qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time] |
1482 | 1482 | --,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
|
1483 | 1483 | FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
|
1484 | 1484 | CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
|
1485 | 1485 | CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
|
1486 | 1486 | WHERE t.dbid = DB_ID()
|
| 1487 | +AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0 |
1487 | 1488 | ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
|
1488 | 1489 | ------
|
1489 | 1490 |
|
|
0 commit comments