Skip to content
Open
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
57 changes: 37 additions & 20 deletions sqlnexus/PerfStatsAnalysis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,24 @@ SELECT w_end.wait_category,
END
)
END AS total_wait_time_ms,
CASE
WHEN (CONVERT(BIGINT, w_end.wait_time_ms) - CASE
WHEN w_start.wait_time_ms IS NULL THEN
0
ELSE
w_start.wait_time_ms
END
) <= 0 THEN
0
ELSE
(CONVERT(BIGINT, w_end.wait_time_ms) - CASE
WHEN w_start.wait_time_ms IS NULL THEN
0
ELSE
w_start.wait_time_ms
END
) / (DATEDIFF(s, @StartTime, @EndTime) + 1) AS wait_time_ms_per_sec
) / (DATEDIFF(s, @StartTime, @EndTime) + 1)
END AS wait_time_ms_per_sec
INTO #waitstats_categories
FROM dbo.vw_WAIT_CATEGORY_STATS w_end
LEFT OUTER JOIN dbo.vw_WAIT_CATEGORY_STATS w_start
Expand All @@ -1160,7 +1171,7 @@ ORDER BY (w_end.wait_time_ms - CASE
) DESC;

-- Get number of available "CPU seconds" in the specified interval (seconds in collection interval times # CPUs on the system)
DECLARE @avail_cpu_time_sec INT;
DECLARE @avail_cpu_time_sec BIGINT;
SELECT @avail_cpu_time_sec =
(
SELECT TOP 1 [PropertyValue] FROM [dbo].[tbl_ServerProperties] WHERE PropertyName = 'cpu_count'
Expand Down Expand Up @@ -1252,8 +1263,13 @@ FROM
AND cat.wait_category NOT IN
(
SELECT TOP 5
cat.wait_category
FROM #waitstats_categories cat
cat2.wait_category
FROM #waitstats_categories cat2
WHERE (
cat2.wait_time_ms_per_sec > 0
OR cat2.total_wait_time_ms > 0
)
AND cat2.wait_category != 'SOS_SCHEDULER_YIELD'
ORDER BY wait_time_ms_per_sec DESC
)
) AS t
Expand All @@ -1262,8 +1278,9 @@ ORDER BY wait_time_ms_per_sec DESC;

GO



IF OBJECT_ID('DataSet_WaitStats_WaitStatsTopCategoriesOther') IS NOT NULL
DROP PROC DataSet_WaitStats_WaitStatsTopCategoriesOther;
GO
CREATE PROC DataSet_WaitStats_WaitStatsTopCategoriesOther
@StartTime DATETIME = '19000101',
@EndTime DATETIME = '29990101',
Expand Down Expand Up @@ -1324,7 +1341,7 @@ ORDER BY (w_end.wait_time_ms - CASE
) DESC;

-- Get number of available "CPU seconds" in the specified interval (seconds in collection interval times # CPUs on the system)
DECLARE @avail_cpu_time_sec INT;
DECLARE @avail_cpu_time_sec BIGINT;
SELECT @avail_cpu_time_sec =
(
SELECT TOP 1 [PropertyValue] FROM [dbo].[tbl_ServerProperties] WHERE PropertyName = 'cpu_count'
Expand Down Expand Up @@ -1412,8 +1429,13 @@ WHERE (
AND cat.wait_category NOT IN
(
SELECT TOP 5
cat.wait_category
FROM #waitstats_categories cat
cat2.wait_category
FROM #waitstats_categories cat2
WHERE (
cat2.wait_time_ms_per_sec > 0
OR cat2.total_wait_time_ms > 0
)
AND cat2.wait_category != 'SOS_SCHEDULER_YIELD'
ORDER BY wait_time_ms_per_sec DESC
)
AND cat.wait_category != 'SOS_SCHEDULER_YIELD'
Expand Down Expand Up @@ -1443,12 +1465,8 @@ IF @EndTime IS NULL
SELECT *
FROM dbo.vw_BLOCKING_CHAINS
WHERE blocking_duration_sec > 0
AND (blocking_start
BETWEEN @StartTime AND @EndTime
)
OR (blocking_end
BETWEEN @StartTime AND @EndTime
);
AND (blocking_start BETWEEN @StartTime AND @EndTime
OR blocking_end BETWEEN @StartTime AND @EndTime);
GO

SELECT CONVERT(VARCHAR, GETDATE(), 126);
Expand Down Expand Up @@ -1548,7 +1566,7 @@ INTO @runtime,
@blocked_tasks,
@command,
@query;
WHILE (@@FETCH_STATUS <> -1)
WHILE (@@FETCH_STATUS = 0)
BEGIN
SET @txtout
= @txtout + ' ' + @runtime + @task_state + @wait_category + @wait_duration_ms + @request_elapsed_time
Expand Down Expand Up @@ -4836,7 +4854,7 @@ BEGIN
(
SELECT *
FROM dbo.tbl_dm_db_stats_properties
WHERE (rows_sampled * 100.00) / [rows] < 5.0
WHERE (rows_sampled * 100.00) / NULLIF([rows], 0) < 5.0
)
BEGIN
UPDATE dbo.tbl_AnalysisSummary
Expand All @@ -4855,7 +4873,7 @@ DECLARE @FileName NVARCHAR(MAX),
@SqlStmt VARCHAR(MAX);

--if xml_plan column is in the table, the the file name (only) of the file that contains the query plan with optimized batch sort
IF (COL_LENGTH('dbo.tblTopSqlPlan', 'xml_plan') IS NULL)
IF (COL_LENGTH('dbo.tblTopSqlPlan', 'xml_plan') IS NOT NULL)
BEGIN
SELECT TOP 1
@FileName = RIGHT([FileName], CHARINDEX('\', REVERSE([FileName])) - 1),
Expand Down Expand Up @@ -5256,8 +5274,7 @@ BEGIN
UPDATE dbo.tbl_SysDatabases
SET is_auto_update_stats_on = 0
WHERE name = 'notexist';
SELECT *
FROM dbo.tbl_AnalysisSummary;

IF EXISTS
(
SELECT *
Expand Down
Loading