如何在SQL Server 2008中查找性能最差的查询?

如何在sql Server 2008中查找性能最差的查询

我发现以下示例,但似乎不起作用:

SELECT TOP 5 obj.name,max_logical_reads,max_elapsed_time
FROM sys.dm_exec_query_stats a
CROSS APPLY sys.dm_exec_sql_text(sql_handle) hnd
INNER JOIN sys.sysobjects obj on hnd.objectid = obj.id
ORDER BY max_logical_reads DESC

取自:

http://www.sqlservercurry.com/2010/03/top-5-costly-stored-procedures-in-sql.html

解决方法

基于…的十大最差查询
SELECT TOP 10
    total_worker_time/execution_count AS Avg_cpu_Time,execution_count,total_elapsed_time/execution_count as AVG_Run_Time,(SELECT
              SUBSTRING(text,statement_start_offset/2,(CASE
                                                           WHEN statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(max),text)) * 2 
                                                           ELSE statement_end_offset 
                                                       END -statement_start_offset)/2
                       ) FROM sys.dm_exec_sql_text(sql_handle)
         ) AS query_text 
FROM sys.dm_exec_query_stats 

--pick your criteria

ORDER BY Avg_cpu_Time DESC
--ORDER BY AVG_Run_Time DESC
--ORDER BY execution_count DESC

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...