Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

시다바리

[Oracle] Oracle Hint 본문

Database/Oracle

[Oracle] Oracle Hint

호서아빠 2008. 8. 21. 11:56

Hint란?
  select문을 실행시키면 DB의 옵티마이져가 조건절 또는 join절 등을 고려하여 액세스 경로를 결정한다. 이때 옵티마이저에게 모든 것을 맡기지 않고 사용자가 원하는 보다 좋은 액세스 경로를 선택할 수 있도록 하는 것이 Hint이다.

힌트의 사용 방법
  힌트를 사용하는 방법은 "/*+ */"와 "--+"의 두 가지 방법이 있다.

/*+ */ 여러 라인에 걸쳐 기술할 때 사용.
--+ 오직 한 라인에만 기술할 수 있고 칼럼은 반드시 다음 라인에 기술해야 한다.

예제 : kkaok이라는 테이블이 있고 kkaok_indx라는 인덱스를 힌트에 사용한다고 가정한다.

SELECT /*+ INDEX(kkaok kkaok_indx) */ name,content FROM kkaok WHERE rownum<=2

SELECT --+ INDEX(kkaok kkaok_indx) name,content FROM kkaok WHERE rownum<=2

힌트의 접근방법
  힌트의 접근방법에는 여러 가지가 있다. 이중에 자주 사용되어지는 몇가지만 알아보겠다.

/*+ CLUSTER(table_name) */

Cluster Scan을 선택하도록 지정한다. 따라서 clustered object들에만 적용된다.

/*+ INDEX(table_name index_name) */

지정된 index사용하도록 지정한다.

/*+ INDEX_ASC(table_name index_name) */

지정된 index를 오름차순으로 사용하도록 지정한다. Default로 Index Scan은 오름차순이다

/*+ INDEX_DESC(table_name index_name) */

지정된 index를 내림차순으로 사용하도록 지정한다.

힌트를 사용한 성능향상 테스트
  50000만 건을 입력하고 전체 카운터를 가져오는 테스트를 해보겠다.
 
 
여기서의 소요시간은 서버환경이나 측정하는 방법에 따라 달라 질 수 있다. 하지만 상대적으로 비교해 볼 수는 있는 것이니 어떤 효과가 있는지를 알기에는 충분하다고 생각한다.

1. select count(idx) idx from 테이블명
- 소요시간 : 203ms

2. select /*+ index(테이블명 인덱스명) */ count(idx) idx from 테이블명
- 소요시간 : 15ms

  카운터는 집계함수이지만 hint를 사용하면 처리 속도가 훨씬 빠른 것을 볼 수 있다. 오라클이 최적의 경로로 처리할 거라고 너무 믿지 말자. 힌트를 사용하면 훨씬 나은 결과를 얻을 수 있는 것이다.

[출처] [펌] oracle에서 hint의 사용|작성자 안젤로


/*+ ALL_ROWS */
 - explicitly chooses the cost-based approach to optimize a statement block with a goal of best throughput (that is, minimum total resource consumption)
 - 가장좋은 단위 처리량의 목표로 문 블록을 최적화하기 위해 cost-based 접근 방법을 선택합니다. (즉, 전체적인 최소의 자원 소비)
/*+ CHOOSE */
 - causes the optimizer to choose between the rule-based approach and the cost-based approach for a SQL statement based on the presence of statistics for the tables accessed by the statement
 - 최적자(optimizer)가 그 문에 의해 접근된 테이블을 위해 통계의 존재에 근거를 두는 SQL 문을 위해 rule-based 접근 방법과 cot-based 접근 방법 사이에 선택하게 합니다.
/*+ FIRST_ROWS */
 - explicitly chooses the cost-based approach to optimize a statement block with a goal of best response time (minimum resource usage to return first row)
 - 가장 좋은 응답 시간의 목표로 문 블록을 최적화하기 위해 cost-based 접근 방법을 선택합니다. (첫번째 행을 되돌려 주는 최소의 자원 사용)
/*+ RULE */
 - explicitly chooses rule-based optimization for a statement block
 - 문 블록을 위하여, rule-based 최적화를 고르는Access Methods - 접근 방법
/*+ AND_EQUAL(table index) */
 - explicitly chooses an execution plan that uses an access path that merges the scans on several single-column indexes
 - 그만큼 실행 계획을 선택합니다. 그리고 여럿의 single-column 색인에 그 scan을 합병하는 접근 경로를 사용합니다.
/*+ CLUSTER(table) */
 - explicitly chooses a cluster scan to access the specified table
 - 선택합니다. 그리고, 클러스터는 그 명시된 테이블을 접근하기 위해 살핍니다.
