Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Hardik Doshi is Technical Lead and systems development professional with iGATE having a total IT experience of more than 7 years. He is MCTS certified professional in SQL Server technology.
Browse by Tags · View All
#SQL Server 3
T-SQL 3
SQL Server 3
Admin 2
IO 2
Query 2
Restore 1
Backup 1
Performance 1
CPU 1

Archive · View All
June 2012 1
May 2012 1
July 2011 1

Retrieve the queries that are Most expensive / use the Most IO

May 22 2012 12:00AM by Hardik Doshi   

The core functionality of database systems is to retrieve data, and this is reflected in the amount of I/O involved, total CPU time, logical reads/writes etc. We can look at the queries that are most expensive (taking more time to execute), use the most I/O to determine whether they can be changed to retrieve data more efficiently.

 

The script below helps to identify the top 10 queries that use the most I/O as ordered by Total IO, taking more time to execute (means most expensive) across all databases on the server.

Query:

  • The query calculates the Total IO by summing the columns total_logical_reads and total_logical_writes.
  • The Average IO is calculated by dividing the sum of the total_logical_reads and total_logical_writes by the number of times the query has executed (execution_count).
  • The other output column are:
    • Database Name
    • Individual Query
    • Parent Query (from where the query is executing)
    • Total elapsed time in seconds
    • Query’s cached plan (query_plan) 
    • The output is sorted by Total IO in descending order as of now.

You can modify the query as per your requirement like filter on database name only, set required Order by.

SELECT TOP 10
        [Individual Query] = 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),
        [Total IO] = ( qs.total_logical_reads + qs.total_logical_writes ),
        [Average IO] = ( qs.total_logical_reads + qs.total_logical_writes ) / qs.execution_count,
        [Execution Count] = qs.execution_count,
        [Total Logical Reads] = qs.total_logical_reads,
        [Total Logical Writes] = qs.total_logical_writes,
        [Total Worker Time/CPU time] = qs.total_worker_time,
        [Total Elapsed Time In Seconds] = qs.total_elapsed_time / 1000000,
        [Parent Query] = qt.text,
        [DatabaseName] = DB_NAME(qt.dbid),
        [Query Plan] = 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
ORDER BY [Total IO] DESC --IO
-- ORDER BY [Total Elapsed Time In Seconds] DESC  --elapsed time
-- ORDER BY qs.total_logical_reads DESC -- logical reads
-- ORDER BY qs.total_logical_writes DESC -- logical writes
-- ORDER BY qs.total_worker_time DESC -- CPU time

 

 To reduce reads you need to look at a couple of things, first being query design, secondly being indexing. If your query is pulling a large number of records that could be filtered by getting a smaller set prior to pulling that data then you can always cut down on reads that way. With improved indexing, specifically with covering indexes, you can reduce the number of pages that are being read as well.


I hope this will be helpful somewhere sometime.
J

Appendix

  • Logical reads - number of pages read from the data cache
    • Logical read indicates total number of data pages needed to be accessed from data cache to process query. It is very possible that logical read will access same data pages many times, so count of logical read value may be higher than actual number of pages in a table. Usually the best way to reduce logical read is to apply correct index or to rewrite the query.
  • Physical reads - number of pages read from disk
    • Physical read indicates total number of data pages that are read from disk. In case no data in data cache, the physical read will be equal to number of logical read in most of the cases. And usually it happens for first query request. And for subsequent same query request the number will be substantially decreased because the data pages have been in data cache.

Tags: T-SQL, Query, DMV, IO, CPU, Performance, Admin, #SQL Server, SQL Server


Hardik Doshi
20 · 9% · 2839
8 Readers Liked this
Nakul Vachhrajani Liked this on 5/22/2012 1:26:00 AM
Profile · Blog · Facebook · Twitter
Nirav Liked this on 5/22/2012 6:34:00 AM
Profile · Blog · Facebook · Twitter
Jacob Sebastian Liked this on 5/22/2012 6:41:00 AM
Profile · Blog · Facebook · Twitter
Guru Samy Liked this on 5/22/2012 11:43:00 PM
Profile · Blog
Chintak Chhapia Liked this on 5/23/2012 12:43:00 AM
Profile · Blog · Facebook
Kirti M.Darji Liked this on 5/23/2012 1:42:00 AM
Profile · Blog · Facebook · Twitter
Olga Medvedeva Liked this on 5/23/2012 4:48:00 AM
Profile · Blog · Twitter
Pronojit Roy Liked this on 6/7/2012 8:25:00 AM
Profile · Facebook
8
Liked
 
 
 
 
0
Incorrect



Submit

1  Comments  

  • Hardik: Good to see you back on the blogging scene. Looking forward to more such posts :)

    commented on May 23 2012 2:32AM
    Nakul Vachhrajani
    4 · 33% · 10680

Your Comment


Sign Up or Login to post a comment.

"Retrieve the queries that are Most expensive / use the Most IO" rated 5 out of 5 by 8 readers
Retrieve the queries that are Most expensive / use the Most IO , 5.0 out of 5 based on 8 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]