Configure the max degree of parallelism (MAXDOP) - Azure SQL Database (2024)

  • Article

Applies to: Configure the max degree of parallelism (MAXDOP) - Azure SQL Database (1) Azure SQL Database

This article describes the max degree of parallelism (MAXDOP) configuration setting in Azure SQL Database.

Note

This content is focused on Azure SQL Database. Azure SQL Database is based on the latest stable version of the Microsoft SQL Server database engine, so much of the content is similar though troubleshooting and configuration options differ. For more on MAXDOP in SQL Server, see Configure the max degree of parallelism Server Configuration Option.

Overview

MAXDOP controls intra-query parallelism in the database engine. Higher MAXDOP values generally result in more parallel threads per query, and faster query execution.

In Azure SQL Database, the default MAXDOP setting for each new single database and elastic pool database is 8. This default prevents unnecessary resource utilization, while still allowing the database engine to execute queries faster using parallel threads. It is not typically necessary to further configure MAXDOP in Azure SQL Database workloads, though it may provide benefits as an advanced performance tuning exercise.

Note

In September 2020, based on years of telemetry in the Azure SQL Database service MAXDOP 8 was made the default for new databases, as the optimal value for the widest variety of customer workloads. This default helped prevent performance problems due to excessive parallelism. Prior to that, the default setting for new databases was MAXDOP 0. MAXDOP was not automatically changed for existing databases created prior to September 2020.

In general, if the database engine chooses to execute a query using parallelism, execution time is faster. However, excess parallelism can consume additional processor resources without improving query performance. At scale, excess parallelism can negatively affect query performance for all queries executing on the same database engine instance. Traditionally, setting an upper bound for parallelism has been a common performance tuning exercise in SQL Server workloads.

The following table describes database engine behavior when executing queries with different MAXDOP values:

MAXDOPBehavior
= 1The database engine uses a single serial thread to execute queries. Parallel threads are not used.
> 1The database engine sets the number of additional schedulers to be used by parallel threads to the MAXDOP value, or the total number of logical processors, whichever is smaller.
= 0The database engine sets the number of additional schedulers to be used by parallel threads to the total number of logical processors or 64, whichever is smaller.

Note

Each query executes with at least one scheduler, and one worker thread on that scheduler.

A query executing with parallelism uses additional schedulers, and additional parallel threads. Because multiple parallel threads may execute on the same scheduler, the total number of threads used to execute a query may be higher than specified MAXDOP value or the total number of logical processors. For more information, see Scheduling parallel tasks.

Considerations

  • In Azure SQL Database, you can change the default MAXDOP value:

    • At the query level, using the MAXDOP query hint.
    • At the database level, using the MAXDOP database scoped configuration.
  • Long-standing SQL Server MAXDOP considerations and recommendations are applicable to Azure SQL Database.

  • Index operations that create or rebuild an index, or that drop a clustered index, can be resource intensive. You can override the database MAXDOP value for index operations by specifying the MAXDOP index option in the CREATE INDEX or ALTER 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, the database scoped configuration option for MAXDOP also controls parallelism of other statements that may use parallel execution, such as DBCC CHECKTABLE, DBCC CHECKDB, and DBCC CHECKFILEGROUP.

Recommendations

Changing MAXDOP for the database can have major impact on query performance and resource utilization, both positive and negative. However, there is no single MAXDOP value that is optimal for all workloads. The recommendations for setting MAXDOP are nuanced, and depend on many factors.

Some peak concurrent workloads may operate better with a different MAXDOP than others. A properly configured MAXDOP should reduce the risk of performance and availability incidents, and in some cases may reduce costs by being able to avoid unnecessary resource utilization, and thus scale down to a lower service objective.

Excessive parallelism

A higher MAXDOP often reduces duration for CPU-intensive queries. However, excessive parallelism can worsen other concurrent workload performance by starving other queries of CPU and worker thread resources. In extreme cases, excessive parallelism can consume all database or elastic pool resources, causing query timeouts, errors, and application outages.

Tip

We recommend that customers avoid setting MAXDOP to 0 even if it does not appear to cause problems currently.

Excessive parallelism becomes most problematic when there are more concurrent requests than can be supported by the CPU and worker thread resources provided by the service objective. Avoid MAXDOP 0 to reduce the risk of potential future problems due to excessive parallelism if a database is scaled up, or if future hardware configurations in Azure SQL Database provide more cores for the same database service objective.