/*+ FULL(table) */
 - explicitly chooses a full table scan for the specified table
 - 그 명시된 테이블을 위하여, 전체 테이블 scan을 고르는
/*+ HASH(table) */
 - explicitly chooses a hash scan to access the specified table
 - 선택합니다. 그리고, 해쉬는 그 명시된 테이블을 접근하기 위해 운율을 살핍니다.
/*+ HASH_AJ(table) */
 - transforms a NOT IN subquery into a hash antijoin to access the specified table
 - 변환, 테이블 접근하는 해쉬 antijoin으로의 NOT IN 부속 조회
/*+ HASH_SJ (table) */
 - transforms a NOT IN subquery into a hash anti-join to access the specified table
 - 변환, 그 명시된 테이블을 접근하는 해쉬 anti-join으로의 NOT IN 부속 조회
/*+ INDEX(table index) */
 - explicitly chooses an index scan for the specified table
 - 그 명시된 테이블을 위하여, 색인 scan을 고르는
/*+ INDEX_ASC(table index) */
 - explicitly chooses an ascending-range index scan for the specified table
 - 그 명시된 테이블을 위하여, ascending-range 색인 scan을 고르는
/*+ INDEX_COMBINE(table index) */
 - If no indexes are given as arguments for the INDEX_COMBINE hint, the optimizer uses whatever Boolean combination of bitmap indexes has the best cost estimate. If particular indexes are given as arguments, the optimizer tries to use some Boolean combination of those particular bitmap indexes.
 - 어떤 색인도 INDEX_COMBINE 암시를 위해 인수로서 주어지지 않는다면, bitmap 색인의 결합이 어떤 부울의를 가장 좋은 수행 난이도 평가를 가지고 있든지 최적자는 이용합니다. 특별한 색인이 인수로서 주어진다면, 최적자는 그 특별한 bitmap 색인의 몇몇의 부울의 결합을 사용하려고 노력합니다.
/*+ INDEX_DESC(table index) */
 - explicitly chooses a descending-range index scan for the specified table
 - 그 명시된 테이블을 위하여, descending-range 색인 scan을 고르는
/*+ INDEX_FFS(table index) */
 - causes a fast full index scan to be performed rather than a full table scan
 - 빠른 전체 색인 scan이 전체 테이블 scan이라기보다는 수행되게 합
/*+ MERGE_AJ (table) */
 - transforms a NOT IN subquery into a merge anti-join to access the specified table
 - 변환, NOT IN 부속 조회, 그 명시된 테이블을 접근하기 위해 anti-join을 합병합니다.
/*+ MERGE_SJ (table) */
 - transforms a correlated EXISTS subquery into a merge semi-join to access the specified table
 - 변환, 관련된 EXISTS 부속 조회, 접근으로 semi-join을 합병합니다 그 명시된 테이블
/*+ ROWID(table) */
 - explicitly chooses a table scan by ROWID for the specified table
 - 그 명시된 테이블을 위하여, ROWID에 의해 테이블 scan을 고르는
/*+ USE_CONCAT */
 - forces combined OR conditions in the WHERE clause of a query to be transformed into a compound query using the UNION ALL set operator
 - 힘은 질의의 WHERE 문절에 있는 UNION ALL 집합 연산자를 사용하는 합성의 질의로 변형되는 OR 조건을 합쳤습니다.

/*+ ORDERED */
 - causes Oracle to join tables in the order in which they appear in the FROM clause
 - 오라클이 어느 것에 순서로 테이블을 결합시키게 합니다.

/*+ STAR */
 - forces the large table to be joined last using a nested-loops join on the index
 - 큰 있는 테이블이 최종 사용/회전율에 nested-loops를 결합시킨 힘은 그 색인에 결합합니다.

/*+ DRIVING_SITE (table) */
 - forces query execution to be done at a different site from that selected by Oracle
 - 힘은 그것과 다른 오라클에 의해 선택된 사이트에 되는 실행을 질의합니다.
/*+ USE_HASH (table) */
 - causes Oracle to join each specified table with another row source with a hash join
 - 오라클이 테이블이 다른 행 자원으로 해쉬 접합으로 명시되면서 각자와 합치게 합니다.
/*+ USE_MERGE (table) */
 - causes Oracle to join each specified table with another row source with a sort-merge join
 - 오라클이 테이블이 다른 행 자원으로 sort-merge 접합으로 명시되면서 각자와 합치게 합니다.
