sql 查找最昂贵的查询

Posted

tags:

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

/*
  As seen on https://blog.sqlauthority.com/2010/05/14/sql-server-find-most-expensive-queries-using-dmv/
  
*/
SELECT TOP 30 
qp.query_plan, db_name(qp.dbid) as [DB Name],
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),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
--WHERE qs.last_execution_time BETWEEN '2017-08-16 06:00:00' AND '2017-08-16 08:00:00'
--ORDER BY qs.total_logical_reads DESC -- logical reads
--ORDER BY qs.total_logical_writes DESC -- logical writes
-- ORDER BY qs.total_worker_time DESC -- CPU time

--ORDER BY qs.total_logical_writes DESC, qs.last_execution_time 
ORDER BY qs.last_elapsed_time DESC

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

sql 查找最昂贵的查询

sql 最昂贵的查询

在java中的项目数组中查找最昂贵的项目

sql 找到昂贵的SQL查询

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

查找第二大值的最简单的 SQL 查询是啥?