SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Rebuilding Stats: Twice or Not At All


Rebuilding Stats: Twice or Not At All

Author
Message
Andy Warren
Andy Warren
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: Moderators
Points: 12097 Visits: 2730
Comments posted to this topic are about the item Rebuilding Stats: Twice or Not At All

Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
Perry Whittle
Perry Whittle
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20590 Visits: 17244
Hi Andy

this was exactly the same line of thinking i had. Very informative. I think you're right no-one ever changes the default for stats during the create index

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
John.Sansom
John.Sansom
SSC Eights!
SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)SSC Eights! (841 reputation)

Group: General Forum Members
Points: 841 Visits: 1558
Thanks Andy!


John Sansom (@sqlBrit) | www.johnsansom.com
Stan Vaughan
Stan Vaughan
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 80
Is it not true that the Automatic Update of statistics is only invoked if a certain percentage of of rows are updated in the underlying table. So if you have a very large table (in terms of rows) that an update of stats may not occur everytime an insert is done even if this insert constitutes thousands of rows (i.e. in a table that has millions) ?
Andy Warren
Andy Warren
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: Moderators
Points: 12097 Visits: 2730
Thats correct. MS has a whitepaper on it, stats get updated when you go from zero to not zero rows, when it crosses 500 changes, and when it crosses 500 changes plus 20%.

20% of even 20 million rows is a lot, but it depends on how your data is being modified as to how important it is to update stats more often. The biggest time when it matters is when the data crosses the threshold from where it would do a bookmark lookup to not.

Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
alen teplitsky
alen teplitsky
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2866 Visits: 4674
back in the sql 2000 days we used to run dbcc reindex and indexdefrag depending on the frag level and then updating statistics. and we had some strange problems sometimes where a query would not use an index even though it had to.

one time we ran a query on the publisher and a subscriber. query hit 1 table and the indexes were the same on both ends. on the publisher we would get an index scan and the subscriber an index seek. had a case with PSS and asked them if they could give us a quick answer. he said check the statistics. we did and they were different. so we stopped updating statistics and alter index only does rebuilds. before that we updated stats with full scan once a week and still didn't solve it. only rebuilding indexes and not updating the statistics seems to work. probably a bug where it rebuilds only statistics
Steve Howard-434180
Steve Howard-434180
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 62
just to quibble with words a little bit: sp_updatestats only checks to see if rowmodctr is 0 or not. If it is not 0, it updates stats. That's a little different from only updating if the statistics need it. It is also worth considering that the rowmodctr that it checks was the actual indicator in SQL 2000, but is only an approximation in SQL 2005. The colmodctr that is actually used for autoupdate of statistics in 2005 is not visible to us.

Despite what a whitepaper may say, I've seen in dbcc show_statistics times when on very large indexes (Very large, as in > 1 billion rows) that the sampling used was less than 1 percent. That's probably a sufficient sampling most times, but can lead to skewed statistics on the very rare occasion. The times where I have seen skewed statistics, there was no mistaking what it did to performance. In cases like these, if statistics are rebuilt occasionally using a higher sampling, then the threshold of modifications that leads to an autoupdate of statistics is never reached, so the statistics don't get updated with the smaller smapling that the autoupdate stats uses.

One of the biggest reasons I can think of to update statistics periodically (nightly if you have slow time during the night) is that the modctr is set back to 0 when you update, and this makes it unlikely that the number of modifications during peak business will cross the threshold that trips autoupdate of stats on a table. The autoupdate should be used like a safety valve in case that threshold is reached, but minimizing autoupdate during your busiest time (by proactively updating during slow time) is a good practice.
magarity kerns
magarity kerns
Mr or Mrs. 500
Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)Mr or Mrs. 500 (542 reputation)

Group: General Forum Members
Points: 542 Visits: 397
What that means is that each time you rebuild (not reorg/defrag) the statistics related to the index will be built at the same time
I couldn't really figure out this sentence; are you saying the index is built when the statistics are rebuilt? It seems more likely that the statistics are refreshed if the index is rebuilt. Pardon if this is a dumb question.
alen teplitsky
alen teplitsky
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2866 Visits: 4674
when you rebuild an index the statistics are also rebuilt for that index. if you rebuild an index and then run update statistics without a full scan it's the equivelant of rebuilding stats with a full scan and then again without a full scan. at least for some of the stats on that table
Anipaul
Anipaul
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7431 Visits: 1407
Nice one....



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search