sql 最昂贵的查询

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 最昂贵的查询相关的知识,希望对你有一定的参考价值。

exec sp_who2 active; --activity monitor
dbcc inputbuffer(52) --show command text for process
sp_helptext 'procname' --show stored proc text
SELECT TOP 50
	[Avg. MultiCore/CPU time(sec)] = qs.total_worker_time / 1000000 / qs.execution_count,
	[Total MultiCore/CPU time(sec)] = qs.total_worker_time / 1000000,
	[Avg. Elapsed Time(sec)] = qs.total_elapsed_time / 1000000 / qs.execution_count,
	[Total Elapsed Time(sec)] = qs.total_elapsed_time / 1000000,
	qs.execution_count,
	[Avg. I/O] = (total_logical_reads + total_logical_writes) / qs.execution_count,
	[Total I/O] = total_logical_reads + total_logical_writes,
	Query = SUBSTRING(qt.[text], (qs.statement_start_offset / 2) + 1,
		(
			(
				CASE qs.statement_end_offset
					WHEN -1 THEN DATALENGTH(qt.[text])
					ELSE qs.statement_end_offset
				END - qs.statement_start_offset
			) / 2
		) + 1
	),
	Batch = qt.[text],
	[DB] = DB_NAME(qt.[dbid]),
	qs.last_execution_time,
	qp.query_plan
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.[sql_handle]) AS qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
where qs.execution_count > 5	--more than 5 occurences
ORDER BY [Total MultiCore/CPU time(sec)] DESC

以上是关于sql 最昂贵的查询的主要内容,如果未能解决你的问题,请参考以下文章

sql 查找最昂贵的查询

sql 查找最昂贵的查询

sql 找到昂贵的SQL查询

SQL Server 活动监视器在多长时间内查看最近的昂贵查询

如果不需要,SQL Server 是不是足够聪明,不会执行昂贵的查询? (短路)

显示最昂贵电影的成本在 2 美元以内的查询