Oracle预估索引大小

 

declare
  used_bytes  number(10);
  alloc_bytes number(10);
begin
  dbms_stats.gather_table_stats(user, 'HISTORYALARM');
  dbms_space.create_index_cost('create index idx_historyalarm on historyalarm(position1)',
                               used_bytes      => used_bytes,
                               alloc_bytes     => alloc_bytes);
  dbms_output.put_line('used_bytes : ' || used_bytes);
  dbms_output.put_line('alloc_bytes : ' || alloc_bytes);
end;

在计算索引大小的时候,你须要先收集表的统计信息,由于Oracle是依据表的数据信息来推算的,以下是输出的结果:

used_bytes : 151994511
alloc_bytes : 251658240

查看索引信息

能够通过上面的方式查看创建成功后的索引:

select * from user_indexes where index_name = upper('idx_historyalarm')

能够通过以下的方式显示所占用的空间的实际数额:

select bytes from user_segments where segment_name = upper('idx_historyalarm')

以下是输出结果,空间分配字节数的预计量略小于实际使用量:

BYTES
--------------------------
293601280

随着记录插入到表中,该索引将添加,对索引大小监控能够确保有足够的磁盘空间,以适应未来的数据添加需求。

posted @ 2015-03-01 18:01  智能先行者  阅读(744)  评论(0)    收藏  举报