If you are using Trusted Oracle7 in DBMS MAC mode, your DBMS label must match the creation label of the object to be analyzed or you must satisfy one of the following criteria:
INDEX
identifies an index to be analyzed (if no FOR clause is used). If you omit schema, Oracle7 assumes the index is in your own schema.
TABLE
identifies a table to be analyzed. If you omit schema, Oracle7 assumes the table is in your own schema. When you collect statistics for a table, Oracle7 also automatically collects the statistics for each of the table's indexes, provided that no FOR clauses are used.
CLUSTER
identifies a cluster to be analyzed. If you omit schema, Oracle7 assumes the cluster is in your own schema. When you collect statistics for a cluster, Oracle7 also automatically collects the statistics for all the cluster's tables and all their indexes, including the cluster index.
COMPUTE STATISTICS
computes exact statistics about the analyzed object and stores them in the data dictionary.
ESTIMATE STATISTICS
estimates statistics about the analyzed object and stores them in the data dictionary.
ROWS causes Oracle7 to sample integer rows of the table or cluster or integer entries from the index. The integer must be at least 1.
PERCENT causes Oracle7 to sample integer percent of the rows from the table or cluster or integer percent of the index entries. The integer can range from 1 to 99.
Histogram statistics are described in Oracle7 Server Tuning. The following clauses only apply to the ANALYZE TABLE version of this command:
FOR TABLE collect table statistics for the table.
FOR ALL COLUMNS
collect column statistics for all columns in the table.
FOR ALL INDEXED COLUMNS
collect column statistics for all indexed columns in the table.
FOR COLUMNS
collect column statistics for the specified columns.
FOR ALL INDEXES
all indexes associated with the table will be analyzed.
SIZE specifies the maximum number of partitions in the histogram. The default value is 75, minimum value is 1, and maximum value is 254.
DELETE STATISTICS
deletes any statistics about the analyzed object that are currently stored in the data dictionary.
VALIDATE STRUCTURE
validates the structure of the analyzed object. If you use this option when analyzing a cluster, Oracle7 automatically validates the structure of the cluster's tables.
CASCADE
LIST CHAINED ROWS
identifies migrated and chained rows of the analyzed table or cluster. You cannot use this option when analyzing an index.
INTO specifies a table into which Oracle7 lists the migrated and chained rows. If you omit schema, Oracle7 assumes the list table is in your own schema. If you omit this clause altogether, Oracle7 assumes that the table is named CHAINED_ROWS. The list table must be on your local database.
If the data dictionary already contains statistics for the analyzed object, Oracle7 updates the existing statistics with the new ones.
The statistics are used by the Oracle7 optimizer to choose the execution plan for SQL statements that access analyzed objects. These statistics may also be useful to application developers who write such statements. For information on how these statistics are used, see Oracle7 Server Tuning.
The following sections list the statistics for indexes, tables, columns, and clusters.
Index statistics appear in the data dictionary views USER_INDEXES, ALL_INDEXES, and DBA_INDEXES.
Table statistics appear in the data dictionary views USER_TABLES, ALL_TABLES, and DBA_TABLES.
The size parameter specifies how many bands the column should be divided into. A size of 1 treats the entire column as a single band, which is equivalent to not using histograms at all.
The column statistics that Oracle7 collects are the following:
When to use Histograms For uniformly distributed data, the cost-based approach makes fairly accurate guesses at the cost of executing a particular statement. For non-uniformly distributed data, Oracle allows you to store histograms describing the data distribution of a particular column. These histograms are stored in the dictionary and can be used by the cost-based optimizer.
Since they are persistent objects, there is a maintenance and space cost for using histograms. You should only compute histograms for columns that you know have highly-skewed data distribution. Also, be aware that histograms, as well as all optimizer statistics, are static. If the data distribution of a column changes frequently, you must reissue the ANALYZE command to recompute the histogram for that column.
Histograms are not useful for columns with the following characteristics:
ANALYZE TABLE emp COMPUTE STATISTICS FOR COLUMNS sal SIZE 10;
Column statistics appear in the data dictionary views USER_TAB_COLUMNS, ALL_TAB_COLUMNS, and DBA_TAB_COLUMNS. Histograms appear in the data dictionary views USER_HISTOGRAMS, DBA_HISTOGRAMS, and ALL_HISTOGRAMS.
Example I
The following statement estimates statistics for the CUST_HISTORY table and all of its indexes:
ANALYZE TABLE cust_history
ESTIMATE STATISTICS
When you use the DELETE STATISTICS option on a table, Oracle7 also automatically removes statistics for all the table's indexes. When you use the DELETE STATISTICS option on a cluster, Oracle7 also automatically removes statistics for all the cluster's tables and all their indexes, including the cluster index.
Example II
The following statement deletes statistics about the CUST_HISTORY table and all its indexes from the data dictionary:
ANALYZE TABLE cust_history
DELETE STATISTICS
Since the validating the structure of a object prevents SELECT, INSERT, UPDATE, and DELETE statements from concurrently accessing the object, do not use this option on the tables, clusters, and indexes of your production applications during periods of high database activity.
When you use the VALIDATE STRUCTURE option on an index, Oracle7 also collects statistics about the index and stores them in the data dictionary view INDEX_STATS. Oracle7 overwrites any existing statistics about previously validated indexes. At any time, INDEX_STATS can contain only one row describing only one index. The INDEX_STATS view is described in the Oracle7 Server Reference.
The statistics collected by this option are not used by the Oracle7 optimizer. Do not confuse these statistics with the statistics collected by the COMPUTE STATISTICS and ESTIMATE STATISTICS options.
Example III
The following statement validates the structure of the index PARTS_INDEX:
ANALYZE INDEX parts_index
VALIDATE STRUCTURE
The following statement analyzes the EMP table and all of its indexes:
ANALYZE TABLE emp
VALIDATE STRUCTURE CASCADE
Example V
The following statement analyzes the ORDER_CUSTS cluster, all of its tables, and all of their indexes, including the cluster index:
ANALYZE CLUSTER order_custs VALIDATE STRUCTURE CASCADE
You can use the INTO clause to specify an output table into which Oracle7 places this information. The definition of a sample output table CHAINED_ROWS is provided in a SQL script available on your distribution media. Your list table must have the same column names, types, and sizes as the CHAINED_ROWS table. On many operating systems, the name of this script is UTLCHAIN.SQL. The actual name and location of this script may vary depending on your operating system.
Example VI
The following statement collects information about all the chained rows of the table ORDER_HIST:
ANALYZE TABLE order_hist LIST CHAINED ROWS INTO cr
The preceding statement places the information into the table CR.
You can then examine the rows with this query:
SELECT * FROM cr OWNER_NAME TABLE_NAME CLUSTER_NAME HEAD_ROWID TIMESTAMP ---------- ---------- ------------ ------------------ --------- SCOTT ORDER_HIST 0000346A.000C.0003 15-MAR-93