Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Update logic to include TempDB check ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
blakedrumm authored Nov 13, 2023
1 parent 9425ec3 commit 46e6b3c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion SQL Queries/maxdop_calculator.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Usage:
2. Review the results and execute the generated script if the recommended settings are acceptable.
Revision History:
2023-11-13: Added ability to check TempDB file count - Blake Drumm ([email protected])
2023-10-31: Fixed the MaxDOP Calculation - Blake Drumm ([email protected])
2023-10-30: Script created by Blake Drumm ([email protected])
Expand All @@ -32,6 +33,8 @@ DECLARE @NumaNodes INT,
@MaxDop INT,
@RecommendedMaxDop INT,
@CostThreshold INT,
@TempDBFileCount INT,
@RecommendedTempDBFileCount INT,
@ChangeScript NVARCHAR(MAX) = '',
@ShowAdvancedOptions INT;

Expand All @@ -41,6 +44,10 @@ SELECT @NumCPUs = cpu_count FROM sys.dm_os_sys_info;
SELECT @MaxDop = CAST(value_in_use AS INT) FROM sys.configurations WHERE name = 'max degree of parallelism';
SELECT @CostThreshold = CAST(value_in_use AS INT) FROM sys.configurations WHERE name = 'cost threshold for parallelism';
SELECT @ShowAdvancedOptions = CAST(value_in_use AS INT) FROM sys.configurations WHERE name = 'show advanced options';
SELECT @TempDBFileCount = COUNT(*) FROM sys.master_files WHERE database_id = 2 AND type_desc = 'ROWS';

-- Recommended TempDB File Count Calculation
SET @RecommendedTempDBFileCount = IIF(@NumCPUs <= 8, @NumCPUs, 8);

-- MAXDOP Calculation
IF @NumaNodes = 1
Expand Down Expand Up @@ -68,7 +75,9 @@ INSERT INTO @Results (Description, Value)
VALUES ('MAXDOP Configured Value', CAST(@MaxDop AS VARCHAR)),
('MAXDOP Recommended Value', CAST(@RecommendedMaxDop AS VARCHAR)),
('Cost Threshold Configured Value', CAST(@CostThreshold AS VARCHAR)),
('Generally Recommended Cost Threshold', '40-50');
('Generally Recommended Cost Threshold', '40-50'),
('TempDB File Count', CAST(@TempDBFileCount AS VARCHAR)),
('TempDB Recommended File Count', CAST(@RecommendedTempDBFileCount AS VARCHAR));

-- Check and build ChangeScript for other settings
IF @MaxDop <> @RecommendedMaxDop
Expand Down

0 comments on commit 46e6b3c

Please sign in to comment.