• 12c inmemory option 体验


    此次测试的目标是对比是用索引去做统计分析与使用内存列式存储去做统计分析。

    检查初始化参数。

    SQL> show parameter inmemory
    
    NAME				     TYPE	 VALUE
    ------------------------------------ ----------- ------------------------------
    inmemory_clause_default 	     string
    inmemory_force			     string	 DEFAULT
    inmemory_max_populate_servers	     integer	 0
    inmemory_query			     string	 ENABLE
    inmemory_size			     big integer 0
    inmemory_trickle_repopulate_servers_ integer	 1
    percent
    optimizer_inmemory_aware	     boolean	 TRUE
    

    设置inmemory_size参数并重启数据库

    SQL> alter system set inmemory_size=100M scope=spfile; 
    
    System altered.
    
    SQL> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    SQL> startup
    ORACLE instance started.
    
    Total System Global Area  599785472 bytes
    Fixed Size		    2927192 bytes
    Variable Size		  364905896 bytes
    Database Buffers	  121634816 bytes
    Redo Buffers		    5459968 bytes
    In-Memory Area		  104857600 bytes
    Database mounted.
    Database opened.
    

    创建测试表

    SQL> create table inmom_tab as select * from dba_objects;
    
    Table created.

    insert into  inmom_tab  select * from inmom_tab;
    ......


    反复执行几次上述sql语句确保测试有效果

    SQL> select count(object_id) from inmom_tab where object_id is not null;

    COUNT(OBJECT_ID)
    ----------------
    11647488

     

     表上建立索引

    create index IDX1 on INMOM_TAB (OBJECT_ID);

    表上启用列式存储

    SQL> ALTER TABLE  inmom_tab  INMEMORY;
    
    Table altered.
    
    SQL> alter table inmom_tab  inmemory (object_id);
    
    Table altered.

    使用全表扫描去做此操作

    select count(distinct object_id) from inmom_tab; SQL> 
    ^Cselect count(distinct object_id) from inmom_tab
                                          *
    ERROR at line 1:
    ORA-01013: user requested cancel of current operation
    
    
    Elapsed: 00:03:52.71
    

      手动终止,时间已经超过3分钟还没结果,不能忍。

    使用索引

    select count(distinct object_id) from inmom_tab where  object_id is not null;
    
    COUNT(DISTINCTOBJECT_ID)
    ------------------------
    		   90996
    
    Elapsed: 00:00:09.73
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 2055747524
    
    --------------------------------------------------------------------------------------------
    | Id  | Operation		| Name	   | Rows  | Bytes |TempSpc| Cost (%CPU)| Time	   |
    --------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT	|	   |	 1 |	13 |	   | 19963   (3)| 00:00:01 |
    |   1 |  SORT AGGREGATE 	|	   |	 1 |	13 |	   |		|	   |
    |   2 |   VIEW			| VW_DAG_0 | 91944 |  1167K|	   | 19963   (3)| 00:00:01 |
    |   3 |    HASH GROUP BY	|	   | 91944 |   448K|   133M| 19963   (3)| 00:00:01 |
    |*  4 |     INDEX FAST FULL SCAN| IDX1	   |	11M|	55M|	   |  7036   (1)| 00:00:01 |
    --------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - filter("OBJECT_ID" IS NOT NULL)
    
    
    Statistics
    ----------------------------------------------------------
    	  7  recursive calls
    	  0  db block gets
          51950  consistent gets
          51927  physical reads
    	  0  redo size
    	560  bytes sent via SQL*Net to client
    	552  bytes received via SQL*Net from client
    	  2  SQL*Net roundtrips to/from client
    	  0  sorts (memory)
    	  0  sorts (disk)
    	  1  rows processed
    

    时间是0.09s 。

    使用内存列式存储访问

    select /*+ no_index(inmom_tab idx1) */count(distinct object_id) from inmom_tab where  object_id is not null;SQL> 
    
    COUNT(DISTINCTOBJECT_ID)
    ------------------------
    		   90996
    
    Elapsed: 00:00:03.77
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1778946740
    
    ---------------------------------------------------------------------------------------------------
    | Id  | Operation		      | Name	  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time	  |
    ---------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT	      | 	  |	1 |    13 |	  | 30957   (2)| 00:00:02 |
    |   1 |  SORT AGGREGATE 	      | 	  |	1 |    13 |	  |	       |	  |
    |   2 |   VIEW			      | VW_DAG_0  | 91944 |  1167K|	  | 30957   (2)| 00:00:02 |
    |   3 |    HASH GROUP BY	      | 	  | 91944 |   448K|   133M| 30957   (2)| 00:00:02 |
    |*  4 |     TABLE ACCESS INMEMORY FULL| INMOM_TAB |    11M|    55M|	  | 18030   (1)| 00:00:01 |
    ---------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       4 - inmemory("OBJECT_ID" IS NOT NULL)
           filter("OBJECT_ID" IS NOT NULL)
    
    
    Statistics
    ----------------------------------------------------------
    	  7  recursive calls
    	  0  db block gets
         263504  consistent gets
         263487  physical reads
    	  0  redo size
    	560  bytes sent via SQL*Net to client
    	552  bytes received via SQL*Net from client
    	  2  SQL*Net roundtrips to/from client
    	  0  sorts (memory)
    	  0  sorts (disk)
    	  1  rows processed
    

    时间是0.03s,速度似乎与使用索引不相上下。

     

     

     

     

     

     
  • 相关阅读:
    hdu 1024 Max Sum Plus Plus DP
    九月回顾 这篇文章和ACM毫无关系= =
    HDU 3974 Assign the task 并查集/图论/线段树
    poj 3264 Balanced Lineup RMQ问题
    zoj 1610 Count the Colors 线段树区间更新/暴力
    poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和
    hdu 4027 Can you answer these queries? 线段树区间开根号,区间求和
    hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序
    codeforces 19D D. Points 树套树
    codeforces 85D D. Sum of Medians Vector的妙用
  • 原文地址:https://www.cnblogs.com/wangxingc/p/5598388.html
Copyright © 2020-2023  润新知