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»»

Rebuilding Stats: Twice or Not At All Expand / Collapse
Author
Message
Posted Tuesday, July 29, 2008 12:14 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: Moderators
Last Login: Friday, August 29, 2014 8:46 AM
Points: 6,783, Visits: 1,881
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
Post #542372
Posted Tuesday, July 29, 2008 1:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, August 29, 2014 9:57 AM
Points: 6,304, Visits: 13,601
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"
Post #542409
Posted Tuesday, July 29, 2008 3:46 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Saturday, August 23, 2014 6:03 AM
Points: 351, Visits: 1,556
Thanks Andy!


John Sansom (@sqlBrit) | www.johnsansom.com
Post #542457
Posted Tuesday, July 29, 2008 5:23 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 1, 2014 8:17 PM
Points: 9, Visits: 74
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) ?
Post #542529
Posted Tuesday, July 29, 2008 5:41 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: Moderators
Last Login: Friday, August 29, 2014 8:46 AM
Points: 6,783, Visits: 1,881
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
Post #542542
Posted Tuesday, July 29, 2008 7:19 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 21, 2014 12:08 PM
Points: 1,414, Visits: 4,540
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


https://plus.google.com/100125998302068852885/posts?hl=en
http://twitter.com/alent1234
x-box live gamertag: i am null
[url=http://live.xbox.com/en-US/MyXbox/Profile[/url]
Post #542618
Posted Tuesday, July 29, 2008 7:22 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 18, 2013 12:27 PM
Points: 21, 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.
Post #542621
Posted Tuesday, July 29, 2008 9:32 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, May 8, 2014 10:08 PM
Points: 358, 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.
Post #542775
Posted Tuesday, July 29, 2008 9:41 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 21, 2014 12:08 PM
Points: 1,414, Visits: 4,540
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

https://plus.google.com/100125998302068852885/posts?hl=en
http://twitter.com/alent1234
x-box live gamertag: i am null
[url=http://live.xbox.com/en-US/MyXbox/Profile[/url]
Post #542790
Posted Tuesday, July 29, 2008 10:14 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, August 29, 2014 4:30 AM
Points: 5,345, Visits: 1,388
Nice one....


Post #542828
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse