您在这里:首页 > 学员专区 > 技术文章
Oracle视频
Oracle
CUUG课程

Oracle 表分析使用方法

 


1、三大功能

(1)搜集和删除索引、表和簇的统计信息

(2)验证表、索引和簇的结构

(3)鉴定表和簇和行迁移和行联接

针对analyze的搜集和删除统计信息功能而言,oracle推荐使用DBMS_STATS包来搜集优化信息,DBMS_STATS可以并行的搜集信息,可以搜集分区表的全局信息,进一步来说,按成本的优化器只会使用DBMS_STATS包所统计出来的信息。

 

2、先决条件

必须在你自己的方案中或有ANALYZE ANY system 的权限,

 

3、语法

ANALYZE

{ TABLE [ schema.]table

[ PARTITION ( partition ) | SUBPARTITION ( subpartition ) ]

| INDEX [ schema. ]index

[ PARTITION ( partition ) | SUBPARTITION ( subpartition ) ]

| CLUSTER [ schema. ]cluster

}

{ COMPUTE [ SYSTEM ] STATISTICS [for_clause]

| ESTIMATE [ SYSTEM ] STATISTICS [for_clause][SAMPLE integer { ROWS | PERCENT }]

| validation_clauses

| LIST CHAINED ROWS [ into_clause ]

| DELETE [ SYSTEM ] STATISTICS

} ;

 

(1)INDEX index:对索引进行分析,分析的结果会放在USER_INDEXES, ALL_INDEXES,或 DBA_INDEXES中

分析的内容:

Depth of the index from its root block to its leaf blocks (BLEVEL)

Number of leaf blocks (LEAF_BLOCKS)

Number of distinct index values (DISTINCT_KEYS)

Average number of leaf blocks for each index value (AVG_LEAF_BLOCKS_PER_KEY)

Average number of data blocks for each index value (for an index on a table) (AVG_DATA_BLOCKS_PER_KEY)

Clustering factor (how well ordered the rows are about the indexed values) (CLUSTERING_FACTOR)

 

(2)TABLE table:对表进行分析,分析的结果会放在USER_TABLES, ALL_TABLES, and DBA_TABLES表中,在分析表的时候,oracle也会分析基于函数的index所引用的表达式

分析的内容:

Number of rows (NUM_ROWS) *

Number of data blocks below the high water mark (that is, the number of data blocks that have been formatted to receive data, regardless whether they currently contain data or are empty) (BLOCKS)

* Number of data blocks allocated to the table that have never been used (EMPTY_BLOCKS) Average available free space in each data block in bytes (AVG_SPACE)

Number of chained rows (CHAIN_COUNT) Average row length, including the row's overhead, in bytes (AVG_ROW_LEN)

 

(3)分析表的限制

不可以分析数据字典表

不可以分析扩展表,但可以用DBMS_STATS来实现这个目的

不可以分析临时表

不可以计算或估计下列字段类型

REFs, varrays, nested tables, LOBs (LOBs are not analyzed, they are skipped), LONGs, or object types.

 

(4)PARTITION | SUBPARTITION:对分区表或索引进行分析

 

(5)CLUSTER cluster:对簇进行分析,分析的结果会放在ALL_CLUSTERS, USER_CLUSTERS and DBA_CLUSTERS.

compute_statistics_clause

 

(6)语法:COMPUTE [ SYSTEM ] STATISTICS [for_clause]

对分析对像进行精确的统计,然后把信息存储的数据字典中。可以选择对表或对字段进行分析。

computed和estimated这两种方式的统计数据都被优化器用来影响sql的执行计划

如果指定system选项就只统计系统产生的信息

for_clause

FOR TABLE:只统计表

FOR COLUMNS:只统计某个字段

FOR ALL COLUMNS:统计所有字段

FOR ALL INDEXED COLUMNS:统计索引的所有字段

estimate_statistics_clause

 

(7)ESTIMATE [ SYSTEM ] STATISTICS [for_clause][SAMPLE integer { ROWS | PERCENT }]

只是对部分行做一个大概的统计。适用于大表

SAMPLE:指定具体统计多少行,如果忽略这个参数的话,oracle会默认为1064行

ROWS causes:行数 Oracle to sample integer rows of the table or cluster or integer entries from the index. The integer must be at least 1.

PERCENT causes:百分数

validation_clauses

 

(8)分析REF或是对像的结构

EG:ANALYZE TABLE employees VALIDATE STRUCTURE CASCADE;

ANALYZE TABLE customers VALIDATE REF UPDATE;

 

(文章来自网络,如有侵权请来信告知,本站将在第一时间删除。)

相关文章 [上一篇] 【Oracle视频第9期_DBA体系结构】
010-88589926(88587026)
CUUG热门培训课程
Oracle DBA就业培训
CUUG名师
网络课程
技术沙龙
最新动态

总机:(010)-88589926,88589826,88587026 QQ讨论群:243729577 182441349 邮箱:cuug_bj@cuug.com
通信地址:北京市海淀区紫竹院路98号北京化工大学科技园609室(CUUG)邮政编码:100089 
中国UNIX用户协会 Copyright 2010  ALL Rights Reserved 北京神脑资讯技术有限公司
京ICP备11008061号  京公网安备110108006275号