SQL> @?/rdbms/admin/utlxplan.sql -- ? 는 $ORACLE HOME 디렉토리 대체하는 기호
SQL> SELECT owner, synonym_name, table_owner, table_name
2 FROM all_synonyms
3 WHERE synonym_name = 'PLAN_TABLE'
4 ;
OWNER SYNONYM_NAME TABLE_OWNER TABLE_NAME
------- -------------- ---------------- -----------------
PUBLIC PLAN_TABLE SYS PLAN_TABLE$
SQL> explain plan set statement id = 'queryl' for -- statement id = 'queryl' 생략가능
2 select * from emp where empno = 7900;
해석되었습니다.
h5.(2) plan_table 포맷팅
SQL> SELECT lpad(id, 4, ' ') || NVL(LPAD(parent_id, 6, ' '), ' ')
2 || ' ' || lpad(' ', (LEVEL - 1) * 2, ' ')
3 || operation || NVL2(options, ' ( ' || options || ' ) ', '')
4 || NVL2(object_name, ' OF '''
5 || object_owner || '.' || object_name, NULL)
6 || NVL2(object_name, '''', '')
7 || decode(parent_id, NULL, ' Optimizer=' || optimizer)
8 || (CASE
9 WHEN cost IS NULL AND cardinality IS NULL AND bytes IS NULL
10 THEN ''
11 ELSE '(' || NVL2(cost, 'Cost=' || cost, '')
12 || NVL2(cardinality, 'Card=' || cardinality, '')
13 || NVL2(bytes, 'Bytes=' || bytes, '')
14 || ')' END) "Execution Plan"
15 FROM plan_table p
16 START WITH statement_id = 'query1' AND id = 0
17 CONNECT BY PRIOR id = parent_id AND PRIOR statement_id = statement_id
18 ORDER BY id;
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1 Card=1 Bytes=32)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'EMP' (Cost=1 Card=1 Bytes=32)
2 1 INDEX (UNIQUE SCAN) OF 'EMP_PK' (Cost=0 Card=1)
SQL> SET LINESIZE 200
SQL> @?/rdbms/admin/utlxpls
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost ( %CPU) |
| 0 | SELECT STATEMENT | | 1 | 32 | 1 (0) |
| 1 | TABLE ACCESS BY INDEX ROWID | EMP | 1 | 32 | 1 (0) |
|* 2 | INDEX UNIQUE SCAN | EMP_PK | 1 | | 0 (0) |
---------------------------------------------------------------------------------------
PLAN TABLE OUTPUT
------------------------------
Plan hash value : 4024650034
Predicate Information (identified by operation id) :
2 - access ( "EMPNO" =7900 )
예를 들어,인텍스 구조를 바꾸고자 할 때 해당 인텍스를 시용하는 쿼리 목록을 뽑아 사 전점검을 실시할 수 있다. 또는 오브젝트 통계정보가 바뀌어 어느 날 갑자기 성능이 나빠진 쿼리가 생겼을 때 이전 실행계획을 빨리 확인하고 예전과 같은 방식으로 수행되도록 빠르게 튜닝할 수 있다.
CREATE TABLE SQL repository(SQL id VARCHAR2(30), SQL text VARCHAR2(4000));
BEGIN
FOR c IN (SELECT sql_id, sql_text frαn sql_repository)
LOOP
EXECUTE IMMEDIATE 'explain plan set statement_id = ''' || c.sql_id
|| ''' into sql_plan_repository'
|| ' for ' || c.sql_text;
COMMIT;
END LOOP;
END;
/