코드 :
--2026년_1월_16일 자습시간 문제
--오늘의 마지막 문제1. HR 계정이 가지고 있는 모든 테이블들에 대해서
--테이블 통계정보를 생성하는 스크립트를 작성하시오
select ' exec dbms_stats.gather_table_stats('''||owner||''', '''||table_name||''', degree=> 12);'
from dba_tables
where owner='HR';
exec dbms_stats.gather_table_stats('HR', 'COUNTRIES', degree=> 12);
exec dbms_stats.gather_table_stats('HR', 'REGIONS', degree=> 12);
exec dbms_stats.gather_table_stats('HR', 'LOCATIONS', degree=> 12);
exec dbms_stats.gather_table_stats('HR', 'DEPARTMENTS', degree=> 12);
exec dbms_stats.gather_table_stats('HR', 'JOBS', degree=> 12);
exec dbms_stats.gather_table_stats('HR', 'EMPLOYEES', degree=> 12);
exec dbms_stats.gather_table_stats('HR', 'JOB_HISTORY', degree=> 12);
--통계정보 확인
select table_name, num_rows, last_analyzed
from dba_tables
where owner='HR';
코드 :
--오늘의 마지막 문제2. 아래의 SQL 에 성능을 높일 수 있도록 테이블 통계정보 수집과 인덱스를 생성하시오
--(튜닝전 버퍼의 갯수와 튜닝후 버퍼의 갯수를 보여주세요)
--SQL 튜닝 이수자 평가 제출물 1번
--테이블 생성
create table sales600
as
select * from sh.sales;
--튜닝 전
select *
from sales600
where prod_id= 13 and amount_sold=1232.16;
--테이블 통계정보 수집
exec dbms_stats.gather_table_stats('C##SCOTT', 'SALES600', degree=> 12);
--통계정보 확인
select table_name, num_rows, last_analyzed
from dba_tables
where owner='C##SCOTT' and table_name = 'SALES600';
--인덱스 생성
create index sales600_amount_sold_prod_id on sales600(amount_sold,prod_id);
--튜닝 후
select *
from sales600
where amount_sold=1232.16 and prod_id= 13;