Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Index Rebuilds Still Leave Fragmentation Expand / Collapse
Author
Message
Posted Monday, January 28, 2008 1:34 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 22, 2014 11:56 AM
Points: 472, Visits: 854
Hello All,

I am running SQL Server 2005 SP2 Standard Edition on a few servers. I run SQL Agent Jobs every week that REBUILD all of the user table indexes i.e. (ALTER INDEX ALL ON [Table] REBUILD) I also run another job that UPDATES STATISTICS. The jobs complete without error and rebuild most all of the indexes removing fragmentation then updating any statistics. Though, there are quite a few indexes that even after running the rebuild script still have the same fragmentation % i/e 67% or fragments as prior to the REBUILD command. Are there some reasons why indexes will remain fragmented even after rebuilding them? I've tried as a test on some tables to rebuild the index in question from SSMS, SQL Agent Job, and the GUI point and click "Rebuild", all results are the same, command competed successfully, but fragmentation remains the same, no change.

Any tips or pointers would be greatly appreciated! There must be some caveat I'm not thinking of..
Post #448556
Posted Monday, January 28, 2008 1:38 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 40,427, Visits: 36,877
How big are the tables in question? How many pages do the indexes take up (visible in sys.dm_db_index_physical_stats)

Edit: btw, a separate update statistics is not necessary (and may even be counter productive) if you're doing an index rebuild. When the index gets rebuilt, the stats get updated as if an update stats with full scan was run.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #448561
Posted Monday, January 28, 2008 1:50 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 22, 2014 11:56 AM
Points: 472, Visits: 854
Hi Gail,

There are quite a few examples but I will stick to one or two. The others are very similar, and / or only average 1 fragment per page.

Stats from the DMV

EXAMPLE
Table Data Size .516 MB
Index Space .719 MB
Table record count : 7012
# of Pages : 14
# of Fragments 8
Avg Frag 50%

EXAMPLE
Table Data Size .039 MB
Index Space .016 MB
Table record count : 568
# of Pages : 5
# of Fragments 5
Avg Frag 80%

Post #448568
Posted Monday, January 28, 2008 4:46 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 10:17 AM
Points: 14, Visits: 213
See if this helps...

http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx


EKD
Post #448639
Posted Monday, January 28, 2008 7:45 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, October 27, 2014 11:15 AM
Points: 2,041, Visits: 1,671
These indexes aren't getting touched - you basically shouldn't bother with index fragmentation unless your index has more than 1000 pages as it'll most probably be entirely contained in cache already and so fragmentation is irrelevant. I thought I'd put that into BOL for DBCC SHOWCONTIG and index_physical_stats but it looks like I didn't.

Checkout this blog post on rebuilds and stats updates - http://www.sqlskills.com/blogs/paul/2008/01/27/SearchEngineQA10RebuildingIndexesAndUpdatingStatistics.aspx. Weird how questions seem to come up in clusters - this week it's index rebuilds.

Hope this helps.


Paul Randal
CEO, SQLskills.com: Check out SQLskills online training!
Blog:www.SQLskills.com/blogs/paul Twitter: @PaulRandal
SQL MVP, Microsoft RD, Contributing Editor of TechNet Magazine
Author of DBCC CHECKDB/repair (and other Storage Engine) code of SQL Server 2005
Post #448659
Posted Tuesday, January 29, 2008 8:47 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, May 22, 2014 11:56 AM
Points: 472, Visits: 854
Thanks, yeah I wasn't worried about performance reasons, as your right there isn't much to the table. It was a curiosity question, as there must be a reason ie size of table, total number of data pages why they were not being touched. The ones that are critical were being rebuilt..

The reason we do the statistics FULL SCAN afterwards is to catch the other statistics that were user created or auto created by the engine in some situations that were not part of an index column. On our databases we have a good maintance window so time is no issue and it really only takes 5-10 min for rebuilds and statistics as a high number. Sometimes we find that one of those statistics should be made into an index and other times they are better served as just statistical info for the engine.
Post #448909
Posted Tuesday, January 29, 2008 2:19 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 10:12 AM
Points: 1,166, Visits: 1,973
GilaMonster (1/28/2008)
How big are the tables in question? How many pages do the indexes take up (visible in sys.dm_db_index_physical_stats)

Edit: btw, a separate update statistics is not necessary (and may even be counter productive) if you're doing an index rebuild. When the index gets rebuilt, the stats get updated as if an update stats with full scan was run.


Gila, I was always under the same impression until I had several phone conversations with Microsoft revolving around performance issues we experienced. Two different SQL Server support techs informed me that issuing a DBCC DBREINDEX, ALTER INDEX REBUILD/REORGANIZE, will NOT update the statistics with fullscan. They recommended having a separate task in our maintenance scripts to update the statistics.

Now I'm curious ... It wouldn't be the first time Microsoft has given me faulty information.


---
SQLSlayer
Making SQL do what we want it to do.

Post #449088
Posted Tuesday, January 29, 2008 4:34 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, October 27, 2014 11:15 AM
Points: 2,041, Visits: 1,671
The quality of support has gone way down - I used to constantly battle incorrect support engineers (a lot easier to do when you're running one of the dev teams they're giving incorrect info about).

They're wrong - and that's pretty annoying. Trust me - I used to own all that code. Reorganize doesn't but rebuild does update stats.


Paul Randal
CEO, SQLskills.com: Check out SQLskills online training!
Blog:www.SQLskills.com/blogs/paul Twitter: @PaulRandal
SQL MVP, Microsoft RD, Contributing Editor of TechNet Magazine
Author of DBCC CHECKDB/repair (and other Storage Engine) code of SQL Server 2005
Post #449127
Posted Wednesday, January 30, 2008 12:05 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 21, 2014 2:56 AM
Points: 2,603, Visits: 2,061
I also face the similar kind of problem:

When the table size is very small and contain a few rows only at that time this kind of problem happen. In addition to this when there is heavy insert/update/delete happen to the database i.e. few transactions per second at that time also you won't get Scan Density 100%.

One shouldn't bother much about the Scan Density on the small table.


---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Post #449202
Posted Wednesday, January 30, 2008 1:36 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:55 AM
Points: 40,427, Visits: 36,877
Adam Bean (1/29/2008) Two different SQL Server support techs informed me that issuing a DBCC DBREINDEX, ALTER INDEX REBUILD/REORGANIZE, will NOT update the statistics with fullscan. They recommended having a separate task in our maintenance scripts to update the statistics.


Paul Randal (1/29/2008)
Trust me - I used to own all that code. Reorganize doesn't but rebuild does update stats.


And it's very easy to prove, if you want to see for yourself Adam.
Run DBCC Show_statistics on an index. Check the date the stats were updates. Rebuild the index, then run show statistics again.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #449667
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse