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.

Chapter 5: Indexing Strategy and Maintenance<br />

the index. These standards should be taken lightly, as a more heavily trafficked index may<br />

need to be rebuilt at a lower fragmentation level, and a less active index could conceivably<br />

wait until its fragmentation reaches the rebuild range, and so is never reorganized.<br />

I tend to stick <strong>with</strong> these standards, except in extreme cases. If we go by those standards,<br />

it is a decent assessment to state that our demo database is in decent shape from an index<br />

fragmentation angle. I would recommend running reorganization commands against the<br />

clustered and non-clustered indexes <strong>with</strong> less than 30% fragmentation, and rebuilding the<br />

two clustered indexes <strong>with</strong> fragmentation in excess of 30%.<br />

For the fragmented heap (demo.sch1.DB340534), I would identify a clustering key and<br />

create the clustered index. If, for some reason, a heap is warranted, then I'd still identify a<br />

clustering key, create the clustered index, and then drop the index. The data will remain<br />

ordered based upon the clustering key identified, but will revert back to a heap object<br />

once you drop the clustered index. Alternatively, if I'm lucky enough to be using a <strong>SQL</strong><br />

<strong>Server</strong> 2008 instance, I can issue ALTER TABLE…REBUILD.<br />

Now that we've shown you how to identify fragmentation in your indexes and heaps,<br />

how do you go about resolving it, <strong>with</strong>out manually crafting a reorganization or rebuild<br />

command for each index identified as being fragmented beyond acceptable levels? I've<br />

created many iterations of such a script over the years, but I've scrapped it in favor of one<br />

created by Andrew Kelly, published in the July 2008 issue of <strong>SQL</strong> <strong>Server</strong> Magazine<br />

(www.sqlmag.com/Article/ArticleID/99019/Rebuild_Only_the_Indexes_that_<br />

Need_Help.html). Based on his code, I generated a <strong>SQL</strong> Agent job that I schedule and<br />

run against selected databases, and rebuild/reorganize indexes accordingly.<br />

214

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

Saved successfully!

Ooh no, something went wrong!