analyze index 时validate structure和compute statistics的区别

analyze index 时validate structure和compute statistics的区别

analyze index index1 validate structure:
analyze index index1 compute statistics:

在分析索引的时候,一般会用到以上二个命令,那么这二个命令是用来干什么呢?
analyze index index1 validate structure:是用来分析索引的数据块是否有坏块,以及根据分析得到的数据(存放在index_stats)來判断索引是否需要重新建立。

什么样的index需要rebuild?
当一个table经常进行DML操作时,它的索引会存在许多block空间的浪费,这是因为index block中的记录只有在全部表示为不可用时, block 才能被加入到freelist中去被重新利用。所以我们需要寻找那些浪费空间很严重的index。
方法是:

  1. analyze index index_name validate structure;
  2. select DEL_LF_ROWS_LEN/LF_ROWS_LEN from index_stats; where name = :index_name;
    DEL_LF_ROWS_LEN(total length of all deleted rows in the index) LF_ROWS_LEN (sum of the lengths of all the leaf rows)
  3. 如果结果大于20%, 那你的Index就可以被rebuild了。

validate structure有二中模式: online, offline, 默认是offline模式。以offline模式分析时, 会對表加一个4级別的锁(表共享),对run系統可能造成一定的影响。 而online模式则没有表lock的影响,但当以online模式分析时, 在视图index_stats没有统计信息。

analyze index index1 compute statistics:是用来统计index的分析信息,来为CBO服务的。从9i开始,Oracle以建议使用dbms_stats package代替 analyze 了。

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

转载于:http://blog.itpub.net/31397003/viewspace-2138933/

posted @ 2022-06-08 08:50  荣码一生  阅读(192)  评论(0编辑  收藏  举报