zoukankan      html  css  js  c++  java
  • 计算索引碎片的一个脚本

      
    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。

      

  • 相关阅读:
    ubuntu常用命令
    安装 Ruby, Rails 运行环境 常见的错误
    dubbo user guider笔记之一Preface
    翻译-Your first Dubbo application
    翻译-1.2 容器概述
    翻译-Core Technologies
    翻译-1.1 关于spring ioc容器和bean的介绍
    TCP协议-滑动窗口及拥塞控制
    QUARTZ之三-JobStores相关概念
    项目经验总结
  • 原文地址:https://www.cnblogs.com/wingsless/p/2259369.html
Copyright © 2011-2022 走看看