为了衡量(我相信您对索引的理解)分配和使用的索引大小,我可能会使用 dbms_space
create or replace procedure tq84_index_size_proc
as
OBJECT_OWNER_in varchar2(30) := user;
OBJECT_NAME_in varchar2(30) := 'TQ84_SIZE_IX';
OBJECT_TYPE_in varchar2(30) := 'INDEX';
SAMPLE_CONTROL_in number := null;
SPACE_USED_out number;
SPACE_ALLOCATED_out number;
CHAIN_PCENT_out number;
SUM_SEGMENT number;
begin
dbms_space.object_space_usage (
OBJECT_OWNER => OBJECT_OWNER_in ,
OBJECT_NAME => OBJECT_NAME_in ,
OBJECT_TYPE => OBJECT_TYPE_in ,
SAMPLE_CONTROL => SAMPLE_CONTROL_in ,
SPACE_USED => SPACE_USED_out ,
SPACE_ALLOCATED => SPACE_ALLOCATED_out ,
CHAIN_PCENT => CHAIN_PCENT_out
);
select sum(bytes) into SUM_SEGMENT
from user_segments
where segment_name = OBJECT_NAME_in;
dbms_output.put_line('Space Used: ' || SPACE_USED_out);
dbms_output.put_line('Space Allocated: ' || SPACE_ALLOCATED_out);
dbms_output.put_line('Segment: ' || SUM_SEGMENT);
end;
/
此过程测量名为* TQ84_SIZE_IX *的索引的分配和使用的大小。为了完整起见,我还添加了所报告的字节数user_segments
。
现在,可以看到以下过程:
create table tq84_size (
col_1 varchar2(40),
col_2 number
);
create index tq84_size_ix on tq84_size(col_1);
insert into tq84_size values ('*', 0);
commit;
exec tq84_index_size_proc;
索引中只有一个条目时,返回以下图:
Space Used: 1078
Space Allocated: 65536
Segment: 65536
填满索引...
insert into tq84_size
select substr(object_name || object_type, 1, 40),
rownum
from dba_objects,
dba_types
where rownum < 500000;
commit;
...并再次获得数据...
exec tq84_index_size_proc;
...报告:
Space Used: 25579796
Space Allocated: 32505856
Segment: 32505856
然后,如果索引为“空”:
delete from tq84_size;
commit;
exec tq84_index_size_proc;
表明:
Space Used: 4052714
Space Allocated: 32505856
Segment: 32505856
这表明分配的大小不会缩小,而已使用的大小会缩小。