본문 바로가기
[DATABASE] ORACLE/Objects (Table, Index, Etc..)

[Index] 인덱스 사이즈 예측

by 기미차니 2021. 12. 14.
반응형

# How To Estimate the Size of Index

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
drop table test;
 
create table test (a NUMBER (10) , b VARCHAR2 (30) ,c VARCHAR2 (30), d date ) tablespace USERS pctfree 10;
 
BEGIN
  FOR i IN 1..100000 LOOP
  INSERT INTO test VALUES (9999999999,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',sysdate);
  END LOOP;
 END;
/
 
exec DBMS_STATS.GATHER_TABLE_STATS (ownname=>'orakim',tabname=>'test',estimate_percent=>100,block_sample=>true,method_opt=>'FOR ALL COLUMNS size 254');
 
set serveroutput on
 
declare
   l_used_bytes number;
   l_alloc_bytes number;
begin
   dbms_space.create_index_cost (
      ddl => 'create index test_indx on test (a,b) tablespace users',
      used_bytes => l_used_bytes,
      alloc_bytes => l_alloc_bytes
   );
   dbms_output.put_line ('Used Bytes      = '||l_used_bytes);
   dbms_output.put_line ('Allocated Bytes = '||l_alloc_bytes);
end;
/   
 
-- 예상
-- Used Bytes      = 3800000
-- Allocated Bytes = 6291456
 
create index test_indx on test (a,b) tablespace users;
 
select BYTES,SEGMENT_TYPE from user_segments where SEGMENT_NAME='TEST_INDX';
 
-- 실제 
--      BYTES SEGMENT_TYPE
-- ---------- ------------------
--    6291456 INDEX
 
 
-------------------------------------------
-- 테스트 emp_1 테이블
-------------------------------------------
 
exec DBMS_STATS.GATHER_TABLE_STATS (ownname=>'orakim',tabname=>'emp_1',estimate_percent=>100,block_sample=>true,method_opt=>'FOR ALL COLUMNS size 254');
 
set serveroutput on
 
declare
   l_used_bytes number;
   l_alloc_bytes number;
begin
   dbms_space.create_index_cost (
      ddl => 'CREATE INDEX IDX_01 ON EMP_1(ENAME,JOB)',
      used_bytes => l_used_bytes,
      alloc_bytes => l_alloc_bytes
   );
   dbms_output.put_line ('Used Bytes      = '||l_used_bytes);
   dbms_output.put_line ('Allocated Bytes = '||l_alloc_bytes);
end;
/   
 
-- 예상
-- Used Bytes      = 132120576
-- Allocated Bytes = 260046848
 
drop index idx_01;
 
create index idx_01 on emp_1(ename,job);
 
select BYTES/1024/1024,SEGMENT_TYPE from user_segments where SEGMENT_NAME='IDX_01';
 
-- 실제
-- 276824064    INDEX
cs
반응형

댓글