Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Index rebuild on sql server

I am doing the index rebuilding on database. I need to verify if it is done or not. Can somebody please guide me. I am using SQL Server 2008 R2

like image 617
Pradeep Avatar asked Mar 07 '11 09:03

Pradeep


People also ask

Does SQL Server rebuild indexes automatically?

As people have mentioned here, your indexes do not automatically rebuild. This is quite a big problem in SQL Server, as your indexes will fragment over time. Your could find your indexes are 95% plus fragmented, affecting query performance badly.

When should I run an index rebuild?

If an index contains less than 100 pages, I will perform no maintenance. If an index is between 10% and 30% fragmented, I will REORGANIZE the index and UPDATE the statistics. If an index is over 30% fragmented, I will REBUILD the index - with no UPDATE STATISTICS , as this is taken care of by the REBUILD .

What is difference between Rebuild index and reorganize in SQL Server?

"Reorganize index" is a process of cleaning, organizing, and defragmenting of "leaf level" of the B-tree (really, data pages). Rebuilding of the index is changing the whole B-tree, recreating the index.

Why do we need index rebuild?

Every so often, we need to rebuild indexes in Oracle, because indexes become fragmented over time. This causes their performance - and by extension - that of your database queries, to degrade. Hence, rebuilding indexes every now and again can be quite beneficial.


2 Answers

If you are looking for details on all indexes and tables in your database you can use.

SELECT OBJECT_NAME(object_id),* 
FROM sys.dm_db_index_physical_stats(DB_ID(),NULL,NULL,NULL,'SAMPLED')

It just occurred to me that you might also be asking how to know the progress of the reindexing. For this you can use

SELECT percent_complete 
from sys.dm_exec_requests 
where session_id= <spid of interest>
like image 168
Martin Smith Avatar answered Sep 28 '22 03:09

Martin Smith


A key thing would be to run the "Index Physical Statistics" report and "Disk Usage by Top Tables" reports before and after you rebuild the indexes.

On the "Index Physical Statistics" report, you can see how fragmented each index is.

To see these reports... * Right Click on database in Sql Server Management Studio * Mouse over "Reports", then "Standard Reports", then select the report you want.

For a script you can set up to identify fragmented indexes and rebuild them (and for more info), check this out:

http://www.foliotek.com/devblog/sql-server-optimization-with-index-rebuilding/

like image 20
Narnian Avatar answered Sep 28 '22 05:09

Narnian