UPDATE STATISTICS
- Last Updated: June 10, 2025
- 4 minute read
- OpenEdge
- Version 12.2
- Documentation
Queries data tables and updates the following statistics:
- Table cardinality
- Index statistics
- Column data distribution for columns that are index components
- Column data distribution for columns that are not index components
Syntax
|
Notes
- In the Update Statistics syntax, partition_name_1,…,partition_name_n are partition names of partitions belonging to table table_name.
- FOR PARTITIONS clause can be used only with partitioned tables and it fetches statistics only from the specified partitions in the partition list.
- FOR PARTITIONS clause, on updating index statistics, updates index statistics from only local indexes for the specified partitions in partition list and does not update global index statistics.
- All statistics are obtained online. Obtaining statistics does not require an exclusive lock on the schema or any table locks. Rows written to statistics tables will be exclusively locked, as in every transaction performing updates. Therefore, statistics can be obtained while normal database operations continue.
- Specifying
TABLE STATISTICSobtains table cardinality only. Table cardinalities are stored in theSYSTBLSTATsystem catalog table. - Specifying
INDEX STATISTICSobtains statistics on the number of unique values in each index. Index statistics are stored in theSYSIDXSTATsystem catalog table. - Specifying
COLUMN STATISTICS(withoutALL) obtains statistics on the data distribution of values for each column that is an index key component. - Specifying
ALL COLUMN STATISTICSobtains statistics on the data distribution of values for all columns. - The
STATISTICSphrase can be repeated so that up to three statistics can be requested by a singleUPDATE STATISTICSstatement. - By default, for the simple statement
UPDATE STATISTICS, where the type of statistics is not specified, SQL will obtain table and index column statistics. This is equivalent to the statementUPDATE TABLE STATISTICS AND COLUMN STATISTICS. - A table containing
LONGdata types can get table, index, and/or column statistics. The columns that areLONGdata types cannot get statistics. - Obtaining table statistics runs in time proportional to the table's primary index.
- Obtaining column statistics runs in time proportional to the table's primary index, plus an additional amount proportional to the number of columns in the table.
- The UPDATE STATISTICS command for data of a sample percentage is applicable only for column statistics. This is not applicable for index and table statistics.
- Obtaining index statistics runs in time proportional to the total size for all indexes for the table.
- Table statistics are often the most useful statistic, as they influence join order substantially.
- Index statistics are important when a table has five or more indexes. This is especially true if some of the indexes are similar to one another.
- Column statistics are the most useful when applications use
range predicates, such as
BETWEENand the operators <, <=, > and >=. - The
FOR TENANTSandFOR PARTITIONSclauses are mutually exclusive. - The
FOR TENANTSclause can be used with multi-tenant tables to create statistics for only the specified tenants in the tenants list. When this caluse is not used, statistics are created for all tenants. - The tenant specified in the
FOR TENANTSclause should not be a super-tenant. - The phrase
FOR CDC SYSTEM TABLESis an alternative to the phraseFOR <tbl>and is the equivalent of running the UPDATE STATISTICS statement for all indivudual CDC system tables. The CDC system tables are as follows:- pub.”_Cdc-Change-Tracking”
-
pub.”_Cdc-Table-Policy”
-
pub.”_Cdc-Field-Policy”
-
pub.”_File”
UPDATE TABLE STATISTICS AND INDEX STATISTICS AND COLUMN STATISTICS;UPDATE TABLE STATISTICS AND INDEX STATISTICS AND ALL COLUMN STATISTICS;Examples
The following example shows default commands for table cardinality and data distribution for index component columns:
|
The following example shows commands for table cardinality only:
|
The following example shows commands for new index statistics:
|
The following example shows commands for updating column statistics for index columns only:
|
The following example shows commands for updating statistics for all columns:
|
The following example shows commands for updating statistics for columns with a sample percentage:
|
The following example shows commands to obtain table cardinality and new index statistics and column statistics for all columns:
|
The following example updates table, and column statistics of partitions
USA_Customer, EUROPE_Customer and
ASIA_Customer for table Customer:
|
The following example updates column statistics of partitions
USA_Customer, EUROPE_Customer and
ASIA_Customer for table Customer:
|
The following example updates all column statistics of partitions
USA_Customer, EUROPE_Customer and
ASIA_Customer for table Customer:
|
The following example shows the commands to get statistics by tenant:
|
The following example shows the commands to update statistics for all CDC system tables:
|
The following example shows the commands to update specific statistics for all CDC system tables:
|