zoukankan      html  css  js  c++  java
  • Hash unique和Sort unique

    SQL> set linesize 200
    SQL> set pagesize 200
    SQL> set autot trace
    SQL> select  distinct department_name
      from hr.departments dept, hr.employees emp
     where dept.department_id = emp.department_id;  2    3  
    
    11 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 93782236
    
    -----------------------------------------------------------------------------------------
    | Id  | Operation	    | Name		| Rows	| Bytes | Cost (%CPU)| Time	|
    -----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |			|    27 |   513 |     4  (25)| 00:00:01 |
    |   1 |  HASH UNIQUE	    |			|    27 |   513 |     4  (25)| 00:00:01 |
    |   2 |   NESTED LOOPS	    |			|   106 |  2014 |     3   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| DEPARTMENTS	|    27 |   432 |     3   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN | EMP_DEPARTMENT_IX |     4 |    12 |     0   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("DEPT"."DEPARTMENT_ID"="EMP"."DEPARTMENT_ID")
    
    
    Statistics
    ----------------------------------------------------------
    	  0  recursive calls
    	  0  db block gets
    	 10  consistent gets
    	  0  physical reads
    	  0  redo size
    	622  bytes sent via SQL*Net to client
    	419  bytes received via SQL*Net from client
    	  2  SQL*Net roundtrips to/from client
    	  0  sorts (memory)
    	  0  sorts (disk)
    	 11  rows processed
    
    
    走的是hash unique:
    Oracle10g在distinct操作时作了算法改进,使用Hash Unique 代理了以前的Sort Unique.该行为由隐藏参数”
    
    _gby_hash_aggregation_enabled”决定,optimizer_features_enable设置为10.2.0.1时默认为TRUE.
    
    SQL> set linesize 200
    SQL> set pagesize 200
    SQL> ALTER SESSION SET "_gby_hash_aggregation_enabled" = FALSE;
    
    Session altered.
    
    SQL> set autot trace
    SQL> select  distinct department_name
      from hr.departments dept, hr.employees emp
     where dept.department_id = emp.department_id;  2    3  
    
    11 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1155849093
    
    -----------------------------------------------------------------------------------------
    | Id  | Operation	    | Name		| Rows	| Bytes | Cost (%CPU)| Time	|
    -----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |			|    27 |   513 |     4  (25)| 00:00:01 |
    |   1 |  SORT UNIQUE	    |			|    27 |   513 |     4  (25)| 00:00:01 |
    |   2 |   NESTED LOOPS	    |			|   106 |  2014 |     3   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| DEPARTMENTS	|    27 |   432 |     3   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN | EMP_DEPARTMENT_IX |     4 |    12 |     0   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - access("DEPT"."DEPARTMENT_ID"="EMP"."DEPARTMENT_ID")
    
    
    Statistics
    ----------------------------------------------------------
    	  1  recursive calls
    	  0  db block gets
    	 10  consistent gets
    	  0  physical reads
    	  0  redo size
    	622  bytes sent via SQL*Net to client
    	419  bytes received via SQL*Net from client
    	  2  SQL*Net roundtrips to/from client
    	  1  sorts (memory)
    	  0  sorts (disk)
    	 11  rows processed

  • 相关阅读:
    JAXB和XStream比较
    CButtonST类公共接口函数的介绍
    為什麼我的派生按鈕的自畫ownerdraw功能總是出錯?
    vc里使用GDI+
    cdecl, stdcall, pascal,fastcall 都有什么区别,具体是什么调用约定?
    SDK编程中窗口ID,句柄,指针三者相互转换函数
    __declspec,__cdecl,__stdcall都是什么意思?
    OnDraw()和OnPaint()
    栈 堆 区别
    MSDN for Visual Studio 6.0 高速下载地址
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352412.html
Copyright © 2011-2022 走看看