select
small_vc
from
t1
where
n1 = 2 -- one in 20
and n3 = 2 -- one in 25
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 20 | 340 | 13 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 20 | 340 | 13 (0)| 00:00:01 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP AND | | | | | |
|* 4 | BITMAP INDEX SINGLE VALUE| T1_I3 | | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| T1_I1 | | | | |
--------------------------------------------------------------------------------------
select
small_vc
from
t1
where
n2 = 2 -- one in 20
and n4 = 2 -- one in 25
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 20 | 340 | 9 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 20 | 340 | 9 (0)| 00:00:01 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP AND | | | | | |
|* 4 | BITMAP INDEX SINGLE VALUE| T1_I4 | | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| T1_I2 | | | | |
--------------------------------------------------------------------------------------
--> 책과 다름
ex) 3천6백만 로우, 800M(107,543블록), 6가지의 속성 및 비트맵 인덱스를 가지는 테이블
sex = 1
and eyes = 1
and hair = 1
and town = 15
and age = 25
and work = 40
추측비용 (목표치는 314) =
74 * 1.1 * 3 + (가장 비용이 낮은 인덱스를 1.1배 증가시켜서 세 번 사용)
0.8 * 313 / 355 + (로우의 80%는 블록 당 335개씩 모여있음)
0.2 * 313 = (로우의 20%는 개별 블록에 흩어져 있음)
244.2 + 62.6 + 0.75 = 307.55 (에러율 2.1%)
alter table t1 modify n1 not null;
select
small_vc
from
t1
where
n1 != 2 -- one in 20, scattered
and n3 = 3 -- one in 25, scattered
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 380 | 6460 | 130 (0)| 00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 380 | 6460 | 130 (0)| 00:00:02 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP MINUS | | | | | |
|* 4 | BITMAP INDEX SINGLE VALUE| T1_I3 | | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| T1_I1 | | | | |
--------------------------------------------------------------------------------------
alter table t1 modify n1 null;
select
small_vc
from
t1
where
n1 != 2 -- one in 20, scattered
and n3 = 3 -- one in 25, scattered
;
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 380 | 6460 | 127 (0)| 00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 380 | 6460 | 127 (0)| 00:00:02 |
| 2 | BITMAP CONVERSION TO ROWIDS | | | | | |
| 3 | BITMAP MINUS | | | | | |
| 4 | BITMAP MINUS | | | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| T1_I3 | | | | |
|* 6 | BITMAP INDEX SINGLE VALUE| T1_I1 | | | | |
|* 7 | BITMAP INDEX SINGLE VALUE | T1_I1 | | | | |
---------------------------------------------------------------------------------------
BITMAP MINUS
create table t1
as
with generator as (
select --+ materialize
rownum id
from all_objects
where rownum <= 3000
)
select
/*+ ordered use_nl(v2) */
decode(
mod(rownum-1,1000),
0, rownum - 1,
null
) n1,
decode(
mod(rownum-1,1000),
0, rownum - 1,
null
) n2,
lpad(rownum-1,10,'0') small_vc
from
generator v1,
generator v2
where
rownum <= 1000000
;
create bitmap index t1_i1 on t1(n1);
create bitmap index t1_i2 on t1(n2);
begin
dbms_stats.gather_table_stats(
user,
't1',
cascade => true,
estimate_percent => null,
method_opt => 'for all columns size 1'
);
end;
/
select
small_vc
from
t1
where
n1 = 50000
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 1 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 1 | 13 | 1 (0)| 00:00:01 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
|* 3 | BITMAP INDEX SINGLE VALUE | T1_I1 | | | | |
--------------------------------------------------------------------------------------
select
small_vc
from
t1
where
n1 = 50000
or n2 = 50000
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1999 | 25987 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 1999 | 25987 | 2 (0)| 00:00:01 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP OR | | | | | |
|* 4 | BITMAP INDEX SINGLE VALUE| T1_I1 | | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| T1_I2 | | | | |
--------------------------------------------------------------------------------------
select
small_vc
from
t1
where
n1 = 50000
or (n2 = 50000 and n2 is not null)
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1000 | 13000 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 1000 | 13000 | 2 (0)| 00:00:01 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP OR | | | | | |
|* 4 | BITMAP INDEX SINGLE VALUE| T1_I1 | | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| T1_I2 | | | | |
--------------------------------------------------------------------------------------
select
small_vc
from
t1
where
(n1 = 50000 and n1 is not null)
or (n2 = 50000 and n2 is not null)
;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID | T1 | 1 | 13 | 2 (0)| 00:00:01 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP OR | | | | | |
|* 4 | BITMAP INDEX SINGLE VALUE| T1_I1 | | | | |
|* 5 | BITMAP INDEX SINGLE VALUE| T1_I2 | | | | |
--------------------------------------------------------------------------------------
- 강좌 URL : http://www.gurubee.net/lecture/4418
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.