drop table t1;
begin
begin execute immediate 'purge recyclebin';
exception when others then null;
end;
begin execute immediate 'begin dbms_stats.delete_system_stats; end;';
exception when others then null;
end;
begin execute immediate 'alter session set "_optimizer_cost_model"=io';
exception when others then null;
end;
end;
/
create table t1
pctfree 70
pctused 30
nologging
as
select
mod((rownum-1),20) n1, -- 20 values, scattered
trunc((rownum-1)/500) n2, -- 20 values, clustered
--
mod((rownum-1),25) n3, -- 25 values, scattered
trunc((rownum-1)/400) n4, -- 25 values, clustered
--
mod((rownum-1),25) n5, -- 25 values, scattered for btree
trunc((rownum-1)/400) n6, -- 25 values, clustered for btree
--
lpad(rownum,10,'0') small_vc,
rpad('x',220) padding
from
all_objects
where
rownum <= 10000
;
create bitmap index t1_i1 on t1(n1)
nologging
pctfree 90
;
create bitmap index t1_i2 on t1(n2)
nologging
pctfree 90
;
create bitmap index t1_i3 on t1(n3)
nologging
pctfree 90
;
create bitmap index t1_i4 on t1(n4)
nologging
pctfree 90
;
create index t1_i5 on t1(n5)
nologging
pctfree 90
;
create index t1_i6 on t1(n6)
nologging
pctfree 90
;
begin
dbms_stats.gather_table_stats(
user,
't1',
cascade => true,
estimate_percent => null,
method_opt => 'for all columns size 1'
);
end;
/
n6 : B-tree Index on clustered column with 25 values
select
small_vc
from t1
where n6 = 2
;
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 400 | 5600 | 54 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 400 | 5600 | 54 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_I6 | 400 | | 9 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
n5 : B-tree Index on scattered column with 25 values
select
small_vc
from t1
where n5 = 2
;
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 400 | 5600 | 304 (1)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| T1 | 400 | 5600 | 304 (1)| 00:00:04 |
--------------------------------------------------------------------------
n4 : Bitmap Index on clustered column with 25 values
select
small_vc
from t1
where n4 = 2
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 400 | 5600 | 131 (0)| 00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 400 | 5600 | 131 (0)| 00:00:02 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
|* 3 | BITMAP INDEX SINGLE VALUE | T1_I4 | | | | |
--------------------------------------------------------------------------------------
n3 : Bitmap Index on scattered column with 25 values
select
small_vc
from t1
where n3 = 2
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 400 | 5600 | 133 (0)| 00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 400 | 5600 | 133 (0)| 00:00:02 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
|* 3 | BITMAP INDEX SINGLE VALUE | T1_I3 | | | | |
--------------------------------------------------------------------------------------
n3 : Bitmap Index on scattered column with 25 values
-----------------------------------------------------
Access Path: index (AllEqRange)
Index: T1_I3
resc_io: 3.00 resc_cpu: 23214
ix_sel: 0.04 ix_sel_with_filters: 0.04
Cost: 3.00 Resp: 3.00 Degree: 0
Access path: Bitmap index - accepted
Cost: 133.31 Cost_io: 133.18 Cost_cpu: 1112318 Sel: 0.04
Not believed to be index-only
Best:: AccessPath: IndexBitmap
Cost: 133.31 Degree: 1 Resp: 133.31 Card: 400.00 Bytes: 0
n4 : Bitmap Index on clustered column with 25 values
-----------------------------------------------------
Access Path: index (AllEqRange)
Index: T1_I4
resc_io: 1.00 resc_cpu: 8171
ix_sel: 0.04 ix_sel_with_filters: 0.04
Cost: 1.00 Resp: 1.00 Degree: 0
Access path: Bitmap index - accepted
Cost: 131.31 Cost_io: 131.18 Cost_cpu: 1097275 Sel: 0.04
Not believed to be index-only
Best:: AccessPath: IndexBitmap
Cost: 131.31 Degree: 1 Resp: 131.31 Card: 400.00 Bytes: 0
--> 책과 다름
- 강좌 URL : http://www.gurubee.net/lecture/4417
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.