Modifying MAXDOP

If you determine that a MAXDOP setting different from the default is optimal for your Azure SQL Database workload, you can use the ALTER DATABASE SCOPED CONFIGURATION T-SQL statement. For examples, see the Examples using Transact-SQL section below. To change MAXDOP to a non-default value for each new database you create, add this step to your database deployment process.

If non-default MAXDOP benefits only a small subset of queries in the workload, you can override MAXDOP at the query level by adding the OPTION (MAXDOP) hint. For examples, see the Examples using Transact-SQL section below.

Thoroughly test your MAXDOP configuration changes with load testing involving realistic concurrent query loads.

MAXDOP for the primary and secondary replicas can be configured independently if different MAXDOP settings are optimal for your read-write and read-only workloads. This applies to Azure SQL Database read scale-out, geo-replication, and Hyperscale secondary replicas. By default, all secondary replicas inherit the MAXDOP configuration of the primary replica.

Security

Permissions

The ALTER DATABASE SCOPED CONFIGURATION statement must be executed as the server admin, as a member of the database role db_owner, or a user that has been granted the ALTER ANY DATABASE SCOPED CONFIGURATION permission.

Examples

These examples use the latest AdventureWorksLT sample database when the SAMPLE option is chosen for a new single database of Azure SQL Database.

PowerShell

MAXDOP database scoped configuration

This example shows how to use ALTER DATABASE SCOPED CONFIGURATION statement to set the MAXDOP configuration to 2. The setting takes effect immediately for new queries. The PowerShell cmdlet Invoke-SqlCmd executes the T-SQL queries to set and the return the MAXDOP database scoped configuration.

$dbName = "sample" $serverName = <server name here>$serveradminLogin = <login here>$serveradminPassword = <password here>$desiredMAXDOP = 8$params = @{ 'database' = $dbName 'serverInstance' = $serverName 'username' = $serveradminLogin 'password' = $serveradminPassword 'outputSqlErrors' = $true 'query' = 'ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = ' + $desiredMAXDOP + '; SELECT [value] FROM sys.database_scoped_configurations WHERE [name] = ''MAXDOP'';' } Invoke-SqlCmd @params

This example is for use with Azure SQL Databases with read scale-out replicas enabled, geo-replication, and Azure SQL Database Hyperscale secondary replicas. As an example, the primary replica is set to a different default MAXDOP as the secondary replica, anticipating that there may be differences between a read-write and a read-only workload.

$dbName = "sample" $serverName = <server name here>$serveradminLogin = <login here>$serveradminPassword = <password here>$desiredMAXDOP_primary = 8$desiredMAXDOP_secondary_readonly = 1 $params = @{ 'database' = $dbName 'serverInstance' = $serverName 'username' = $serveradminLogin 'password' = $serveradminPassword 'outputSqlErrors' = $true 'query' = 'ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = ' + $desiredMAXDOP_primary + '; ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = ' + $desiredMAXDOP_secondary_readonly + '; SELECT [value], value_for_secondary FROM sys.database_scoped_configurations WHERE [name] = ''MAXDOP'';' } Invoke-SqlCmd @params

Transact-SQL

You can use the Azure portal query editor, SQL Server Management Studio (SSMS), or Azure Data Studio to execute T-SQL queries against your Azure SQL Database.

  1. Open a new query window.

  2. Connect to the database where you want to change MAXDOP. You cannot change database scoped configurations in the master database.

  3. Copy and paste the following example into the query window and select Execute.

MAXDOP database scoped configuration

This example shows how to determine the current database MAXDOP database scoped configuration using the sys.database_scoped_configurations system catalog view.

SELECT [value] FROM sys.database_scoped_configurations WHERE [name] = 'MAXDOP';

This example shows how to use ALTER DATABASE SCOPED CONFIGURATION statement to set the MAXDOP configuration to 8. The setting takes effect immediately.

ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 8;

This example is for use with Azure SQL Databases with read scale-out replicas enabled, geo-replication, and Hyperscale secondary replicas. As an example, the primary replica is set to a different MAXDOP than the secondary replica, anticipating that there may be differences between the read-write and read-only workloads. All statements are executed on the primary replica. The value_for_secondary column of the sys.database_scoped_configurations contains settings for the secondary replica.

ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 8;ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = 1;SELECT [value], value_for_secondary FROM sys.database_scoped_configurations WHERE [name] = 'MAXDOP';

