{"id":3438,"date":"2009-08-31T18:07:26","date_gmt":"2009-08-31T16:07:26","guid":{"rendered":"http:\/\/www.glorf.it\/blog\/?p=3438"},"modified":"2010-01-27T08:56:41","modified_gmt":"2010-01-27T07:56:41","slug":"sql-server-langlaeufer","status":"publish","type":"post","link":"http:\/\/www.glorf.it\/blog\/2009\/08\/31\/sql-talk\/sql-server-langlaeufer","title":{"rendered":"SQL Server: Langl&#228;ufer"},"content":{"rendered":"<p>In dem Artikel &quot;<a href=\"http:\/\/www.glorf.it\/blog\/2007\/04\/24\/sql-server\/sql-server-wer-sind-heute-meine-5-langlaeufer\">Wer sind heute meine 5 Langl&#228;ufer? <\/a>&quot; beschrieb ich ein gefundenes SQL-Statement mit dem man sich Infos zu den langsamsten SQL-Statement anzeigen lassen kann. Im Laufe der zeit modifizierte ich die Abfrage immer weiter.<\/p>\n<p>Hier ist die verbesserte Fassung, die viele weitere interessante Angaben &#252;ber den Befehl macht:<\/p>\n<p><code lang=\"sql\">SELECT TOP(200)<br \/>\n\t\tqs.execution_count AS &quot;Executions&quot;,<br \/>\n\t\tCAST(CAST(qs.total_elapsed_time AS NUMERIC(20,4))\/1000\/qs.execution_count AS NUMERIC(20,4)) AS &quot;AvgDuration[ms]&quot;, &#8211; Umrechung in Millisekunden<br \/>\n\t\tCAST(CAST(qs.total_worker_time AS NUMERIC(20,4))\/1000\/qs.execution_count AS NUMERIC(20,4))  AS &quot;AvgCpuTime[ms]&quot;, &#8211; Umrechung in Millisekunden<br \/>\n\t\tSUBSTRING(st.text,(qs.statement_start_offset+2)\/2, &#8211; Offset wird in Bytes angegeben<br \/>\n\t\t\t\t\t(CASE WHEN qs.statement_end_offset = -1<br \/>\n\t\t\t\t\t\t\tTHEN LEN(CAST(st.text AS NVARCHAR(MAX)))*2<br \/>\n\t\t\t\t\t\t\tELSE qs.statement_end_offset<br \/>\n\t\t\t\t\t\tEND &#8211; qs.statement_start_offset)\/2)\t\t\t\t\t\t  AS &quot;SqlStatement&quot;,<br \/>\n\t\tCAST(CAST(qs.last_elapsed_time AS NUMERIC(20,4))\/1000  AS NUMERIC(20,4))  AS &quot;LastDuration[ms]&quot;,  &#8211; Umrechung in Millisekunden<br \/>\n\t\tCAST(CAST(qs.last_worker_time AS NUMERIC(20,4))\/1000  AS NUMERIC(20,4))   AS &quot;LastCpuTime[ms]&quot;,   &#8211; Umrechung in Millisekunden<br \/>\n\t\tCAST(CAST(qs.total_elapsed_time AS NUMERIC(20,4))\/1000  AS NUMERIC(20,4)) AS &quot;TotalDuration[ms]&quot;, &#8211; Umrechung in Millisekunden<br \/>\n\t\tCAST(CAST(qs.total_worker_time AS NUMERIC(20,4))\/1000  AS NUMERIC(20,4))  AS &quot;TotalCpuTime[ms]&quot;,  &#8211; Umrechung in Millisekunden<br \/>\n\t\tqs.total_logical_reads\t\t  AS &quot;TotalLogicalReads&quot;,<br \/>\n\t\tqs.total_physical_reads\t\t  AS &quot;TotalPhysicalReads&quot;,<br \/>\n\t\tqs.total_logical_writes\t\t  AS &quot;TotalLogicalWrites&quot;,<br \/>\n\t\tqs.creation_time\t\t  AS &quot;FirstExecution&quot;,<br \/>\n\t\tqs.last_execution_time\t\t  AS &quot;LastExecution&quot;,<br \/>\n\t\tdb_name(st.dbid)\t\t  AS &quot;Database&quot;<br \/>\nFROM\tsys.dm_exec_query_stats AS qs<br \/>\nCROSS APPLY sys.dm_exec_sql_text(sql_handle) AS st<br \/>\nWHERE qs.total_elapsed_time  > 0<br \/>\nORDER BY &quot;AvgDuration[ms]&quot; DESC, qs.execution_count DESC<\/code><\/p>\n<p>Viel Erfolg damit&#8230; \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In dem Artikel &quot;Wer sind heute meine 5 Langl&#228;ufer? &quot; beschrieb ich ein gefundenes SQL-Statement mit dem man sich Infos zu den langsamsten SQL-Statement anzeigen lassen kann. Im Laufe der zeit modifizierte ich die Abfrage immer weiter. Hier ist die verbesserte Fassung, die viele weitere interessante Angaben &#252;ber den Befehl macht: SELECT TOP(200) qs.execution_count AS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[576,579],"_links":{"self":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/posts\/3438"}],"collection":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/comments?post=3438"}],"version-history":[{"count":14,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/posts\/3438\/revisions"}],"predecessor-version":[{"id":4088,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/posts\/3438\/revisions\/4088"}],"wp:attachment":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/media?parent=3438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/categories?post=3438"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/tags?post=3438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}