SELECT /*+ USE_NL(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 4 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 10 | 280 | 4 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 140 | 1 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | T1N2 | 10 | | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2N2 | 10 | | 1 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID | T2 | 1 | 14 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
SELECT /*+ NO_USE_NL(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 3 (34)| 00:00:01 |
|* 1 | HASH JOIN | | 10 | 280 | 3 (34)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 140 | 1 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | T1N2 | 10 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| T2 | 10 | 140 | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2N2 | 10 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
-- 조인 순서 별도 지정 필요 (LEADING)
SELECT /*+ USE_NL_WITH_INDEX(T1 T1N2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 0;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 17 | 476 | 2 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 17 | 476 | 2 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 140 | 1 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | T1N2 | 10 | | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2N4 | 11 | | 1 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID | T2 | 11 | 154 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
SELECT /*+ USE_NL_WITH_INDEX(T1 T1N3) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N3 = 0;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 392 | 2 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 14 | 392 | 2 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| T1 | 55 | 770 | 1 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | T1N3 | 100 | | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2N4 | 11 | | 1 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID | T2 | 11 | 154 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
-- 드라이빙 테이블의 처리주관 인덱스 지정할때 사용
SELECT /*+ USE_MERGE(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 4 (50)| 00:00:01 |
| 1 | MERGE JOIN | | 10 | 280 | 4 (50)| 00:00:01 |
| 2 | SORT JOIN | | 10 | 140 | 2 (50)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 140 | 1 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | T1N2 | 10 | | 1 (0)| 00:00:01 |
|* 5 | SORT JOIN | | 10 | 140 | 2 (50)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID| T2 | 10 | 140 | 1 (0)| 00:00:01 |
|* 7 | INDEX RANGE SCAN | T2N2 | 10 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
-- 조인 순서 별도 지정 필요
SELECT /*+ NO_USE_MERGE(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 3 (34)| 00:00:01 |
|* 1 | HASH JOIN | | 10 | 280 | 3 (34)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 140 | 1 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | T1N2 | 10 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| T2 | 10 | 140 | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2N2 | 10 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
SELECT /*+ USE_HASH(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 3 (34)| 00:00:01 |
|* 1 | HASH JOIN | | 10 | 280 | 3 (34)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 140 | 1 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | T1N2 | 10 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| T2 | 10 | 140 | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2N2 | 10 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
-- 통계가 없는 경우 (인라인뷰)에 한해서 조인 순서 별도 지정 (LEADING)
SELECT /*+ NO_USE_HASH(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 280 | 4 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 10 | 280 | 4 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 140 | 1 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | T1N2 | 10 | | 1 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | T2N2 | 10 | | 1 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID | T2 | 1 | 14 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
- 강좌 URL : http://www.gurubee.net/lecture/4443
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.