MAXDOP query hint

This example shows how to execute a query using the query hint to force the max degree of parallelism to 2.

SELECT ProductID, OrderQty, SUM(LineTotal) AS Total FROM SalesLT.SalesOrderDetail WHERE UnitPrice < 5 GROUP BY ProductID, OrderQty ORDER BY ProductID, OrderQty OPTION (MAXDOP 2); GO

MAXDOP index option

This example shows how to rebuild an index using the index option to force the max degree of parallelism to 12.

ALTER INDEX ALL ON SalesLT.SalesOrderDetail REBUILD WITH ( MAXDOP = 12 , SORT_IN_TEMPDB = ON , ONLINE = ON);

See also

  • ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL)
  • sys.database_scoped_configurations (Transact-SQL)
  • Configure Parallel Index Operations
  • Query Hints (Transact-SQL)
  • Set Index Options
  • Understand and resolve Azure SQL Database blocking problems

Next steps

  • Monitor and Tune for Performance
Configure the max degree of parallelism (MAXDOP) - Azure SQL Database (2024)

FAQs

What is the max degree of parallelism in Azure SQL Database? ›

In Azure SQL Database, the MAXDOP database-scoped configuration is set to 8. In Azure SQL Managed Instance, the max degree of parallelism (MAXDOP) server configuration option is set to 8. For more on MAXDOP in Azure SQL Database, see Configure the max degree of parallelism (MAXDOP) in Azure SQL Database.

What is the maximum degree of parallelism in Maxdop? ›

Max Degree of Parallelism can be set to a value ranging between 0 and 32,767. The value tells SQL Server how many processors it should use for parallel plan execution. The default MAXDOP setting of 0 tells SQL Server to use all available processors (up to a max of 64).

What is the best setting for max degree of parallelism? ›

Setting MAXDOP to 2, 4, or 8 generally provides the best results in most use cases. We recommend that you test your workload and monitor for any parallelism-related wait types such as CXPACKET .

What is the Maxdop setting in SQL Server? ›

MAXDOP controls intra-query parallelism in the database engine. Higher MAXDOP values generally result in more parallel threads per query, and faster query execution. In Azure SQL Database, the default MAXDOP setting for each new single database and elastic pool database is 8.

How do you find the maximum degree of parallelism? ›

Where can I find the values my system is using?
  1. Right mouse click on your SQL Server.
  2. Select Properties.
  3. From Select a Page, select Advanced.
  4. Scroll down and locate Max Degree of Parallelism (Also note Cost Threshold for Parallelism option which we will discuss)
Jul 12, 2021

What is maximum parallelism? ›

Maximum parallelism refers to the maximum number of parallel threads that process a single mapping pipeline stage.

How do you set the degree of parallelism? ›

You can use any of the following methods to set the degree of parallelism:
  1. Use a constant value for the width parameter in the @parallel annotation. ...
  2. Use a composite operator parameter in the @parallel annotation. ...
  3. Use a submission-time value for the width parameter in the @parallel annotation.

What is the degree of parallelism in database? ›

Degree of parallelism (DOP) feedback identifies parallelism inefficiencies for repeating queries, based on elapsed time and waits. If parallelism usage is deemed inefficient, DOP feedback will lower the DOP for the next execution of the query, from whatever is the configured DOP, and verify if it helps.

What is the max query parallel degree? ›

max query parallel degree defines the number of worker processes to use for a given query. This parameter is relevant only if you do not want to enable parallelism globally. You must configure the number of worker processes to a value greater than zero, but max query parallel degree must be set to 1.

What is the #1 rule of parallelism? ›

Rule 1: When providing a list of items within a sentence, mention all of them in the same syntactic form. Rule 2: When listing out points, make sure they are in the same structure. Rule 3: When mentioning a series of actions in a sentence, see to it that all of them are written in the same verb forms.

Why use Maxdop 1? ›

I find myself often using MAXDOP(1) in SQL Server which determines the maximum degree of parallelism threads to be used to execute your query (1 set it to 1 thread). The reason is parallel execution kept masking bad queries, as they would execute fast but use large IO/CPUs because they were inefficiently written.

What is the default degree of parallelism? ›

Default degree is 1. If you specify the DOP during table creation it will help set to that degree of parallelism.

