ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle_merge

oracle_merge

原创 Linux操作系统 作者:wisdomone1 时间:2012-12-20 00:14:00 0 删除 编辑
hint_merge
1,optimizer_secure_view_merging
2,如果查询块包括group by或在select中有distinct,且开启complex view merging
  优化器自动把查询块合并到整个访问SQL语句中
3,如果子查询不是关联子查询会把in子查询合并到整个访问SQL语句中
4,在11g中测试,exist与in(关联与非联)子查询,皆可以用merge
SQL> explain plan for select emp.deptno  from (select distinct deptno as deptno
from emp) emp,dept where emp.deptno=dept.deptno;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2714056117
--------------------------------------------------------------------------------
| Id  | Operation            | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |         |     3 |    48 |     3  (34)| 00:00:01 |
|   1 |  NESTED LOOPS        |         |     3 |    48 |     3  (34)| 00:00:01 |
|   2 |   VIEW               |         |     3 |    39 |     3  (34)| 00:00:01 |
|   3 |    HASH UNIQUE       |         |     3 |     9 |     3  (34)| 00:00:01 |
|   4 |     TABLE ACCESS FULL| EMP     |    12 |    36 |     2   (0)| 00:00:01 |
|*  5 |   INDEX UNIQUE SCAN  | PK_DEPT |     1 |     3 |     0   (0)| 00:00:01 |

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   5 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")
已选择17行。
SQL> explain plan for select /*+ merge(emp) */  emp.deptno  from (select distinc
t deptno as deptno from emp) emp,dept where emp.deptno=dept.deptno;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2673482842
--------------------------------------------------------------------------------
--
| Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)| Time
 |
--------------------------------------------------------------------------------
--

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |           |     3 |    39 |     3  (34)| 00:00:01
 |
|   1 |  VIEW                | VM_NWVW_1 |     3 |    39 |     3  (34)| 00:00:01
 |
|   2 |   HASH UNIQUE        |           |     3 |    54 |     3  (34)| 00:00:01
 |
|   3 |    NESTED LOOPS      |           |    12 |   216 |     2   (0)| 00:00:01
 |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------

|   4 |     TABLE ACCESS FULL| EMP       |    12 |    36 |     2   (0)| 00:00:01
 |
|*  5 |     INDEX UNIQUE SCAN| PK_DEPT   |     1 |    15 |     0   (0)| 00:00:01
 |
--------------------------------------------------------------------------------
--
 
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   5 - access("DEPTNO"="DEPT"."DEPTNO")
已选择17行。
SQL>
SQL> explain plan for select /*+ merge(emp) */  emp.deptno  from (select distinc
t deptno as deptno from emp where deptno in (select deptno from dept)) emp,dept
where emp.deptno=dept.deptno;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2673482842
--------------------------------------------------------------------------------
--
| Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)| Time
 |
--------------------------------------------------------------------------------
--

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |           |     3 |    39 |     3  (34)| 00:00:01
 |
|   1 |  VIEW                | VM_NWVW_1 |     3 |    39 |     3  (34)| 00:00:01
 |
|   2 |   HASH UNIQUE        |           |     3 |    54 |     3  (34)| 00:00:01
 |
|   3 |    NESTED LOOPS      |           |    12 |   216 |     2   (0)| 00:00:01
 |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------

|   4 |     TABLE ACCESS FULL| EMP       |    12 |    36 |     2   (0)| 00:00:01
 |
|*  5 |     INDEX UNIQUE SCAN| PK_DEPT   |     1 |    15 |     0   (0)| 00:00:01
 |
--------------------------------------------------------------------------------
--
 
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   5 - access("DEPTNO"="DEPT"."DEPTNO")
已选择17行。
SQL>

SQL> explain plan for select /*+ merge(emp) */  emp.deptno  from (select distinc
t deptno as deptno from emp where deptno in (select deptno from dept where deptn
o=emp.deptno)) emp,dept where emp.deptno=dept.deptno;
已解释。
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2673482842
--------------------------------------------------------------------------------
--
| Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)| Time
 |
--------------------------------------------------------------------------------
--

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |           |     3 |    39 |     3  (34)| 00:00:01
 |
|   1 |  VIEW                | VM_NWVW_1 |     3 |    39 |     3  (34)| 00:00:01
 |
|   2 |   HASH UNIQUE        |           |     3 |    54 |     3  (34)| 00:00:01
 |
|   3 |    NESTED LOOPS      |           |    12 |   216 |     2   (0)| 00:00:01
 |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------

|*  4 |     TABLE ACCESS FULL| EMP       |    12 |    36 |     2   (0)| 00:00:01
 |
|*  5 |     INDEX UNIQUE SCAN| PK_DEPT   |     1 |    15 |     0   (0)| 00:00:01
 |
--------------------------------------------------------------------------------
--
 
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   4 - filter("DEPTNO" IS NOT NULL AND "DEPTNO" IS NOT NULL)
   5 - access("DEPTNO"="DEPT"."DEPTNO")
已选择18行。
SQL>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-751381/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12686064