|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 12:49 PM
Points: 467,
Visits: 851
|
|
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..
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 9:42 AM
Points: 37,662,
Visits: 29,914
|
|
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
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 12:49 PM
Points: 467,
Visits: 851
|
|
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%
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, February 18, 2013 2:19 PM
Points: 14,
Visits: 211
|
|
See if this helps...
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
EKD
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 1:23 PM
Points: 1,905,
Visits: 1,601
|
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 12:49 PM
Points: 467,
Visits: 851
|
|
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.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, April 23, 2013 12:18 PM
Points: 1,103,
Visits: 1,781
|
|
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.
--
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 1:23 PM
Points: 1,905,
Visits: 1,601
|
|
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
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 3:39 AM
Points: 1,768,
Visits: 1,312
|
|
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."
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 9:42 AM
Points: 37,662,
Visits: 29,914
|
|
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
|
|
|
|