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 2008 Forums
 Transact-SQL (2008)
 update statistics

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-11-23 : 03:04:54
Hi,
At present, in sql server 2008, I have set up a job which runs every day at 3:00 am.
This job has in it the following sql:
use DBName1
exec sp_updatestats
GO
use DBName2
exec sp_updatestats

Questions:
1- Is what I am doing a good thing?
2- How about doingthe following instead:
alter database DBName1 set auto_update_statistics on
3- Is there a property to make sure is on so that it does the necessary auto-stats, etc?
Thanks

Kristen
Test

22859 Posts

Posted - 2011-11-23 : 03:41:56
Auto Update Statistics is usually a good thing, 'coz if the server discovers the statistics are out-of-shape getting them rebuilt will help the queries. But SQL will trigger that update when the index goes out of shape which will, usually, be when the server is at its busiest - i.e. the time when inserts/updates are happening most.

I prefer to update statistics in the quiet period of our day, and to be able to use options that suit me; and then Auto Update is just a fall back in case something goes out of shape between scheduled updates.
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-11-23 : 03:46:19
So, is my job doing the right thing?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-11-23 : 08:25:17
We do:

UPDATE STATISTICS [owner].[table] WITH FULLSCAN
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-11-23 : 09:06:07
You are doing it for one table.
But I am doing it for all the tables at 3:00 am
Is that not a good idea?
Thanks
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-11-23 : 13:51:30
quote:
Originally posted by arkiboys

You are doing it for one table.


No, that's an example. We do it for tables on which we want to update the statistics.

sp_updatestats doesn't have the option to use FULLSCAN - unless it happens to have been the previously used option, and remains, always, the previously used open (and you use 'resample' option), and it also does all tables - whether they need it or not.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-23 : 13:56:38
Fullscan isn't realistic on large tables that are busy 24/7. If you have a situation like this like we do, use sp_updatestats.

We use both auto update stats and sp_updatestats.

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

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-11-23 : 14:48:09
Tara your use of "large" and mine are probably different!! We use Full Scan on everything because we then know we are on a level playing field. Perhaps I should trust SQL to use a scan-sample, but ... how accurate/reliable is it?

And if your last Update Stats on a given table was FullScan isn't sp_updatestats 'resample' going to so the same thing? (Perhaps you don;t use 'resample'?)

Anyways ... I prefer to be in control
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-23 : 15:57:36
I don't use resample anymore, used to, but not anymore.

Most of my systems are very busy 24/7. The performance hit that occurs with fullscan is too great to do it. For the ones that can do it though, I do use fullscan. It's just rare that I can use fullscan. The sampling is fine on our systems. Very rarely will I have to step in and run it manually with fullscan, very, very rarely. Typically recompiling a stored procedure fixes our issues, and we're working towards not needing to do that either.

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

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-11-24 : 02:53:27
In that case I should probably trust it more than I do . Useful input, thanks.
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-11-24 : 04:54:15
quote:
Originally posted by tkizer


We use both auto update stats and sp_updatestats.

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

Subscribe to my blog


Can you please elaborate on when to use each?
Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-24 : 17:42:59
Use both. If you can afford to do a fullscan, then don't use sp_updatestats. If you can't afford to do the fullscan, then use it. In either case though, keep auto update stats enabled.

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

Subscribe to my blog
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2011-11-24 : 17:58:36
Note: sp_updatestats will only affect statistics that need to be updated. It no longer works against all statistics.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-24 : 18:07:53
What's the point of updating stats if it's not needed anyway? I mean it could be wrong on when it's needed of course, but we supplement with update stats on certain tables where needed.

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

Subscribe to my blog
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2011-11-25 : 01:50:32
Just answering Kristen statement that sp_updatestats affects all tables/stats whether they need it or not. It no longer does that and only affects statistics that need to be updated.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-11-25 : 11:08:20
Useful to know, thanks for that
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-25 : 14:38:57
quote:
Originally posted by jeffw8713

Just answering Kristen statement that sp_updatestats affects all tables/stats whether they need it or not. It no longer does that and only affects statistics that need to be updated.




Cool, didn't realize you were referencing back to that.

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 -