开发者

need help understanding the following very complex query [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

if anyone can break the query up into logical parts; it will be of great help. just a short note and pointers on what each part is doing ..

SELECT qs.execution_count AS [Runs], 
                     (qs.total_worker_time - qs.last_worker_time) / (qs.execution_count - 1) AS [Avg time],
                     qs.last_worker_time AS [Last time], 
                     (qs.last_worker_time - ((qs.total_worker_time - qs.last_worker_time) /
                     (qs.execution_count - 1))) AS [Time Deviation], 
                     CASE WHEN qs.last_worker_time = 0 
                          THEN 100
                          ELSE (qs.last_worker_time - ((qs.total_worker_time -
                                qs.last_worker_time) / (qs.execution_count - 1))) * 100
                     END
                     / (((qs.total_worker_time - qs.last_worker_time) /
                         (qs.execution_count - 1.0))) AS [% Time Deviation],
                     qs.last_logical_reads + qs.last_logical_writes + qs.last_physical_reads AS [Last IO],
                     ((qs.total_logical_reads + qs.total_logical_writes + qs.total_physical_reads) -
                     (qs.last_logical_reads + last_logical_writes + qs.last_physical_reads)) / 
                     (qs.execution_count - 1) AS [Avg IO], 
                     SUBSTRING (qt.text,(qs.statement_start_offset/2) + 1,
                               ((CASE WHEN qs.statement_end_offset = -1
                               THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
                               ELSE qs.statement_end_offset
                               END - qs.statement_start_offset)/2) + 1) AS [Ind开发者_Go百科ividual Query], 
                    qt.text AS [Parent Query], 
                    DB_NAME(qt.dbid) AS [DatabaseName]
              INTO #SlowQueries
              FROM sys.dm_exec_query_stats qs
              CROSS APPLY sys.dm_exec_sql_text(qs.plan_handle) qt
              WHERE qs.execution_count > 1
              AND qs.total_worker_time != qs.last_worker_time
              ORDER BY [% Time Deviation] DESC

              SELECT [Runs], [Avg time], [Last time], [Time Deviation], [% Time Deviation], 
                     [Last IO], [Avg IO], [Last IO] - [Avg IO] AS [IO Deviation], 
                     CASE WHEN [Avg IO] = 0
                          THEN 0
                          ELSE ([Last IO]- [Avg IO]) * 100 / [Avg IO]
                     END AS [% IO Deviation], 
                     [Individual Query], [Parent Query], [DatabaseName]
             INTO #SlowQueriesByIO
             FROM #SlowQueries
             ORDER BY [% Time Deviation] DESC

            SELECT [Runs], [Avg time], [Last time], [Time Deviation], [% Time Deviation], [Last IO],
                   [Avg IO], [IO Deviation], [% IO Deviation], 
                   [Impedance] = [% Time Deviation] - [% IO Deviation], [Individual Query], [Parent Query],
                   [DatabaseName]
            FROM #SlowQueriesByIO
            WHERE [% Time Deviation] - [% IO Deviation] > 20
            ORDER BY [Impedance] DESC
            DROP TABLE #SlowQueries
            DROP TABLE #SlowQueriesByIO

Can anyone please help me understand the above query. Its simply too complex for me to understand. its a DMV of SQL server i found .


This explains it all:

http://www.sqlservercentral.com/articles/Performance+Tuning/63638/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