有没有办法检索到SQL Server中给定表中的平均(或更好的分发)插入时间的信息,直到当前时间点?
e.g。插入“员工”平均每条记录占用1毫秒。
我在这里谈论历史数据,例如在过去的一年中,不是我在分析时可以获得的特定查询。
答案 0 :(得分:2)
You should also check plan cache. From there you can calculate the average duration per statement, and assuming you're not inserting into the table using a lot of different statements (and your queries are parametrized) you should get quite good results.
Here's one example how to query the DMVs:
select top 100
SUBSTRING(t.text, (s.statement_start_offset/2)+1,
((CASE s.statement_end_offset
WHEN -1 THEN DATALENGTH(t.text)
ELSE s.statement_end_offset
END - s.statement_start_offset)/2) + 1) as statement_text,
t.text,
s.total_logical_reads, s.total_logical_reads / s.execution_count as avg_logical_reads,
s.total_worker_time, s.total_worker_time / s.execution_count as avg_worker_time,
s.execution_count,
creation_time,
last_execution_time
--,cast(p.query_plan as xml) as query_plan
from sys.dm_exec_query_stats s
cross apply sys.dm_exec_sql_text (sql_handle) t
--cross apply sys.dm_exec_text_query_plan (plan_handle, statement_start_offset, statement_end_offset) p
order by s.execution_count desc
The part commented out is for query plans.
答案 1 :(得分:0)
SQL事件探查器不准确,也是从SQL 2012开始被标记为已弃用。
用于捕获与性能相关的数据的最佳工具是扩展事件或perfmon。不要认为perfmon会为您提供对象级别的性能,但它会告诉您是否存在IO级别的瓶颈。您需要为数据收集启用这些工具/功能,因此如果尚未启用,则可能无法获取历史数据。