Configure the max degree of parallelism Server Configuration Option

02/12/2020

6 minutes to read

+8



In this article

Applies to: SQL Server (all supported versions)

This topic describes how to configure the max degree of parallelism (MAXDOP) server configuration option in SQL Server by using SQL Server Management Studio or Transact-SQL. When an instance of SQL Server runs on a computer that has more than one microprocessor or CPU, it detects the degree of parallelism, that is, the number of processors employed to run a single statement, for each parallel plan execution. You can use the max degree of parallelism option to limit the number of processors to use in parallel plan execution. SQL Server considers parallel execution plans for queries, index data definition language (DDL) operations, parallel inserts, online alter column, parallel stats collection, and static and keyset-driven cursor population.

Note SQL Server 2019 (15.x) introduces automatic recommendations for setting the MAXDOP server configuration option during the installation process. The setup user interface allows you to either accept the recommended settings or enter your own value. For more information, see Database Engine Configuration - MaxDOP page.

Before You Begin

Limitations and Restrictions

If the affinity mask option is not set to the default, it may restrict the number of processors available to SQL Server on symmetric multiprocessing (SMP) systems.

The max degree of parallelism (MAXDOP) limit is set per task. It is not a per request or per query limit. This means that during a parallel query execution, a single request can spawn multiple tasks up to the MAXDOP limit, and each task will use one worker and one scheduler. For more information, see the Scheduling parallel tasks section in the Thread and Task Architecture Guide.

Recommendations

This option is an advanced option and should be changed only by an experienced database administrator or certified SQL Server professional.

To enable the server to determine the maximum degree of parallelism, set this option to 0, the default value. Setting maximum degree of parallelism to 0 allows SQL Server to use all the available processors up to 64 processors. To suppress parallel plan generation, set max degree of parallelism to 1. Set the value to a number from 1 to 32,767 to specify the maximum number of processor cores that can be used by a single query execution. If a value greater than the number of available processors is specified, the actual number of available processors is used. If the computer has only one processor, the max degree of parallelism value is ignored.

You can override the max degree of parallelism value in queries by specifying the MAXDOP query hint in the query statement. For more information, see Query Hints (Transact-SQL).

Index operations that create or rebuild an index, or that drop a clustered index, can be resource intensive. You can override the max degree of parallelism value for index operations by specifying the MAXDOP index option in the index statement. The MAXDOP value is applied to the statement at execution time and is not stored in the index metadata. For more information, see Configure Parallel Index Operations.

In addition to queries and index operations, this option also controls the parallelism of DBCC CHECKTABLE, DBCC CHECKDB, and DBCC CHECKFILEGROUP. You can disable parallel execution plans for these statements by using trace flag 2528. For more information, see Trace Flags (Transact-SQL).

Tip To accomplish this at the query level, use the MAXDOP query hint.

To accomplish this at the database level, use the MAXDOP database scoped configuration.

To accomplish this at the workload level, use the MAX_DOP Resource Governor workload group configuration option.

Guidelines

Starting with SQL Server 2016 (13.x), during service startup if the Database Engine detects more than eight physical cores per NUMA node or socket at startup, soft-NUMA nodes are created automatically by default. The Database Engine places logical processors from the same physical core into different soft-NUMA nodes. The recommendations in the table below are aimed at keeping all the worker threads of a parallel query within the same soft-NUMA node. This will improve the performance of the queries and distribution of worker threads across the NUMA nodes for the workload. For more information, see Soft-NUMA.

Starting with SQL Server 2016 (13.x), use the following guidelines when you configure the max degree of parallelism server configuration value:

Server configuration Number of processors Guidance Server with single NUMA node Less than or equal to 8 logical processors Keep MAXDOP at or below # of logical processors Server with single NUMA node Greater than 8 logical processors Keep MAXDOP at 8 Server with multiple NUMA nodes Less than or equal to 16 logical processors per NUMA node Keep MAXDOP at or below # of logical processors per NUMA node Server with multiple NUMA nodes Greater than 16 logical processors per NUMA node Keep MAXDOP at half the number of logical processors per NUMA node with a MAX value of 16

Note NUMA node in the above table refers to soft-NUMA nodes automatically created by SQL Server 2016 (13.x) and higher versions, or hardware-based NUMA nodes if soft-NUMA has been disabled.

Use these same guidelines when you set the max degree of parallelism option for Resource Governor workload groups. For more information, see CREATE WORKLOAD GROUP (Transact-SQL).

From SQL Server 2008 through SQL Server 2014 (12.x), use the following guidelines when you configure the max degree of parallelism server configuration value:

Server configuration Number of processors Guidance Server with single NUMA node Less than or equal to 8 logical processors Keep MAXDOP at or below # of logical processors Server with single NUMA node Greater than 8 logical processors Keep MAXDOP at 8 Server with multiple NUMA nodes Less than or equal to 8 logical processors per NUMA node Keep MAXDOP at or below # of logical processors per NUMA node Server with multiple NUMA nodes Greater than 8 logical processors per NUMA node Keep MAXDOP at 8

Security

Permissions

Execute permissions on sp_configure with no parameters or with only the first parameter are granted to all users by default. To execute sp_configure with both parameters to change a configuration option or to run the RECONFIGURE statement, a user must be granted the ALTER SETTINGS server-level permission. The ALTER SETTINGS permission is implicitly held by the sysadmin and serveradmin fixed server roles.

Using SQL Server Management Studio

To configure the max degree of parallelism option

In Object Explorer, right-click a server and select Properties. Click the Advanced node. In the Max Degree of Parallelism box, select the maximum number of processors to use in parallel plan execution.

Using Transact-SQL

To configure the max degree of parallelism option

Connect to the Database Engine. From the Standard bar, click New Query. Copy and paste the following example into the query window and click Execute. This example shows how to use sp_configure to configure the max degree of parallelism option to 16 .

USE AdventureWorks2012 ; GO EXEC sp_configure 'show advanced options', 1; GO RECONFIGURE WITH OVERRIDE; GO EXEC sp_configure 'max degree of parallelism', 16; GO RECONFIGURE WITH OVERRIDE; GO

For more information, see Server Configuration Options (SQL Server).

Follow Up: After you configure the max degree of parallelism option

The setting takes effect immediately without restarting the server.

See Also

ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL)

affinity mask Server Configuration Option

Server Configuration Options (SQL Server)

sp_configure (Transact-SQL)

Query Processing Architecture Guide

Thread and Task Architecture Guide

Configure Parallel Index Operations

Query Hints (Transact-SQL)

Set Index Options

Next steps

RECONFIGURE (Transact-SQL) Monitor and Tune for Performance