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

Create successful ePaper yourself

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

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

REORGANIZE<br />

Yet another BE CAREFUL! warning on this one. If you disable the clustered index<br />

for your table, it has the effect of disabling the table. The data will remain, but will<br />

be inaccessible by all indexes (since they all depend on the clustered index) until<br />

you rebuild the clustered index.<br />

BINGO!, from the developer perspective. With REORGANIZE, you hit much more of a happy medium in<br />

life. When you reorganize your index, you get a slightly less complete optimization than you get with a<br />

full rebuild, but one that occurs online (users can still utilize the index).<br />

This should, if you’re paying attention, bring about the question, “What exactly do you mean by ‘slightly<br />

less complete’?” Well, REORGANIZE works only on the leaf level of your index — non-leaf levels of the<br />

index go untouched. This means that you’re not quite getting a full optimization, but for the lion’s share<br />

of indexes, that is not where your real cost of fragmentation is (though it can happen, and your mileage<br />

may vary).<br />

Given its much lower impact on users, this is usually the tool you’ll want to use as part of your regular<br />

maintenance plan. We’ll look into this a bit more later when talking fragmentation.<br />

Dropping Indexes<br />

If you’re constantly reanalyzing the situation and adding indexes, don’t forget to drop indexes, too.<br />

Remember the overhead on inserts. It doesn’t make much sense to look at the indexes that you need<br />

and not also think about which indexes you do not need. Always ask yourself: “Can I get rid of any of<br />

these?”<br />

The syntax to drop an index is pretty much the same as that used to drop a table. The only hitch is that<br />

you need to qualify the index name with the table or view it is attached to:<br />

DROP INDEX .<br />

And it’s gone.<br />

Take a Hint from the Query Plan<br />

New with <strong>SQL</strong> <strong>Server</strong> <strong>2008</strong> is an indexing hint right within the query-plan information that will tell you<br />

about any indexes that the query optimizer thought would have helped, but that didn’t exist.<br />

Use the Database Engine Tuning Advisor<br />

290<br />

It is my hope that you’ll learn enough about indexes not to need the Database Engine Tuning Advisor all<br />

that much, but it still can be quite handy. It works by taking a workload file, which you generate using<br />

the <strong>SQL</strong> <strong>Server</strong> Profiler (discussed in Professional <strong>SQL</strong> <strong>Server</strong> <strong>2008</strong> Programming), and looking over that<br />

information for what indexes and/or partitions will work best on your system.

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

Saved successfully!

Ooh no, something went wrong!