(on) Hints for Join Operations

USE_NLNO_USE_NL
{code:sqltitleBGColor=#FFFFFFtitle=!http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/img/use_nl_hint.gif!borderStyle=solid}
SELECT /*+ USE_NL(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;






















--

IdOperationNameRowsBytesCost (%CPU)Time






















--

0SELECT STATEMENT102804 (0)00:00:01
1NESTED LOOPS
2NESTED LOOPS102804 (0)00:00:01
3TABLE ACCESS BY INDEX ROWIDT1101401 (0)00:00:01
  • 4
INDEX RANGE SCANT1N2101 (0)00:00:01
  • 5
INDEX RANGE SCANT2N2101 (0)00:00:01
  • 6
TABLE ACCESS BY INDEX ROWIDT21141 (0)00:00:01






















--

|{code:sql|titleBGColor=#FFFFFF|title=!http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/img/no_use_nl_hint.gif!|borderStyle=solid}
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)

|

USE_NL_WITH_INDEX
{code:sqltitleBGColor=#FFFFFFtitle=!http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/img/use_nl_with_index_hint.gif!borderStyle=solid}
SELECT /*+ USE_NL_WITH_INDEX(T1 T1N2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 0;






















--

IdOperationNameRowsBytesCost (%CPU)Time






















--

0SELECT STATEMENT174762 (0)00:00:01
1NESTED LOOPS
2NESTED LOOPS174762 (0)00:00:01
3TABLE ACCESS BY INDEX ROWIDT1101401 (0)00:00:01
  • 4
INDEX RANGE SCANT1N2101 (0)00:00:01
  • 5
INDEX RANGE SCANT2N4111 (0)00:00:01
6TABLE ACCESS BY INDEX ROWIDT2111541 (0)00:00:01






















--

SELECT /*+ USE_NL_WITH_INDEX(T1 T1N3) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N3 = 0;






















--

IdOperationNameRowsBytesCost (%CPU)Time






















--

0SELECT STATEMENT143922 (0)00:00:01
1NESTED LOOPS
2NESTED LOOPS143922 (0)00:00:01
3TABLE ACCESS BY INDEX ROWIDT1557701 (0)00:00:01
  • 4
INDEX RANGE SCANT1N31001 (0)00:00:01
  • 5
INDEX RANGE SCANT2N4111 (0)00:00:01
6TABLE ACCESS BY INDEX ROWIDT2111541 (0)00:00:01






















--

-- 드라이빙 테이블의 처리주관 인덱스 지정할때 사용

|

||USE_MERGE||NO_USE_MERGE||
|{code:sql|titleBGColor=#FFFFFF|title=!http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/img/use_merge_hint.gif!|borderStyle=solid}
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 |
--------------------------------------------------------------------------------------

-- 조인 순서 별도 지정 필요

|

!http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/img/no_use_merge_hint.gif!


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 |
-------------------------------------------------------------------------------------

|

USE_HASHNO_USE_HASH
{code:sqltitleBGColor=#FFFFFFtitle=!http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/img/use_hash_hint.gif!borderStyle=solid}
SELECT /*+ USE_HASH(T1 T2) */ *
FROM T1, T2
WHERE T1.N4 = T2.N4
AND T1.N2 = 10
AND T2.N2 = 10;






















-

IdOperationNameRowsBytesCost (%CPU)Time






















-

0SELECT STATEMENT102803 (34)00:00:01
  • 1
HASH JOIN102803 (34)00:00:01
2TABLE ACCESS BY INDEX ROWIDT1101401 (0)00:00:01
  • 3
INDEX RANGE SCANT1N2101 (0)00:00:01
4TABLE ACCESS BY INDEX ROWIDT2101401 (0)00:00:01
  • 5
INDEX RANGE SCANT2N2101 (0)00:00:01






















-

-- 통계가 없는 경우 (인라인뷰)에 한해서 조인 순서 별도 지정 (LEADING)

|{code:sql|titleBGColor=#FFFFFF|title=!http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/img/no_use_hash_hint.gif!|borderStyle=solid}
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 |
--------------------------------------------------------------------------------------

|