gpt4 book ai didi

sql - 如何找到 SQL Server 2008 中性能最差的查询?

转载 作者:行者123 更新时间:2023-12-02 06:55:21 24 4
gpt4 key购买 nike

如何查找 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

最佳答案

基于...的前 10 个最差查询:

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

关于sql - 如何找到 SQL Server 2008 中性能最差的查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2499910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com