그럼 언제 예상 실행계획을 보고 언제 실제 실행계획을 봐야하는가?
답: 튜닝해야할 쿼리문이 너무 오래 돌면 예상 실행계획
어느정도 기다릴 수 있는 쿼리문이면 실제 실행계획을 봅니다.
실제 실행계획을 주로 본다.
▣ 1. 예상 실행계획 보는 방법
explain plan for
select deptno, job, sum(sal)
from emp
group by grouping sets( (deptno), (job) );
select * from table(dbms_xplan.display);
▣ 2. 실제 실행계획 보는 방법
select /*+ gather_plan_statistics */ deptno, job, sum(sal)
from emp
group by grouping sets( (deptno), (job) );
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
문제 5. 아래의 sql의 튜닝전 sql의 버퍼의 갯수와 튜닝후 sql의 버퍼의 갯수를 비교해서 고객에게 제출하시오.
튜닝전:
create index emp_job on emp(job);
select /*+ gather_plan_statistics */ ename, job
from emp
where substr(job, 1, 5)='SALES';
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
튜닝 후:
select /*+ gather_plan_statistics */ ename, job
from emp
where job like 'SALES%';
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));