适用于:
Oracle Database - Enterprise Edition - 版本 12.1.0.2 和更高版本本文档所含信息适用于所有平台
目标
无论何时我们想放置表到 in-memory 中,我们需要访问整个表以把表放入 in-memory。
这篇文档将提供信息说明,一个表上更新/删除语句将不会像查询语句一样把表放置到 in-memory 中。
解决方案
已经使用 In-Memory 的配置信息:
SQL> show parameter inmemory
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
inmemory_clause_default string
inmemory_force string DEFAULT
inmemory_max_populate_servers integer 2
inmemory_query string ENABLE
inmemory_size big integer 200M
inmemory_trickle_repopulate_servers_ integer 1
percent
optimizer_inmemory_aware boolean TRUE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
inmemory_clause_default string
inmemory_force string DEFAULT
inmemory_max_populate_servers integer 2
inmemory_query string ENABLE
inmemory_size big integer 200M
inmemory_trickle_repopulate_servers_ integer 1
percent
optimizer_inmemory_aware boolean TRUE
连接到 sales 用户实施测试:
SQL> conn sh/oracle
Connected.
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS;
no rows selected
SQL> alter table times inmemory priority critical;
Table altered.
SQL> select TABLE_NAME,INMEMORY_PRIORITY,INMEMORY_DISTRIBUTE,INMEMORY_COMPRESSION from user_tables where table_name='TIMES';
TABLE_NAME INMEMORY INMEMORY_DISTRI INMEMORY_COMPRESS
------------------------- -------- --------------- -----------------
TIMES CRITICAL AUTO FOR QUERY LOW
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS;
no rows selected
SQL> update times times set END_OF_CAL_YEAR=sysdate;
1826 rows updated.
SQL> commit;
Commit complete.
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS;
no rows selected
Connected.
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS;
no rows selected
SQL> alter table times inmemory priority critical;
Table altered.
SQL> select TABLE_NAME,INMEMORY_PRIORITY,INMEMORY_DISTRIBUTE,INMEMORY_COMPRESSION from user_tables where table_name='TIMES';
TABLE_NAME INMEMORY INMEMORY_DISTRI INMEMORY_COMPRESS
------------------------- -------- --------------- -----------------
TIMES CRITICAL AUTO FOR QUERY LOW
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS;
no rows selected
SQL> update times times set END_OF_CAL_YEAR=sysdate;
1826 rows updated.
SQL> commit;
Commit complete.
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS;
no rows selected
上面的更新语句没有把表放置到 in-memory:
用简单查询比较:
SQL> select count(*) from times;
COUNT(*)
----------
1826
1 row selected.
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS
SEGMENT_NAME INMEMORY_SIZE BYTES
------------------------------ ------------- ----------
TIMES 1179648 524288
1 row selected.
COUNT(*)
----------
1826
1 row selected.
SQL> SELECT segment_name, inmemory_size, bytes FROM V$IM_SEGMENTS
SEGMENT_NAME INMEMORY_SIZE BYTES
------------------------------ ------------- ----------
TIMES 1179648 524288
1 row selected.
上面的查询语句把表放置到 in-memory 中。
通过上面的测试结果,我们可以看出更新/删除语句不会把表放入到 in-memory 数据库,除非我们访问整个表的所有行。