Site sponsored by: Idera The gold standard of SQL Server performance monitoring & diagnostics.
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

System Data Collection Reports
Recover Data Using Database Snapshots
Analyze and Fix Index Fragmentation in SQL Server 2008
Powerful Geographical Visualisations made easy with SQL 2008 Spatial (Part 2) ...

More     
 
Latest FAQ's

How to alter a User Defined Data Type?
How to unzip a File in SSIS?
How to view previous query plans?
ALTER TABLE SWITCH statement failed because the object '%.*ls' is not ...

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> performance tuning >> Measure TSQL Statement Performance

Measure TSQL Statement Performance

By : Greg Larsen
Dec 19, 2007

Page 4 / 4

I/O Usage

Like the other performance measures there are a number of ways to display the amount of I/O used by a TSQL statement.  There are 2 different kinds of I/Os that are tracked within SQL Server: Logical and Physical IOs.  Logical I/O account for data that is processed from the buffer pool which resides in memory, hence the phrase Logical I/O.  Physical I/Os are I/Os that are associated with accessing data directly from the physical disks that SQL Server uses to store databases.   Physical I/O’s are more expensive I/O’s, meaning they take longer to process.  I/O is general the single most expensive operation that impacts the overall performance of a TSQL statement.  So when you are tuning your queries you want to minimize the number of logical and physical I/O’s operation performed to produce a result set.

One method to show the amount of I/O associated with a TSQL statement or batch of statements is to turn on the I/O statistics gathering process by using the “SET STATISTICS IO ON” statement.  When you have issued this statement during your connection SQL Server will output the number of I/O used to resolve your TSQL statement.  Below is an example where I used the “SET STASTISTICS IO ON” statement to display the amount of I/O needed to resolve a simple query against the AdventureWorks database:

 

Here you can see my SELECT statement performed 2 “logical reads”, and 2 “physical reads”.  Now when I run this batch of statements a second time I get this output:

Here you will note that the second time I issue my TSQL SELECT statement it only required 2 “logical reads and 0 “physical reads”, this because the AdventureWorks pages holding the data for this query are already in the buffer pool.   If you are doing repetitive testing trying to improve the performance of your query you need to make sure you eliminate this I/O counting discrepancy that can arise when pages required by your query are already in the buffer cache.  To eliminate this counting issue, you can issue the “DBCC DROPCLEANBUFFER” command prior to running each test.  This will allow your queries to run with a clean buffer pool without stopping and restarting SQL server.   

Another method to track I/O’s for queries is to use SQL Server Profiler.  To do this just make sure you include the I/O related columns when identify the events and columns you want your trace to monitor.

 

Conclusion

Being able to track the resource consumptions of your different queries is a critical piece to monitor the performance of your application.   Knowing what TSQL statements are using the most resources helps you determine where to focus your attention when trying to optimize your application.  The “sys.dm_exec_query_stats” DMV helps DBA’s quickly identify those TSQL statements using the most resources.   Using various “SET” statements, system_variables and/or SQL Server Profiler events/columns can help measure CPU, I/O and the elapsed time for your problem TSQL statements. Identifying, measuring and improving performance of your application queries will help you optimize the code behind your application.


<< Prev Page         








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved