Oracle DBMS_STATS 用法例子

来源:互联网 发布:药品怎么在淘宝上买 编辑:程序博客网 时间:2024/06/07 01:05
General
Note: The drawback to collecting REDUNDANT column stats is that they have to be loaded into the dictionary cache, and they have to be considered when the query is optimised. This waste shared pool space and CPU.

On the other hand, if the statistics add value about the data - which does mean EVEN on unindexed columns - queries can run faster.

Most systems should have only a few column histograms in place, but there is no obvious requirement that they should only be on indexed columns.
Source{ORACLE_HOME}/rdbms/admin/dbmsstat.sql
First Available8.1.5
Character SetsFor DBMS_STATS to run properly may require the US numeric separators. If problems exist try the following:

alter session set NLS_NUMERIC_CHARACTERS='.,';

Constants
ConstantData TypeUsage
AUTO_CASCADEBOOLEANWhether to collect statistics for indexes or not
AUTO_DEGREENUMBERSelect the degree of parallelism
AUTO_INVALIDATEBOOLEANDecide when to invalidate dependent cursors
AUTO_SAMPLE_SIZENUMBERIndicate that auto-sample size algorithms should be used
DEFAULT_DEGREENUMBERUsed to determine the system default degree of parallelism

Default Constants
ConstantData TypeValue
DEFAULT_CASCADEBOOLEANNULL
DEFAULT_DEGREE_VALUENUMBER32766
DEFAULT_ESTIMATE_PERCENTNUMBER101
DEFAULT_METHOD_OPTVARCHAR2(1)'Z'
DEFAULT_NO_INVALIDATEBOOLEANNULL
DEFAULT_GRANULARITYVARCHAR2(1)'Z'
DEFAULT_PUBLISHBOOLEANTRUE
DEFAULT_INCREMENTALBOOLEANFALSE
DEFAULT_STALE_PERCENTNUMBER10
DEFAULT_AUTOSTATS_TARGETVARCHAR2(1)'Z'

Method_opt Constants
Accepts:

* FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
* FOR COLUMNS [size clause] column|attribute [size_clause] [,column|attribute [size_clause]...]

size_clause is defined as size_clause := SIZE {integer | REPEAT | AUTO | SKEWONLY}

- integer : Number of histogram buckets: Range [1,254].
- REPEAT : Collects histograms only on columns that already have
histograms.
- AUTO : Determines the columns to collect histograms based on
data distribution and the workload of the columns.
- SKEWONLY : Determines the columns to collect histograms based on
the data distribution of the columns.

The default is FOR ALL COLUMNS SIZE AUTO.The default value can be changed using the SET_PARAM Procedure.
Degree ConstantsDegree of parallelism. The default for degree is NULL. The default value can be changed using the SET_PARAM Procedure. NULL means use the table default value specified by the DEGREE clause in the CREATE TABLE or ALTER TABLE statement. Use the constant DBMS_STATS.DEFAULT_DEGREE to specify the default value based on the initialization parameters. The AUTO_DEGREE value determines the degree of parallelism automatically. This is either 1 (serial execution) or DEFAULT_DEGREE (the system default value based on number of CPUs and initialization parameters) according to size of the object.

Granularity Constants
Granularity of statistics to collect (only pertinent if the table is partitioned).
ConstantDescription
ALLGathers all (subpartition, partition, and global) statistics
AUTODetermines the granularity based on the partitioning type. This is the default value
DEFAULTGathers global and partition-level statistics. This option is obsolete, and while currently supported, it is included in the documentation for legacy reasons only. You should use the 'GLOBAL AND PARTITION' for this functionality
GLOBALGathers global statistics
GLOBAL AND PARTITIONgathers the global and partition level statistics. No subpartition level statistics are gathered even if it is a composite partitioned object
PARTITIONgathers partition-level statistics
SUBPARTITIONgathers subpartition-level statistics

Data Types
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 fltarray IS VARRAY(256) OF BINARY_FLOAT;
TYPE dblarray IS VARRAY(256) OF BINARY_DOUBLE;

TYPE StatRec IS RECORD (
epc    NUMBER,
minval RAW(2000),
maxval RAW(2000),
bkvals NUMARRAY,
novals NUMARRAY,
chvals CHARARRAY,
eavs   NUMBER);

