h2.비트맵 인덱스
create BITMAP index JOB_IDX ON emp ( job ) ;
[표 11-6] 오라클 JOB_IDX 비트냅 인덱스를 저장하는 방식
-. 비트맵 인덱스는 NULL 엔트리도 저장한다.(엔트리에 없다면, NULL 값이 존재 하지 않음 )
[표 11-7] 비트아이즈 OR 연산의 표현
SQL> SELECT COUNT(*) FROM EMP WHERE job ='CLERK' or job='MANAGER';
Execution Plan
----------------------------------------------------------
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 0 (0)|
| 1 | SORT AGGREGATE | | 1 | 6 | |
| 2 | BITMAP CONVERSION COUNT | | 1 | 6 | |
|* 3 | BITMAP INDEX FAST FULL SCAN| JOB_IDX | | | |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("JOB"='CLERK' OR "JOB"='MANAGER')
==> 비트냅 인덱스에서 Count 만 하면 됌
SQL> select * from emp where job='CLERK' or job='MANAGER';
Execution Plan
----------------------------------------------------------
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 87 | 2 (0)|
|* 1 | TABLE ACCESS FULL| EMP | 1 | 87 | 2 (0)|
---------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("JOB"='CLERK' OR "JOB"='MANAGER')
SQL>
==> * 로 테이블 접근 필요가 있음
Select count(*)
from T
where gender ='M'
and location in ( 1, 10, 30 )
and age_group ='41 and over';
select *
from T
where ( ( gender ='M' and location = 20)
or ( gender ='F' and location = 22))
and age_group = '18 and under' ;
select count(*)
from T
where location in ( 11,20,30 );
select count(*)
from T
where age_group ='41 and over'
and gender ='F';
SQL> create table t
( gender not null,
location not null,
age_group not null,
data
)
as
select decode(ceil(dbms_random.value(1,2)),1,'M',2,'F') gender,
ceil(dbms_random.value(1,50)) location,
decode(ceil(dbms_random.value(1,5)), 1,'18 and under'
, 2,'19-25'
, 3,'26-30'
, 4,'31-40'
, 5,'41 and over'),
rpad('*',20,'*')
from big_table
where rownum <= 100000
/
Table created.
SQL> create bitmap index gender_idx on t (gender );
Index created.
SQL> create bitmap index location_idx on t (location );
Index created.
SQL> create bitmap index age_group_idx on t ( age_group);
Index created.
SQL> exec dbms_stats.gather_table_stats(user,'T');
PL/SQL procedure successfully completed.
SQL>
SQL> set autotrace traceonly
SQL> select count(*)
2 from T
3 where gender='M'
4 and location in ( 1,10,30 )
5 and age_group ='41 and over' ;
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
1 SORT AGGREGATE (cr=2 pr=0 pw=0 time=73 us)
0 BITMAP CONVERSION COUNT (cr=2 pr=0 pw=0 time=65 us)
0 BITMAP AND (cr=2 pr=0 pw=0 time=58 us)
0 BITMAP INDEX SINGLE VALUE GENDER_IDX (cr=2 pr=0 pw=0 time=33 us)
0 BITMAP INDEX SINGLE VALUE AGE_GROUP_IDX (cr=0 pr=0 pw=0 time=2 us)
0 BITMAP OR (cr=0 pr=0 pw=0 time=14 us)
0 BITMAP INDEX SINGLE VALUE LOCATION_IDX (cr=0 pr=0 pw=0 time=2 us)
0 BITMAP INDEX SINGLE VALUE LOCATION_IDX (cr=0 pr=0 pw=0 time=1 us)
0 BITMAP INDEX SINGLE VALUE LOCATION_IDX (cr=0 pr=0 pw=0 time=1 us)
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("GENDER"='M' AND "AGE_GROUP"='41 and over' AND ("LOCATION"=1 OR
"LOCATION"=10 OR "LOCATION"=30))
3 - access(ROWID=ROWID)
4 - access(ROWID=ROWID)
6 - access("GENDER"='M')
8 - access("AGE_GROUP"='41 and over')
11 - access("LOCATION"=1 OR "LOCATION"=10 OR "LOCATION"=30)
select *
from T
where ( ( GENDER ='M' AND LOCATION = 20 )
OR ( GENDER ='F' AND LOCATION = 22 ))
AND age_group ='18 and under';
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
0 TABLE ACCESS BY INDEX ROWID T (cr=2 pr=0 pw=0 time=69 us)
0 BITMAP CONVERSION TO ROWIDS (cr=2 pr=0 pw=0 time=69 us)
0 BITMAP AND (cr=2 pr=0 pw=0 time=63 us)
0 BITMAP INDEX SINGLE VALUE AGE_GROUP_IDX (cr=2 pr=0 pw=0 time=38 us)
0 BITMAP OR (cr=0 pr=0 pw=0 time=19 us)
0 BITMAP AND (cr=0 pr=0 pw=0 time=10 us)
0 BITMAP INDEX SINGLE VALUE LOCATION_IDX (cr=0 pr=0 pw=0 time=2 us)
0 BITMAP INDEX SINGLE VALUE GENDER_IDX (cr=0 pr=0 pw=0 time=2 us)
0 BITMAP AND (cr=0 pr=0 pw=0 time=5 us)
0 BITMAP INDEX SINGLE VALUE GENDER_IDX (cr=0 pr=0 pw=0 time=2 us)
0 BITMAP INDEX SINGLE VALUE LOCATION_IDX (cr=0 pr=0 pw=0 time=2 us)
*. 9i에서 소개된 새로운 인덱스 유형
SQL> CREATE BITMAP INDEX EMP_BM_IDX
ON EMP ( D.DNAME)
FROM EMP E, DEPT D
WHERE E.DEPTNO = D.DEPTNO;
Statement Processed.
SQL> BEGIN
DBMS_STATS.SET_TABLE_STATS(USER,'EMP', NUMROWS =>1000000, NUMBLKS => 300000);
DBMS_STATS.SET_TABLE_STATS(USER,'DEPT', NUMROWS =>100000, NUMBLKS => 300000);
DBMS_STATS.DELETE_INDEX_STATS(USER,'EMP_BM_IDX');
END;
/
Statement Processed.
==> 통계정보를 업데이트 하여, EMP,DEPT 가 대량의 데이터처럼 조정
CREATE INDEX 로 인한 COMPUTE STATISTICS 수행 정보를 삭제 하기 위해서 DELETE_INDEX_STATS 수행
SELECT COUNT(*)
FROM EMP, DEPT
WHERE EMP.DEPTNO = DEPT.DEPTNO
AND DEPT.DNAME ='SALES'
Misses in library cache during parse: 0
Optimizer goal: ALL_ROWS
Parsing user: OPS$ORACLE (ID=59)
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
1 SORT AGGREGATE (cr=1 pr=0 pw=0 time=46 us)
0 BITMAP CONVERSION COUNT (cr=1 pr=0 pw=0 time=41 us)
0 BITMAP INDEX SINGLE VALUE EMP_BM_IDX (cr=1 pr=0 pw=0 time=29 us)
SQL> set autotrace traceonly explain
SQL> select count(*)
2 from emp, dept
3 where emp.deptno = dept.deptno
4 and dept.dname ='SALES';
Execution Plan
----------------------------------------------------------
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 1 (0)|
| 1 | SORT AGGREGATE | | 1 | 13 | |
| 2 | BITMAP CONVERSION COUNT | | 10 | 130 | 1 (0)|
|* 3 | BITMAP INDEX SINGLE VALUE| EMP_BM_IDX | | | |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("EMP"."SYS_NC00009$"='SALES')
SQL> CREATE BITMAP INDEX EMP_BM_IDX
ON DEPT ( E.ENAME )
FROM EMP E, DEPT D
WHERE E.DEPTNO = D.DEPTNO
ORA-25954: missing primary key or unique constraint on dimension