Tuesday, August 3, 2010

Rebuild vs Reorganize

Today I came across a scenario where a batch job was getting deadlocked with another Long running query. This job had a peice of code to drop and create some indexes on a table which was being used by the query. As the query was supposed to get executed for more than 2 hours to return the result set, the batch job was stuck for all this while.

When I looked into the code, there was no need to drop and create the indexes as the data getting inserted was not much. But the table containing data had almost 6 million rows.

Hence it was necessary to either rebuild or reorganise the indexes frequently. Out of my R&D this is what I figured out:

a. Rebuilng takes much lesser time than reorganizing.
b. Rebuilding Indexes creates a deadlock if some other query is accessing the Table whereas Reorganizing Indexes gets executes smoothly.
c. Reorganizing indexes took much lesser time in second run.

Also, above behavior is expected. For further information on this topic, refer msdn

http://technet.microsoft.com/en-us/library/ms189858.aspx

1 comment: