Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
SQL database in Microsoft Fabric
This topic defines max degree of parallelism and explains how to modify this setting in SQL Server by using SQL Server Management Studio or Transact-SQL.
On multiprocessor systems that are running SQL Server Enterprise or higher, index statements may use multiple processors (CPUs) to perform the scan, sort, and index operations associated with the index statement just like other queries do. The number of CPUs used to run a single index statement is determined by the max degree of parallelism server configuration option, the current workload, and the index statistics. The max degree of parallelism option determines the maximum number of processors to use in parallel plan execution. If the SQL Server Database Engine detects that the system is busy, the degree of parallelism of the index operation is automatically reduced before statement execution starts. The Database Engine can also reduce the degree of parallelism if the leading key column of a non-partitioned index has a limited number of distinct values or the frequency of each distinct value varies significantly. For more information, see Query Processing Architecture Guide.
Note
Parallel index operations are not available in every SQL Server edition. For more information, see Editions and supported features of SQL Server 2022.
In This Topic
Before you begin:
To set the max degree of parallelism, using:
The number of processors that are used by the query optimizer typically provides optimal performance. However, operations such as creating, rebuilding, or dropping very large indexes are resource intensive and can cause insufficient resources for other applications and database operations for the duration of the index operation. When this problem occurs, you can manually configure the maximum number of processors that are used to run the index statement by limiting the number of processors to use for the index operation.
The MAXDOP index option overrides the max degree of parallelism configuration option only for the query specifying this option. The following table lists the valid integer values that can be specified with the max degree of parallelism configuration option and the MAXDOP index option.
Value | Description |
---|---|
0 | Specifies that the server determines the number of CPUs that are used, depending on the current system workload. This is the default value and recommended setting. |
1 | Suppresses parallel plan generation. The operation will be executed serially. |
2-64 | Limits the number of processors to the specified value. Fewer processors may be used depending on the current workload. If a value larger than the number of available CPUs is specified, the actual number of available CPUs is used. |
Parallel index execution and the MAXDOP index option apply to the following Transact-SQL statements:
DROP INDEX (This applies to clustered indexes only.)
The MAXDOP index option cannot be specified in the ALTER INDEX (...) REORGANIZE
statement.
Memory requirements for partitioned index operations that require sorting can be greater if the Query Optimizer applies degrees of parallelism to the build operation. The higher the degrees of parallelism, the greater the memory requirement is. For more information, see Partitioned Tables and Indexes.
Requires ALTER
permission on the table or view.
In Object Explorer, click the plus sign to expand the database that contains the table on which you want to set max degree of parallelism for an index.
Expand the Tables folder.
Click the plus sign to expand the table on which you want to set max degree of parallelism for an index.
Expand the Indexes folder.
Right-click the index for which you want to set the max degree of parallelism and select Properties.
Under Select a page, select Options.
Select Maximum degree of parallelism, and then enter some value between 1 and 64.
Click OK.
In Object Explorer, connect to an instance of Database Engine.
On the Standard bar, click New Query.
Copy and paste the following example into the query window and click Execute.
USE AdventureWorks2022;
GO
/*Alters the IX_ProductVendor_VendorID index on the Purchasing.ProductVendor table so that, if the server has eight or more processors, the Database Engine will limit the execution of the index operation to eight or fewer processors.
*/
ALTER INDEX IX_ProductVendor_VendorID ON Purchasing.ProductVendor
REBUILD WITH (MAXDOP=8);
GO
For more information, see ALTER INDEX (Transact-SQL).
In Object Explorer, connect to an instance of Database Engine.
On the Standard bar, click New Query.
Copy and paste the following example into the query window and click Execute.
USE AdventureWorks2022;
GO
CREATE INDEX IX_ProductVendor_NewVendorID
ON Purchasing.ProductVendor (BusinessEntityID)
WITH (MAXDOP=8);
GO
Query Processing Architecture Guide
CREATE INDEX (Transact-SQL)
ALTER INDEX (Transact-SQL)
DROP INDEX (Transact-SQL)
ALTER TABLE (Transact-SQL)
ALTER TABLE table_constraint (Transact-SQL)
ALTER TABLE index_option (Transact-SQL)
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Configure databases for optimal performance - Training
Configure databases for optimal performance
Certification
Microsoft Certified: Azure Database Administrator Associate - Certifications
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Documentation
SORT_IN_TEMPDB Option For Indexes - SQL Server
SORT_IN_TEMPDB Option For Indexes
Server configuration: max degree of parallelism - SQL Server
Learn about the max degree of parallelism (MAXDOP) option. See how to use it to limit the number of processors that SQL Server uses in parallel plan execution.
Maintaining indexes optimally to improve performance and reduce resource utilization - SQL Server
This article describes index maintenance concepts, and a recommended strategy to maintain indexes.