Before You Begin
This 15-minute tutorial shows you how to create and populate in-memory external tables.
Background
Oracle Database 18c enables the population of data from
external tables into the In-Memory column store (IM column
store). This allows the population of data that is not stored in
Oracle Database but in source data files.
Nevertheless, the population must be completed
manually by executing the DBMS_INMEMORY.POPULATE
procedure.
In Oracle Database 19c, querying an in-memory enabled external table automatically initiates the population of the external data into the IM column store.
What Do You Need?
- Oracle Database 19c installed
- A CDB and a PDB
- The source data file for the external table:
cent20.dat. Download the .dat file to the labs directory created on your server in its associated subdirectory,/home/oracle/labs/CENT20
Configure
the IM Column Store Size
- Log in to the CDB root as
SYS.sqlplus / AS SYSDBAALTER SYSTEM SET inmemory_SIZE = 800M SCOPE=SPFILE; - Restart the instance and open the database.
SHUTDOWN IMMEDIATESTARTUPALTER PLUGGABLE DATABASE pdb1 OPEN;
Create
the Logical Directories for the External Source Files
In this section, you create the logical directory to store the source data files for external data files of the external table.
- Log in to the PDB as
SYSTEM.CONNECT system@PDB1 Enter password: password - Create the logical directory
CENT20to store the source data filecent20.datfor theCENT20external source data file.CREATE DIRECTORY cent20 AS '/home/oracle/labs/CENT20';
Create
the In-Memory External Table
- Create the user that owns the in-memory hybrid partitioned
table.
CREATE USER hypt IDENTIFIED BY password; - Grant the read and write privileges on the directory that
stores the source data file, to the table owner.
GRANT read, write ON DIRECTORY cent20 TO hypt; - Grant the
CREATE SESSION,CREATE TABLE, andUNLIMITED TABLESPACEprivileges to the table owner.GRANT create session, create table, unlimited tablespace TO hypt; - Create the in-memory external table
INMEM_EXT_TABwith the following attributes:- The table is partitioned by range on the
TIME_IDcolumn. - The default tablespace for external source data files is
CENT20. - The fields in the records of the external files are separated by comma ','.
- The in-memory compression is
FOR CAPACITY HIGH.
CREATE TABLE hypt.inmem_ext_tab (history_event NUMBER, time_id DATE) ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY cent20 ACCESS PARAMETERS (FIELDS TERMINATED BY ',') LOCATION ('cent20.dat')) INMEMORY MEMCOMPRESS FOR CAPACITY HIGH; - The table is partitioned by range on the
- Display the in-memory attributes of the external table.
Read the result from theSELECT * FROM dba_external_tables WHERE owner='HYPT';table_attributestext file.
Query
the In-Memory External Table
- Query the table. Queries of in-memory external tables must
have the
QUERY_REWRITE_INTEGRITYinitialization parameter set tostale_tolerated.ALTER SESSION SET query_rewrite_integrity=stale_tolerated;
Read the result from theSELECT * FROM hypt.inmem_ext_tab ORDER BY 1;result1text file. - Verify that the data is populated into the IM column store.
Querying the in-memory external table initiates the population into the IM column store in the same way that it does for an internal table. Executing theSELECT segment_name, tablespace_name, populate_status FROM v$im_segments; SEGMENT_NAME TABLESPACE_NAME POPULATE_STAT -------------- ------------------------ ------------- INMEM_EXT_TAB SYSTEM COMPLETEDDBMS_INMEMORY.POPULATEprocedure is not required.
Find
How Data In In-Memory External Table Is Accessed
- Display the execution plan for a query on the in-memory
external table with a degree of parallelism of 2.
EXPLAIN PLAN FOR SELECT /*+ PARALLEL(2) */ * FROM hypt.inmem_ext_tab;
Read the result from theSELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);result2text file. TheEXTERNAL TABLE ACCESS INMEMORY FULLoperation shows that the external data was accessed from the IM column store after having been populated automatically during the query.
Clean
Up the Environment
- Drop the external table
HYPT.INMEM_EXT_TAB.DROP TABLE hypt.inmem_ext_tab PURGE; - Quit the session.
EXIT
Create
and Populate In-Memory External Tables