计算索引碎片的一个脚本

简介:
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。





本文转自 vfast_chenxy 51CTO博客,原文链接:http://blog.51cto.com/chenxy/735328,如需转载请自行联系原作者

目录
相关文章
|
6月前
|
算法 C# C++
1000多个文件,占用空间10G,删除的效率
1000多个文件,占用空间10G,删除的效率
|
7月前
|
存储 人工智能 测试技术
唯一索引比普通索引快吗?运行原理是什么?
唯一索引比普通索引快吗?运行原理是什么?
72 0
|
关系型数据库 MySQL 索引
|
存储 SQL 缓存
为什么索引可以让查询变快?终于有人说清楚了!
上表是一张真实的数据库表,其中每一行是一条记录,每条记录都有字段。假设上面的数据库是一个有10万条记录的大数据库。现在,我们想从10万条记录中搜索一些内容,那么挨着一个一个搜索无疑将花费很长的时间,这个时候我们在数据结构与算法里学的二分查找法就派上了用场。
为什么索引可以让查询变快?终于有人说清楚了!
|
SQL 缓存 数据库

热门文章

最新文章