分析Oracle索引,检查其碎片是否严重

查看表:

  1. train@reg>desc LY_SB_TEST  
  2.  名称                                是否为空? 类型  
  3.  ----------------------------------- -------- ------------------  
  4.  NSR                                          VARCHAR2(44)  
  5.  SSSQ_Q                                       VARCHAR2(8)  
  6.  SSSQ_Z                                       VARCHAR2(8)  
  7.  SE                                           NUMBER  

–LY_SB_TEST总共有36万行数据

train@reg>–索引做统计分析

  1. train@reg>BEGIN  
  2.     DBMS_STATS.GATHER_TABLE_STATS(USER,'LY_SB_TEST',CASCADE => TRUE);  
  3.   END;  
  4.   /  
  5. PL/SQL 过程已成功完成。  

分析索引,验证索引结构

  1. train@reg>analyze index IDX_LY_SB_TEST_N1 validate structure;  
  2.   
  3. 索引已分析  
  4.   
  5. train@reg>select t.name--索引名  
  6.         t.lf_rows, --number of leaf rows (values in the index)  
  7.         t.lf_blks,  
  8.         t.del_lf_rows, --number of deleted leaf rows in the index  
  9.         (t.del_lf_rows / t.lf_rows)*100 ratio --删除比例  
  10.    from index_stats t  
  11.    where t.name='IDX_LY_SB_TEST_N1';  
  12.   
  13. NAME                              LF_ROWS    LF_BLKS DEL_LF_ROWS      RATIO  
  14. ------------------------------ ---------- ---------- ----------- ----------  
  15. IDX_LY_SB_TEST_N1                  360000       1300           0          0  
模拟数据删除,让索引产生大量碎片
  1. train@reg>delete  ly_sb_test where mod(se,3)=1;  
  2.   
  3. 已删除143643行。  
  4.   
  5. train@reg>commit;  
  6.   
  7. 提交完成。  
  8.   
  9. 已用时间:  00: 00: 00.01  
  10. train@reg>--分析索引,查看索引碎片是否严重  
  11. train@reg>  
  12. train@reg>analyze index IDX_LY_SB_TEST_N1 validate structure;  
  13.   
  14. 索引已分析  
  15.   
  16. 已用时间:  00: 00: 00.37  
  17. train@reg>select t.name--索引名  
  18.          t.lf_rows, --number of leaf rows (values in the index)  
  19.          t.lf_blks,  
  20.          t.del_lf_rows, --number of deleted leaf rows in the index  
  21.          (t.del_lf_rows / t.lf_rows)*100 ratio --删除比例  
  22.     from index_stats t  
  23.     where t.name='IDX_LY_SB_TEST_N1';  
  24.   
  25. NAME                              LF_ROWS    LF_BLKS DEL_LF_ROWS      RATIO  
  26. ------------------------------ ---------- ---------- ----------- ----------  
  27. IDX_LY_SB_TEST_N1                  360000       1300      143643 39.9008333  
  28.   
  29. 已用时间:  00: 00: 00.01    

如果RATIO值大于30%以上就需要考虑索引重建了。



From:http://www.idb-stock.net/idb/2011/05/10/66.html



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值