사례 1. SQL분석 시 차이
[개요]
Optimizer mode가 Rule base일 때와 Cost base일 때 SQL을
해석함에 있어 어떤 차이가 있는지를 구체적으로 알아 보고자
합니다.
해석함에 있어 어떤 차이가 있는지를 구체적으로 알아 보고자
합니다.
- 인덱스정보
EC_TASK : EC_TASK_PK : COURSE_CODE + TASK_NO
EC_TASK_TERM : EC_TASK_TERM_PK : COURSE_CODE + YEAR + COURSE_SQ_NO + TASK_NO
EC_TASK_TERM : EC_TASK_TERM_IDX00 : COURSE_CODE + TASK_NO + YEAR + COURSE_SQ_NO
EC_TASK : EC_TASK_PK : COURSE_CODE + TASK_NO
EC_TASK_TERM : EC_TASK_TERM_PK : COURSE_CODE + YEAR + COURSE_SQ_NO + TASK_NO
EC_TASK_TERM : EC_TASK_TERM_IDX00 : COURSE_CODE + TASK_NO + YEAR + COURSE_SQ_NO
SQL#01_01
SELECT *
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND A.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1;
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND A.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1;
EC_TASK_PK : COURSE_CODE(= 36) + TASK_NO
※ 가정 및 요구사항
1) Rule Base로 가정
2) 위의 SQL에 대한 실행계획 확인 및 분석
2) 위의 SQL에 대한 실행계획 확인 및 분석
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.01 0.00 0 0 0 0
Fetch 6 0.00 0.00 0 30 0 5
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 8 0.01 0.00 0 30 0 5
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.01 0.00 0 0 0 0
Fetch 6 0.00 0.00 0 30 0 5
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 8 0.01 0.00 0 30 0 5
Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: CHOOSE
5 TABLE ACCESS (BY INDEX ROWID) OF 'EC_TASK_TERM' (B)
13 NESTED LOOPS
7 TABLE ACCESS (BY INDEX ROWID) OF 'EC_TASK' (A)
7 INDEX (RANGE SCAN) OF 'EC_TASK_PK' (UNIQUE)
5 INDEX (RANGE SCAN) OF 'EC_TASK_TERM_IDX00' (NON-UNIQUE)
SQL#01_02
SELECT *
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND A.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1
AND B.,COURSE_CODE = 36 <---------
AND A.TASK_NO = 1; <------
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND A.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1
AND B.,COURSE_CODE = 36 <---------
AND A.TASK_NO = 1; <------
EC_TASK_PK : COURSE_CODE(= 36) + TASK_NO(= 1)
※ 가정 및 요구사항
1) Cost Base로 가정
- 이를 위해서 다음 명령의 실행을 먼저 하도록 합니다:
SQL> ANALYZE TABLE EC_TASK COMPUTE STATISTICS;
SQL> ANALYZE TABLE EC_TASK_TERM COMPUTE STATISTICS;
SQL> ANALYZE TABLE EC_TASK_TERM COMPUTE STATISTICS;
2) 위의 SQL에 대한 실행계획에 대한 확인 및 분석을 통해
Rule Base에서의 실행계획과의 차이점 비교
Rule Base에서의 실행계획과의 차이점 비교
Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: CHOOSE
5 NESTED LOOPS
1 TABLE ACCESS GOAL: ANALYZED (BY INDEX ROWID) OF 'EC_TASK' (A)
1 INDEX GOAL: ANALYZED (UNIQUE SCAN) OF 'EC_TASK_PK' (UNIQUE)
5 TABLE ACCESS GOAL: ANALYZED (BY INDEX ROWID) OF 'EC_TASK_TERM' (B)
5 INDEX GOAL: ANALYZED (RANGE SCAN) OF 'EC_TASK_TERM_IDX00'(NON-UNIQUE)
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: CHOOSE
5 NESTED LOOPS
1 TABLE ACCESS GOAL: ANALYZED (BY INDEX ROWID) OF 'EC_TASK' (A)
1 INDEX GOAL: ANALYZED (UNIQUE SCAN) OF 'EC_TASK_PK' (UNIQUE)
5 TABLE ACCESS GOAL: ANALYZED (BY INDEX ROWID) OF 'EC_TASK_TERM' (B)
5 INDEX GOAL: ANALYZED (RANGE SCAN) OF 'EC_TASK_TERM_IDX00'(NON-UNIQUE)
Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: CHOOSE
5 TABLE ACCESS (BY INDEX ROWID) OF 'EC_TASK_TERM' (B)
13 NESTED LOOPS
7 TABLE ACCESS (BY INDEX ROWID) OF 'EC_TASK' (A)
7 INDEX (RANGE SCAN) OF 'EC_TASK_PK' (UNIQUE)
5 INDEX (RANGE SCAN) OF 'EC_TASK_TERM_IDX00' (NON-UNIQUE)
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: CHOOSE
5 TABLE ACCESS (BY INDEX ROWID) OF 'EC_TASK_TERM' (B)
13 NESTED LOOPS
7 TABLE ACCESS (BY INDEX ROWID) OF 'EC_TASK' (A)
7 INDEX (RANGE SCAN) OF 'EC_TASK_PK' (UNIQUE)
5 INDEX (RANGE SCAN) OF 'EC_TASK_TERM_IDX00' (NON-UNIQUE)
SQL#01_03
SELECT *
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND B.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1;
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND B.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1;
내부적으로 다음과 같은 형식으로 만들어진다.
SELECT *
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND B.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1
AND A.COURSE_CODE = 36
AND A.TASK_NO = 1;
SELECT *
FROM EC_TASK A, EC_TASK_TERM B
WHERE A.COURSE_CODE = B.COURSE_CODE
AND A.TASK_NO = B.TASK_NO
AND B.COURSE_CODE = 36
AND B.TASK_NO = 1
AND B.COURSE_SQ_NO = 1
AND A.COURSE_CODE = 36
AND A.TASK_NO = 1;
※ 가정 및 요구사항
1) Cost Base로 가정
2) 위의 SQL에 대한 실행 확인 및 분석
2) 위의 SQL에 대한 실행 확인 및 분석
Rows Execution Plan
------- ---------------------------------------------------
0 SELECT STATEMENT GOAL: CHOOSE
5 NESTED LOOPS
1 TABLE ACCESS GOAL: ANALYZED (BY INDEX ROWID) OF 'EC_TASK' (A)
1 INDEX GOAL: ANALYZED (UNIQUE SCAN) OF 'EC_TASK_PK' (UNIQUE)
5 TABLE ACCESS GOAL: ANALYZED (BY INDEX ROWID) OF 'EC_TASK_TERM' (B)
5 INDEX GOAL: ANALYZED (RANGE SCAN) OF 'EC_TASK_TERM_IDX00' (NON-UNIQUE)
'04번. IT 힌트얻기 > ▶ DB Tuning' 카테고리의 다른 글
[Tuning] optimizer_mode (0) | 2011.10.10 |
---|---|
[Tuning] 인덱스 매칭률 (0) | 2011.10.10 |
[Tuning] SQL Trace (0) | 2011.10.10 |
[실행계획] Exercise_04 (0) | 2011.10.07 |
[실행계획] Exercise_03 (0) | 2011.10.06 |