Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6146463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:57:13+00:00 2026-05-23T18:57:13+00:00

if anyone can break the query up into logical parts; it will be of

  • 0

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 [Individual 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 .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:57:14+00:00Added an answer on May 23, 2026 at 6:57 pm

    This explains it all:

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me write this query more efficiently? I have a table that
Anyone can help me? Trying to Add a Slow function with my smoothscroll and
anyone can explain me, why this parts of code are acting differently? while((c =
Just wondering if anyone can optimize this usortMonths() function to be better? Basically I
Wondering if anyone can suggest a good file replication tool that will replicate across
Hey, I'm having a strange issue. I'm wondering if anyone can help me make
Anyone can tell me which one is better (JAXB or Apache XMLBeans) taking in
Anyone can explain in details what the following macro does? #define write_XDATA(address,value) (((char *)0x010000)
Anyone can tell me what I'm doing wrong? I am creating a simple system
I wonder if anyone can point me in the right direction I'm fairly new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.