April 22, 2015 at 6:56 pm
Hi All,
How do I find out top expensive queries from SQL Server 2008 – Standard edition ?
Thank you
Cheers
April 22, 2015 at 11:14 pm
WhiteLotus (4/22/2015)
Hi All,How do I find out top expensive queries from SQL Server 2008 – Standard edition ?
Thank you
Cheers
Query the sys.dm_exec_query_stats
😎
April 23, 2015 at 12:20 am
Thanks for the reply
I came across this query from Google :
SELECT TOP 20
qs.sql_handle,
qs.execution_count,
qs.total_worker_time AS Total_CPU,
total_CPU_inSeconds = --Converted from microseconds
qs.total_worker_time/1000000,
average_CPU_inSeconds = --Converted from microseconds
(qs.total_worker_time/1000000) / qs.execution_count,
qs.total_elapsed_time,
total_elapsed_time_inSeconds = --Converted from microseconds
qs.total_elapsed_time/1000000,
st.text,
qp.query_plan
FROM
sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
CROSS apply sys.dm_exec_query_plan (qs.plan_handle) AS qp
ORDER BY qs.total_worker_time DESC
What do you think ?:)
April 23, 2015 at 1:35 am
Slightly improved version
😎
USE master;
GO
SELECT TOP 20
ISNULL(DB_NAME(st.dbid),N'N/A') AS DATABASE_NAME
,ROUND(qs.max_elapsed_time * 0.000001,2) AS MAX_ELAPSED_SEC
,qs.total_physical_reads / qs.execution_count AS AVG_PHYS_READ
,qs.total_logical_reads / qs.execution_count AS AVG_LOGIC_READ
,qs.execution_count AS EXEC_COUNT
,qs.creation_time AS CREATE_TIME
,qs.last_execution_time AS LAST_EXEC_TIME
,qs.total_worker_time AS Total_CPU
,ROUND(qs.total_worker_time * 0.000001,2) AS total_CPU_inSeconds
,ROUND((qs.total_worker_time * 0.000001)
/ qs.execution_count,2) AS average_CPU_inSeconds
,qs.total_elapsed_time
,ROUND(qs.total_elapsed_time * 0.000001,2) AS total_elapsed_time_inSeconds
,st.text AS QUERY_TEXT
,qp.query_plan AS EXECUTION_PLAN
FROM sys.dm_exec_query_stats qs
OUTER APPLY sys.dm_exec_sql_text(qs.sql_handle) st
OUTER APPLY sys.dm_exec_query_plan (qs.plan_handle) qp
ORDER BY qs.total_worker_time / qs.execution_count DESC;
April 23, 2015 at 2:16 am
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 23, 2015 at 2:20 am
GilaMonster (4/23/2015)
https://www.simple-talk.com/sql/performance/finding-the-causes-of-poor-performance-in-sql-server,-part-1/
Thanks Gail
😎
April 23, 2015 at 5:45 pm
Thanks Eri
April 23, 2015 at 5:46 pm
Thanks Gail
April 23, 2015 at 5:48 pm
Hi Gail ,
That's a very good article !
I just wonder what about if I need to monitor for 3 days ( from Wed until Friday ) ?
In that article giving the example for monitoring SQL in 30 mins
Cheers..
April 24, 2015 at 2:59 am
WhiteLotus (4/23/2015)
I just wonder what about if I need to monitor for 3 days ( from Wed until Friday ) ?
Why do you need to?
In that article giving the example for monitoring SQL in 30 mins
Yup, because most systems have a pattern of activity. The stuff being run on Tuesday at 10AM is much the same as the stuff being run on Thursday at 3PM. You're trying to get a representative view of what runs on the server. Unless what the users do on Wednesday radically differs from what the users do on Friday, you don't need to trace for 3 days straight.
You can if you want to, but beware of the file sizes. I have a client who's system generates 10GB of trace data an hour at peak times. If I was to trace his server for 3 days straight, I'd probably be looking at around 400-500GB of trace data. That's hard to move, takes forever to analyse and requires a lot of disk space and won't give me a much better understanding of what his workload looks like than tracing for 1 hour twice in one day.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 27, 2015 at 7:14 pm
Thats make sense to me Gail ... I will discuss with my team about it ..cheers mate 🙂
April 28, 2015 at 6:17 am
...and then there's always SSMS' built-in reports (right-click on the database instance in Object Explorer).
Presumably they do something very similar to Eirikur's query under the hood, but with prettier output.
April 28, 2015 at 8:22 am
Gary Harding (4/28/2015)
...and then there's always SSMS' built-in reports (right-click on the database instance in Object Explorer).Presumably they do something very similar to Eirikur's query under the hood, but with prettier output.
Heh... and now we know the answer to one of my favorite interview questions when people claim to know anything about performance tuning. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
April 29, 2015 at 1:28 pm
Also, so it's more readable, you can convert miliseconds to hh:mmss format using something like the following.
...
,convert(varchar,dateadd(ms,last_elapsed_time,getdate())-getdate(),108)last_elapsed_time
...
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply