• 阻止子查询进行 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行。
    
    
    
  • 相关阅读:
    隔离的级别?
    集中式与进程内负载均衡的区别是什么?
    静态变量和实例变量的区别?
    什么是SolrCloud
    页面编码和被请求的资源编码如果不一致如何处理?
    SQL笔试题:下面是学生表(student)的结构说明
    笔记本加装SSD并装系统
    vs2015 MSB600 "inf2cat.ext"已退出,代码为2
    $time $stime $realtime
    python网站(持续更新)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348725.html
Copyright © 2020-2023  润新知