2.13 NFOJ* (Native Full Outer Join) : Full Outer 조인시 중복 Scan되는 테이블을 제거하라

  • 10g R2 버전에서 Full Outer 조인을 실행하면 Union All로 분리 되어 Outer 조인과 Anti Join이 각각
    수행된다. 이것은 파라미터 _optimizer _native_full_outer join가 off로 설정되어 있기 때문이다 하지만
    11g부터는 Default가 Force로 설정되어 있으므로 Union All과 Anti Join이 사라진다 향상된 Full Outer Join을 살펴보자
{code:SQLtitle= _optimizer_native_full_outer_join=FORCEborderStyle=solid}
alter session set "_optimizer_native_full_outer_join" = FORCE;

ALTER SESSION SET EVENTS '10053 trace name context forever, level 1';

SELECT /*+ gather_plan_statistics */
a.employee_id, a.first_name, a.last_name, b.department_name
FROM employee a FULL OUTER JOIN department b
ON (a.department_id = b.department_id) ;

ALTER SESSION SET EVENTS '10053 trace name context off';
============
Plan Table
============











---+







---+

IdOperationNameRowsBytesCostTime











---+







---+

0SELECT STATEMENT5
1VIEWVW_FOJ_01226832500:00:01
2HASH JOIN FULL OUTER1224392500:00:01
3TABLE ACCESS FULLDEPARTMENT27378200:00:01
4TABLE ACCESS FULLEMPLOYEE1072354200:00:01











---+







---+
Predicate Information:





--2 - access("A"."DEPARTMENT_ID"="B"."DEPARTMENT_ID")


||* Union All과 Anti 조인이 사라졌다. 같은 테이블을 2 번씩 Scan하는 비효율이 제거되었다
-이 기능은 Native Hash Full Outer Join 이라고 불린다 
-Native Full Outer Join이 발생하면 VW_FOJ_0(Full Outer Join)뷰가 생성된다.
-Native Hash Full Outer Join은 힌트로도 제어가 가능
/*+ NO_NATIVE_FULL_OUTER_JOIN */ Native Hash Full Outer Join 기능 제거
/*+ NATIVE_FULL_OUTER_JOIN */ Native Hash Full Outer Join 기능 사용|
|* Native Hash Full Outer Join 기능 때문에 Query Transformation을 방해하는 것을 여러 곳에서 볼 수 있다.
{code:SQL|title= Query transformations |borderStyle=solid}
**************************
Query transformations (QT)
**************************
JF: Checking validity of join factorization for query block SEL$1 (#0)
JF: Bypassed: not a UNION or UNION-ALL query block.
ST: not valid since star transformation parameter is FALSE
TE: Checking validity of table expansion for query block SEL$1 (#0)
TE: Bypassed: Full outer-joined table.
Check Basic Validity for Non-Union View for query block SEL$1 (#0)
JPPD:     JPPD bypassed: View has full outer join.                           <--
JF: Checking validity of join factorization for query block SEL$2 (#0)
JF: Bypassed: not a UNION or UNION-ALL query block.
ST: not valid since star transformation parameter is FALSE
TE: Checking validity of table expansion for query block SEL$2 (#0)
TE: Bypassed: No partitioned table in query block.
CBQT bypassed for query block SEL$2 (#0): no complex view, sub-queries or UNION (ALL) queries.
CBQT: Validity checks failed for 9kpbkmnjhbsrn.
CSE: Considering common sub-expression elimination in query block SEL$2 (#0)
*************************
Common Subexpression elimination (CSE)
*************************
CSE: Considering common sub-expression elimination in query block SEL$1 (#0)
*************************
Common Subexpression elimination (CSE)
*************************
CSE:     CSE not performed on query block SEL$1 (#0).
CSE:     CSE not performed on query block SEL$2 (#0).
OBYE:   Considering Order-by Elimination from view SEL$2 (#0)
***************************
Order-by elimination (OBYE)
***************************
OBYE:     OBYE bypassed: no order by to eliminate.
CVM: Considering view merge in query block SEL$2 (#0)
OJE: Begin: find best directive for query block SEL$2 (#0)
OJE: OJ to IJ validity check falied.
OJE: End: finding best directive for query block SEL$2 (#0)
CVM:   Checking validity of merging in query block SEL$1 (#0)
CVM: Considering view merge in query block SEL$1 (#0)
OJE: Begin: find best directive for query block SEL$1 (#0)
OJE: End: finding best directive for query block SEL$1 (#0)
SVM:     SVM bypassed: Full Outer Join.                                    <--
SLP: Removed select list item QCSJ_C000000000300000 from query block SEL$1
SLP: Removed select list item QCSJ_C000000000300001 from query block SEL$1
query block SEL$2 (#0) unchanged
Considering Query Transformations on query block SEL$2 (#0)
**************************
Query transformations (QT)
**************************
JF: Checking validity of join factorization for query block SEL$1 (#0)
JF: Bypassed: not a UNION or UNION-ALL query block.
ST: not valid since star transformation parameter is FALSE
TE: Checking validity of table expansion for query block SEL$1 (#0)
TE: Bypassed: Full outer-joined table.
Check Basic Validity for Non-Union View for query block SEL$1 (#0)
JPPD:     JPPD bypassed: View has full outer join.                           <--

  • 이처럼 Native Full Outer Join 기능 사용시 Query Transformation이 발생하지 않는 경우가 있다.
    이점만 주의한다면 Native Full Outer Join은 최적의 선택이 될 것이다.