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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5: Indexing Strategy and Maintenance<br />

Fragmentation statistics (index_physical_stats)<br />

The sys.dm_db_index_physical_stats DMF provides invaluable information<br />

regarding the state of your index partitions, including type of index, index depth, and<br />

degree of fragmentation. An index in this context can mean several things: a clustered<br />

index, heap, index, or a partition of either of these. These physical stats all serve to tell<br />

you of the condition of an index. Even the most potentially beneficial index in terms of<br />

optimizing query execution can become useless if it is not maintained properly.<br />

Data stored in this DMF is cumulative but refreshed when the server is restarted or<br />

when the index is dropped and recreated. Statistics live on when the index is rebuilt or<br />

reorganized, and even when it is disabled and rebuilt.<br />

Like the operational_stats DMF, the physical_stats DMF accepts the<br />

database_id, object_id, index_id, and partition_number as parameters, in<br />

order to identify the object (heap, index or partition) in question, and returns detailed<br />

"physical stats" for each partition. All the parameters can be NULL or DEFAULT if you<br />

want to return all rows, in which case the DMF will return a row for every partition in<br />

every database. It also accepts a mode parameter, which determines the thoroughness<br />

<strong>with</strong> which the statistics are collected. Possible values are:<br />

• LIMITED is the default and the least costly, but it also will leave a lot of the columns as<br />

NULL; LIMITED will not scan the leaf level of the indexes and the data pages of heaps<br />

are not scanned<br />

• SAMPLED mode returns statistics based only upon a 1% sample of all pages of the<br />

indexes and heaps in the scope of the function call; if any page or heap <strong>with</strong>in<br />

the scope of the function call has less than 10,000 pages, then DETAILED is<br />

automatically used<br />

• DETAILED provides the most complete result set from this function of the three, but<br />

can require ample resources; it scans all pages; it returns all statistics.<br />

210

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

Saved successfully!

Ooh no, something went wrong!