Oracle8i Supplied Packages Reference Release 8.1.5 A68001-01 |
|
DBMS_STATS
provides a mechanism for you to view and modify optimizer statistics gathered for database objects.The statistics can reside in two different locations:
Only statistics stored in the dictionary itself have an impact on the cost-based optimizer.
This package also facilitates the gathering of some statistics in parallel. The package is divided into three main sections:
Most of the DBMS_STATS
procedures include the three parameters statown
, stattab
, and statid
. These parameters allow you to store statistics in your own tables (outside of the dictionary), which does not affect the optimizer. Therefore, you can maintain and experiment with sets of statistics.
The stattab
parameter specifies the name of a table in which to hold statistics, and it is assumed that it resides in the same schema as the object for which statistics are collected (unless the statown
parameter is specified). Users may create multiple tables with different stattab
identifiers to hold separate sets of statistics.
Additionally, users can maintain different sets of statistics within a single stattab
by using the statid
parameter, which can help avoid cluttering the user's schema.
For all of the SET
or GET
procedures, if stattab
is not provided (i.e., NULL
), then the operation works directly on the dictionary statistics; therefore, users do not need to create these statistics tables if they only plan to modify the dictionary directly. However, if stattab
is not NULL
, then the SET
or GET
operation works on the specified user statistics table, and not the dictionary.
Types for minimum/maximum values and histogram endpoints:
TYPE numarray IS VARRAY(256) OF NUMBER; TYPE datearray IS VARRAY(256) OF DATE; TYPE chararray IS VARRAY(256) OF VARCHAR2(4000); TYPE rawarray IS VARRAY(256) OF RAW(2000); type StatRec is record ( epc NUMBER, minval RAW(2000), maxval RAW(2000), bkvals NUMARRAY, novals NUMARRAY);
Types for listing stale tables:
type ObjectElem is record ( ownname VARCHAR2(30), -- owner objtype VARCHAR2(6), -- 'TABLE' or 'INDEX' objname VARCHAR2(30), -- table/index partname VARCHAR2(30), -- partition subpartname VARCHAR2(30), -- subpartition confidence NUMBER); -- not used type ObjectTab is TABLE of ObjectElem;
Subprogram | Description |
---|---|
PREPARE_COLUMN_VALUES procedure |
Converts user-specified minimum, maximum, and histogram endpoint datatype-specific values into Oracle's internal representation for future storage via |
SET_COLUMN_STATS procedure |
Sets column-related information. |
SET_INDEX_STATS procedure |
Sets index-related information. |
SET_TABLE_STATS procedure |
Sets table-related information. |
CONVERT_RAW_VALUE procedure |
Convert the internal representation of a minimum or maximum value into a datatype-specific value. |
GET_COLUMN_STATS procedure |
Gets all column-related information. |
GET_INDEX_STATS procedure |
Gets all index-related information. |
GET_TABLE_STATS procedure |
Gets all table-related information. |
DELETE_COLUMN_STATS procedure |
Deletes column-related statistics. |
DELETE_INDEX_STATS procedure |
Deletes index-related statistics. |
DELETE_TABLE_STATS procedure |
Deletes table-related statistics. |
DELETE_SCHEMA_STATS procedure |
Deletes schema-related statistics. |
DELETE_DATABASE_STATS procedure |
Deletes statistics for the entire database. |
CREATE_STAT_TABLE procedure |
Creates a table with name |
DROP_STAT_TABLE procedure |
Drops a user stat table created by |
EXPORT_COLUMN_STATS procedure |
Retrieves statistics for a particular column and stores them in the user stat table identified by |
EXPORT_INDEX_STATS procedure |
Retrieves statistics for a particular index and stores them in the user stat table identified by |
EXPORT_TABLE_STATS procedure |
Retrieves statistics for a particular table and stores them in the user stat table. |
EXPORT_SCHEMA_STATS procedure |
Retrieves statistics for all objects in the schema identified by ownname and stores them in the user stat table identified by |
EXPORT_DATABASE_STATS procedure |
Retrieves statistics for all objects in the database and stores them in the user stat table identified by |
IMPORT_COLUMN_STATS procedure |
Retrieves statistics for a particular column from the user stat table identified by |
IMPORT_INDEX_STATS procedure |
Retrieves statistics for a particular index from the user stat table identified by |
IMPORT_TABLE_STATS procedure |
Retrieves statistics for a particular table from the user stat table identified by |
IMPORT_SCHEMA_STATS procedure |
Retrieves statistics for all objects in the schema identified by |
IMPORT_DATABASE_STATS procedure |
Retrieves statistics for all objects in the database from the user stat table and stores them in the dictionary. |
GATHER_INDEX_STATS procedure |
Gathers index statistics. |
GATHER_TABLE_STATS procedure |
Gathers table and column (and index) statistics. |
GATHER_SCHEMA_STATS procedure |
Gathers statistics for all objects in a schema. |
GATHER_DATABASE_STATS procedure |
Gathers statistics for all objects in the database. |
GENERATE_STATS procedure |
Generates object statistics from previously collected statistics of related objects. |
The following procedures enable the storage and retrieval of individual column-, index-, and table-related statistics:
PREPARE_COLUMN_VALUES SET_COLUMN_STATS SET_INDEX_STATS SET_TABLE_STATS CONVERT_RAW_VALUE GET_COLUMN_STATS GET_INDEX_STATS GET_TABLE_STATS DELETE_COLUMN_STATS DELETE_INDEX_STATS DELETE_TABLE_STATS DELETE_SCHEMA_STATS DELETE_DATABASE_STATS
This procedure converts user-specified minimum, maximum, and histogram endpoint datatype-specific values into Oracle's internal representation for future storage via SET_COLUMN_STATS
.
DBMS_STATS.PREPARE_COLUMN_VALUES ( srec IN OUT StatRec, charvals CHARARRAY); DBMS_STATS.PREPARE_COLUMN_VALUES ( srec IN OUT StatRec, datevals DATEARRAY); DBMS_STATS.PREPARE_COLUMN_VALUES ( srec IN OUT StatRec, numvals NUMARRAY); DBMS_STATS.PREPARE_COLUMN_VALUES ( srec IN OUT StatRec, rawvals RAWARRAY); DBMS_STATS.PREPARE_COLUMN_VALUES_NVARCHAR ( srec IN OUT StatRec, nvmin NVARCHAR2, nvmax NVARCHAR2); DBMS_STATS.PREPARE_COLUMN_VALUES_ROWID ( srec IN OUT StatRec, rwmin ROWID, rwmax ROWID);
pragma restrict_references(prepare_column_values, WNDS, RNDS, WNPS, RNPS); pragma restrict_references(prepare_column_values_nvarchar, WNDS, RNDS, WNPS, RNPS); pragma restrict_references(prepare_column_values_rowid, WNDS, RNDS, WNPS, RNPS);
Datatype specific input parameters (one of the following):
ORA-20001
: Invalid or inconsistent input values.
This procedure sets column-related information.
DBMS_STATS.SET_COLUMN_STATS ( ownname VARCHAR2, tabname VARCHAR2, colname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL, distcnt NUMBER DEFAULT NULL, density NUMBER DEFAULT NULL, nullcnt NUMBER DEFAULT NULL, srec StatRec DEFAULT NULL, avgclen NUMBER DEFAULT NULL, flags NUMBER DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
ORA-20001
: Invalid or inconsistent input values.
This procedure sets index-related information.
DBMS_STATS.SET_INDEX_STATS ( ownname VARCHAR2, indname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, numrows NUMBER DEFAULT NULL, numlblks NUMBER DEFAULT NULL, numdist NUMBER DEFAULT NULL, avglblk NUMBER DEFAULT NULL, avgdblk NUMBER DEFAULT NULL, clstfct NUMBER DEFAULT NULL, indlevel NUMBER DEFAULT NULL, flags NUMBER DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000:
Object does not exist or insufficient privileges.
ORA-20001:
Invalid input value.
This procedure sets table-related information.
DBMS_STATS.SET_TABLE_STATS ( ownname VARCHAR2, tabname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, numrows NUMBER DEFAULT NULL, numblks NUMBER DEFAULT NULL, avgrlen NUMBER DEFAULT NULL, flags NUMBER DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
ORA-20001
: Invalid input value.
This procedure converts the internal representation of a minimum or maximum value into a datatype-specific value. The minval and maxval fields of the StatRec
structure as filled in by GET_COLUMN_STATS
or PREPARE_COLUMN_VALUES
are appropriate values for input.
DBMS_STATS.CONVERT_RAW_VALUE ( rawval RAW, resval OUT VARCHAR2); DBMS_STATS.CONVERT_RAW_VALUE ( rawval RAW, resval OUT DATE); DBMS_STATS.CONVERT_RAW_VALUE ( rawval RAW, resval OUT NUMBER); DBMS_STATS.CONVERT_RAW_VALUE_NVARCHAR ( rawval RAW, resval OUT NVARCHAR2); DBMS_STATS.CONVERT_RAW_VALUE_ROWID ( rawval RAW, resval OUT ROWID);
pragma restrict_references(convert_raw_value, WNDS, RNDS, WNPS, RNPS); pragma restrict_references(convert_raw_value_nvarchar, WNDS, RNDS, WNPS, RNPS); pragma restrict_references(convert_raw_value_rowid, WNDS, RNDS, WNPS, RNPS);
Parameter | Description |
---|---|
rawval |
The raw representation of a column minimum or maximum datatype-specific output parameters. |
resval |
The converted, type-specific value. |
None.
This procedure gets all column-related information.
DBMS_STATS.GET_COLUMN_STATS ( ownname VARCHAR2, tabname VARCHAR2, colname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, distcnt OUT NUMBER, density OUT NUMBER, nullcnt OUT NUMBER, srec OUT StatRec, avgclen OUT NUMBER, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges or no statistics have been stored for requested object.
This procedure of gets all index-related information.
DBMS_STATS.GET_INDEX_STATS ( ownname VARCHAR2, indname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, numrows OUT NUMBER, numlblks OUT NUMBER, numdist OUT NUMBER, avglblk OUT NUMBER, avgdblk OUT NUMBER, clstfct OUT NUMBER, indlevel OUT NUMBER, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges or no statistics have been stored for requested object.
This procedure gets all table-related information.
DBMS_STATS.GET_TABLE_STATS ( ownname VARCHAR2, tabname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, numrows OUT NUMBER, numblks OUT NUMBER, avgrlen OUT NUMBER, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges or no statistics have been stored for requested object
This procedure deletes column-related statistics.
DBMS_STATS.DELETE_COLUMN_STATS ( ownname VARCHAR2, tabname VARCHAR2, colname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, cascade_parts BOOLEAN DEFAULT TRUE, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges
This procedure deletes index-related statistics.
DBMS_STATS.DELETE_INDEX_STATS ( ownname VARCHAR2, indname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, cascade_parts BOOLEAN DEFAULT TRUE, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
This procedure deletes table-related statistics.
DBMS_STATS.DELETE_TABLE_STATS ( ownname VARCHAR2, tabname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, cascade_parts BOOLEAN DEFAULT TRUE, cascade_columns BOOLEAN DEFAULT TRUE, cascade_indexes BOOLEAN DEFAULT TRUE, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
This procedure deletes statistics for an entire schema.
DBMS_STATS.DELETE_SCHEMA_STATS ( ownname VARCHAR2, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges
This procedure deletes statistics for an entire database.
DBMS_STATS.DELETE_DATABASE_STATS ( stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
The following procedures enable the transference of statistics from the dictionary to a user stat table (export_
*) and from a user stat table to the dictionary (import_
*):
CREATE_STAT_TABLE DROP_STAT_TABLE EXPORT_COLUMN_STATS EXPORT_INDEX_STATS EXPORT_TABLE_STATS EXPORT_SCHEMA_STATS EXPORT_DATABASE_STATS IMPORT_COLUMN_STATS IMPORT_INDEX_STATS IMPORT_TABLE_STATS IMPORT_SCHEMA_STATS IMPORT_DATABASE_STATS
This procedure creates a table with name stattab
in ownname
's schema which is capable of holding statistics. The columns and types that compose this table are not relevant as it should be accessed solely through the procedures in this package.
DBMS_STATS.CREATE_STAT_TABLE ( ownname VARCHAR2, stattab VARCHAR2, tblspace VARCHAR2 DEFAULT NULL);
ORA-20000
: Table already exists or insufficient privileges.
ORA-20001
: Tablespace does not exist.
This procedure drops a user stat table.
DBMS_STATS.DROP_STAT_TABLE ( ownname VARCHAR2, stattab VARCHAR2);
Parameter | Description |
---|---|
ownname |
Name of the schema. |
stattab |
User stat table identifier. |
ORA-20000
: Table does not exists or insufficient privileges.
This procedure retrieves statistics for a particular column and stores them in the user stat table identified by stattab
.
DBMS_STATS.EXPORT_COLUMN_STATS ( ownname VARCHAR2, tabname VARCHAR2, colname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
This procedure retrieves statistics for a particular index and stores them in the user stat table identified by stattab
.
DBMS_STATS.EXPORT_INDEX_STATS ( ownname VARCHAR2, indname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
This procedure retrieves statistics for a particular table and stores them in the user stat table. Cascade results in all index and column stats associated with the specified table being exported as well.
DBMS_STATS.EXPORT_TABLE_STATS ( ownname VARCHAR2, tabname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, cascade BOOLEAN DEFAULT TRUE, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
This procedure retrieves statistics for all objects in the schema identified by ownname and stores them in the user stat tables identified by stattab
.
DBMS_STATS.EXPORT_SCHEMA_STATS ( ownname VARCHAR2, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
This procedure retrieves statistics for all objects in the database and stores them in the user stat tables identified by statown
.stattab
DBMS_STATS.EXPORT_DATABASE_STATS ( stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
This procedure retrieves statistics for a particular column from the user stat table identified by stattab
and stores them in the dictionary.
DBMS_STATS.IMPORT_COLUMN_STATS ( ownname VARCHAR2, tabname VARCHAR2, colname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
ORA-20001
: Invalid or inconsistent values in the user stat table.
This procedure retrieves statistics for a particular index from the user stat table identified by stattab
and stores them in the dictionary.
DBMS_STATS.IMPORT_INDEX_STATS ( ownname VARCHAR2, indname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
ORA-20001
: Invalid or inconsistent values in the user stat table.
This procedure retrieves statistics for a particular table from the user stat table identified by stattab
and stores them in the dictionary. Cascade results in all index and column stats associated with the specified table being imported as well.
DBMS_STATS.IMPORT_TABLE_STATS ( ownname VARCHAR2, tabname VARCHAR2, partname VARCHAR2 DEFAULT NULL, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, cascade BOOLEAN DEFAULT TRUE, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
ORA-20001
: Invalid or inconsistent values in the user stat table.
This procedure retrieves statistics for all objects in the schema identified by ownname from the user stat table and stores them in the dictionary.
DBMS_STATS.IMPORT_SCHEMA_STATS ( ownname VARCHAR2, stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
ORA-20001
: Invalid or inconsistent values in the user stat table.
This procedure retrieves statistics for all objects in the database from the user stat table(s) and stores them in the dictionary.
DBMS_STATS.IMPORT_DATABASE_STATS ( stattab VARCHAR2, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Object does not exist or insufficient privileges.
ORA-20001
: Invalid or inconsistent values in the user stat table.
The following procedures enable the gathering of certain classes of optimizer statistics, with possible performance improvements over the ANALYZE
command:
GATHER_INDEX_STATS GATHER_TABLE_STATS GATHER_SCHEMA_STATS GATHER_DATABASE_STATS
The statown
, stattab
, and statid
parameters instruct the package to backup current statistics in the specified table before gathering new statistics.
Oracle also provides the following procedure for generating some statistics for derived objects when we have sufficient statistics on related objects:
GENERATE_STATS
This procedure gathers index statistics. It is equivalent to running ANALYZE
INDEX
[ownname
.]indname
[PARTITION
partname]
COMPUTE
STATISTICS
|
ESTIMATE
STATISTICS
SAMPLE
estimate_percent
PERCENT
It does not execute in parallel.
DBMS_STATS_GATHER_INDEX_STATS ( ownname VARCHAR2, indname VARCHAR2, partname VARCHAR2 DEFAULT NULL, estimate_percent NUMBER DEFAULT NULL, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Index does not exist or insufficient privileges.
ORA-20001
: Bad input value.
This procedure gathers table and column (and index) statistics. It attempts to parallelize as much of the work as possible, but there are some restrictions as described in the individual parameters. This operation does not parallelize if the user does not have select privilege on the table being analyzed.
DBMS_STATS.GATHER_TABLE_STATS ( ownname VARCHAR2, tabname VARCHAR2, partname VARCHAR2 DEFAULT NULL, estimate_percent NUMBER DEFAULT NULL, block_sample BOOLEAN DEFAULT FALSE, method_opt VARCHAR2 DEFAULT 'FOR ALL COLUMNS SIZE 1', degree NUMBER DEFAULT NULL, granularity VARCHAR2 DEFAULT 'DEFAULT', cascade BOOLEAN DEFAULT FALSE, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Table does not exist or insufficient privileges.
ORA-20001
: Bad input value.
This procedure gathers statistics for all objects in a schema.
DBMS_STATS.GATHER_SCHEMA_STATS ( ownname VARCHAR2, estimate_percent NUMBER DEFAULT NULL, block_sample BOOLEAN DEFAULT FALSE, method_opt VARCHAR2 DEFAULT 'FOR ALL COLUMNS SIZE 1', degree NUMBER DEFAULT NULL, granularity VARCHAR2 DEFAULT 'DEFAULT', cascade BOOLEAN DEFAULT FALSE); DBMS_STATS.GATHER_SCHEMA_STATS ( ownname VARCHAR2, estimate_percent NUMBER DEFAULT NULL, block_sample BOOLEAN DEFAULT FALSE, method_opt VARCHAR2 DEFAULT 'FOR ALL COLUMNS SIZE 1', degree NUMBER DEFAULT NULL, granularity VARCHAR2 DEFAULT 'DEFAULT', cascade BOOLEAN DEFAULT FALSE, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, options VARCHAR2 DEFAULT 'GATHER', objlist OUT ObjectTab, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Schema does not exist or insufficient privileges.
ORA-20001
: Bad input value.
This procedure gathers statistics for all objects in the database.
DBMS_STATS.GATHER_DATABASE_STATS ( estimate_percent NUMBER DEFAULT NULL, block_sample BOOLEAN DEFAULT FALSE, method_opt VARCHAR2 DEFAULT 'FOR ALL COLUMNS SIZE 1', degree NUMBER DEFAULT NULL, granularity VARCHAR2 DEFAULT 'DEFAULT', cascade BOOLEAN DEFAULT FALSE); DBMS_STATS.GATHER_DATABASE_STATS ( estimate_percent NUMBER DEFAULT NULL, block_sample BOOLEAN DEFAULT FALSE, method_opt VARCHAR2 DEFAULT 'FOR ALL COLUMNS SIZE 1', degree NUMBER DEFAULT NULL, granularity VARCHAR2 DEFAULT 'DEFAULT', cascade BOOLEAN DEFAULT FALSE, stattab VARCHAR2 DEFAULT NULL, statid VARCHAR2 DEFAULT NULL, options VARCHAR2 DEFAULT 'GATHER', objlist OUT ObjectTab, statown VARCHAR2 DEFAULT NULL);
ORA-20000
: Insufficient privileges.
ORA-20001
: Bad input value.
This procedure generates object statistics from previously collected statistics of related objects. For fully populated schemas, the gather procedures should be used instead when more accurate statistics are desired.The currently supported objects are b-tree and bitmap indexes.
DBMS_STATS.GENERATE_STATS ( ownname VARCHAR2, objname VARCHAR2, organized NUMBER DEFAULT 7);
ORA-20000
: Unsupported object type of object does not exist.
ORA-20001
: Invalid option or invalid statistics.
There has been a lot of modification against the emp
table since the last time statistics were gathered. To ensure that the cost-based optimizer is still picking the best plan, statistics should be gathered once again; however, the user is concerned that new statistics will cause the optimizer to choose bad plans when the current ones are acceptable. The user can do the following:
BEGIN DBMS_STATS.CREATE_STAT_TABLE ('scott', 'savestats'); DBMS_STATS.GATHER_TABLE_STATS ('scott', 'emp', 5, stattab => 'savestats'); END;
This operation gathers new statistics on emp
, but first saves the original statistics in a user stat table: emp
.savestats
.
If the user believes that the new statistics are causing the optimizer to generate poor plans, then the original stats can be restored as follows:
BEGIN DBMS_STATS.DELETE_TABLE_STATS ('scott', 'emp'); DBMS_STATS.IMPORT_TABLE_STATS ('scott', 'emp', stattab => 'savestats'); END;