1 / 2

INTELLIGENT STATISTICS UPDATE

For most of the application databases, sp_updatestats does a good job of updating the statistics to give a good enough performance. However, sp_updatestats scans only a default sample of rows to arrive at statistics, which can be skewed if there is wide variation of data values with the tables and may not be enough for some applications to generate optimal query plans.

Download Presentation

INTELLIGENT STATISTICS UPDATE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INTELLIGENT STATISTICS UPDATE For most of the application databases, sp_updatestats does a good job of updating the statistics to give a good enough performance. However, sp_updatestats scans only a default sample of rows to arrive at statistics, which can be skewed if there is wide variation of data values with the tables and may not be enough for some applications to generate optimal query plans. We can resort to updating statistics with FULLSCAN option (which samples all rows in the table to obtain the cardinality), but this may put unnecessary overhead on the server and take long time. A way to mitigate the overhead of FULLSCAN option is to implement an intelligent custom script, which will use higher sampling ratio than sp_updatestats, especially for biggest tables. It would be prudent to have a script where you can specify a custom sampling ratio for small (< 10,000 rows), medium (between 10,000 and 1 million rows) and large tables (> 1 million rows). I have written the attached script (usp_UPDATE_STATS_ALL_DBs_2012_11_02), which accepts as parameters the sampling ratio for small (@paramSmallSizeTableSampleRate), medium (@paramMediumSizeTableSampleRate), (@paramLargeSizeTableSampleRate) tables. Here are some salient points about this script: and large 1. By default, it will update statistics with FULLSCAN option for small tables only (< 10,000 rows) and at 50 PERCENT scan for medium size tables (between 10,000 and 1 million rows) and 10 PERCENT scan for large size tables (> 1 million rows). These scan percentage can be customized as needed to suit the environment in question but the default values should provide optimal results for most environments 2. It will update statistics only if the table had a DML operation (update/insert/delete) since the last statistics update 3. It runs at a low deadlock priority as a secondary measure to preclude interference with production activities 4. It can be stopped and resumed without loss of completed work 5. It updates both index and column statistics

  2. 6. It will generate verbose logging and each step is time stamped (some of the items that are logged include statistics updated, scan percentage, etc.) 7. It will update all statistics in all user databases and is compatible with SQL 2000, 2005, 2008 and 2012 Satish Kartan has been working with SQL Server for the past 20 years. To read more, please visit Satish Kartan's blog at http://www.sqlfood.com/ where he has shared more details on this.

More Related