February 15, 2009 at 12:30 am
I need to find queries that use the highest amount of memory or are executed many times.
Could anyone tell me please how I can find those?
February 15, 2009 at 8:17 am
you really need to start with creating a trace with profiler....create one and let it run for a while...I'd say one business day.
with that, it will give you every query, as well as the execution time for every query that was run...and you can manipulate it to see which queries were called the most., which were the slowest, etc.
Lowell
February 16, 2009 at 6:15 am
Hi,
Use BOL and try to find something about sys.dm_exec_query_stats
February 16, 2009 at 7:33 am
See if this query gives you what you are looking for. I have found ordering by execution_count useful in the past especially for those queries that might execute hundreds of thousands of times per day where an increase of a half second is a huge performance impact.
SELECT TOP 20 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.min_logical_reads, qs.max_logical_reads,
qs.total_elapsed_time, qs.last_elapsed_time,
qs.min_elapsed_time, qs.max_elapsed_time,
qs.last_execution_time,
qp.query_plan
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 qt.encrypted=0
ORDER BY qs.total_logical_reads DESC
--Ben
February 16, 2009 at 7:42 am
Well half a second times 250 000 executions = 34 hours of processing.
Improvement here is an understatement !!!!
February 16, 2009 at 7:58 am
I wish it stopped there. I like the ones where the application has an hourly job that takes 1.5 hours to run. For some reasons, the developers never see that as a problem...hmmm. I guess peformance really is subjective.
--Ben
February 16, 2009 at 8:07 am
What happens if the job doesn't run??? I think that goes beyond performance!
February 17, 2009 at 12:54 am
Lowell (2/15/2009)
you really need to start with creating a trace with profiler....create one and let it run for a while...I'd say one business day.with that, it will give you every query, as well as the execution time for every query that was run...and you can manipulate it to see which queries were called the most., which were the slowest, etc.
SHould I use any special profiler template? or standard template will suffice? what about events?
February 17, 2009 at 1:00 am
Lowell (2/15/2009)
you really need to start with creating a trace with profiler....create one and let it run for a while...I'd say one business day.with that, it will give you every query, as well as the execution time for every query that was run...and you can manipulate it to see which queries were called the most., which were the slowest, etc.
SHould I use any special profiler template? or standard template will suffice? what about events?
February 17, 2009 at 1:02 am
bjhogan (2/16/2009)
See if this query gives you what you are looking for. I have found ordering by execution_count useful in the past especially for those queries that might execute hundreds of thousands of times per day where an increase of a half second is a huge performance impact.SELECT TOP 20 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.min_logical_reads, qs.max_logical_reads,
qs.total_elapsed_time, qs.last_elapsed_time,
qs.min_elapsed_time, qs.max_elapsed_time,
qs.last_execution_time,
qp.query_plan
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 qt.encrypted=0
ORDER BY qs.total_logical_reads DESC
--Ben
Thanks I'll try that
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply