天天看点

Analyze 命令的使用方法 

ANALYZE      
  { TABLE [ schema. ]table      
      [ PARTITION ( partition ) | SUBPARTITION ( subpartition ) ]      
  | INDEX [ schema. ]index      
      [ PARTITION ( partition ) | SUBPARTITION ( subpartition ) ]      
  | CLUSTER [ schema. ]cluster      
  }      
  { compute_statistics_clause      
  | estimate_statistics_clause      
  | validation_clauses      
  | LIST CHAINED ROWS [ into_clause ]      
  | DELETE [ SYSTEM ] STATISTICS      
  } ;      

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)

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)

分析表的限制

不可以分析数据字典表

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

不可以分析临时表

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

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

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

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

compute_statistics_clause

语法: 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

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

分析 REF 或是对像的结构

EG : ANALYZE TABLE employees VALIDATE STRUCTURE CASCADE;

ANALYZE TABLE customers VALIDATE REF UPDATE;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27018451/viewspace-731856/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27018451/viewspace-731856/