30.06.2013 Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6: Physical Disk Statistics and Utilization<br />

necessarily directly comparable to the previous count-based ratio, obtained from sys_<br />

dm_io_virtual_file_stats. These numbers, however, provide a better representation<br />

of the actual number of read and write operations, as they are counted at the object<br />

level, whether or not the utilization is logical or physical. Note, too, that only objects that<br />

have been used in a DML statement will be included, so after a reboot, you may get not<br />

get any results for some objects.<br />

The query shown in Listing 6.20 is based on one first suggested by Jamie Massie, in his<br />

blog entry entitled Is 80/20 a 90's Estimate? For all objects in a given database, it sums<br />

seeks, scans and lookups as read operations, and updates as changes to the data (the CASE<br />

expressions prevent divide by zero errors when the table has never been used).<br />

DECLARE @databaseName SYSNAME<br />

SET @databaseName = 'BusyDatabase' --obviously not the real name<br />

--'%' gives all databases<br />

SELECT CASE<br />

WHEN ( SUM(user_updates + user_seeks + user_scans + user_lookups) = 0 )<br />

THEN NULL<br />

ELSE ( CAST(SUM(user_seeks + user_scans + user_lookups)<br />

AS DECIMAL)<br />

/ CAST(SUM(user_updates + user_seeks + user_scans<br />

+ user_lookups) AS DECIMAL) )<br />

END AS RatioOfReads ,<br />

CASE<br />

WHEN ( SUM(user_updates + user_seeks + user_scans + user_lookups) = 0 )<br />

THEN NULL<br />

ELSE ( CAST(SUM(user_updates) AS DECIMAL)<br />

/ CAST(SUM(user_updates + user_seeks + user_scans<br />

+ user_lookups) AS DECIMAL) )<br />

END AS RatioOfWrites ,<br />

SUM(user_updates + user_seeks + user_scans + user_lookups)<br />

AS TotalReadOperations ,<br />

SUM(user_updates) AS TotalWriteOperations<br />

FROM sys.dm_db_index_usage_stats AS ddius<br />

WHERE DB_NAME(database_id) LIKE @databaseName<br />

Listing 6.20: Read:write ratio for all objects in a given database.<br />

255

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!