Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2017 March SQL Server: SET STATISTICS IO and SET STATISTICS TIME measure the Query Performance

SQL Server: SET STATISTICS IO and SET STATISTICS TIME measure the Query Performance

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

Microsoft SQL Server provides different ways to measure the performance of Query Execution.
But two of my favourite options are SET STATISTICS IO and SET STATISTICS TIME.

Both the options are very easy to use and return the execution statistics of Query.
Both are session specific options; you can set ON/OFF at session level and returns the result in the Message Window.

STATISTICS IO:
Using this option, you can find that how your query is interacting with your Physical Storage.
You will get the information like:

  • Scan count: Total number of seeks/scans started after reaching the leaf level in any direction to retrieve all the values to construct the final dataset for the output.
  • Physical Reads: Physical access of total number of 8kb pages which are not available in Memory.
  • Logical Reads: Total number of pages read from the data cache.
  • Read-ahead Reads: Total number of pages placed into the cache for the query.

SET STATISTICS IO ON/OFF:

1
2
SET STATISTICS IO ON;
SET STATISTICS IO OFF;

STATISTICS TIME:

You can use SET STATISTICS TIME to see the number of milliseconds required to parse, compile, and execute of a Query.

This is very useful for tracking different stages of Query Execution.
Using CPU time, You can find server side CPU usage and using Elapsed time, you can find that how long it took to return the data to the client.

SET STATISTICS TIME ON/OFF:

1
2
SET STATISTICS TIME ON;
SET STATISTICS TIME OFF;
Example Result of STATISTICS TIME ON:
1
2
3
4
SQL Server Execution Times:
CPU time = 10 ms, elapsed time = 23 ms.
SQL Server parse and compile time:
CPU time = 115 ms, elapsed time = 50 ms.
Mar 15, 2017Anvesh Patel
SQL Server: Reasons for Error 3201 Cannot open backup device. Operating system error 5 (Access is denied)SQL Server Interview: The Indexed View - Frequently asked questions
Comments: 3
  1. Suresh
    March 16, 2017 at 6:53 am

    Hi Anvesh, Thanks for posting about Set statistics IO & TIME ON.
    I want more detail abt how to troubleshoot high value of Elapsed time values and compare with CPU time value…
    Also requested that how to check Client statistics and its values to performance issue.
    I am waiting your valuable response.

    • Anvesh Patel
      Anvesh Patel
      March 16, 2017 at 6:29 pm

      It depends on your size of data. You can measure the value on different size of data set and time difference between elapsed time and cpu time should be as much as less.

      • Anjaneyulu
        March 19, 2017 at 7:18 pm

        Hi Anvesh,
        Thanks for posting tips.Its really helpful .

Anvesh Patel
Anvesh Patel

Database Engineer

March 15, 2017 SQL ServerAnvesh Patel, database, database research and development, dbrnd, Query analysis, Query CPU usage, Query disk usage, SET STATISTICS IO ON, SET STATISTICS TIME ON, SQL Query, SQL Server, SQL Server Administrator, SQL Server Monitoring, SQL Server Performance Tunning, SQL Server Tips and Tricks, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....