您好,欢迎访问一九零五行业门户网

Oracle入门教程:leading vs ordered hint

odered hint 可以指示oracle 使用from 关键字后面的表的顺序进行join连接!cbo会优先按照from 后面的表的顺序来进行join,当统计
leading hint 可以指示oracle使用leading 中指定的表作为驱动表,
比如 正常的访问计划如下
scott@> select e.ename, hiredate, b.comm
  2   from emp e, bonus b
  3   where e.ename = b.ename;
execution plan
----------------------------------------------------------
plan hash value: 1125985041
----------------------------------------------------------------------------
| id  | operation          | name  | rows  | bytes | cost (%cpu)| time     |
----------------------------------------------------------------------------
|   0 | select statement   |       |     1 |    34 |     6  (17)| 00:00:01 |
|*  1 |  hash join         |       |     1 |    34 |     6  (17)| 00:00:01 |
|   2 |   table access full| bonus |     1 |    20 |     2   (0)| 00:00:01 |
|   3 |   table access full| emp   |    14 |   196 |     3   (0)| 00:00:01 |
----------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
   1 - access(e.ename=b.ename)
我们在leading 提示中指定 emp 表为驱动表
scott@> select /*+ leading(e b) */ e.ename,hiredate,b.comm
  2   from emp e, bonus b
  3   where e.ename = b.ename;
execution plan
----------------------------------------------------------
plan hash value: 1842254584
----------------------------------------------------------------------------
| id  | operation          | name  | rows  | bytes | cost (%cpu)| time     |
----------------------------------------------------------------------------
|   0 | select statement   |       |     1 |    34 |     6  (17)| 00:00:01 |
|*  1 |  hash join         |       |     1 |    34 |     6  (17)| 00:00:01 |
|   2 |   table access full| emp   |    14 |   196 |     3   (0)| 00:00:01 |
|   3 |   table access full| bonus |     1 |    20 |     2   (0)| 00:00:01 |
----------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
   1 - access(e.ename=b.ename)
如结果执行计划中将emp 作为驱动表!
1 在leading 提示同时使用ordered hint,则leading hint无效
scott@> select /*+ leading(b e)  ordered */  e.ename,hiredate, b.comm
  2   from emp e, bonus b
  3   where e.ename = b.ename;
execution plan
----------------------------------------------------------
plan hash value: 1842254584
----------------------------------------------------------------------------
| id  | operation          | name  | rows  | bytes | cost (%cpu)| time     |
----------------------------------------------------------------------------
|   0 | select statement   |       |     1 |    34 |     6  (17)| 00:00:01 |
|*  1 |  hash join         |       |     1 |    34 |     6  (17)| 00:00:01 |
|   2 |   table access full| emp   |    14 |   196 |     3   (0)| 00:00:01 |
|   3 |   table access full| bonus |     1 |    20 |     2   (0)| 00:00:01 |
----------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
   1 - access(e.ename=b.ename)
2 使用两个冲突的leading hint ,则oracle cbo会忽略所有的leading 提示!
scott@> select /*+ leading(b e) leading(e b) */e.ename,hiredate, b.comm
  2   from emp e, bonus b
  3   where e.ename = b.ename;
execution plan
----------------------------------------------------------
plan hash value: 1125985041
----------------------------------------------------------------------------
| id  | operation          | name  | rows  | bytes | cost (%cpu)| time     |
----------------------------------------------------------------------------
|   0 | select statement   |       |     1 |    34 |     6  (17)| 00:00:01 |
|*  1 |  hash join         |       |     1 |    34 |     6  (17)| 00:00:01 |
|   2 |   table access full| bonus |     1 |    20 |     2   (0)| 00:00:01 |
|   3 |   table access full| emp   |    14 |   196 |     3   (0)| 00:00:01 |
----------------------------------------------------------------------------
predicate information (identified by operation id):
---------------------------------------------------
   1 - access(e.ename=b.ename)

其它类似信息

推荐信息