What is Microsoft recommendation for Maxdop? ›

If you have specific complex queries (most commonly reports), then you may want to spend time trying to tune these, but your effort is generally better spent concentrating on the query and index optimisation, rather than server configuration settings like MAXDOP. MAXDOP should stay at 8 is what Microsoft recommends.

What is the difference between Maxdop and Max degree of parallelism? ›

The max degree of parallelism (MAXDOP) configuration option controls the number of processors that are used for the execution of a query in a parallel plan. This option determines the number of threads that are used for the query plan operators that perform the work in parallel.

What is Maxdop and cost threshold for parallelism? ›

Based on different workloads and customer experiences(reference link) the value of MAXDOP can be set to 8 safely and value of Cost Threshold can be set anything between 25 to 50.

What are the concurrency limits in Azure SQL Database? ›

General Purpose - serverless compute - standard-series (Gen5) (part 1 of 3)
Min-max vCores0.5 - 10.5 - 4
Max concurrent workers75300
Max concurrent logins75300
Max concurrent external connections 4730
Max concurrent sessions30,00030,000
17 more rows
Jul 2, 2024

What is the concurrency limit in Azure? ›

The limit-concurrency policy prevents enclosed policies from executing by more than the specified number of requests at any time. When that number is exceeded, new requests will fail immediately with the 429 Too Many Requests status code.

What is the cost threshold for parallelism in Azure? ›

The cost threshold for parallelism option can be set to any value from 0 through 32767.

Top Articles
The best vegan sticky toffee pudding recipe
Coronation Chicken Recipe
Craigslist Houses For Rent In Denver Colorado
Was ist ein Crawler? | Finde es jetzt raus! | OMT-Lexikon
Ixl Elmoreco.com
1movierulzhd.fun Reviews | scam, legit or safe check | Scamadviser
360 Training Alcohol Final Exam Answers
Comcast Xfinity Outage in Kipton, Ohio
Embassy Suites Wisconsin Dells
Encore Atlanta Cheer Competition
Obituary Times Herald Record
Classic Lotto Payout Calculator
Velocity. The Revolutionary Way to Measure in Scrum
Dark Chocolate Cherry Vegan Cinnamon Rolls
Jbf Wichita Falls
Publix Super Market At Rainbow Square Shopping Center Dunnellon Photos
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Indiana Wesleyan Transcripts
Days Until Oct 8
Uconn Health Outlook
Kaitlyn Katsaros Forum
Used Safari Condo Alto R1723 For Sale
Ice Dodo Unblocked 76
Del Amo Fashion Center Map
Globle Answer March 1 2023
Sienna
15 Primewire Alternatives for Viewing Free Streams (2024)
Hesburgh Library Catalog
Die wichtigsten E-Nummern
Vlacs Maestro Login
Stouffville Tribune (Stouffville, ON), March 27, 1947, p. 1
Craigslist/Phx
25Cc To Tbsp
Play 1v1 LOL 66 EZ → UNBLOCKED on 66games.io
Lowell Car Accident Lawyer Kiley Law Group
Lehpiht Shop
Duff Tuff
Evil Dead Rise (2023) | Film, Trailer, Kritik
Andrew Lee Torres
Cocorahs South Dakota
Hkx File Compatibility Check Skyrim/Sse
Shell Gas Stations Prices
Online-Reservierungen - Booqable Vermietungssoftware
Reli Stocktwits
Tom Kha Gai Soup Near Me
Mytmoclaim Tracking
French Linen krijtverf van Annie Sloan
Publix Store 840
Hampton Inn Corbin Ky Bed Bugs
Hkx File Compatibility Check Skyrim/Sse
91 East Freeway Accident Today 2022
Cataz.net Android Movies Apk
Latest Posts
Article information

Author: Jonah Leffler

Last Updated:

Views: 5787

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Jonah Leffler

Birthday: 1997-10-27

Address: 8987 Kieth Ports, Luettgenland, CT 54657-9808

Phone: +2611128251586

Job: Mining Supervisor

Hobby: Worldbuilding, Electronics, Amateur radio, Skiing, Cycling, Jogging, Taxidermy

Introduction: My name is Jonah Leffler, I am a determined, faithful, outstanding, inexpensive, cheerful, determined, smiling person who loves writing and wants to share my knowledge and understanding with you.