zoukankan      html  css  js  c++  java
  • 阻止子查询进行 Subquery Unnesting

    hint NO_UNNEST 可以禁止CBO 进行 Subquery Unnesting    
    
    
    SQL> set linesize 200
    SQL> set pagesize 200
    SQL> explain plan for select * from test1 where owner='SCOTT' and  object_id in(select    object_id from test2 where owner='SCOTT');
    
    已解释。
    
    
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 3819917785
    
    ----------------------------------------------------------------------------
    | Id  | Operation	   | Name  | Rows  | Bytes | Cost (%CPU)| Time	   |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |	   |	 6 |  1422 |   355   (1)| 00:00:05 |
    |*  1 |  HASH JOIN SEMI    |	   |	 6 |  1422 |   355   (1)| 00:00:05 |
    |*  2 |   TABLE ACCESS FULL| TEST1 |	 6 |  1242 |	 8   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |	14 |   420 |   347   (1)| 00:00:05 |
    ----------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - access("OBJECT_ID"="OBJECT_ID")
       2 - filter("OWNER"='SCOTT')
       3 - filter("OWNER"='SCOTT')
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    已选择21行。
    
    
    1.禁止cbo 进行Subquery Unnesting 
    
    
    
    SQL> set linesize 200
    SQL> set pagesize 200
    SQL> explain plan for select * from test1 where owner='SCOTT' and  object_id in(select    /*+ NO_UNNEST */   object_id from test2 where owner='SCOTT');
    
    已解释。
    
    SQL> select * from table(dbms_xplan.display());
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 1896454807
    
    ----------------------------------------------------------------------------
    | Id  | Operation	   | Name  | Rows  | Bytes | Cost (%CPU)| Time	   |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |	   |	 1 |   207 |  1049   (1)| 00:00:13 |
    |*  1 |  FILTER 	   |	   |	   |	   |		|	   |
    |*  2 |   TABLE ACCESS FULL| TEST1 |	 6 |  1242 |	 8   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TEST2 |	 1 |	30 |   347   (1)| 00:00:05 |
    ----------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter( EXISTS (SELECT /*+ NO_UNNEST */ 0 FROM "TEST2" "TEST2"
    	      WHERE "OBJECT_ID"=:B1 AND "OWNER"='SCOTT'))
       2 - filter("OWNER"='SCOTT')
       3 - filter("OBJECT_ID"=:B1 AND "OWNER"='SCOTT')
    
    Note
    -----
       - dynamic sampling used for this statement (level=2)
    
    已选择22行。
    
    
    
  • 相关阅读:
    10分钟学会在Ubuntu 18.04 LTS上安装NFS服务器和客户端
    脱发、秃头防不胜防?这里有一份给码农的减压指南 [转自机器之心]
    Ubuntu通过apt-get安装指定版本和查询软件源有多少个版本
    ubuntu tree 查看目录结构
    Clion快捷键
    斜杠与反斜杠的记法
    C++ 既有约定
    docker其他参考资料
    标准错误重定向、标准输入重定向
    第一本Docker书读书笔记
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348725.html
Copyright © 2011-2022 走看看