cost threshold for parallelism 选项

使用 cost threshold for parallelism 选项指定 MicrosoftSQL Server 创建和运行并行查询计划的阈值。仅当运行同一查询的串行计划的估计开销高于在 cost threshold for parallelism 中设置的值时,SQL Server 才创建和运行该查询的并行计划。开销指的是在特定硬件配置中运行串行计划估计需要花费的时间(秒)。只能在对称多处理器系统上设置 cost threshold for parallelism

并行计划对需时较长的查询通常更加有益;其性能优势将抵消初始化、同步和终止并行计划所需的额外时间开销。短时间和长时间查询混合运行时,可以灵活使用 cost threshold for parallelism 选项。短时间查询使用串行计划运行,而长时间查询使用并行计划运行。cost threshold for parallelism 的值确定哪些查询是短时间查询,因而应该使用串行计划运行。

在某些情况下,即使查询的开销计划小于当前 cost threshold for parallelism 的值,也有可能选择并行计划。出现这种情况,是因为使用并行还是串行计划是根据完成完全优化之前所提供的开销估计确定的。

cost threshold for parallelism 选项可设置为 0 到 32767 之间的任何值。默认值为 5。

在下列情况下,SQL Server 将忽略 cost threshold for parallelism 的值:

  • 计算机只有一个处理器。

  • 由于 affinity mask 配置选项的限制,SQL Server 只能使用一个 CPU。

  • max degree of parallelism 选项设置为 1。

    注意注意

    如果使用 MAXDOP 查询选项,则 SQL Server 将不忽略 cost-threshold-for-parallelism 值。

cost threshold for parallelism 选项是一个高级选项。如果使用 sp_configure 系统存储过程来更改该设置,则只有在 show advanced options 设置为 1 时才能更改 cost threshold for parallelism。该设置更改后立即生效,而不需要重新启动服务器。

示例

以下示例将 cost threshold for parallelism 设置为 10 秒。

sp_configure 'show advanced options', 1;

GO

reconfigure;

GO

sp_configure 'cost threshold for parallelism', 10;

GO

reconfigure;

GO