gpt4 book ai didi

sql-server - Sql Server 2000 存储过程防止并行性之类的?

转载 作者:行者123 更新时间:2023-12-03 11:23:33 24 4
gpt4 key购买 nike

我有一个巨大的令人厌恶的存储过程,几个月前它还不慢,但现在是。我几乎不知道这个东西是做什么的,而且我对重写它一点兴趣也没有。

我确实知道,如果我获取存储过程的主体,然后声明/设置参数值并在查询分析器中运行它,它的运行速度会快 20 倍以上。

我从互联网上了解到,这可能是由于缓存的查询计划不正确造成的。因此,我尝试在 EXEC 之后使用“WITH RECOMPILE”运行 sp,我还尝试将“WITH RECOMPLE”放入 sp 中,但这些都没有一点帮助。

当我查看 sp 与查询的执行计划时,最大的区别是 sp 到处都有“并行”操作,而查询没有。这可能是速度差异的原因吗?

谢谢,任何想法都会很棒......我被困住了。

最佳答案

如果两个查询计划之间的唯一区别是并行性,请尝试将 OPTION (MAXDOP 1) 放在查询的末尾以将其限制为串行计划。

至于为什么它们不同,我不确定,但我记得 SQL Server 2000 优化器是,嗯,挑剔的。与您的情况类似,我们通常看到的是临时查询批处理会很快,而通过 sp_executesql 进行的相同查询会很慢。从来没有完全弄清楚发生了什么。

不过,串行与并行绝对可以解释速度上的差异。在 SQL Server 2000 上,并行计划 use all the processors on the machine ,而不仅仅是它需要的:

If SQL Server chooses to use parallelism, it must use all the configured processors (as determined by the MAXDOP query hint configuration) for the execution of a parallel plan. For example, if you use MAXDOP=0 on a 32-way server, SQL Server tries to use all 32 processors even if seven processors might perform the job more efficiently as compared to a serial plan that only uses one processor. Because of this all-or-nothing behavior, if SQL Server chooses the parallel plan and you do not restrict the MAXDOP query hint[...], the time that it takes SQL Server to coordinate all the processors on a high-end server outweighs the advantages of using a parallel plan.

默认情况下,我认为 MAXDOP 的服务器范围设置为 0,这意味着尽可能多地使用。如果您最近用更多处理器升级了数据库服务器以提高性能,这可能会讽刺地解释为什么您的性能会受到影响。如果是这种情况,您可以尝试将 MAXDOP 提示设置为您之前拥有的处理器数量,看看是否有帮助。

关于sql-server - Sql Server 2000 存储过程防止并行性之类的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2477818/

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