ANALYZE
Description
This statement is used to collect statistics for a table or a table partition.
Syntax
ANALYZE TABLE table_name UPDATE HISTOGRAM ON column_name_list WITH INT_NUM BUCKETS;
When the enable_sql_extension parameter is set to TRUE, you can use the following syntax:
ANALYZE TABLE table_name [use_partition] COMPUTE STATISTICS [ for_clause ];
use_partition:
PARTITION (parition_name [,partition_name,....])
| SUBPARTITION(subpartition_name, [,subpartition_name,...])
analyze_statistics_clause:
COMPUTE STATISTICS [analyze_for_clause]
| ESTIMATE STATISTICS [analyze_for_clause] [SAMPLE INTNUM {ROWS | PERCENTAGE}]
analyze_for_clause:
FOR TABLE
| FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
| FOR COLUMNS [size clause] column [size_clause] [,column [size_clause]...]
size_clause:
SIZE integer
| SIZE REPEAT
| SIZE AUTO
| SIZE SKEWONLY
column:
column_name
| (column_name [, column_name])
Parameter description
| Parameter | Description |
|---|---|
| table_name | Specifies the table to analyze. |
| INT_NUM | An integer indicating the number of buckets. For more information about the value of buckets, see method_opt. |
| use_partition | Specifies the partition name. If the value is set to the table name, statistics for partitions are not collected. |
| compute_statistics_clause | Specifies that COMPUTE STATISTICS calculates precise statistics for the analysis target and stores them in the data dictionary. When analyzing a table, statistics for both the table and its columns are collected. |
| for_clause | Specifies whether to analyze the entire table or only specific columns.
|
| estimate_statistics_clause | Specifies that ESTIMATE STATISTICS estimates statistics for the analysis target and stores them in the data dictionary. |
| SAMPLE | Specifies the amount of sampling data used to estimate statistics. If this parameter is omitted, the database optimizer automatically selects an appropriate sampling ratio.
|
Examples
- Collect statistics for the
testtable, with 30 buckets per column.
CREATE TABLE test (c1 NUMBER(30) PRIMARY KEY,c2 VARCHAR(50));
Query OK, 0 rows affected (0.001 sec)
ANALYZE TABLE test UPDATE HISTOGRAM ON c1,c2 with 30 buckets;
Query OK, 0 rows affected (0.001 sec)
- When the
enable_sql_extensionparameter is set toTRUE, use the following syntax to collect statistics for thetesttable of useruser01, with 128 buckets per column.
ALTER SYSTEM SET enable_sql_extension = TRUE;
Query OK, 0 rows affected (0.001 sec)
ANALYZE TABLE test COMPUTE STATISTICS FOR ALL COLUMNS SIZE 128;
Query OK, 0 rows affected (0.001 sec)