You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/database-engine/configure-windows/configure-the-cost-threshold-for-parallelism-server-configuration-option.md
description: Learn about the cost threshold for parallelism option. See how its value affects whether SQL Server runs parallel plans for queries, and find out how to set it.
This article describes how to configure the `cost threshold for parallelism` server configuration option in [!INCLUDE [ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE [tsql](../../includes/tsql-md.md)]. The `cost threshold for parallelism` option specifies the threshold at which [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] creates and runs parallel plans for queries. [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] creates and runs a parallel plan for a query only when the estimated cost to run a serial plan for the same query is higher than the value set in `cost threshold for parallelism`. The cost refers to an estimated cost required to run the serial plan on a specific hardware configuration, and isn't a unit of time. The `cost threshold for parallelism` option can be set to any value from 0 through 32767.
18
+
This article describes how to configure the `cost threshold for parallelism` server configuration option in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] by using [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE [tsql](../../includes/tsql-md.md)].
18
19
19
-
## Limitations
20
+
## About cost threshold for parallelism
21
+
22
+
The `cost threshold for parallelism` option specifies the threshold at which [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] considers parallel plans on computers with more than one [logical processor](../../sql-server/compute-capacity-limits-by-edition-of-sql-server.md#remarks). The `cost threshold for parallelism` option can be set to any value from 0 through 32,767.
23
+
24
+
Cost is the sum of *estimated* operator costs in a query plan (for example, CPU and I/O). It's a relative measure used only for plan selection; it doesn't measure actual runtime.
20
25
21
-
The cost refers to an abstracted unit of cost and not a unit of estimated time. Only set `cost threshold for parallelism` on symmetric multiprocessors.
26
+
Certain Transact-SQL components can inhibit a parallel plan. For example, noninlineable scalar user-defined functions (UDFs), table variable modifications, and certain system calls. [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] evaluates parallel alternatives only when the best serial plan's estimated cost exceeds the `cost threshold for parallelism` value, and might then choose a cheaper parallel plan.
27
+
28
+
## Limitations
22
29
23
30
[!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] ignores the `cost threshold for parallelism` value under the following conditions:
24
31
25
32
- Your computer has only one logical processor.
26
33
27
34
- Only a single logical processor is available to [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] because of the `affinity mask` configuration option.
28
35
29
-
- The `max degree of parallelism` option is set to `1`.
36
+
- The `max degree of parallelism`server configuration option is set to `1`.
30
37
31
-
A logical processor is the basic unit of processor hardware that allows the operating system to dispatch a task or execute a thread context. Each logical processor can execute only one thread context at a time. The processor core is the circuitry that decodes and executes instructions. A processor core might contain one or more logical processors. The following [!INCLUDE [tsql](../../includes/tsql-md.md)] query can be used for obtaining CPU information for the system.
38
+
## Recommendations
32
39
33
-
```sql
34
-
SELECT (cpu_count / hyperthread_ratio) AS PhysicalCPUs,
35
-
cpu_count AS logicalCPUs
36
-
FROMsys.dm_os_sys_info;
37
-
```
40
+
This option is an advanced option, and should be changed only by an experienced database professional.
38
41
39
-
## Recommendations
42
+
The default value of `5` is a starting point, not a recommendation. On modern [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] systems, raising it can help to keep smaller OLTP queries executing with serial plans. Use small increments and observe a full business cycle before further changes. Perform application testing with higher and lower values if needed to optimize application performance.
43
+
44
+
> [!NOTE]
45
+
> In [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], you can't set `cost threshold for parallelism`. Use `MAXDOP` to control parallelism instead. For more information, see [Changing default MAXDOP in Azure SQL Database and Azure SQL Managed Instance](https://techcommunity.microsoft.com/blog/azuresqlblog/changing-default-maxdop-in-azure-sql-database-and-azure-sql-managed-instance/1538528).
46
+
47
+
In certain cases, a parallel plan might be chosen even though the query's plan cost is less than the current `cost threshold for parallelism` value. The decision to use a parallel or serial plan is based on a cost estimate provided earlier in the optimization process. For more information, see the [Query Processing Architecture Guide](../../relational-databases/query-processing-architecture-guide.md#parallel-query-processing).
40
48
41
-
This option is an advanced option and should be changed only by an experienced database administrator or certified [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] professional.
49
+
## Remarks
42
50
43
-
In certain cases, a parallel plan might be chosen even though the query's cost plan is less than the current `cost threshold for parallelism`value. This can happen because the decision to use a parallel or serial plan is based on a cost estimate provided earlier in the optimization process. For more information, see the [Query Processing Architecture Guide](../../relational-databases/query-processing-architecture-guide.md#parallel-query-processing).
51
+
To see if the `cost threshold for parallelism`server configuration option is set too high or too low for your workload, look for the following indicators.
44
52
45
-
While the default value of `5` is adequate for most systems, a different value might be appropriate. Perform application testing with higher and lower values if needed to optimize application performance.
|**Too low**| - Too many CPU-light queries go parallel.<br /><br /> - In [Query Store](../../relational-databases/performance/monitoring-performance-by-using-the-query-store.md), many plans have `is_parallel_plan` set to `1`.<br /><br /> - `CXPACKET` and `CXCONSUMER` dominate wait type statistics. You might also see `THREADPOOL` and `SOS_SCHEDULER_YIELD` waits. |
56
+
|**Too high**| - Not enough of the workload's CPU-heavy queries go parallel, and CPU utilization is higher than optimal as a result.<br /><br /> - `SOS_SCHEDULER_YIELD` dominates wait type statistics. |
46
57
47
58
## Permissions
48
59
@@ -56,13 +67,13 @@ Execute permissions on `sp_configure` with no parameters or with only the first
56
67
57
68
1. Select the **Advanced** node.
58
69
59
-
1. Under **Parallelism**, change the `cost threshold for parallelism` option to the value you want. Type or select a value from 0 to 32767.
70
+
1. Under **Parallelism**, change the `cost threshold for parallelism` option to the value you want. Type or select a value from 0 to 32,767.
60
71
61
72
<aid="TsqlProcedure"></a>
62
73
63
74
## Use Transact-SQL
64
75
65
-
This example shows how to use [sp_configure](../../relational-databases/system-stored-procedures/sp-configure-transact-sql.md) to set the value of the `cost threshold for parallelism`option to `10`.
76
+
This example shows how to use [sp_configure](../../relational-databases/system-stored-procedures/sp-configure-transact-sql.md) to set the value of `cost threshold for parallelism` to `20`.
66
77
67
78
```sql
68
79
USE master;
@@ -74,7 +85,7 @@ GO
74
85
RECONFIGURE;
75
86
GO
76
87
77
-
EXECUTE sp_configure 'cost threshold for parallelism', 10;
88
+
EXECUTE sp_configure 'cost threshold for parallelism', 20;
0 commit comments