The information in this article applies to:
SUMMARYThe newly-introduced statistical maintenance functionality, AutoStat, may generate unwanted overhead on a production system by performing one of the following actions:
MORE INFORMATIONGeneral InformationSQL Server makes use of a cost-based optimizer that can be extremely sensitive to statistical information that is provided on tables and indexes. Without correct and up-to-date statistical information, SQL Server can be challenged to determine the best execution plan for a particular query.Statistics maintained on each table in SQL Server 7.0 to aid the optimizer in cost-based decision making include the:
To maintain the statistical information in an as up-to-date fashion as possible, SQL Server 7.0 introduces AutoStat, which, through SQL Server's monitoring of table modifications, is capable of automatically updating the statistics for a table when a certain change threshold has been reached. Additionally, SQL Server 7.0 introduces auto-create-statistics, which causes the server to automatically generate all statistics required for the accurate optimization of a specific query. Determining When AutoStat Generation Is ImminentAs mentioned above, AutoStat will automatically update the statistics for a particular table when a "change threshold" has been reached. The sysindexes.rowmodctr column maintains a running total of all modifications to a table that, over time, can adversely affect the query processor's decision making process. This counter is updated each time any of the following events occurs:
Further, in situations in which a stored procedure's execution plan is taken from cache and that plan is sensitive to statistics, the statistics schema version will be compared to the current version. If there are new statistics available, the plan for the stored procedure will be recompiled. The basic algorithm for auto update statistics is:
The following are two examples to help demonstrate this concept: Example 1Consider the authors table in the pubs database, which contains 23 rows and has two indexes. The unique clustered index, UPKCL_auidind, is indexed on one column, au_id, and a composite nonclustered index, aunmind, has been created on the au_lname and au_fname columns. Because this table contains fewer than 500 rows, AutoStat will begin after 500 changes to the table data have occurred. The changes can be one of 500 or more inserts, deletes, changes to an indexed column such as au_lname, or any combination thereof.You can, therefore, predict when UPDATE STATISTICS will be initiated by monitoring the sysindexes.rowmodctr value, which will be incremented upon each update. When it reaches or exceeds 500, you can expect UPDATE STATISTICS to be started. Example 2Consider a second table, t2, that has a cardinality of 1,000. For tables with greater than 500 rows, SQL Server 7.0 will UPDATE STATISTICS when (500 + 20 percent) changes have been made. Doing the math, 20 percent of 1,000 is 200, so you can expect to see AutoStat start after approximately 700 modifications have been made to the table.Automating Autostats DeterminationTo automate the determination of when AutoStat will be run, you can poll the sysindexes table and identify when table modifications are reaching the starting point. The following is a basic algorithm for doing so:
You could later schedule a job to do the following:
Controlling Whether UPDATE STATISTICS Are Run Against a TableThe most obvious solution to this question, when AutoStat has proven to be Problematic, is to disable auto statistic generation, thereby leaving the database administrators free to schedule UPDATE STATISTICS during less intrusive times. You can do this either by using the UPDATE STATISTICS statement or the sp_autostats stored procedure. The syntax for the UPDATE STATISTICS statement is:
The syntax for the sp_autostats stored procedure is: sp_autostats <table_name>, <stats_flag>, <index_name> where <stats_flag> is either "on" or "off". You can also use sp_dboption to disable the automatic occurrence of UPDATE STATISTICS or CREATE STATISTICS on a per-database level: sp_dboption <dbname>,'auto update statistics', <on | off> Controlling the Number of Concurrent UPDATE STATISTICS ProcessesCurrently, short of disabling AutoStat for specific tables, it is not possible to configure the number of automatic UPDATE STATISTICS statements that are being run concurrently (DCR 51539 has been filed for this). The server does, however, limit the number of concurrent UPDATE STATISTICS processes to four per processor.Determining When Autostats Are Being RunYou can use trace flag 205 to report when a statistics-dependent stored procedure is being recompiled as a result of AutoStat. This trace flag will write the following messages to the error log:
When trace flag 205 is enabled, the following message will also bracket the AutoStat message from 8721 when statistics are updated. The opening message of the bracket can be distinguished by the RowModCnt value, which will be greater than 0. The closing bracket, after the UPDATE STATISTICS, will have a RowModCnt value of 0:
For this message, "RowModCnt" is the total number of modifications to the table. "RowModLimit" is the threshold which, when exceeded, results in an UPDATE STATISTICS statement execution for the table. It is also possible to enable trace flag 8721, which will dump information into the error log when AutoStat has been run. The following is an example of the type of message that you can expect to see:
For this message, "Mods" is the total number of modifications to the table. "Bound" is the modification threshold, "Duration" is the amount of time that the UPDATE STATISTICS statement required to complete, and "UpdCount" is the count of updated statistics. You can also use the SQL Server Profiler to identify when UPDATE STATISTICS statements are being run. To do this, perform the following steps:
Schema LocksSQL Server 7.0 employs two types of schema locks, both of which are taken when it updates the statistics for a table:
You can view these locks by running sp_lock or by selecting from the syslockinfo table. Additional query words: prodsql indices non-clustered stat kick off errorlog SQL Server Profiler
Keywords : |
Last Reviewed: August 12, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |