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

Summary<br />

296<br />

Indexes are sort of a cornerstone topic in <strong>SQL</strong> <strong>Server</strong> or any other database environment, and are not<br />

something to be taken lightly. They can drive your performance successes, but they can also drive your<br />

performance failures.<br />

Top-level things to think about with indexes:<br />

❑ Clustered indexes are usually faster than non-clustered indexes (one could come very close to<br />

saying always, but there are exceptions).<br />

❑ Only place non-clustered indexes on columns where you are going to get a high level of selectivity<br />

(that is, 95 percent or more of the rows are unique).<br />

❑ All Data Manipulation Language (DML: INSERT, UPDATE, DELETE, SELECT) statements can benefit<br />

from indexes, but inserts, deletes, and updates (remember, they use a delete and insert approach)<br />

are slowed by indexes. The lookup part of a query is helped by the index, but anything that modifies<br />

data will have extra work to do (to maintain the index in addition to the actual data).<br />

❑ Indexes take up space.<br />

❑ Indexes are used only if the first column in the index is relevant to your query.<br />

❑ Indexes can hurt as much as they help — know why you’re building the index, and don’t build<br />

indexes you don’t need.<br />

❑ Indexes can provide structured data performance to your unstructured XML data, but keep in<br />

mind that like other indexes, there is overhead involved.<br />

When you’re thinking about indexes, ask yourself these questions:<br />

Question Response<br />

Are there a lot of inserts or<br />

modifications to this table?<br />

Is this a reporting table? That is,<br />

not many inserts, but reports<br />

run lots of different ways?<br />

Is there a high level of selectivity<br />

on the data?<br />

Have I dropped the indexes I no<br />

longer need?<br />

Do I have a maintenance strategy<br />

established?<br />

If yes, keep indexes to a minimum. This kind of table usually<br />

has modifications done through single-record lookups of the<br />

primary key, and usually, this is the only index you want on<br />

the table. If the inserts are non-sequential, think about using<br />

something other than a clustered index.<br />

More indexes are fine. Target the clustered index to frequently<br />

used information that is likely to be extracted in ranges.<br />

OLAP installations will often have many times the number of<br />

indexes seen in an OLTP environment.<br />

If yes, and it is frequently the target of a WHERE clause, then<br />

add that index.<br />

If not, why not?<br />

If not, why not?

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

Saved successfully!

Ooh no, something went wrong!