Untitled

인덱스 full scan은 인덱스의 구조에 따라 전체를 스캔하는 스캔방법입니다.

대용량 테이블의 데이터를 빠르게 count하고 싶을때 주로 사용합니다.

실습예제1. 직업, 직업별 인원수를 출력하시오!

create index emp_job on emp(job);

select job, count(*)
from emp
group by job;

select * from  table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));

full table scan을 하면서 buffer의 갯수가 7개를 읽어들였습니다.

실습예제2. 위의 실행계획을 index full scan으로 유도하시오!

job에 not null제약을 걸면 됩니다.

alter table emp
modify job constraint emp_job_nn not null;

select job, count(*)
from emp
group by job;

select * from  table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));

문제 38. 아래의 sql을 검색속도를 높이시오!

create index emp_deptno on emp(deptno);

select deptno, count(*)
from emp
group by deptno;
alter table emp
modify deptno constraint emp_deptno_nn not null;

create index emp_deptno on emp(deptno);
select deptno, count(*)
from emp
group by deptno;

not null 제약을 걸 수 없는 상황인 경우 where 절에 not null을 쓰면 됩낟.

select deptno, count(*)
from emp
where deptno is not null
group by deptno;