天天看點

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/