Rebuilding Indexes and Updating Statistics, the correct sequence...

Wednesday, 24 December 2008 10:11 Alex Rosa SQL Server - Indexes
Print
(3 Votes)
User Rating: / 3
PoorBest 

Rebuilding Indexes or Updating Statistics, which do you do first?
Why?
Are there differences?

Rebuilding an index will update statistics with the equivalent of a full scan - doesn't matter whether you use DBCC DBREINDEX or ALTER INDEX...REBUILD
, the effect is the same. It can do this because it sees a complete picture of the index while it’s doing the rebuild.

Reorganizing an index (using the old
DBCC INDEXDEFRAG, or the new ALTER INDEX...REORGANIZE) will NOT update statistics at all, because it only sees a few pages of the index at a time.
 

So, which is the correct sequence?

 

So what's the solution?

The simple answer is not to update statistics on indexes that have just been rebuilt.


The more complicated answer is to:

  1. Have a list of indexes (F) that you know will cause workload performance problems if they get fragmented
  2. Have a list of indexes (S) that you know will cause workload performance problems if the statistics don't get regularly updated
  3. Evaluate fragmentation for list (F), and choose to reorganize, rebuild, or do nothing
  4. For all indexes in list (S) that were not rebuilt in step 3, update statistics


 

Reference:
Paul S. Randal
http://www.sqlskills.com/blogs/paul/post/Search-Engine-QA-10-Rebuilding-Indexes-and-Updating-Statistics.aspx