Analyze 命令的使用方法

时间:2023-01-10 18:44:33

1、三大功能ITPUB个人空间sWY+w&k)WvWF j-}
搜集和删除索引、表和簇的统计信息ITPUB个人空间C&R"e"LPO2~8XP`6V
验证表、索引和簇的结构ITPUB个人空间7gY QYo9bY `
鉴定表和簇和行迁移和行联接

ITPUB个人空间A$}/acV w {[
针对analyze的搜集和删除统计信息功能而言,oracle推荐使用DBMS_STATS包来搜集优化信息,DBMS_STATS可以并行的搜集信息,可以搜集分区表的全局信息,进一步来说,按成本的优化器只会使用DBMS_STATS包所统计出来的信息。

2、先决条件
P K-D,xx0a,_C0必须在你自己的方案中或有ANALYZE ANY system 的权限,

3、语法ITPUB个人空间3GE[ U*Qpv)FSdt
ANALYZEITPUB个人空间v9l`U$HGqe
{ TABLE [ schema.]tableITPUB个人空间tM*w&N%B)U+W
[ PARTITION ( partition ) | SUBPARTITION ( subpartition ) ]
3y"h%R0ds9W2Es0D*b3X0| INDEX [ schema. ]indexITPUB个人空间SW/cI-G/A*[ c6|
[ PARTITION ( partition ) | SUBPARTITION ( subpartition ) ]ITPUB个人空间fa3[@%UuS t
| CLUSTER [ schema. ]clusterITPUB个人空间'r4m4@ El(C:m-Y"x2c
}ITPUB个人空间'h Q$k*_e3e
{ COMPUTE [ SYSTEM ] STATISTICS [for_clause]ITPUB个人空间9Er rRU4jADL2Z
| ESTIMATE [ SYSTEM ] STATISTICS [for_clause][SAMPLE integer { ROWS | PERCENT }]
A4m"e/:{2C*u0| validation_clausesITPUB个人空间u7M6p^5QU1NU/J
| LIST CHAINED ROWS [ into_clause ]ITPUB个人空间U3eo-yb;z
| DELETE [ SYSTEM ] STATISTICSITPUB个人空间(ToqQr%ma-xT HQ
} ;

INDEX index:对索引进行分析,分析的结果会放在USER_INDEXES, ALL_INDEXES,或 DBA_INDEXES中
h;W#hRt"A^0分析的内容:ITPUB个人空间u-A+c4Z;B2jf ^
Depth of the index from its root block to its leaf blocks (BLEVEL)ITPUB个人空间v,J/$S{ w?[
Number of leaf blocks (LEAF_BLOCKS)
z3N/y5x%L0Number of distinct index values (DISTINCT_KEYS)ITPUB个人空间${+A*[$v_
Average number of leaf blocks for each index value (AVG_LEAF_BLOCKS_PER_KEY)ITPUB个人空间{hv!?LW
Average number of data blocks for each index value (for an index on a table) (AVG_DATA_BLOCKS_PER_KEY)ITPUB个人空间 n6X]}o*wxL I
Clustering factor (how well ordered the rows are about the indexed values) (CLUSTERING_FACTOR)

ITPUB个人空间B4L2Ax`2u V:CGs
TABLE table:对表进行分析,分析的结果会放在USER_TABLES, ALL_TABLES, and DBA_TABLES表中,在分析表的时候,oracle也会分析基于函数的index所引用的表达式ITPUB个人空间;M+CEZ[z7Z
分析的内容:ITPUB个人空间E1P(c p|*a2M
Number of rows (NUM_ROWS) *
tu0OO/`!WE0Number 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)
2Tx4I4Zxw0* 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)ITPUB个人空间@O_;Y(^)W+Kd
Number of chained rows (CHAIN_COUNT) Average row length, including the row's overhead, in bytes (AVG_ROW_LEN)

分析表的限制ITPUB个人空间:o W p3c(|m0F
不可以分析数据字典表
Z)r(wL]"BGI5P0不可以分析扩展表,但可以用DBMS_STATS来实现这个目的
8~k?HW2JL uw$wq0不可以分析临时表ITPUB个人空间&t%Aa/G!D,Mt-i
不可以计算或估计下列字段类型ITPUB个人空间2xXQz2N0{+A$o.xy,F+b
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_clauseITPUB个人空间 gy Db+nt5/
语法:COMPUTE [ SYSTEM ] STATISTICS [for_clause]
K/w,Hi.i0对分析对像进行精确的统计,然后把信息存储的数据字典中。可以选择对表或对字段进行分析。

computed和estimated这两种方式的统计数据都被优化器用来影响sql的执行计划ITPUB个人空间OE1l0ZG Q0X o&i
如果指定system选项就只统计系统产生的信息
(/Z8Be!k Oyn0for_clauseITPUB个人空间;S3]4|P0~D2Vs
FOR TABLE:只统计表ITPUB个人空间 o/JAWh s`G
FOR COLUMNS:只统计某个字段ITPUB个人空间H X#G!RA
FOR ALL COLUMNS:统计所有字段
1Q$|.j.r@0FOR ALL INDEXED COLUMNS:统计索引的所有字段

ITPUB个人空间']` ^5k)pI;L0o
estimate_statistics_clauseITPUB个人空间"NN(c_{(j?J{
ESTIMATE [ SYSTEM ] STATISTICS [for_clause][SAMPLE integer { ROWS | PERCENT }]ITPUB个人空间b[3j.|tb Q*t$GA
只是对部分行做一个大概的统计。适用于大表
C xS/K5@j3D0SAMPLE:指定具体统计多少行,如果忽略这个参数的话,oracle会默认为1064行ITPUB个人空间{%X-q|$_7H^-{
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.ITPUB个人空间)K&Zr!Wa+~"X V2]
PERCENT causes:百分数


N(o'T/iL}3B0validation_clausesITPUB个人空间vO3dV'h4q%U;K
分析REF或是对像的结构
,F c7?vl0W&O(d&[0EG:ANALYZE TABLE employees VALIDATE STRUCTURE CASCADE;
r._W-hoy"P:a0

ANALYZE TABLE customers VALIDATE REF UPDATE;