计算索引碎片的一个脚本

  
declare
cursor cur_ind is
    select ui.index_name from user_indexes ui;
  ind_name  user_indexes.index_name%type;
  v_name    index_stats.name%type;
  v_height  index_stats.height%type;
  v_percent number;
begin
  dbms_output.enable(10000000000);
  open cur_ind;
  loop
    fetch cur_ind
      into ind_name;
    exit when cur_ind%notfound;
    execute immediate 'analyze index ' || ind_name || ' validate structure'; --分析每个索引
    select ist.name,
           ist.height,
           round((del_lf_rows / (lf_rows + 0.0000000001)) * 100)
      into v_name, v_height, v_percent
      from index_stats ist;
    if (v_height > 4 or v_percent > 10) then
      dbms_output.put_line('索引名:' || v_name || ', ' || '高度:' || v_height || ', ' ||
                           '百分比:' || v_percent || ', ' || '需要重建');
    end if;
  end loop;
  close cur_ind;
end;

      今天在网上看到了一个估计索引碎片的方法,所以写了个小过程,对用户下的所有索引进行一次计算,挑选二元高度大于4的或者碎片率大于10%的索引进行输出。 需要说明的是,这种估计索引碎片的方法来自网上,还没有查询官方文档上的相关部分,仅供参考,我不对分析出的结果负责。

      我在一些OCP的教材上看到了有关analyze validate的说明,据称可以分析出碎片数,但是现在还没在官方文档上找到确切的证据,希望知道的人给我讲一下,以下是我从官方文档上找到的一些关于analyze validate的说明:  

      For an index, Oracle Database verifies the integrity of each data block in the index and checks for block corruption. This clause does not confirm that each row in the table has an index entry or that each index entry points to a row in the table. You can perform these operations by validating the structure of the table with the CASCADE clause.
      Oracle 验证每一个索引的数据块完整性以及检查block corruption。

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值