17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

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 9: <strong>SQL</strong> <strong>Server</strong> Storage and Index Structures<br />

Now, the question is how do we use this information once we have it? The answer is, of course, that it<br />

depends.<br />

Using the output from our fragmentation query, we have a decent idea of whether our database is full,<br />

fragmented, or somewhere in between (the latter is, most likely, what we want to see). If we’re running<br />

an OLAP system, then having full pages would be great — fragmentation would bring on depression.<br />

For an OLTP system, we would want much the opposite (although only to a point).<br />

So, how do we take care of the problem? To answer that, we need to look into the concept of index<br />

rebuilding and fillfactors.<br />

ALTER INDEX and FILLFACTOR<br />

294<br />

Stat What It Means<br />

Logical Scan<br />

Fragmentation<br />

Extent Scan<br />

Fragmentation<br />

The percentage of pages that are out of order as checked by scanning the leaf<br />

pages of an index. Only relevant to scans related to a clustered table. An out-oforder<br />

page is one for which the next page indicated in the index allocation map<br />

(IAM) is different from that pointed to by the next page pointer in the leaf page.<br />

This one is telling whether an extent is not physically located next to the extent<br />

that it should be logically located next to. This just means that the leaf pages of<br />

your index are not physically in order (though they still can be logically), and<br />

it shows what percentage of the extents this problem pertains to.<br />

As we saw earlier in the chapter, <strong>SQL</strong> <strong>Server</strong> gives us an option for controlling just how full our leaf<br />

level pages are and, if we choose, another option to deal with non-leaf level pages. Unfortunately, these<br />

are proactive options. They are applied once, and then you need to reapply them as necessary by<br />

rebuilding or reorganizing your indexes to reapply the options.<br />

To rebuild indexes, we can either drop them and create them again (if you do, using the DROP_EXISTING<br />

option usually is a good idea), or make use of the ALTER INDEX command with the REBUILD option.<br />

Keep in mind, however, what was said previously about rebuilding indexes — unless you have the<br />

ONLINE option available, rebuilding indexes takes the index (and possibly the entire table) totally offline<br />

until the rebuild is complete. In general, reorganizing is going to be a better option.<br />

A reorg affects only the leaf level of the index (where most of the issue is likely to be anyway) and keeps<br />

the index online while the reorg is taking place. Reorganizing your indexes restructures all the leaf level<br />

information in those indexes, and reestablishes a base percentage that your pages are full. If the index in<br />

question is a clustered index, then the physical data is also reorganized. Unfortunately, REORGANIZE<br />

does not allow for the change of several index settings, such as FILLFACTOR.<br />

If the index has not had a specific fillfactor specified, the pages will be reconstituted to be full, minus<br />

two records. Just as with the CREATE TABLE syntax, you can set the FILLFACTOR to be any value between<br />

1 and 100 as long as you are doing a full rebuild (as opposed to just a reorg). This number will be the<br />

percent that your pages are full once the database reorganization is complete. Remember, though, that as<br />

your pages split, your data will still be distributed 50-50 between the two pages — you cannot control<br />

the fill percentage on an ongoing basis other than by regularly rebuilding the indexes.

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

Saved successfully!

Ooh no, something went wrong!