TIL/DB

[Oracle] APPEND 힌트와 Direct Load Insert

JoJobum 2024. 2. 14.

APPEND Hint란?

공식 문서의 APPEND Hint 정의

💡 The APPEND hint instructs the optimizer to use direct-path INSERT with the subquery syntax of the INSERT statement.
Conventional INSERT is the default in serial mode. In serial mode, direct path can be used only if you include the APPEND hint.Direct-path INSERT is the default in parallel mode. In parallel mode, conventional insert can be used only if you specify the NOAPPEND hint.
The decision whether the INSERT will go parallel or not is independent of the APPEND hint.
In direct-path INSERT, data is appended to the end of the table, rather than using existing space currently allocated to the table. As a result, direct-path INSERT can be considerably faster than conventional INSERT.
The APPEND hint is only supported with the subquery syntax of the INSERT statement, not the VALUES clause. If you specify the APPEND hint with the VALUES clause, it is ignored and conventional insert will be used. To use direct-path INSERT with the VALUES clause, refer to "APPEND_VALUES Hint".

 

위 정의를 요약하면

옵티마이저에게 Direct Path I/O 사용하여 Insert 하도록 지시하는 힌트

Direct Path Insert 수행시 테이블이 현재 할당되어 있는 공간이 아닌 테이블의 끝에 데이터 추가됨 ⇒ Conventional Path I/O 에 비해 빠를 수 있음

 

Direct Path I/O? Conventional Path I/O?

오라클에는 Direct Path I/O 와 Conventional Path I/O 라는 개념 존재

 

 

둘의 차이는 데이터 블록을 읽고 쓸 때 cache buffer를 거치냐 안거치냐의 차이

 

Direct Path Insert의 장단점

장점

conventional Path I/O 와 다르게 버퍼를 거치지 않기에 빠름

단점

테이블에 대한 배타 락이 걸리기에 Insert를 종료할 때까지 다른 트랜잭션에서 DML(insert/update/delete)를 동시 수행할 수 없음

비파티션 테이블에 대한 Direct Path Insert는 테이블의 기존의 빈 영어에 Insert를 하는 것이 아니라 새로운 영역을 할당해 Insert하기에 더 많은 영역 사용 (Insert 중에 temporary segment로 불러서 작업 후 Insert 종료 후에 기존의 테이블에 Merge)

 

예시

Insert 
/*+ APPEND PARARREL(A 8) */
Into 테이블1 A
(
	-- 컬럼들
)
Select /*+ FULL(B) PARARREL(A 8) */
	-- 컬럼들
FROM 테이블2 B
Where 조건들

위와 같이 사용

 

관련 주의점

2개의 Step으로 구성된 배치 Job이 있는데 특정 테이블에 각각 다른 테이블에서 가져온 대량의 데이터를 적재하는 건이였다.

2번 Step이 1번 Step에 의존관계를 가지고 있었다 (1번 Step이 수행되고 수행)

내용 상으로는 굳이 의존관계를 가질 필요가 없는데 왜 그럴까? 라고 생각을 했었는데

APPEND 힌트를 사용하기에 Insert 하고자 하는 테이블에 배타 락이 걸려 동시에 테이블에 접근할 수 없기 때문이였다.

 

 

Ref)

Comments (oracle.com)

오라클(Oracle) - APPEND 와 APPEND_VALUES 힌트 | Hoing

[Oracle] 오라클 Direct Path I/O, Direct Path Insert (jungmina.com)

반응형

'TIL > DB' 카테고리의 다른 글

[DB] soft delete vs hard delete (feat. isDeleted)  (2) 2022.09.05
[DB] Delete vs Truncate vs Drop  (0) 2022.08.17
[DB] Postgres 명령어  (0) 2022.08.17
[DB] 외래키를 사용해? 말어?  (0) 2022.07.16

댓글