gpt4 book ai didi

sql - 在 SQL Server 中使用 OPTION(MAXDOP 1) 的目的是什么?

转载 作者:行者123 更新时间:2023-12-01 17:53:26 30 4
gpt4 key购买 nike

我一直没有清楚地理解MAXDOP的用法。我确实知道它使查询速度更快,并且它是我可以用于查询优化的最后一项。

但是,我的问题是,何时何地最适合在查询中使用它?

最佳答案

正如 Kaboing 提到的,MAXDOP(n) 实际上控制查询处理器中使用的 CPU 核心数量。

在完全空闲的系统上,SQL Server 将尝试尽快将表拉入内存并在内存中连接它们。就您的情况而言,最好使用单个 CPU 来完成此操作。这可能与使用OPTION (FORCE ORDER)具有相同的效果,后者强制查询优化器使用您指定的联接顺序。在某些情况下,我发现 OPTION (FORCE PLAN) 将查询的执行时间从 26 秒减少到 1 秒。

Books Online 继续指出 MAXDOP 的可能值为:

0 - Uses the actual number of available CPUs depending on the current system workload. This is the default value and recommended setting.

1 - Suppresses parallel plan generation. The operation will be executed serially.

2-64 - Limits the number of processors to the specified value. Fewer processors may be used depending on the current workload. If a value larger than the number of available CPUs is specified, the actual number of available CPUs is used.

我不确定 MAXDOP 的最佳用法是什么,但是我会猜测,如果您有一个包含 8 个分区的表,则需要指定 MAXDOP(8) 由于 I/O 限制,但我可能是错的。

以下是我找到的一些有关 MAXDOP 的快速链接:

Books Online: Degree of Parallelism

General guidelines to use to configure the MAXDOP option

关于sql - 在 SQL Server 中使用 OPTION(MAXDOP 1) 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/163917/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com