SSISO Community

시소당

간단한 oracle plan 보기..

튜닝을 하기 위해서 오라클이 어떠한 방식으로 동작 했느냐를 알아야 하고
그 기본이 되는것이 plan 을 떠보는 것이다.
실제 실행과 plan 은 다를수 있다...
간단히..
? = $ORACLE_HOME
UNIX 환경이라면 echo $ORACLE_HOME 하시고 그아래 Path 는 같습니다.
 
1. Plan_table 생성
  Explain plan을 sql에 포함해서 수행하면 옵티마이저가 실행 계획까지만
 수립하여 plan_table에 저장해 둔다.
 이 table을 생성하기 위한 script는 ?/rdbms/admin/utlxplan.sql 이다.

2. Index 생성
 테이블 생성 후 수행 속도 향상과 동일한 statement_id가 생성되는 것을
 방지하기 위해  index를 생성한다.                                               
SQL> create unique index plan_index on plan_table(statement_id,id);           
                                                      
3. 이제
 SQL> alter session set sql_trace = true ;
  원하는 sql 문장을 마구 날리자..
 SQL> alter session set sql_trace = faule ;
4. Oracle udmp 로 이동 하면 가장 최근에 떨어진 trace 화일이 있다.
ls -lrt
ora_122338_craft.trc <== 이런식으로..
우리가 보고 이해하기 쉽게 변경 하자 아래와 같이 해서..
tkprof ora_122338_craft.trc 200601232.sql
 
5. 이제 보자..
more 200601232.sql
 
alter session set sql_trace = true

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        0      0.00       0.00          0          0          0           0
Execute      1      0.00       0.02          0          0          0           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        1      0.00       0.02          0          0          0           0
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer goal: CHOOSE
Parsing user id: 130
********************************************************************************
select *
from
 emp

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        2      0.00       0.00          0          2          4          14
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        4      0.00       0.00          0          2          4          14
Misses in library cache during parse: 0
Optimizer goal: CHOOSE
Parsing user id: 130
..
중략..
이제 오라클이 해당 SQL문에 대한 동작 원리가 나왔으니,
연구하자 ㅡ_ㅡ;
여기가 진짜 시작 이겠죠
ㅡ_____________________________________ㅡ+
 
 
SQL 상에서
SQL> explain plan  for select * from emp ;
 
SQL> select * from plan_table ;
 
위에껀 무식 하게 보는거..
 
SQL> explain plan set statement_id = '20060123'
         for select * from emp ;
-- statement_id 를 명시해서 나중에 보기 편하게 하자..

SQL> !more display_plan.sql
col OPERATION format a25
set linesize 120
select lpad(' ',2*(level-1))||operation operation,options, object_name, position
from PLAN_TABLE
start with id = 0 and statement_id = '&statement_id'
connect by prior id = parent_id and
statement_id = '&statement_id';
SQL>@display_plan.sql
Enter value for statement_id: 20060123
old   3: start with id = 0 and statement_id = '&statement_id'
new   3: start with id = 0 and statement_id = '20060123'
Enter value for statement_id: 20060123
old   5: statement_id = '&statement_id'
new   5: statement_id = '20060123'
OPERATION                 OPTIONS                        OBJECT_NAME                      POSITION
------------------------- ------------------------------ ------------------------------ ----------
SELECT STATEMENT
  TABLE ACCESS            FULL                           EMP                                     1
이상..

1497 view

4.0 stars