SQL Server 执行计划 - 实际与估计
我正在阅读 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我读过此更准确的是,恕我直言,
格兰特的看法也是这里
I'd read this which is more accurate, IMHO
Grant's take is here too