您的位置:首页 > 数据库 > Oracle

oracle 表 的 join 方式-1

2014-10-01 21:26 316 查看
SQL> select /*+ ordered use_nl ( e d)*/ d.dname,e.deptno,e.ename from emp_sys e,dept_sys d where e.deptno=d.deptno;

DNAME              DEPTNO ENAME

-------------- ---------- ----------

RESEARCH               20 SMITH

SALES                  30 ALLEN

SALES                  30 WARD

RESEARCH               20 JONES

SALES                  30 MARTIN

SALES                  30 BLAKE

ACCOUNTING             10 CLARK

RESEARCH               20 SCOTT

ACCOUNTING             10 KING

SALES                  30 TURNER

RESEARCH               20 ADAMS

SALES                  30 JAMES

RESEARCH               20 FORD

ACCOUNTING             10 MILLER

已选择14行。

执行计划

----------------------------------------------------------

Plan hash value: 3319758173

-------------------------------------------------------------------------------

| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |          |    14 |   588 |     8   (0)| 00:00:01 |

|   1 |  NESTED LOOPS      |          |    14 |   588 |     8   (0)| 00:00:01 |

|   2 |   TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|*  3 |   TABLE ACCESS FULL| DEPT_SYS |     1 |    22 |     0   (0)| 00:00:01 |

