So kann man sich z.B. die teuersten Queries des Datenbank-Caches anzeigen lassen:
select top 50 SUBSTRING( st.text , (qs.statement_start_offset/2) + 1 , ((CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS StatementText , qs.last_execution_time , qs.execution_count , qs.total_elapsed_time/1000000 total_elapsed_sec , qs.last_elapsed_time/1000000 last_elapsed_sec , qs.total_logical_reads , qs.last_logical_reads , qp.query_plan from sys.dm_exec_query_stats 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.last_elapsed_time desc
Oder die Queries, für die laut Optimizer Indizes fehlen:
select st.text , qp.query_plan , qs.* from Sys.dm_exec_query_stats qs cross apply sys.dm_exec_sql_text(qs.sql_handle) st cross apply sys.dm_exec_query_plan(qs.plan_handle) qp where convert(nvarchar(max), qp.query_plan) like '%MissingIndex%'
Oder die aktuell laufenden Abfragen:
select ses.login_name , ses.host_name , ses.program_name , st.text , req.session_id , req.start_time , req.status , req.command , req.blocking_session_id , req.cpu_time/1000 cpu_secs , req.total_elapsed_time/1000 ela_secs , req.logical_reads , qp.query_plan from sys.dm_exec_requests req inner join sys.dm_exec_sessions ses on req.session_id = ses.session_id cross apply sys.dm_exec_sql_text(req.sql_handle) AS st cross apply sys.dm_exec_query_plan(req.plan_handle) AS qp
Oder auch die aktuell verbundenen Sessions
select ses.login_name , ses.* from sys.dm_exec_sessions ses where login_name not in ('sa', 'jira') order by ses.login_name
Detailliertere Erläuterungen zu den verwendeten DMVs findet man hier. Auf den untergeordneten Seiten findet man dort auch allerlei Analysequeries.
Keine Kommentare:
Kommentar veröffentlichen