Oracle 12c In-Memory in Tablespaces
上篇文章講了在表層級可以開啟In-Memory,其實在Tablespaces也可指定開啟Tablespaces ,在Tablespaces 層級指定後,儲存在這個Tablespaces 上的表也都開啟了In-Memory。下面我們來測試一下。
1.建立一個資料表空間,並指定INMEMORY字句
SQL> CREATE TABLESPACE tbs1 datafile 'tbs1' SIZE 40M DEFAULT INMEMORY;
2.在建立立的資料表空間上建立一張表,且表不指定INMEMORY
SQL> create table bmw.tt tablespace tbs1 as select * from dba_objects ;
Table created.
3.可以看到建立立的表也都開啟了INMEMORY,這是因為我們在資料表空間層級開啟了INMEMORY。
SQL> l
1* select TABLE_NAME,INMEMORY_PRIORITY,INMEMORY_DISTRIBUTE,INMEMORY_COMPRESSION from dba_tables where table_name='TT'
SQL> /
TABLE_NAME INMEMORY_PRIORITY INMEMORY_DISTRIBUTE INMEMORY_COMPRESSION
-------------------- ------------------------ --------------------------------------------- ------------------------------
TT NONE AUTO FOR QUERY LOW
SQL> l
1 SELECT * FROM V$INMEMORY_AREA
2*
SQL> /
POOL ALLOC_BYTES USED_BYTES POPULATE_S CON_ID
---------- ----------- ---------- ---------- ----------
1MB POOL 837812224 4194304 DONE 3
64KB POOL 201326592 131072 DONE 3
當表沒有查詢時,我們可以看到並未分配記憶體
4.查詢表
SQL> set autot trace
SQL> SELECT * FROM bmw.tt;
90935 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 264906180
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 90935 | 9M| 32 (16)| 00:00:01 |
| 1 | TABLE ACCESS INMEMORY FULL| TT | 90935 | 9M| 32 (16)| 00:00:01 |
-----------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
6 recursive calls
0 db block gets
7485 consistent gets
1527 physical reads
0 redo size
4945264 bytes sent via SQL*Net to client
67234 bytes received via SQL*Net from client
6064 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
90935 rows processed
以上雖然使用了TABLE ACCESS INMEMORY FULL,但由於表未在記憶體中,還是產生了大量的 consistent gets
5.再查詢測試一下,可以看到consistent gets降到了3
SQL> /
90935 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 264906180
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 90935 | 9M| 32 (16)| 00:00:01 |
| 1 | TABLE ACCESS INMEMORY FULL| TT | 90935 | 9M| 32 (16)| 00:00:01 |
-----------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
4945264 bytes sent via SQL*Net to client
67234 bytes received via SQL*Net from client
6064 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
90935 rows processed
SQL> set autot off
SQL> SELECT * FROM V$INMEMORY_AREA;
POOL ALLOC_BYTES USED_BYTES POPULATE_S CON_ID
---------- ----------- ---------- ---------- ----------
1MB POOL 837812224 8388608 DONE 3
64KB POOL 201326592 262144 DONE 3
在V$INMEMORY_AREA視圖中也可以看到已經分配了多少記憶體。
如果取消資料表空間層級的INMEMORY,可以使用 ALTER TABLESPACE tbsname NO INMEMORY 子句.