嵌套循环支持等值和非等值连接

驱动表,外部表


被驱动表  内部表

 select  /*+ LEADING(e) use_nl(e,d)*/ e.ename,e.job,d.dname from emp e,dept d  where e.deptno=d.deptno and e.sal<2000;


select e.*,d.*
  from emp e, dept d
 where e.deptno <> d.deptno
   and e.sal < 2000
   order by 1 asc


SQL> set linesize 200
SQL> set pagesie 200
SP2-0158: 未知的 SET 选项 "pagesie"
SQL> set pagesize 200
SQL> explain plan for select e.*,d.*
  from emp e, dept d
 where e.deptno <> d.deptno
   and e.sal < 2000
   order by 1 asc
  2    3    4    5    6  ;

已解释。

SQL> 
SQL> select * from table(dbms_xplan.display());

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 4097972272

----------------------------------------------------------------------------
| Id  | Operation	    | Name | Rows  | Bytes | Cost (%CPU)| Time	   |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |	   |	25 |  1450 |	11  (10)| 00:00:01 |
|   1 |  SORT ORDER BY	    |	   |	25 |  1450 |	11  (10)| 00:00:01 |
|   2 |   NESTED LOOPS	    |	   |	25 |  1450 |	10   (0)| 00:00:01 |
|   3 |    TABLE ACCESS FULL| DEPT |	 4 |	80 |	 3   (0)| 00:00:01 |
|*  4 |    TABLE ACCESS FULL| EMP  |	 6 |   228 |	 2   (0)| 00:00:01 |
----------------------------------------------------------------------------

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

   4 - filter("E"."SAL"<2000 AND "E"."DEPTNO"<>"D"."DEPTNO")

已选择16行。

如:>,< >=,<= like
原文地址:https://www.cnblogs.com/hzcya1995/p/13348748.html