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 />

I think most of us had our start as DBAs using the <strong>SQL</strong> <strong>Server</strong> Maintenance Plans<br />

Wizard built into Enterprise Manager or <strong>SQL</strong> <strong>Server</strong> <strong>Management</strong> Studio. This is how<br />

we cut our teeth when backing up data and log files, checking our databases for errors,<br />

and rebuilding our indexes. The issue <strong>with</strong> using maintenance plans, particularly for<br />

index maintenance, is that it is an all-or-nothing process: you either rebuild all the<br />

indexes in your database (and all the databases in the maintenance plan) or you rebuild<br />

none of them. There is no middle ground.<br />

Even now, many years and editions later, this rather large hammer is the only built-in tool<br />

at our disposal for performing index maintenance. However, <strong>with</strong> the help of this DMF,<br />

at least we can find out which indexes really are suffering from fragmentation and then,<br />

based on this, build our own index maintenance plans, which limit rebuilds to just those<br />

indexes that need them, or just clustered or non-clustered indexes, indexes of a certain<br />

size, or of a specific table, and so on. In short, this DMF gives the DBA an element of<br />

control over the index maintenance process that is sadly lacking in the current<br />

Maintenance Plans tool.<br />

A brief overview of index fragmentation<br />

The leaf level of a clustered index is implemented as a doubly-linked list. This means that<br />

every leaf level of the index includes a pointer to both the previous and the next page in<br />

the index. The data will be stored in the logical order dictated by the clustering key and<br />

new data will be added in its correct place on the relevant page. So, assuming there is<br />

room on that page, the logical order will match the physical order.<br />

The pointers in the doubly-linked list make it easy to scan ranges of data and, when the<br />

data is ordered as described above, this becomes a very efficient operation. In turn, nonclustered<br />

indexes on a table <strong>with</strong> a clustered index, are implemented as a doubly-linked<br />

list, and have the same benefits (by contrast, indexes on heaps are not implemented this<br />

way, and have no knowledge of which page to scan next).<br />

208

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

Saved successfully!

Ooh no, something went wrong!