|
1 | | ---- |
2 | | -title: "Configure the cost threshold for parallelism (server configuration option)" |
3 | | -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. |
4 | | -author: rwestMSFT |
5 | | -ms.author: randolphwest |
6 | | -ms.date: "03/02/2017" |
7 | | -ms.service: sql |
8 | | -ms.subservice: configuration |
9 | | -ms.topic: conceptual |
10 | | -helpviewer_keywords: |
11 | | - - "cost threshold for parallelism option" |
12 | | ---- |
13 | | -# Configure the cost threshold for parallelism (server configuration option) |
14 | | - [!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)] |
15 | | - |
16 | | - This topic 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 is not a unit of time. The **cost threshold for parallelism** option can be set to any value from 0 through 32767. |
17 | | - |
18 | | - **In This Topic** |
19 | | - |
20 | | -- **Before you begin:** |
21 | | - |
22 | | - [Limitations and Restrictions](#Restrictions) |
23 | | - |
24 | | - [Recommendations](#Recommendations) |
25 | | - |
26 | | - [Security](#Security) |
27 | | - |
28 | | -- **To configure the cost threshold for parallelism option, using:** |
29 | | - |
30 | | - [SQL Server Management Studio](#SSMSProcedure) |
31 | | - |
32 | | - [Transact-SQL](#TsqlProcedure) |
33 | | - |
34 | | -- **Follow Up:** [After you configure the cost threshold for parallelism option](#FollowUp) |
35 | | - |
36 | | -## <a name="BeforeYouBegin"></a> Before You Begin |
37 | | - |
38 | | -### <a name="Restrictions"></a> Limitations and Restrictions |
39 | | - |
40 | | -- 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. |
41 | | - |
42 | | -- [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] ignores the **cost threshold for parallelism** value under the following conditions: |
43 | | - |
44 | | - - Your computer has only one logical processor. |
45 | | - |
46 | | - - Only a single logical processor is available to [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] because of the **affinity mask** configuration option. |
47 | | - |
48 | | - - The **max degree of parallelism** option is set to 1. |
49 | | - |
50 | | -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 provides ability to decode and execute instructions. A processor core may 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. |
51 | | - |
52 | | -```sql |
53 | | -SELECT (cpu_count / hyperthread_ratio) AS PhysicalCPUs, |
54 | | -cpu_count AS logicalCPUs |
55 | | -FROM sys.dm_os_sys_info |
56 | | -``` |
57 | | - |
58 | | -### <a name="Recommendations"></a> Recommendations |
59 | | - |
60 | | -- 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. |
61 | | - |
62 | | -- In certain cases, a parallel plan may 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, refer to the [Query Processing Architecture Guide](../../relational-databases/query-processing-architecture-guide.md#parallel-query-processing). |
63 | | - |
64 | | -- While the default value of 5 is adequate for most systems, a different value may be appropriate. Perform application testing with higher and lower values if needed to optimize application performance. |
65 | | - |
66 | | -### <a name="Security"></a> Security |
67 | | - |
68 | | -#### <a name="Permissions"></a> Permissions |
69 | | - 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. |
70 | | - |
71 | | -## <a name="SSMSProcedure"></a> Using SQL Server Management Studio |
72 | | - |
73 | | -#### To configure the cost threshold for parallelism option |
74 | | - |
75 | | -1. In Object Explorer, right-click a server and select **Properties**. |
76 | | - |
77 | | -2. Click the **Advanced** node. |
78 | | - |
79 | | -3. Under **Parallelism**, change the **Cost Threshold for Parallelism** option to the value you want. Type or select a value from 0 to 32767. |
80 | | - |
81 | | -## <a name="TsqlProcedure"></a> Using Transact-SQL |
82 | | - |
83 | | -#### To configure the cost threshold for parallelism option |
84 | | - |
85 | | -1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)]. |
86 | | - |
87 | | -2. From the Standard bar, click **New Query**. |
88 | | - |
89 | | -3. Copy and paste the following example into the query window and click **Execute**. 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`. |
90 | | - |
91 | | -```sql |
92 | | -USE AdventureWorks2022; |
93 | | -GO |
94 | | -EXEC sp_configure 'show advanced options', 1 ; |
95 | | -GO |
96 | | -RECONFIGURE |
97 | | -GO |
98 | | -EXEC sp_configure 'cost threshold for parallelism', 10 ; |
99 | | -GO |
100 | | -RECONFIGURE |
101 | | -GO |
102 | | -``` |
103 | | - |
104 | | - For more information, see [Server Configuration Options (SQL Server)](../../database-engine/configure-windows/server-configuration-options-sql-server.md). |
105 | | - |
106 | | -## <a name="FollowUp"></a> Follow Up: After you configure the cost threshold for parallelism option |
107 | | - The setting takes effect immediately without restarting the server. |
108 | | - |
109 | | -## See Also |
110 | | - [Configure Parallel Index Operations](../../relational-databases/indexes/configure-parallel-index-operations.md) |
111 | | - [Query Hints (Transact-SQL)](../../t-sql/queries/hints-transact-sql-query.md) |
112 | | - [ALTER WORKLOAD GROUP (Transact-SQL)](../../t-sql/statements/alter-workload-group-transact-sql.md) |
113 | | - [affinity mask Server Configuration Option](../../database-engine/configure-windows/affinity-mask-server-configuration-option.md) |
114 | | - [RECONFIGURE (Transact-SQL)](../../t-sql/language-elements/reconfigure-transact-sql.md) |
115 | | - [Server Configuration Options (SQL Server)](../../database-engine/configure-windows/server-configuration-options-sql-server.md) |
116 | | - [sp_configure (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-configure-transact-sql.md) |
117 | | - |
118 | | - |
| 1 | +--- |
| 2 | +title: Configure the cost threshold for parallelism (server configuration option) |
| 3 | +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. |
| 4 | +author: rwestMSFT |
| 5 | +ms.author: randolphwest |
| 6 | +ms.date: 09/27/2023 |
| 7 | +ms.service: sql |
| 8 | +ms.subservice: configuration |
| 9 | +ms.topic: conceptual |
| 10 | +helpviewer_keywords: |
| 11 | + - "cost threshold for parallelism option" |
| 12 | +--- |
| 13 | +# Configure the cost threshold for parallelism (server configuration option) |
| 14 | + |
| 15 | +[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)] |
| 16 | + |
| 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 | + |
| 19 | +## Limitations |
| 20 | + |
| 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. |
| 22 | + |
| 23 | +[!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] ignores the **cost threshold for parallelism** value under the following conditions: |
| 24 | + |
| 25 | +- Your computer has only one logical processor. |
| 26 | + |
| 27 | +- Only a single logical processor is available to [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] because of the **affinity mask** configuration option. |
| 28 | + |
| 29 | +- The **max degree of parallelism** option is set to 1. |
| 30 | + |
| 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 provides ability to decode and execute instructions. A processor core may 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. |
| 32 | + |
| 33 | +```sql |
| 34 | +SELECT (cpu_count / hyperthread_ratio) AS PhysicalCPUs, |
| 35 | + cpu_count AS logicalCPUs |
| 36 | +FROM sys.dm_os_sys_info; |
| 37 | +``` |
| 38 | + |
| 39 | +## Recommendations |
| 40 | + |
| 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. |
| 42 | + |
| 43 | +- In certain cases, a parallel plan may 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). |
| 44 | + |
| 45 | +- While the default value of `5` is adequate for most systems, a different value may be appropriate. Perform application testing with higher and lower values if needed to optimize application performance. |
| 46 | + |
| 47 | +## Permissions |
| 48 | + |
| 49 | +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. |
| 50 | + |
| 51 | +## <a id="SSMSProcedure"></a> Use SQL Server Management Studio |
| 52 | + |
| 53 | +1. In Object Explorer, right-click a server and select **Properties**. |
| 54 | + |
| 55 | +1. Select the **Advanced** node. |
| 56 | + |
| 57 | +1. Under **Parallelism**, change the **Cost Threshold for Parallelism** option to the value you want. Type or select a value from 0 to 32767. |
| 58 | + |
| 59 | +## <a id="TsqlProcedure"></a> Use Transact-SQL |
| 60 | + |
| 61 | +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`. |
| 62 | + |
| 63 | +```sql |
| 64 | +USE master; |
| 65 | +GO |
| 66 | +EXEC sp_configure 'show advanced options', 1; |
| 67 | +GO |
| 68 | +RECONFIGURE |
| 69 | +GO |
| 70 | +EXEC sp_configure 'cost threshold for parallelism', 10; |
| 71 | +GO |
| 72 | +RECONFIGURE |
| 73 | +GO |
| 74 | +``` |
| 75 | + |
| 76 | +For more information, see [Server Configuration Options (SQL Server)](server-configuration-options-sql-server.md). |
| 77 | + |
| 78 | +## <a id="FollowUp"></a> Follow Up: After you configure the cost threshold for parallelism option |
| 79 | + |
| 80 | +The setting takes effect immediately without restarting the server. |
| 81 | + |
| 82 | +## Related content |
| 83 | + |
| 84 | +- [Configure Parallel Index Operations](../../relational-databases/indexes/configure-parallel-index-operations.md) |
| 85 | +- [Query Hints (Transact-SQL)](../../t-sql/queries/hints-transact-sql-query.md) |
| 86 | +- [ALTER WORKLOAD GROUP (Transact-SQL)](../../t-sql/statements/alter-workload-group-transact-sql.md) |
| 87 | +- [affinity mask (server configuration option)](affinity-mask-server-configuration-option.md) |
| 88 | +- [RECONFIGURE (Transact-SQL)](../../t-sql/language-elements/reconfigure-transact-sql.md) |
| 89 | +- [Server configuration options (SQL Server)](server-configuration-options-sql-server.md) |
| 90 | +- [sp_configure (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-configure-transact-sql.md) |
0 commit comments