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.

High selectivity<br />

Chapter 5: Indexing Strategy and Maintenance<br />

If you've chosen a low selectivity column for the index key (i.e. where each key value<br />

matches many rows), then the optimizer may decide to simply perform a table scan to<br />

return a piece of data. Table scans have a bad reputation, but this is because they often<br />

mean reading a huge number of rows; in small tables, scanning all the rows is sometimes<br />

quicker than reading the data from the leaf levels of an index.<br />

You're looking for selective columns to form your index key and, certainly, the leading<br />

(first) column should be selective. However, this does not mean each index should<br />

start <strong>with</strong> the PK column; it must be a column that is likely to get searched on.<br />

A good discussion of index selectivity and column ordering can be found at http://<br />

sqlserverpedia.com/wiki/Index_Selectivity_and_Column_Order.<br />

Neither too many nor too few<br />

The drive to cover queries does not mean you should simply create an index for<br />

every query in your workload. If a table contains many rows and is subject to frequent<br />

modifications, the presence of numerous indexes will significantly slow down these modifications,<br />

as the data must be maintained in both the index and the underlying table.<br />

Examine the workload characteristics for a given table as this will affect how many<br />

indexes you might want to have per table. If a table is pretty static, you can manage <strong>with</strong><br />

more indexes, but on tables subject to frequent updates, you'll want as few as you can get<br />

away <strong>with</strong>.<br />

Narrow indexes (<strong>with</strong>in reason)<br />

Neither does the drive to cover queries mean that you should create huge, 16-column<br />

indexes in an attempt to "cover everything at once;" if your index key values are wide,<br />

181

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

Saved successfully!

Ooh no, something went wrong!