IM column store is the main feature of Oracle12.1.0.2 version. This feature allows columns, tables, partitions, and materialized views to be stored in memory in columnar format instead of the usual row format. The benefits of having data in memory are obvious, and columnar storage is ideal for analytical queries in business intelligence (BI) products.
Column Store is a standalone licensing option for Oracle Enterprise Edition.
1 Introduction
The memory column store is a new section in the SGA, and the size is specified by the initialization parameter INMEMORY_SIZE. You can select certain columns, whole table, materialized view or combination of table partitions to be stored in this section. Alternatively, you can enable the in-memory column store at the tablespace layer, so that all tables and materialized views in the table space automatically enable in-memory column store. The following commands have been modified to include additional in-memory clauses.
CREATE TABLE
ALTER TABLE
CREATE TABLESPACE
ALTER TABLESPACE
CREATE MATERIALIZED VIEW
ALTER MATERIALIZED VIEW
General use cases will be shown later.
The documentation states that the following scenarios are suitable for in-memory column storage.
- Large data volume scans using "=", "<", ">" and "IN" predicates.
- Queries that return only a few columns of a table with many columns.
- Queries that join small and large tables.
- Queries that aggregate data.
The documentation also mentions that this feature is not suitable for the following scenarios.
- Queries with complex predicates.
- Queries that return a large number of columns.
- Queries that return a large number of rows.
- Queries that join multiple large tables.
From the above, the most important thing to remember is that you are responsible for deciding which objects will benefit from it. If the decision is correct, you will see a huge increase in performance. If you decide wrong, you will waste a lot of memory that could be used by the buffer.
2. Enable memory column store
Remember, the in-memory column store is part of the SGA, so the SGA must be able to include the NMEMORY_SIZE parameter you specify. In a multihomed library environment, if any PDB needs to access the in-memory column store, the INMEMORY_SIZE parameter must be set in the CDB.
1) If you are using AMM (MEMORY_TARGET), it will have to be extended to fit the INMEMORY_SIZE parameter value.
2) If you are using ASMM (SGA_TARGET), it will have to be extended to accommodate the INMEMORY_SIZE parameter value.
Assuming the COMPATIBLE parameter is set to 12.1.0 or higher, and the SGA always has enough space for the in-memory columnar store, the following procedure will turn on the in-memory columnar store. Here set the INMEMORY_SIZE parameter to 2G.
ALTER SYSTEM SET SGA_TARGET=3G SCOPE=SPFILE;
ALTER SYSTEM SET INMEMORY_SIZE=2GSCOPE=SPFILE;
SHUTDOWN IMMEDIATE;
STARTUP;
ORACLE instance started.
Total System Global Area 3221225472 bytes
Fixed Size 2929552 bytes
Variable Size 419433584 bytes
Database Buffers 637534208 bytes
Redo Buffers 13844480 bytes
In-Memory Area 2147483648 bytes
Database mounted.
Database opened.
SQL>
Note that the "In-Memory Area" line is displayed during startup.
The current IM related settings will be displayed as follows. Except for size, all other relevant parameters are default values.
SQL> SHOW PARAMETER INMEMORY
NAME TYPE VALUE
----------------------------------------------- ------------------------------
inmemory_clause_default string
inmemory_force string DEFAULT
inmemory_max_populate_servers integer 1
inmemory_query string ENABLE
inmemory_size big integer 2G
inmemory_trickle_repopulate_servers_integer 1
percent
optimizer_inmemory_aware boolean TRUE
SQL>
Unless the INMEMORY_SIZE parameter is explicitly set at the PDB level, this parameter setting will be inherited by all PDBs. Changing the INMEMORY_SIZE parameter at the PDB level does not require restarting the instance or PDB.
CONN sys@pdb1 AS SYSDBA
-- Disable IM column store in the PDB
ALTER SYSTEM SET INMEMORY_SIZE=0;
-- OR
ALTER SYSTEM RESET INMEMORY_SIZE;
-- Assign a PDB-specific size.
ALTER SYSTEM SET INMEMORY_SIZE=1G;
3. Turn off the memory column
Depending on your purpose, there are several ways to turn off the in-memory column store.
Setting the INMEMORY_FORCE parameter to "OFF" means that the object is no longer kept in the in-memory column store, switching it back to "DEFAULT" will restore its default behavior.
-- System level
ALTER SYSTEM SET INMEMORY_FORCE=OFF;
ALTER SYSTEM SET INMEMORY_FORCE=DEFAULT;
Setting the INMEMORY_QUERY parameter to "DISABLE" means that the optimizer will no longer consider the in-memory column store when optimizing the query. Switching it back to "ENABLE" will restore its default functionality.
-- System level
ALTER SYSTEM SET INMEMORY_QUERY=DISABLE;
ALTER SYSTEM SET INMEMORY_QUERY=ENABLE;
-- Session level
ALTER SESSION SET INMEMORY_QUERY=DISABLE;
ALTER SESSION SET INMEMORY_QUERY=ENABLE;
To completely disable the in-memory column store and free up memory, simply reset the INMEMORY_SIZE parameter.
ALTER SYSTEM RESET INMEMORY_SIZESCOPE=SPFILE;
SHUTDOWN IMMEDIATE;
STARTUP;
As mentioned earlier, PDB-level settings can be changed without requiring instance or PDB restarts.
4. Management table
The CREATE TABLE and ALTER TABLE commands have been improved so that you can decide whether a table is to be stored in an in-memory column store. A table created with a NO INMEMORY clause is the same as an indeterminate clause. The following example will show three tables created with three syntaxes.
The view [DBA|ALL|USER]_TABLES has been improved to contain in-memory column store related information.
CONN test/test@pdb1
CREATE TABLE im_tab (
id NUMBER
) INMEMORY;
CREATE TABLE noim_tab (
id NUMBER
) NO INMEMORY;
CREATE TABLE default_tab (
id NUMBER
);
COLUMN table_name FORMAT A20
SELECT table_name,
inmemory,
inmemory_priority,
inmemory_distribute,
inmemory_compression,
inmemory_duplicate
FROM user_tables
ORDER BY table_name;
TABLE_NAME INMEMORY INMEMORY INMEMORY_DISTRIINMEMORY_COMPRESS INMEMORY_DUPL
-------------------- -------- ----------------------- ----------------- -------------
DEFAULT_TAB DISABLED
IM_TAB ENABLED NONE AUTO FOR QUERY LOW NO DUPLICATE
NOIM_TAB DISABLED
3 rows selected.
SQL>
The ALTER TABLE command can change the state of an object's in-memory column store. The following example easily changes the state of the in-memory column store.
ALTER TABLE IM_TAB NO INMEMORY;
ALTER TABLE NOIM_TAB INMEMORY MEMCOMPRESS FORCAPACITY LOW;
ALTER TABLE DEFAULT_TAB INMEMORY PRIORITYHIGH;
SELECT table_name,
inmemory,
inmemory_priority,
inmemory_distribute,
inmemory_compression,
inmemory_duplicate
FROM user_tables
ORDER BY table_name;
TABLE_NAME INMEMORY INMEMORY INMEMORY_DISTRIINMEMORY_COMPRESS INMEMORY_DUPL
-------------------- -------- -------- -------------------------------- -------------
DEFAULT_TAB ENABLED HIGH AUTO FOR QUERY LOW NO DUPLICATE
IM_TAB DISABLED
NOIM_TAB ENABLED NONE AUTO FOR CAPACITY LOW NO DUPLICATE
3 rows selected.
SQL>
5. Manage columns
The following example shows the syntax for placing a partial column into an in-memory column store.
CREATE TABLE im_col_tab (
id NUMBER,
col1NUMBER,
col2NUMBER,
col3NUMBER,
col4NUMBER
) INMEMORY
INMEMORY MEMCOMPRESS FOR QUERY HIGH (col1,col2)
INMEMORY MEMCOMPRESS FOR CAPACITY HIGH (col3)
NO INMEMORY (id, col4);
Get information about column settings by querying the view V$IM_COLUMN_LEVEL.
CONN sys@pdb1 AS SYSDBA
SELECT table_name,
segment_column_id,
column_name,
inmemory_compression
FROM v$im_column_level
WHERE owner = 'TEST'
and table_name = 'IM_COL_TAB'
ORDER BY segment_column_id;
TABLE_NAME SEGMENT_COLUMN_ID COLUMN_NAME INMEMORY_COMPRESSION
-------------------- ------------------------------------------------ --------------------------
IM_COL_TAB 1 ID NO INMEMORY
IM_COL_TAB 2 COL1 FOR QUERY HIGH
IM_COL_TAB 3 COL2 FOR QUERY HIGH
IM_COL_TAB 4 COL3 FOR CAPACITY HIGH
IM_COL_TAB 5 COL4 NO INMEMORY
5 rows selected.
SQL>
In-memory column store settings can be changed with the ALTER TABLE command.
CONN test/test@pdb1
ALTER TABLE im_col_tab
NOT IMMEMORY (col1, col2)
INMEMORY MEMCOMPRESS FOR CAPACITY HIGH (col3)
NO INMEMORY (id, col4);
CONN sys@pdb1 AS SYSDBA
SELECT table_name,
segment_column_id,
column_name,
inmemory_compression
FROM v$im_column_level
WHERE owner = 'TEST'
and table_name = 'IM_COL_TAB'
ORDER BY segment_column_id;
TABLE_NAME SEGMENT_COLUMN_ID COLUMN_NAME INMEMORY_COMPRESSION
-------------------- ------------------------------------------------ --------------------------
IM_COL_TAB 1 ID NO INMEMORY
IM_COL_TAB 2 COL1 NO INMEMORY
IM_COL_TAB 3 COL2 NO INMEMORY
IM_COL_TAB 4 COL3 FOR CAPACITY HIGH
IM_COL_TAB 5 COL4 NO INMEMORY
5 rows selected.
SQL>
6. Managing Materialized Views
The CREATE MATERIALIZED VIEW and ALTER MATERIALIZED VIEW commands are similar to the CREATE TABLE and ALTER TABLE commands.
CONN test/test@pdb1
CREATE TABLE t1 AS
SELECT * FROM all_objects;
CREATE MATERIALIZED VIEW t1_mv INMEMORY
ASSELECT * FROM t1;
SELECT table_name,
inmemory,
inmemory_priority,
inmemory_distribute,
inmemory_compression,
inmemory_duplicate
FROM user_tables
WHERE table_name = 'T1_MV';
TABLE_NAME INMEMORY INMEMORY INMEMORY_DISTRIINMEMORY_COMPRESS INMEMORY_DUPL
-------------------- -------- ----------------------- ----------------- -------------
T1_MV ENABLED NONE AUTO FOR QUERY LOW NO DUPLICATE
1 row selected.
SQL>
ALTER MATERIALIZED VIEW t1_mv
INMEMORY MEMCOMPRESS FOR CAPACITY HIGH PRIORITY HIGH;
SELECT table_name,
inmemory,
inmemory_priority,
inmemory_distribute,
inmemory_compression,
inmemory_duplicate
FROM user_tables
WHERE table_name = 'T1_MV';
TABLE_NAME INMEMORY INMEMORY INMEMORY_DISTRIINMEMORY_COMPRESS INMEMORY_DUPL
-------------------- -------- ----------------------- ----------------- -------------
T1_MV ENABLED HIGH AUTO FOR CAPACITY HIGHNO DUPLICATE
1 row selected.
SQL>
ALTER MATERIALIZED VIEW t1_mv NO INMEMORY;
SELECT table_name,
inmemory,
inmemory_priority,
inmemory_distribute,
inmemory_compression,
inmemory_duplicate
FROM user_tables
WHERE table_name = 'T1_MV';
TABLE_NAME INMEMORY INMEMORY INMEMORY_DISTRIINMEMORY_COMPRESS INMEMORY_DUPL
-------------------- -------- ----------------------- ----------------- -------------
T1_MV DISABLED
1 row selected.
SQL>
7. Manage tablespaces
Setting the default in-memory columnstore parameters for a tablespace means that all tables and materialized views within that tablespace will use those settings, except for display overrides.
The following will show how to set in-memory columnstore parameters during tablespace creation. The keyword DEFAULT is part of the in-memory column store clause. The default in-memory column store settings can be viewed by querying the DBA_TABLESPACES view.
CONN sys@pdb1 AS SYSDBA
CREATE TABLESPACE new_ts
DATAFILE '/u01/app/oracle/oradata/CDB1/datafile/pdb1/pdb1_new_ts.dbf'SIZE 10M
DEFAULT INMEMORY;
SELECT tablespace_name,
def_inmemory,
def_inmemory_priority,
def_inmemory_distribute,
def_inmemory_compression,
def_inmemory_duplicate
FROM dba_tablespaces
ORDER BY tablespace_name;
TABLESPACE_NAME DEF_INME DEF_INMEDEF_INMEMORY_DI DEF_INMEMORY_COMP DEF_INMEMORY_
------------------------------ ---------------- --------------- ----------------- -------------
NEW_TS ENABLED NONE AUTO FOR QUERY LOW NO DUPLICATE
SYSAUX DISABLED
SYSTEM DISABLED
TEMP DISABLED
USERS DISABLED
5 rows selected.
SQL>
The ALTER TABLESPACE command is used to modify the in-memory column store parameters.
ALTER TABLESPACE new_ts
DEFAULT INMEMORY MEMCOMPRESS FOR CAPACITY HIGH;
SELECT tablespace_name,
def_inmemory,
def_inmemory_priority,
def_inmemory_distribute,
def_inmemory_compression,
def_inmemory_duplicate
FROM dba_tablespaces
ORDER BY tablespace_name;
TABLESPACE_NAME DEF_INME DEF_INMEDEF_INMEMORY_DI DEF_INMEMORY_COMP DEF_INMEMORY_
------------------------------ ---------------- --------------- ----------------- -------------
NEW_TS ENABLED NONE AUTO FOR CAPACITY HIGHNO DUPLICATE
SYSAUX DISABLED
SYSTEM DISABLED
TEMP DISABLED
USERS DISABLED
SQL>
ALTER TABLESPACE new_ts
DEFAULT NO INMEMORY;
SELECT tablespace_name,
def_inmemory,
def_inmemory_priority,
def_inmemory_distribute,
def_inmemory_compression,
def_inmemory_duplicate
FROM dba_tablespaces
ORDER BY tablespace_name;
TABLESPACE_NAME DEF_INME DEF_INMEDEF_INMEMORY_DI DEF_INMEMORY_COMP DEF_INMEMORY_
------------------------------ ---------------- --------------- ----------------- -------------
NEW_TS DISABLED
SYSAUX DISABLED
SYSTEM DISABLED
TEMP DISABLED
USERS DISABLED
5 rows selected.
SQL>
Tablespace default settings can be overridden by the object-level settings shown above.
8. Views
We have seen that some previous views have been modified to include in-memory column store information. The following V$ views have been added with in-memory column store related information.