Skip to content

Commit 188fb6d

Browse files
authored
Merge pull request #35119 from rwestMSFT/rw-0825-ctfp
Cost threshold for parallelism tweaks
2 parents ca4009c + 69e26ac commit 188fb6d

1 file changed

Lines changed: 30 additions & 19 deletions

File tree

docs/database-engine/configure-windows/configure-the-cost-threshold-for-parallelism-server-configuration-option.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,57 @@ title: "Server configuration: cost threshold for parallelism"
33
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.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 10/18/2024
6+
ms.date: 08/25/2025
77
ms.service: sql
88
ms.subservice: configuration
99
ms.topic: conceptual
1010
helpviewer_keywords:
1111
- "cost threshold for parallelism option"
12+
monikerRange: ">=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current"
1213
---
1314
# Server configuration: cost threshold for parallelism
1415

15-
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
16+
[!INCLUDE [sql-asdbmi](../../includes/applies-to-version/sql-asdbmi.md)]
1617

17-
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)].
1819

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.
2025

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
2229

2330
[!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] ignores the `cost threshold for parallelism` value under the following conditions:
2431

2532
- Your computer has only one logical processor.
2633

2734
- Only a single logical processor is available to [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] because of the `affinity mask` configuration option.
2835

29-
- The `max degree of parallelism` option is set to `1`.
36+
- The `max degree of parallelism` server configuration option is set to `1`.
3037

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
3239

33-
```sql
34-
SELECT (cpu_count / hyperthread_ratio) AS PhysicalCPUs,
35-
cpu_count AS logicalCPUs
36-
FROM sys.dm_os_sys_info;
37-
```
40+
This option is an advanced option, and should be changed only by an experienced database professional.
3841

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).
4048

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
4250

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.
4452

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.
53+
| Cost threshold for parallelism setting | Description |
54+
| --- | --- |
55+
| **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. |
4657

4758
## Permissions
4859

@@ -56,13 +67,13 @@ Execute permissions on `sp_configure` with no parameters or with only the first
5667

5768
1. Select the **Advanced** node.
5869

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.
6071

6172
<a id="TsqlProcedure"></a>
6273

6374
## Use Transact-SQL
6475

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`.
6677

6778
```sql
6879
USE master;
@@ -74,7 +85,7 @@ GO
7485
RECONFIGURE;
7586
GO
7687

77-
EXECUTE sp_configure 'cost threshold for parallelism', 10;
88+
EXECUTE sp_configure 'cost threshold for parallelism', 20;
7889
GO
7990

8091
RECONFIGURE;

0 commit comments

Comments
 (0)