I have been working on index fragmentation for indexes that are heavily used and causing performance decreases. Our standard job checks fragmentation levels and reorgs if >5% and <30%, and rebuilds if >30%. As far as I have found these don't seem to be functionally different but I'm being asked if a drop/create is more effective as a client tried this on their own and believes they saw greater improvement. Is this truly possible?
This is comparing a full DROP and CREATE vs ALTER INDEX REBUILD on a non-clustered index.
Best Answer
From Microsoft SQL Server 2012 Internals, page 366
But appeals to authority are boring, so let's test it ourselves!
Performance:
Set up a table with a non-clustered index, load it with junk, and build a table for logging time.
Now let's build some procs that will DROP/CREATE or REBUILD, plus log (approximately) the time taken:
OK, now we can run each procedure multiple times and gather data
Here are my own results: average time in ms for DROP/CREATE: 2547, for REBULD: 1314
It looks like in my contrived example, the winner is REBUILD.
Constraints
What if the index was created to support a constraint? In this case, a simple DROP and CREATE will fail because you have to drop the constraint first. Let's look at the clustered index from the previous example.
Note that the other two methods succeed:
Of course, like Erik alluded to, your actual problems probably have nothing to do with fragmentation, but hey, this was fun.