“查询成本”如何运作?在执行计划中?
我正在尝试提高我的一项请求性能。 我的请求是由 10 个不同的 select 组成的。
实际生产查询的执行时间为 36 秒。
如果我显示执行计划,对于一项选择,我的查询成本为 18%。
因此,我使用 xml 查询 (http://www.codeproject.com/KB/database/InClauseAndSQLServer.aspx) 更改 in 子句(在此选择中)。
新的查询现在需要 28 秒来执行,但是 sql server 告诉我上面的 select 的查询成本为 100%。这是我所做的唯一改变。并且任何查询中都没有并行性。
生产 : 36秒,我选择的是18%(其他的是10%)。
新版本: 28秒,我的选择是100%(其他都是0%)。
你知道 sql server 如何计算这个“查询成本”吗? (我开始相信它是随机的或类似的东西)。
I am trying to increase one of my request performance.
My request is made of 10 different select .
The actual production query is taking 36sec to execute.
If I display the execution plan, for one select I have a query cost of 18%.
So I change a in clause (in this select) with an xml query (http://www.codeproject.com/KB/database/InClauseAndSQLServer.aspx).
The new query now takes 28 sec to execute, but sql server tells me that the above select has a query cost of 100%. And this is the only change I made. And there is no parallelism in any query.
PRODUCTION :
36sec, my select is 18% (the others are 10%).
NEW VERSION :
28sec, my select is 100% (the others are 0%).
Do you have any idea how sql server compute this "query cost" ? (I start to believe that it's random or something like that).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询成本是 CPU 周期、内存和磁盘 IO 组合的无单位度量。
很多时候,您会看到成本较高但执行时间更快的运算符或计划。
这主要是由于上述三个组件的速度差异造成的。 CPU 和内存的速度相当快,而且也很少成为瓶颈。如果您可以将一些压力从磁盘 IO 子系统转移到 CPU,查询可能会显示更高的成本,但执行速度应该会快得多。
如果您想获得有关特定查询执行的更多详细信息,您可以使用:
这会将有关 CPU 周期、计划创建和页面读取(从磁盘和内存)的详细信息输出到消息选项卡。
Query cost is a unitless measure of a combination of CPU cycles, memory, and disk IO.
Very often you will see operators or plans with a higher cost but faster execution time.
Primarily this is due to the difference in speed of the above three components. CPU and Memory are fairly quick, and also uncommon as bottlenecks. If you can shift some pressure from the disk IO subsystem to the CPU, the query may show a higher cost but should execute substantially faster.
If you want to get more detailed information about the execution of your specific queries, you can use:
This will output detailed information about CPU cycles, plan creation, and page reads (both from disk and from memory) to the messages tab.