h2.11. 집합 연산을 조인으로 변환
select job,mgr from emp
minus
select job,mgr from emp
where deptno=10;
Execution Plan
----------------------------------------------------------
Plan hash value: 3686975449
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 213 | 8 (63)| 00:00:01 |
| 1 | MINUS | | | | | |
| 2 | SORT UNIQUE | | 14 | 168 | 4 (25)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 168 | 3 (0)| 00:00:01 |
| 4 | SORT UNIQUE | | 3 | 45 | 4 (25)| 00:00:01 |
|* 5 | TABLE ACCESS FULL| EMP | 3 | 45 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter("DEPTNO"=10)
SQL> alter session set "_convert_set_to_join" = true;
select job,mgr from emp
minus
select job,mgr from emp
where deptno=10;
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 213 | 8 (63)| 00:00:01 |
| 1 | MINUS | | | | | |
| 2 | SORT UNIQUE | | 14 | 168 | 4 (25)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 168 | 3 (0)| 00:00:01 |
| 4 | SORT UNIQUE | | 3 | 45 | 4 (25)| 00:00:01 |
|* 5 | TABLE ACCESS FULL| EMP | 3 | 45 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter("DEPTNO"=10)
select distinct job, mgr from emp e
where not exists (
select 'x' from emp
where deptno = 10
and sys_op_map_nonnull(job) = sys_op_map_nonnull(e.job)
and sys_op_map_nonnull(mgr) = sys_op_map_nonnull(e.mgr)
) ;
Execution Plan
----------------------------------------------------------
Plan hash value: 4030040631
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 162 | 8 (25)| 00:00:01 |
| 1 | HASH UNIQUE | | 6 | 162 | 8 (25)| 00:00:01 |
|* 2 | HASH JOIN ANTI | | 6 | 162 | 7 (15)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 168 | 3 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| EMP | 3 | 45 | 3 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access(SYS_OP_MAP_NONNULL("JOB")=SYS_OP_MAP_NONNULL("E"."JOB")
AND SYS_OP_MAP_NONNULL("MGR")=SYS_OP_MAP_NONNULL("E"."MGR"))
4 - filter("DEPTNO"=10)