Oracle 工具类 Sql 分析索引的 碎片率

 

CBO基于成本的优化器分析  分配合适的存储桶 使用存储过程DBMS_STATS

1、索引分析

分析语句:
SQL>analyze index <index_name> validate structure online;

分析表:
analyze table tablename compute statistics;

analyze index indexname compute statistics;

查看索引碎片的情况:
SQL>select name,del_lf_rows_len,lf_rows_len,(del_lf_rows_len/lf_rows_len)*100 from index_stats;
索引碎片率:(del_lf_rows_len/lf_rows_len)*100
如果索引碎片率超过20%,oracle就会认为索引碎片已经非常严重,此时就需要对索引碎片进行整理。

2、索引碎片整理
索引碎片整理包括两种策略:
(1)重建索引(rebuild)
SQL>alter index <index_name> rebuild;
(2)压缩索引(coalesce)
SQL>alter index <index_name> coalesce;

oracle建议定期分析之后采用重建索引(rebuild)的策略。

原文地址:https://www.cnblogs.com/liwenchaoCode/p/8242274.html