Analyze 命令的使用方法

tolywang發表於2008-08-21

1、三大功能
蒐集和刪除索引、表和簇的統計資訊
驗證表、索引和簇的結構
鑑定表和簇和行遷移和行聯接


       針對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
} ;

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/35489/viewspace-431665/,如需轉載,請註明出處,否則將追究法律責任。

相關文章