
Asynchronous Statistics Updates
A query that initiates an update of out-of-date statistics must wait for those statistics to be updated before compiling and returning a result set. This can cause unpredictable query response times and may cause applications that have aggressive time-outs to fail.
The database option AUTO_UPDATE_STATISTICS_ASYNC provides asynchronous statistics updating. When this option is set to ON, queries do not wait for the statistics to be updated before compiling. Instead, the out-of-date statistics are put on a queue for updating by a worker thread in a background process. The query and any other concurrent queries compile immediately by using the existing out-of-date statistics. Because there is no delay for updated statistics, query response times are predictable; however, the out-of-date statistics may cause the query optimizer to choose a less-efficient query plan. Queries that start after the updated statistics are ready will use those statistics. This may cause the recompilation of cached plans that depend on the older statistics version. Updating asynchronous statistics cannot take place if any data definition language (DDL) statements, such as CREATE, ALTER, and DROP statements, occur in the same explicit user transaction.
The AUTO_UPDATE_STATISTICS_ASYNC option is set at the database level and determines the update method for all statistics in the database. It is applicable only to statistics updating and cannot be used to asynchronously create statistics. Setting this option to ON has no effect unless AUTO_UPDATE_STATISTICS is also set to ON. By default, the AUTO_UPDATE_STATISTICS_ASYNC option is OFF. For more information about setting this option, see ALTER DATABASE (Transact-SQL).
Before you set a database to SINGLE_USER, verify the AUTO_UPDATE_STATISTICS_ASYNC option is set to OFF. When set to ON, the background thread used to update statistics takes a connection against the database, and you will be unable to access the database in single-user mode. If the option is set to ON, perform the following tasks:
-
Set AUTO_UPDATE_STATISTICS_ASYNC to OFF.
-
Check for active asynchronous statistics jobs by querying the sys.dm_exec_background_job_queue dynamic management view.
-
If there are active jobs, either allow the jobs to complete or manually terminate them by using KILL STATS JOB.
Best Practice Considerations
You should consider setting the AUTO_UPDATE_STATISTICS_ASYNC option ON when the following characteristics apply to your application:
-
Has experienced client request time-outs caused by one or more queries waiting for updated statistics.
-
Query compilations and query executions occur simultaneously. If statistics are out of date and AUTO-UPDATE_STATISTICS_ASYNC is OFF, executing queries will wait for updated statistics and compiling queries will not wait. Thus, the benefit of forcing some queries to wait for updated statistics is reduced.
Viewing Asynchronous Update Statistics Properties
To view the ON or OFF status of the AUTO_UPDATE_STATISTICS_ASYNC option, select the is_auto_update_stats_async_on column from the sys.databases catalog view. For more information, see sys.databases (Transact-SQL).
To view whether statistics are queued for updating or in the process of updating, use the sys.dm_exec_background_job_queue dynamic management view. For statistics, the column object_id1 displays the table or view ID, and the column object_id2 displays the statistics ID. Use the sys.dm_exec_background_job_queue_stats dynamic management view to view aggregate statistics of all background job queues, such as the number of job requests waiting for execution, number of failed requests, and average execution times of previously submitted requests.