Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Rebuilding Indexes

Author  Topic 

dbist
Yak Posting Veteran

52 Posts

Posted - 2008-06-13 : 09:44:28
Hello,

I'm new to rebuilding and reorg indexes. I used the standard report feature in 2005 to look up Index Physical Statistics on one db. I found recommendation to rebuild a few indexes that contain a number of fragments. I created a maint. task, I know maint. tasks are not a cure-all but so far I am just testing the waters. I created two tasks, one to rebuild and another to reorg. After I ran the job, I looked at the report and it still showed recommendation to rebuild the indexes. What is a better solution for my case?

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-06-13 : 10:42:20
You don't have to reorg if already you rebuild it. Usually only if the fragmentation is above 40-50% you should rebuild indexes and it should be done in offline hours (Rebuild).
Go to Top of Page

dbist
Yak Posting Veteran

52 Posts

Posted - 2008-06-13 : 11:10:04
thanks, this is a copy of my prod db so time I do it doesn't matter. Fragmentation shows 75%. There are four fragments on this particular nonclustered index.

I ran this:

ALTER INDEX CareProvVisitRoleAlt3Idx
ON dbo.CV3ActiveCareProvVisitRole
REBUILD;
GO

I also ran this:

ALTER INDEX [CareProvVisitRoleAlt3Idx] ON [dbo].[CV3ActiveCareProvVisitRole] REBUILD WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, SORT_IN_TEMPDB = ON, ONLINE = OFF )
GO


I refreshed the management studio databases view and looked up the report. It still showed 4 fragments, 75% fragmentation and recommendation to rebuild.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-06-13 : 11:12:41
What does DBCC showcontig on those indexes show?
Go to Top of Page

dbist
Yak Posting Veteran

52 Posts

Posted - 2008-06-13 : 12:07:34
DBCC SHOWCONTIG scanning 'CV3ActiveCareProvVisitRole' table...
Table: 'CV3ActiveCareProvVisitRole' (519060985); index ID: 1, database ID: 10

TABLE level scan performed.
- Pages Scanned................................: 17
- Extents Scanned..............................: 9
- Extent Switches..............................: 8
- Avg. Pages per Extent........................: 1.9
- Scan Density [Best Count:Actual Count].......: 33.33% [3:9]
- Logical Scan Fragmentation ..................: 41.18%
- Extent Scan Fragmentation ...................: 77.78%
- Avg. Bytes Free per Page.....................: 1715.0
- Avg. Page Density (full).....................: 78.81%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-06-13 : 12:42:46
Your fragmentation shows you need to rebuild.Kick the rebuild job and see how it affects
Go to Top of Page

Ola Hallengren
Starting Member

33 Posts

Posted - 2008-06-13 : 14:04:50
I think that small indexes often show a high fragmentation also after you've just rebuilt them. I think that fragmentation on small indexes has a very low performance impact. I wouldn't be concerned about that.

Microsoft has as whitepaper on this.
"Generally, you should not be concerned with fragmentation levels of indexes with less than 1,000 pages. In the tests, indexes containing more than 10,000 pages realized performance gains, with the biggest gains on indexes with significantly more pages (greater than 50,000 pages)."
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx

Kalen Delaney has also written a blog post about this.
http://sqlblog.com/blogs/kalen_delaney/archive/2008/02/28/fragmentation-revisited.aspx

I have a stored procedure that you could use to dynamically rebuild or reorganize indexes. It has a filter on the index size.
http://blog.ola.hallengren.com/blog/_archives/2008/1/1/3440068.html

Ola Hallengren
http://ola.hallengren.com
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-13 : 14:12:14
Here's my defrag stored procedure:
http://weblogs.sqlteam.com/tarad/archive/2007/11/27/60415.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -