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.

The Database Engine Tuning Advisor is found on the Tools menu of the <strong>SQL</strong> <strong>Server</strong> Management Studio.<br />

It can also be reached as a separate program item from the Windows Start menu. Like most any tuning<br />

tool, I don’t recommend using this tool as the sole way to decide what indexes to build, but it can be<br />

quite handy at making some suggestions that you may not have thought of.<br />

Maintaining Your Indexes<br />

As developers, we often tend to forget about our product after it goes out the door. For many kinds of<br />

software, that’s something you can get away with just fine — you ship it, then you move on to the next<br />

product or next release. However, with database-driven projects, it’s virtually impossible to get away<br />

with. You need to take responsibility for the product well beyond the delivery date.<br />

Please don’t take me to mean that you have to go serve a stint in the tech support department — I’m<br />

actually talking about something even more important: maintenance planning.<br />

There are really two issues to be dealt with in terms of the maintenance of indexes:<br />

❑ Page splits<br />

❑ Fragmentation<br />

Both are related to page density, and while the symptoms are substantially different, the troubleshooting<br />

tool is the same, as is the cure.<br />

Fragmentation<br />

Chapter 9: <strong>SQL</strong> <strong>Server</strong> Storage and Index Structures<br />

We’ve already talked about page splits quite a bit, but we haven’t really touched on fragmentation. I’m<br />

not talking about the fragmentation that you may have heard of with your O/S files and the defrag tool<br />

you use, because that won’t help with database fragmentation.<br />

Fragmentation happens when your database grows, pages split, and then data is eventually deleted.<br />

While the B-Tree mechanism is really not that bad at keeping things balanced from a growth point of<br />

view, it doesn’t really have a whole lot to offer as you delete data. Eventually, you may get down to a situation<br />

where you have one record on this page, a few records on that page — a situation where many of<br />

your data pages are holding only a small fraction of the amount of data that they could hold.<br />

The first problem with this is probably the first you would think about — wasted space. Remember that<br />

<strong>SQL</strong> <strong>Server</strong> allocates an extent of space at a time. If only one page has one record on it, then that extent is<br />

still allocated.<br />

The second problem is the one that is more likely to cause you grief: Records that are spread out all over<br />

the place cause additional overhead in data retrieval. Instead of just loading up one page and grabbing<br />

the 10 rows it requires, <strong>SQL</strong> <strong>Server</strong> may have to load 10 separate pages to get that same information. It<br />

isn’t just reading the row that causes effort — <strong>SQL</strong> <strong>Server</strong> has to read that page in first. More pages =<br />

more work on reads.<br />

291

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

Saved successfully!

Ooh no, something went wrong!