![]() |
|
|
By: Chad Boyd | Read Comments | Print Chad is an Architect, Administrator and Developer with technologies such as SQL Server, .NET, and Windows Server. Related Tips: More |
|
In our 2nd to last post in the Fragmentation series, we'll discuss our options on addressing and removing/correcting fragmentation. In our next and final post in the series, we'll end with a full-fledged SQL script that will walk you through all the different things we've talked about in the series to give you some up close and personal experience with what we've gone through.
Once you've detected that you have fragmentation, understand what it impacts in your workload, and understand the different types of fragmentation and the type you're trying to correct, you have a couple of options to address it - realistically, you have 3:
The most frequently used options are the 1st and 2nd listed - here's a matrix comparing some of the key functional differences between the rebuild and reorganize options:
| Functionality | REBUILD / DBREINDEX | REORGANIZE / DEFRAG |
| Online / Offline | Offline; Online possible with 2005 Enterprise Edition | Online |
| Faster when logical fragmentation is | High | Low |
| Parallel Processing | Yes | No |
| Compacts Pages | Yes | Yes |
| Can be stopped/started without losing completed work to that point | No | Yes |
| Able to untangle interleaved pages | Yes | No |
| Additional free space required in data file for process | Yes - 1.2x - 2x existing size | No |
| Faster on larger indexes | Yes | No |
| Rebuilds Statistics | Yes | No |
| Log Space Used | Full Recovery - High; Bulk/Simple Recovery - Low; | Depends on work performed |
| May skip pages on busy system | No | Yes |
| Can specify additional options (fillfactor, etc.) | Yes | No |
Of course, one other option to 'addressing' fragmentation could be to choose to not fix it. Hopefully you're not the type of engineer who simply rebuilds/defrags indexes every day just for the sake of doing so or because it makes you feel better - instead, try to work out a plan to understand which indexes in your schema actually matter the most, are impacted by the different kinds of fragmentation, etc. and those that aren't.
Let's take a look at the internals for defrag and reorganizing - reorganizing an index is performed in basically 2 stages:
Let's take a look at some visual examples on how these stages work - the defrag-ing stage is the same for both 2000 and 2005, but the page compaction stage uses a different and improved in 2005 using a new sliding-window algorithm.
SQL 2000 Defrag Compaction (left-to-right, top-to-bottom)
SQL 2005 Reorganize Compaction (left-to-right, top-to-bottom)
Page Reordering Stage (left-to-right, top-to-bottom)
That wraps up our 2nd to last post in the series, in our next and final post we'll wrap it up with an all-in-one script for everyone to use in a test environment of your own to verify everything we've discussed.
Chad Boyd ~~~ This posting is provided "AS IS" with no warranties, and confers no rights. Use of any included script samples are subject to the terms specified at http://www.mssqltips.com/disclaimer.asp and http://www.mssqltips.com/copyright.asp.
| Share: | Share | Tweet |
|
![]() |
![]() |
Free SQL Server Learning |
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |