hash join 外连接改变驱动表:
select /*+ swap_join_inputs(e) use_hash(e,d)*/ e.ename,e.job,d.dname from emp e left join dept d on e.deptno=d.deptno
SQL> explain plan for select /*+ swap_join_inputs(e) use_hash(e,d)*/ e.ename,e.job,d.dname from emp e left join dept d on e.deptno=d.deptno ;
已解释。
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3387915970
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 420 | 6 (0)| 00:00:01 |
|* 1 | HASH JOIN OUTER | | 14 | 420 | 6 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 238 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| DEPT | 4 | 52 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("E"."DEPTNO"="D"."DEPTNO"(+))
已选择15行。
select /*+ swap_join_inputs(d) use_hash(e,d)*/ e.ename,e.job,d.dname from emp e left join dept d on e.deptno=d.deptno
SQL> explain plan for select /*+ swap_join_inputs(d) use_hash(e,d)*/ e.ename,e.job,d.dname from emp e left join dept d on e.deptno=d.deptno ;
已解释。
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 4261033907
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 420 | 6 (0)| 00:00:01 |
|* 1 | HASH JOIN RIGHT OUTER| | 14 | 420 | 6 (0)| 00:00:01 |
| 2 | TABLE ACCESS FULL | DEPT | 4 | 52 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL | EMP | 14 | 238 | 3 (0)| 00:00:01 |
------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("E"."DEPTNO"="D"."DEPTNO"(+))
已选择15行。