SQL Server 执行计划 - 实际与估计

发布于 2024-09-17 06:06:42 字数 372 浏览 4 评论 0原文

我正在阅读 Grant Fritkey 的优秀著作 SQL Server 执行计划。上页。 21 他指出,“当查询提交到服务器时,优化器会创建估计的执行计划。创建该计划后,在将其传递到存储引擎之前,优化器会将此估计的计划与计划缓存中已经存在的实际执行计划。”他接着说这样做是因为生成查询计划的成本很高。

这听起来像 SQL Sever 将由优化器计算一个估计计划,如果估计计划与计划缓存中的实际计划不匹配,则创建一个实际计划并将其存储在缓存中。因此,听起来无论计划缓存中是否存在现有计划,SQL Server 总是会生成一个估计计划。如果无论如何都要这样做,为什么还要在缓存中存储任何东西呢?为什么不总是计算一个计划,因为无论如何它至少会执行一次?我错过了什么吗?

谢谢。

I am reading Grant Fritchey's excellent book, SQL Server Execution Plans. On pg. 21 he states, "When a query is submitted to the server, an estimated execution plan is created by the optimizer. Once that plan is created, and before it gets passed to the storage engine, the optimizer compares this estimated plan to the actual execution plan that already exist in the plan cache." He goes on to say that this is done because it's expensive to generate query plans.

This sounds like SQL Sever will calculate an estimated plan, by the optimizer, and, if the estimated plan doesn't match an actual plan in the plan cache, create an actual plan and store it in the cache. So, it sounds like whether an existing plan exists in the plan cache or not, SQL Server will always generate an estimated plan. If it's going to do this anyway, why bother storing anything in a cache? Why not just always calculate a plan, since it's going to do it at least once anyway? Am I missing something?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜光 2024-09-24 06:06:42

我读过更准确的是,恕我直言,

格兰特的看法也是这里

I'd read this which is more accurate, IMHO

Grant's take is here too

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文