Types for listing stale tables include:
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;
/

Dependencies
SELECT name
FROM dba_dependencies
WHERE referenced_name = 'DBMS_STATS'
UNION
SELECT referenced_name
FROM dba_dependencies
WHERE name = 'DBMS_STATS';

Exceptions
Error CodeReason
20000Table already exists or insufficient privileges (or) Insufficient privileges
(or) Index does not exist or insufficient privileges (or) Object does not exist or insufficient privileges
20001Tablespace does not exist (or) Bad input value (or) Invalid or inconsistent values in the user statistics table
20002Bad user statistics table; may need to be upgraded
20003Unable to set system statistics (or) Unable to gather system statistics
20004Parameter does not exist (or) Error in the INTERVAL mode: system parameter job_queue_processes must be >0
20005Object statistics are locked
20006Unable to restore statistics, statistics history not available

Granularity Parameters
ParameterDescription
ALLGathers all (subpartition, partition, and global) stats.
AUTODetermines the granularity based on the partitioning type, and collects the global, partition level and subpartition level statistics if the subpartitioning method is LIST, and the global and partition level only otherwise. This is the default value.
DEFAULTGathers global and partition-level statistics. This option is obsolete, and while currently supported, it is included in the documentation for legacy reasons only. You should use the 'GLOBAL AND PARTITION' for this functionality. Note that the default value is now 'AUTO'.
GLOBALGathers global statistics.
GLOBAL AND PARTITIONGathers the global and partition level statistics. No subpartition level statistics are gathered even if it is a composite partitioned object.
PARTITIONGathers partition-level statistics.
SUBPARTITIONGathers subpartition-level statistics.

Options Parameters
ParameterDescription
GATHERGathers statistics on all objects in the schema
GATHER AUTOGathers all necessary statistics automatically. Oracle implicitly determines which objects need new statistics, and determines how to gather those statistics. When GATHER AUTO is specified, the only additional valid parameters are stattab, statid, objlist and statown; all other parameter settings are ignored. Returns a list of processed objects
GATHER STALEGathers statistics on stale objects as determined by looking at the *_tab_modifications views. Also, return a list of objects found to be stale
GATHER EMPTYGathers statistics on objects which currently have no statistics. Return a list of objects found to have no statistics
LIST AUTOReturns a list of objects to be processed with GATHER AUTO
LIST STALEReturns a list of stale objects determined by looking at the *_tab_modifications views
LIST EMPTYReturns a list of objects which currently have no statistics

pname Parameter for GET and SET PARAM
ParameterDescription
CASCADEThe default value for CASCADE set by SET_PARAM is not used by export/import procedures.It is used only by gather procedures
DEGREEDegree of parallelism
ESTIMATE_PERCENT
METHOD_OPT'FOR COLUMNS REPEAT'
'FOR ALL COLUMNS SIZE REPEAT'
'FOR ALL COLUMNS SIZE 1'
NO_VALIDATE

pname Parameter for GET_SYSTEM_STATS
ParameterDescription
CPUSPEEDAverage number of CPU cycles for each second, in millions, captured for the workload (statistics collected using 'INTERVAL' or 'START' and 'STOP' options)
SPUSPEEDNWAverage number of CPU cycles for each second, in millions, captured for the noworkload (statistics collected using 'NOWORKLOAD' option
IOSEEKTIMSeek time + latency time + operating system overhead time, in milliseconds
IOTFRSPEEDI/O transfer speed in bytes for each millisecond
MAXTHRMaximum I/O system throughput, in bytes/second
MBRCAverage multiblock read count for sequential read, in blocks
MREADTIMAverage time to read an mbrc block at once (sequential read), in milliseconds
SLAVETHRAverage slave I/O throughput, in bytes/second
SREADTIMAverage time to read single block (random read), in milliseconds
System PrivilegesFor some of the DBMS_STATS procedures one or more of the following may be required:

ANALYZE ANY DICTIONARY
ANALYZE ANY
Enable automatic statistics collectionexec dbms_scheduler.enable('GATHER_STATS_JOB');
Disable automatic statistics collectionexec dbms_scheduler.disalbe('GATHER_STATS_JOB');

from:http://www.psoug.org/reference/dbms_stats.html

--End--
原创粉丝点击