/*+ USE_NL (table) */
 - causes Oracle to join each specified table to another row source with a nested-loops join using the specified table as the inner table
 - 오라클이 그 명시된 테이블을 그 안의 테이블로 사용하는 nested-loops 접합과 각자와 다른 행 자원에 대한 명시된 테이블을 합치게 합니다.

/*+ APPEND */ , /*+ NOAPPEND */
 - specifies that data is simply appended (or not) to a table; existing free space is not used. Use these hints only following the INSERT keyword.
 - 데이타가 테이블로 단순히 덧붙여진다는 (or not)것 명시합니다; 무료인 현존하는 영역은 사용되지 않습니다. 단지 그 삽입 키 핵심어를 따르는 이 암시를 사용하시오.
/*+ NOPARALLEL(table) */
 - disables parallel scanning of a table, even if the table was created with a PARALLEL clause
 - 그 테이블이 PARALLEL 문절로 새로 만들어졌다면 테이블의 평행의 순차 검색을 무능하게 만듭니다.
/*+ PARALLEL(table, instances) */
 - allows you to specify the desired number of concurrent slave processes that can be used for the operation. DELETE, INSERT, and UPDATE operations are considered for parallelization only if the session is in a PARALLEL DML enabled mode. (Use ALTER SESSION PARALLEL DML to enter this mode.)
 - 당신이 그 연산을 위해 사용될 수 있는 동시의 슬레이브(slave) 프로세스의 요구된 수를 명시하는 것을 허락합니다. 그 세션이 가능하게 된 PARALLEL DML에 모드를 있다면, DELETE, INSERT, UPDATE 연산은 단지 parallelization에 대해 고려됩니다. (사용은 이 모드에 들어가기 위해 평행의 세션 DML을 변경합니다.)
/*+ PARALLEL_INDEX */
 - allows you to parallelize fast full index scan for partitioned and nonpartitioned indexes that have the PARALLEL attribute
 - parallelize에 당신에게 빠른 가득한 색인 scan을 허락합니다. 그런데,그것은 PARALLEL 속성을 가지고 있는 색인을 분할했고 nonpartitioned했습니다.
/*+ NOPARALLEL_INDEX */
 - overrides a PARALLEL attribute setting on an index
 - 병렬이 색인을 나아가는 것을 속하게 하는 대체
/*+ CACHE */
 - specifies that the blocks retrieved for the table in the hint are placed at the most recently used end of the LRU list in the buffer cache when a full table scan is performed
 - 그 블록이 찾아서 가져왔다는 것을 명시합니다. 그리고 그 테이블을 위해 그 암시에 놓여집니다. 그런데, 그것은 가장 요즈음 사용된 언제 그 버퍼 캐쉬, 가득한 테이블 scan에 있는 LRU 리스트의 끝입니다. 수행됩니다.
/*+ NOCACHE */
 - specifies that the blocks retrieved for this table are placed at the least recently used end of the LRU list in the buffer cache when a full table scan is performed
  - 그 명시합니다. 그리고, 그 블록은 이 테이블을 위해 검색되면서 요즈음 사용된 언제 그 버퍼 캐쉬, 가득한 테이블 scan에 있는 LRU 리스트의 가장 작은 끝에 놓여집니다. 수행됩니다.
/*+ MERGE (table) */
 - causes Oracle to eval!uate complex views or subqueries before the surrounding query
 - 오라클이 그 둘러싸는 질의 전에 복잡한 뷰나 부속 조회를 평가하게 합니다.
/*+ NO_MERGE (table) */
 - causes Oracle not to merge mergeable views
 - 오라클이 mergeable 뷰를 합병하지 않게 하지 않습니다
/*+ PUSH_JOIN_PRED (table) */
 - causes the optimizer to eval!uate, on a cost basis, whether or not to push individual join predicates into the view
 - 개개 접합을 미는 것이 그 뷰 안으로 단정 하든 간에 비용 방식으로 최적자가 평가하게 합니다.
/*+ NO_PUSH_JOIN_PRED (table) */
 - Prevents pushing of a join predicate into the view
 - 접합 술부 중에서 그 뷰로 밀면서, 막는
/*+ PUSH_SUBQ */
 - causes nonmerged subqueries to be eval!uated at the earliest possible place in the execution plan
 - 원인은 그 실행 계획에서의 가장 이른 가능한 장소에 평가되는 부속 조회를 nonmerged했습니다.
/*+ STAR_TRANSFORMATION */
 - makes the optimizer use the best plan in which the transformation has been used.
 - 최적자가 그 변형이 사용된 가장 좋은 계획을 사용하는 제작

[출처] ## HINT|작성자 안젤로

Comments