-------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   3 - filter("E"."DEPTNO"="D"."DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

         47  consistent gets

          0  physical reads

          0  redo size

        853  bytes sent via SQL*Net to client

        415  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

         14  rows processed

SQL> select /*+ use_nl ( e d)*/ d.dname,e.deptno,e.ename from emp_sys e,dept_sys d where e.deptno=d.deptno;

DNAME              DEPTNO ENAME

-------------- ---------- ----------

ACCOUNTING             10 CLARK

ACCOUNTING             10 KING

ACCOUNTING             10 MILLER

RESEARCH               20 SMITH

RESEARCH               20 JONES

RESEARCH               20 SCOTT

RESEARCH               20 ADAMS

RESEARCH               20 FORD

SALES                  30 ALLEN

SALES                  30 WARD

SALES                  30 MARTIN

SALES                  30 BLAKE

SALES                  30 TURNER

SALES                  30 JAMES

已选择14行。

执行计划

----------------------------------------------------------

Plan hash value: 1972627781

-------------------------------------------------------------------------------

| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |          |    14 |   588 |     5   (0)| 00:00:01 |

|   1 |  NESTED LOOPS      |          |    14 |   588 |     5   (0)| 00:00:01 |

|   2 |   TABLE ACCESS FULL| DEPT_SYS |     4 |    88 |     2   (0)| 00:00:01 |--与上面相比驱动表变成了[b]DEPT_SYS ,差在order.[/b]

|*  3 |   TABLE ACCESS FULL| EMP_SYS  |     4 |    80 |     1   (0)| 00:00:01 |

-------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   3 - filter("E"."DEPTNO"="D"."DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          7  recursive calls

          0  db block gets

         25  consistent gets

          0  physical reads

          0  redo size

        764  bytes sent via SQL*Net to client

        415  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          2  sorts (memory)

          0  sorts (disk)

         14  rows processed

=============================================================================================================

SQL> select /*+ ordered use_nl ( e d)*/ d.dname,e.deptno,e.ename from emp_sys e,dept_sys d where e.deptno=d.deptno;

DNAME              DEPTNO ENAME

-------------- ---------- ----------

RESEARCH               20 SMITH

SALES                  30 ALLEN

SALES                  30 WARD

RESEARCH               20 JONES

SALES                  30 MARTIN

SALES                  30 BLAKE

ACCOUNTING             10 CLARK

RESEARCH               20 SCOTT

ACCOUNTING             10 KING

SALES                  30 TURNER

RESEARCH               20 ADAMS

SALES                  30 JAMES

RESEARCH               20 FORD

ACCOUNTING             10 MILLER

已选择14行。

执行计划

----------------------------------------------------------

Plan hash value: 3319758173

------------------------------------------------------------------------------

| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |          |    14 |   588 |     8   (0)| 00:00:01 |

|   1 |  NESTED LOOPS      |          |    14 |   588 |     8   (0)| 00:00:01 |

|   2 |   TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|*  3 |   TABLE ACCESS FULL| DEPT_SYS |     1 |    22 |     0   (0)| 00:00:01 |

-------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   3 - filter("E"."DEPTNO"="D"."DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

         47  consistent gets

          0  physical reads

          0  redo size

        853  bytes sent via SQL*Net to client

        415  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

         14  rows processed

SQL> 

SQL> select e.deptno,e.ename from emp_sys e where e.deptno not in(select deptno from dept_sys);

未选定行

执行计划

----------------------------------------------------------

Plan hash value: 3477241526

-------------------------------------------------------------------------------

| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |          |    14 |   462 |     5  (20)| 00:00:01 |

|*  1 |  HASH JOIN ANTI NA |          |    14 |   462 |     5  (20)| 00:00:01 |---NA 什么意思不知道?????

|   2 |   TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|   3 |   TABLE ACCESS FULL| DEPT_SYS |     4 |    52 |     2   (0)| 00:00:01 |

-------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   1 - access("E"."DEPTNO"="DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

          6  consistent gets

          0  physical reads

          0  redo size

        346  bytes sent via SQL*Net to client

        404  bytes received via SQL*Net from client

          1  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          0  rows processed

SQL> select e.deptno,e.ename from emp_sys e where e.deptno not in(select /*+ merge_aj */deptno from dept_sys);

未选定行

执行计划

----------------------------------------------------------

Plan hash value: 3477241526

-------------------------------------------------------------------------------

| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |          |    14 |   462 |     5  (20)| 00:00:01 |

|*  1 |  HASH JOIN ANTI NA |          |    14 |   462 |     5  (20)| 00:00:01 | ---NA 什么意思不知道?????

|   2 |   TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|   3 |   TABLE ACCESS FULL| DEPT_SYS |     4 |    52 |     2   (0)| 00:00:01 |

-------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   1 - access("E"."DEPTNO"="DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          7  recursive calls

          0  db block gets

         14  consistent gets

          0  physical reads

          0  redo size

        346  bytes sent via SQL*Net to client

        404  bytes received via SQL*Net from client

          1  SQL*Net roundtrips to/from client

          2  sorts (memory)

          0  sorts (disk)

          0  rows processed

SQL> 

SQL> alter table emp_sys modify(deptno not null);

表已更改。

SQL> alter table dept_sys modify(deptno not null);

表已更改。

SQL> select e.deptno,e.ename from emp_sys e where e.deptno
not in(select /*+ MERGE_AJ */
deptno from dept_sys);

未选定行

执行计划

----------------------------------------------------------

Plan hash value: 3084791470

--------------------------------------------------------------------------------

| Id  | Operation           | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------

|   0 | SELECT STATEMENT    |          |    14 |   462 |     6  (34)| 00:00:01 |

|   1 |  MERGE JOIN ANTI    |          |    14 |   462 |     6  (34)| 00:00:01 |-----终于实现了排序合并反连接...

|   2 |   SORT JOIN         |          |    14 |   280 |     3  (34)| 00:00:01 |

|   3 |    TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|*  4 |   SORT UNIQUE       |          |     4 |    52 |     3  (34)| 00:00:01 |

|   5 |    TABLE ACCESS FULL| DEPT_SYS |     4 |    52 |     2   (0)| 00:00:01 |

--------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   4 - access("E"."DEPTNO"="DEPTNO")

       filter("E"."DEPTNO"="DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

        231  recursive calls

          0  db block gets

         36  consistent gets

          0  physical reads

          0  redo size

        346  bytes sent via SQL*Net to client

        404  bytes received via SQL*Net from client

          1  SQL*Net roundtrips to/from client

          8  sorts (memory)

          0  sorts (disk)

          0  rows processed

SQL> select e.deptno,e.ename from emp_sys e where e.deptno not in(select  deptno from dept_sys);

未选定行

执行计划

----------------------------------------------------------

Plan hash value: 305931308

-------------------------------------------------------------------------------

| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |          |    14 |   462 |     5  (20)| 00:00:01 |

|*  1 |  HASH JOIN ANTI    |          |    14 |   462 |     5  (20)| 00:00:01 |---NA终于没有了,而且实现了哈希反连接...

|   2 |   TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|   3 |   TABLE ACCESS FULL| DEPT_SYS |     4 |    52 |     2   (0)| 00:00:01 |

-------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   1 - access("E"."DEPTNO"="DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          7  recursive calls

          0  db block gets

         14  consistent gets

          0  physical reads

          0  redo size

        346  bytes sent via SQL*Net to client

        404  bytes received via SQL*Net from client

          1  SQL*Net roundtrips to/from client

          2  sorts (memory)

          0  sorts (disk)

          0  rows processed

SQL> 

SQL> select e.deptno,e.ename from emp_sys e where e.deptno not in(select /*+ MERGE_AJ */ deptno from dept_sys);

未选定行

执行计划

----------------------------------------------------------

Plan hash value: 3084791470

--------------------------------------------------------------------------------

| Id  | Operation           | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------

|   0 | SELECT STATEMENT    |          |    14 |   462 |     6  (34)| 00:00:01 |

|   1 |  MERGE JOIN ANTI    |          |    14 |   462 |     6  (34)| 00:00:01 |

|   2 |   SORT JOIN         |          |    14 |   280 |     3  (34)| 00:00:01 |

|   3 |    TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|*  4 |   SORT UNIQUE       |          |     4 |    52 |     3  (34)| 00:00:01 |

|   5 |    TABLE ACCESS FULL| DEPT_SYS |     4 |    52 |     2   (0)| 00:00:01 |

--------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   4 - access("E"."DEPTNO"="DEPTNO")

       filter("E"."DEPTNO"="DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

          6  consistent gets

          0  physical reads

          0  redo size

        346  bytes sent via SQL*Net to client

        404  bytes received via SQL*Net from client

          1  SQL*Net roundtrips to/from client

          2  sorts (memory)

          0  sorts (disk)

          0  rows processed

SQL> select e.deptno,e.ename from emp_sys e where e.deptno
not in(select /*+ nl_aj */ deptno from dept_sys);

未选定行

执行计划

----------------------------------------------------------

Plan hash value: 4115224242

-------------------------------------------------------------------------------

| Id  | Operation          | Name     | Rows  | Bytes | Cost (%CPU)| Time     |

-------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |          |    14 |   462 |     8   (0)| 00:00:01 |

|   1 |  NESTED LOOPS ANTI |          |    14 |   462 |     8   (0)| 00:00:01 |-----实现了嵌套循环反连接...

|   2 |   TABLE ACCESS FULL| EMP_SYS  |    14 |   280 |     2   (0)| 00:00:01 |

|*  3 |   TABLE ACCESS FULL| DEPT_SYS |     1 |    13 |     0   (0)| 00:00:01 |

-------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   3 - filter("E"."DEPTNO"="DEPTNO")

Note

-----

   - dynamic sampling used for this statement (level=2)

统计信息

----------------------------------------------------------

          7  recursive calls

          0  db block gets

         20  consistent gets

          0  physical reads

          0  redo size

        346  bytes sent via SQL*Net to client

        404  bytes received via SQL*Net from client

          1  SQL*Net roundtrips to/from client

          2  sorts (memory)

          0  sorts (disk)

          0  rows processed
SQL>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle join 方式
相关文章推荐