说明计划显示了不同的联接类型

时间:2018-12-25 09:45:35

标签: database oracle database-administration sql-execution-plan sqlperformance

当我获得下面查询的执行计划时,即使我写右外部联接,它也会写左外部联接。

select * from employees e right outer join departments d
using(department_id);

这是输出:

--------------------------------------------------------------------------------------------
| Id  | Operation                    | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |             |   122 | 10980 |     6  (17)| 00:00:01 |
|   1 |  MERGE JOIN OUTER            |             |   122 | 10980 |     6  (17)| 00:00:01 |
|   2 |   TABLE ACCESS BY INDEX ROWID| DEPARTMENTS |    27 |   567 |     2   (0)| 00:00:01 |
|   3 |    INDEX FULL SCAN           | DEPT_ID_PK  |    27 |       |     1   (0)| 00:00:01 |
|*  4 |   SORT JOIN                  |             |   107 |  7383 |     4  (25)| 00:00:01 |
|   5 |    TABLE ACCESS FULL         | EMPLOYEES   |   107 |  7383 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("D"."DEPARTMENT_ID"="E"."DEPARTMENT_ID"(+))
       filter("D"."DEPARTMENT_ID"="E"."DEPARTMENT_ID"(+))

如果我使用左外部联接,则这次显示右外部联接。是什么原因呢?

select * from employees e left outer join departments d using(department_id);


-------------------------------------------------------------------------------------
| Id  | Operation             | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |             |   107 |  9630 |     6   (0)| 00:00:01 |
|*  1 |  HASH JOIN RIGHT OUTER|             |   107 |  9630 |     6   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL   | DEPARTMENTS |    27 |   567 |     3   (0)| 00:00:01 |
|   3 |   TABLE ACCESS FULL   | EMPLOYEES   |   107 |  7383 |     3   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID"(+)) 

谢谢。

0 个答案:

没有答案