index fast full scan 은 index full scan 처럼 table full scan 보다 빠르게 데이터를 검색해냅니다. 그런데 index fast full scan 이 index full scan 보다 더 빠릅니다.
index fast full scan > index full scan > table full scan
왜 index fast full scan 이 index full scan 보다 더 빠른가 ?
데이터를 정렬하지 않습니다.
single block i/o 가 아니라 muti block i/o 를 합니다.
예: 책의 목차가 50장이 있다고 가정하겠습니다. 50장의 목차를 full 로 스캔하는데 만약 싱글 블럭 i/o를 한다면 책장을 한번 넘길때 1장씩 넘기는거고 multi block i/o를 한다면 책장을 한번 넘길때 10장씩 넘기는겁니다.
■ 실습1. 직업, 직업별 토탈월급을 출력하는데 index fast full scan 이 되게 하시오
@demo
create index emp_job_sal on emp(job, sal);
select job, sum(sal)
from emp
where job is not null
group by job;
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
select /*+ index_ffs(emp emp_job_sal) */ job, sum(sal)
from emp
where job is not null
group by job;
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
문제 40. 부서번호, 부서번호별 토탈 월급을 출력하는데 아래의 쿼리의 결과가 index full scan을 했을 때와 index fast full scan을 했을 때 정렬된 결과의 차이가 있는지 확인하시오!
create index emp_deptno_sal on emp(deptno,sal);
select deptno, sum(sal)
from emp
where deptno is not null
group by deptno;
튜닝 후
select /*+ index_ffs(emp emp_job_sal) */ deptno, sum(sal)
from emp
where deptno is not null
group by deptno;
문제 41. 아래의 환경을 구성하고 sale_gb 별 인원수를 출력하시오!
drop table mcustsum purge;
create table mcustsum
as
select rownum custno
, '2008' || lpad(ceil(rownum/100000), 2, '0') salemm
, decode(mod(rownum, 12), 1, 'A', 'B') salegb
, round(dbms_random.value(1000,100000), -2) saleamt
from dual
connect by level <= 1200000 ;
create index m_salegb_saleamt on mcustsum(salegb, saleamt);