Orcle 12c 新特性---IM虚拟列

1 说明

In-Memory virtual columns enable some or all of the user-defined virtual columns on a table to have their values materialized (precalculated) and populated into the In-Memory Column Store along with all of the non-virtual columns for that table.

In-Memory虚拟列可以使表中的一些或所有用户定义的虚拟列实现其值的具体化(预先计算),并将其插入到In-Memory的列存储中,并与所有非虚拟列一起存储在该表中。

Materializing the values of user-defined virtual columns into the In-Memory Column Store can greatly improve query performance by enabling the virtual column values to be scanned and filtered using In-Memory techniques such as SIMD (single instruction, multiple data) vector processing, just like a non-virtual column.

通过预先计算(比如,提前对某列的值进行复杂的运算,将得到的值作为一个虚拟列,下次直接使用虚拟列即可,无需重新计算),可以大大提高查询的性能。

为了将IM虚拟列插入到IM列式存储中,要设置INMEMORY_VIRTUAL_COLUMNS参数:

  • MANUAL (default): If a table is enabled for the IM column store, then no IM virtual columns defined on this table are eligible for population, unless they are explicitly set as INMEMORY. --需要显示指定虚拟列

  • ENABLE: If a table is enabled for the IM column store, then all IM virtual columns defined on this table are eligible for population, unless they are explicitly set as NO INMEMORY. --除非显示指定虚拟列不插入

  • DISABLE:无法将IM虚拟列插入到IM列式存储中。

2 实验-启用IM虚拟列

2.1 首先要启用IM列式存储

INMEMORY_SIZE值不为0,最小为100M。

ALTER SYSTEM SET INMEMORY_SIZE = 100M SCOPE=SPFILE;
SQL> SHOW PARAMETER INMEMORY_SIZE
NAME	     TYPE	    VALUE
------------------------------------ ---------------------- ------------------------------
inmemory_size	     big integer	    100M

2.2 设置INMEMORY_VIRTUAL_COLUMNS参数

SQL> SHOW PARAMETER INMEMORY_VIRTUAL_COLUMNS
NAME	     TYPE	    VALUE
------------------------------------ ---------------------- ------------------------------
inmemory_virtual_columns	     string	    MANUAL

–重启生效

SQL> ALTER SYSTEM SET INMEMORY_VIRTUAL_COLUMNS=ENABLE SCOPE=SPFILE;
System altered.

2.3 将包含虚拟列的表启用IM列式存储

2.3.1 将已有的表添加虚拟列并启用IM列式存储

SQL> alter table bonus add(weekly_sal as (ROUND(SAL*12/52,2)));
Table altered.

SQL> ALTER TABLE bonus INMEMORY;
Table altered.

–查看BONUS表结构,多了一列WEEKLY_SAL

SQL> desc bonus

 Name	   Null?    Type
 ----------------------------------------- -------- ----------------------------
 ENAME	    VARCHAR2(10)
 JOB	    VARCHAR2(9)
 SAL	        NUMBER
 COMM	    NUMBER
 WEEKLY_SAL     NUMBER

2.3.2 新建表(包含虚拟列),并显示指定虚拟列插入到IM列式存储

  • 新建表
CREATE TABLE  emp (
      empno      NUMBER(5) PRIMARY KEY,
      ename      VARCHAR2(15) NOT NULL,
      job        VARCHAR2(10),
      sal        NUMBER(7,2),
      hrly_rate NUMBER(7,2) GENERATED ALWAYS AS (sal/2080), --虚拟列将sal列除以2080
      deptno     NUMBER(3) NOT NULL)
   INMEMORY;
  • 将hrly_rate虚拟列插入到IM列式存储中
ALTER TABLE LEI.emp INMEMORY(hrly_rate);

更为详细信息参考官方文档:
http://docs.oracle.com/database/122/INMEM/populating-objects-in-memory.htm#INMEM-GUID-C0BC34D3-2BD8-41A5-B2F0-9AB109C1B617

猜你喜欢

转载自blog.csdn.net/qianglei6077/article/details/92794847