-- 오늘의 마지막 문제. 사원 테이블의 월급을 기준으로 파티션 테이블을 생성하시오.
-- 그리고 아래의 SQL의 튜닝 전과 튜닝 후의 성능 차이가 있는지 확인하시오
--select *
-- from emp
-- where sal = 1250;
--
--select *
-- from emp_partition_sal
-- where sal = 1250;
-- 범위 확인
select ntile(3) over (order by sal), sal from emp;
-- 1: 800~1250
-- 2: 1300~2850
-- 3: 2975~5000
-- 파티션 테이블 생성
create table emp_partition_sal
partition by range(sal)
(
partition p1 values less than(1300),
partition p2 values less than(2975),
partition p3 values less than(5001)
)
as select * from emp;
-- 생성 후 확인
select * from emp_partition_sal;
-- 튜닝 전
select *
from emp
where sal = 1250;
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
-- table access full, buffers 7
-- 튜닝 후
select *
from emp_partition_sal
where sal = 1250;
select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
-- partition range single, table access full, buffers 2