A select 语句和作为批处理的 Multiple select 语句之间的比较
我有一个存储过程,其中包含一些返回它们的联合结果的 Select 语句。
我想写一个select而不是几个Select,并想比较它们的执行计划(SP和一个Select语句)。
问题是当运行这个 twe 语句(SP 和 Select)时,sp 中的所有 select 语句都有其执行计划。我希望将 SP 的执行计划作为一个单元。
我还有另一个问题。考虑一下附加到这篇文章的执行计划。所有语句的执行计划的总成本必须是 100% 吗?
但为什么这个执行计划的所有语句的总成本不是100%呢?
谢谢
I have a stored procedure that contains some Select statements that return union result of them.
I think and write one select instead of several Select and want to compare EXECUTION PLAN of them (SP and one Select statement).
the problem is when run this twe statement(SP and Select) all select statement in sp have their execution plan.I want to have execution plan of SP as an UNIT.
I have another question.Consider execution plan that attached to this post.Is sum cost of an execution plan for all statement must be 100%?
But why sum cost of all statement of this execution plan not be 100%?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试比较两个版本的逻辑,则可以使用以下脚本:
会让您做到这一点。是的,执行计划将向您显示存储过程中的所有查询。查找 SP 外部发生的查询的计划。如果他们给出总成本> 50%则SP表现更好。
附带说明一下,如果您的 SP 采用参数,请确保比较一系列参数值的执行计划。
If you are trying to compare two versions of the logic then a script along the lines of:
Will let you do it. Yes the execution plan will show you all of the queries inside the stored proc. Look for the plans for the queries that occur outside of the SP. If they give a total cost > 50% then the SP performed better.
As a side note, if your SP takes parameters make sure you compare the execution plans across a range of parameter values.
UNION
是多个选择语句。您实质上是在说“向我显示此查询的结果,与此查询的结果连接,与此查询的结果连接...” SQL Server 如何在不执行这些查询的情况下获取这些查询的结果?A
UNION
is several select statements. You are essentially saying "Show me the results from this query, joined with the results from this query, joined with the results from this query..." How else will SQL Server get the results from those queries without executing them?