Updating statistics

Adaptive Server’s cost-based optimizer uses statistics about the tables, indexes, and columns named in a query to estimate query costs. It chooses the access method that the optimizer determines has the least cost. But this cost estimate cannot be accurate if statistics are not accurate.

update statistics updates the column-related statistics such as histograms and densities. Statistics need to be updated on those columns where the distribution of keys in the index changes in ways that affect the use of indexes for your queries.Running the update statistics wizard requires system resources. Like other maintenance tasks, it should be scheduled at times when load on the server is light. In particular, update statistics requires table scans or leaf-level scans of indexes, may increase I/O contention, may use the CPU to perform sorts, and uses the data and procedure caches. Use of these resources can adversely affect queries running on the server if you run update statistics at times when usage is high. In addition, some update statistics commands require shared locks, which can block updates.

You can update statistics for a table, column, or a partition (for Adaptive Server 15.0 and later) using the update statistics, update all statistics, update index statistics, and update table statistics commands.

To update statistics, select the Update Statistics wizard from the Context menu for the appropriate object.

See the Adaptive Server Reference Manual: Commands for more information about update statitistics.

Automatically updating statistics

Job Scheduler must be enabled before you configure update statistics to run automatically. The update statistics wizard includes the datachange threshold screen for configuring automatic update statistics only for Adaptive Server release 15.0 and later.

Only a table owner or a database owner can update index statistics

When update statistics run is determined by the datachange function. datachange measures the amount of change in the data distribution since update statistics last ran. Specifically, it measures the number of inserts, updates, and deletes that have occurred on the given object, partition, or column, and helps you determine if invoking update statistics would benefit the query plan.

Once you set it to run automatically, update statistics runs when its threshold is less than or equal to the value of datachange.

See the Adaptive Server Reference Manual: Commands for more information about datachange.

Privileges

Only a table owner or a database owner can update index statistics.

StepsTo start the update statistics wizard

  1. Select the table, column, or partition whose statistics you are updating.

  2. Select File | Update Statistics.

  3. Follow the steps in the Update Statistics wizard.

Shortcut

Right-click the index icon. Select Update Statistics from the shortcut menu.