Entering content frame

UPDATE STATISTICS Statement (update_statistics_statement) 

The UPDATE STATISTICS statement (update_statistics_statement) defines the storage requirements of tables and indexes as well as the value distribution of columns, and stores this information in the database catalog.

Syntax

<update statistics statement> ::=
  UPDATE STAT[ISTICS] COLUMN <table name>.<column name> [ESTIMATE [<sample definition>]]
| UPDATE STAT[ISTICS] COLUMN (<column name>,...) FOR <table name> [ESTIMATE [<sample definition>]]
| UPDATE STAT[ISTICS] COLUMN (*) FOR <table name> [ESTIMATE [<sample definition>]]
| UPDATE STAT[ISTICS] <table name> [ESTIMATE [<sample definition>]]
| UPDATE STAT[ISTICS] [<owner>.][<identifier>]* [ESTIMATE [<sample definition>]]

table_name, column_name, sample_definition, owner, identifier

Explanation

When the update statistics statement is executed, information on the table, such as the number of rows, the number of pages used, the sizes of indexes, the value distribution within columns or indexes, and so on, is stored in the database catalog. These values are used by the SQL Optimizer to determine the best strategy for executing SQL statements.

The update statistics statement implicitly performs a COMMIT statement for each base table; i.e. the transaction within which the update statistics statement has been executed is closed.

When a CREATE INDEX statement is executed, the above-mentioned information is stored in the database catalog for the index as well as for the base table for which this index is being defined. No information is stored for other indexes defined on this base table.

The statistical values stored in the database catalog can be retrieved by selecting the system table OPTIMIZERSTATISTICS. Each row of the table describes statistical values of indexes, columns or the size of a table.

For a definition of the statistics system tables, see the System Tables manual, section Definition of the System Tables.

<table_name>

If a table name is specified, the table must be a non-temporary base table and the user must have a privilege for it.

<column_name>

If a column name is specified, this column must exist in specified table.

If * is specified, all columns in the table are assumed.

<identifier>*

Specifying <identifier>* has the same effect as issuing the update statistics statement for all base tables for which the current user has a privilege, and whose table name begins with the identifier.

UPDATE STATISTICS *

The database system administrator (SYSDBA user) can use UPDATE STATISTICS * to execute the update statistics statement for all base tables, even if the SYSDBA has not been assigned a privilege for these tables.

ESTIMATE

·        If ESTIMATE and a sample definition are specified, the database system estimates the statistical values by selecting data at random. The number of random selects can be given as number of rows or as percentage. For a specification of 50% or more, all rows are analyzed. The runtime of the update statistics statement can be considerably reduced by specifying ESTIMATE. In most cases, the precision of the statistical values determined is sufficient.

·        If ESTIMATE is specified without a sample definition, the database system estimates the statistical values by selecting data at random. The number of selects was defined with the CREATE TABLE statement or an ALTER TABLE statement by means of a sample_definition for the specified table. For a specification of 50% or more, all rows are analyzed. The runtime of the update statistics statement can be considerably reduced by specifying ESTIMATE. In most cases, the precision of the statistical values determined is sufficient.

·        If ESTIMATE is not specified, the database system determines exact statistical values by considering the complete data of the table. For large tables, the runtime can be considerably long.

 

Leaving content frame