[英]How to examine slow running queries in SQL Server
I have a query which can either execute for a long time or a normal time.我有一个可以执行很长时间或正常时间的查询。 I want to find reasons for when it runs long.
我想找出运行时间长的原因。
What I've already tried:我已经尝试过的:
Check locks for objects which used in query.检查查询中使用的对象的锁。 It doesn't exist for the query
查询不存在
Check a plan.检查计划。 All events have normal costs, so costs is the same every time
所有事件都有正常成本,所以每次的成本都是一样的
Can you suggest some other steps I might try, or other explanations for the differences in runtime?您能否建议我可以尝试的其他一些步骤,或者对运行时差异的其他解释?
I've defined three points which should be investigated:我已经定义了应该调查的三点:
In that step, you should find the most expansive operations in the execution plan (use option "Include Actual Execution Plan")在该步骤中,您应该在执行计划中找到最广泛的操作(使用选项“包括实际执行计划”)
wait events.等待事件。 Here you need to find session_id for your query.
在这里,您需要为您的查询找到 session_id。 If the query running then uses:
如果查询运行然后使用:
SELECT * FROM sys.dm_exec_requests CROSS APPLY sys.dm_exec_sql_text(sql_handle)
and investigate columns last_wait_type, wait_type, wait_time并调查列 last_wait_type、wait_type、wait_time
locks锁
The query above also returns blocks information this information in the column BlkBy上面的查询还在 BlkBy 列中返回块信息此信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.