Background information
OceanBase Database currently supports three data import methods: Load Data, obloader, and OMS. All of them write data by using the INSERT statement. However, the INSERT operation involves SQL query, transaction processing, and LSM-tree storage. Because OceanBase Database adopts the LSM-tree storage structure, data inserted by using the INSERT statement is first written to a memory table (MemTable), and then stored in the final SSTable through multiple rounds of flushing and compaction. This process consumes a large amount of CPU resources and results in a slow import speed.
To solve this problem, OceanBase Database introduces the direct load technology. This technology bypasses the intermediate processing steps and directly writes data to the Major SSTable. This technology is not only applicable to data import, but also to SQL operations that involve a large amount of write operations, such as INSERT INTO SELECT.
ClickBench is an AP benchmark proposed by ClickHouse. You can use this benchmark to test the query performance of OceanBase Database in AP scenarios. Before you run this benchmark, you must import data. The import data step allows you to experience the data import performance of OceanBase Database. You can also use direct load to prepare data for other AP benchmarks such as TPC-H and TPC-DS. This topic describes how to use direct load to accelerate the import of massive data and experience the high performance of OceanBase Database.
Scenarios
- Data preparation for AP scenarios: such as ClickHouse Benchmark, TPC-H, and TPC-DS.
- Acceleration of batch write operations: such as
INSERT INTO SELECT.
You can use direct load to significantly improve the data import efficiency in scenarios where you need to quickly load massive data.
Technical architecture
You can import data by using one of the following two paths.
Traditional path: The traditional path, indicated by the blue arrow, involves SQL query, transaction processing, and data storage.
Direct load path: The direct load path, indicated by the green arrow, mainly involves data type conversion and sorting by primary key (if any), and then writing the sorted data to the Major SSTable. Direct load is a short path that consumes fewer system resources and accelerates the import.
The following figure shows the two paths.

Prerequisites
Environment preparation
Environment requirements:
- An OceanBase Database V4.3 or later cluster has been deployed, and a MySQL-compatible tenant has been created.
- The resource specifications of the cluster are 16 CPU cores and 32 GB of memory. All steps and test results are based on this configuration.
For more information about how to deploy an OceanBase Database cluster, see Overview. After the cluster is deployed, you can execute the following SQL statements in the sys tenant to view the cluster and tenant information:
-- View the cluster information. SELECT * FROM GV$OB_SERVERS; -- View the tenant information. SELECT * FROM oceanbase.DBA_OB_TENANTS;Permission requirements:
The created tenant must have the
INSERTandSELECTpermissions. For more information about the permissions of OceanBase Database, see Permissions in MySQL-compatible mode.
Data preparation
Download the test data
Go to the ClickHouse website and download the hits dataset.
Decompress the data to a specified path, for example,
/path/to/hits.tsv.
Procedure
Step 1: Create a columnstore table
Execute the following statement to create a columnstore table:
CREATE TABLE hits ( WatchID BIGINT NOT NULL, JavaEnable SMALLINT NOT NULL, Title TEXT NOT NULL, GoodEvent SMALLINT NOT NULL, EventTime TIMESTAMP NOT NULL, EventDate Date NOT NULL, CounterID INTEGER NOT NULL, ClientIP INTEGER NOT NULL, RegionID INTEGER NOT NULL, UserID BIGINT NOT NULL, CounterClass SMALLINT NOT NULL, OS SMALLINT NOT NULL, UserAgent SMALLINT NOT NULL, URL TEXT NOT NULL, Referer TEXT NOT NULL, IsRefresh SMALLINT NOT NULL, RefererCategoryID SMALLINT NOT NULL, RefererRegionID INTEGER NOT NULL, URLCategoryID SMALLINT NOT NULL, URLRegionID INTEGER NOT NULL, ResolutionWidth SMALLINT NOT NULL, ResolutionHeight SMALLINT NOT NULL, ResolutionDepth SMALLINT NOT NULL, FlashMajor SMALLINT NOT NULL, FlashMinor SMALLINT NOT NULL, FlashMinor2 TEXT NOT NULL, NetMajor SMALLINT NOT NULL, NetMinor SMALLINT NOT NULL, UserAgentMajor SMALLINT NOT NULL, UserAgentMinor VARCHAR(255) NOT NULL, CookieEnable SMALLINT NOT NULL, JavascriptEnable SMALLINT NOT NULL, IsMobile SMALLINT NOT NULL, MobilePhone SMALLINT NOT NULL, MobilePhoneModel TEXT NOT NULL, Params TEXT NOT NULL, IPNetworkID INTEGER NOT NULL, TraficSourceID SMALLINT NOT NULL, SearchEngineID SMALLINT NOT NULL, SearchPhrase TEXT NOT NULL, AdvEngineID SMALLINT NOT NULL, IsArtifical SMALLINT NOT NULL, WindowClientWidth SMALLINT NOT NULL, WindowClientHeight SMALLINT NOT NULL, ClientTimeZone SMALLINT NOT NULL, ClientEventTime TIMESTAMP NOT NULL, SilverlightVersion1 SMALLINT NOT NULL, SilverlightVersion2 SMALLINT NOT NULL, SilverlightVersion3 INTEGER NOT NULL, SilverlightVersion4 SMALLINT NOT NULL, PageCharset TEXT NOT NULL, CodeVersion INTEGER NOT NULL, IsLink SMALLINT NOT NULL, IsDownload SMALLINT NOT NULL, IsNotBounce SMALLINT NOT NULL, FUniqID BIGINT NOT NULL, OriginalURL TEXT NOT NULL, HID INTEGER NOT NULL, IsOldCounter SMALLINT NOT NULL, IsEvent SMALLINT NOT NULL, IsParameter SMALLINT NOT NULL, DontCountHits SMALLINT NOT NULL, WithHash SMALLINT NOT NULL, HitColor CHAR NOT NULL, LocalEventTime TIMESTAMP NOT NULL, Age SMALLINT NOT NULL, Sex SMALLINT NOT NULL, Income SMALLINT NOT NULL, Interests SMALLINT NOT NULL, Robotness SMALLINT NOT NULL, RemoteIP INTEGER NOT NULL, WindowName INTEGER NOT NULL, OpenerName INTEGER NOT NULL, HistoryLength SMALLINT NOT NULL, BrowserLanguage TEXT NOT NULL, BrowserCountry TEXT NOT NULL, SocialNetwork TEXT NOT NULL, SocialAction TEXT NOT NULL, HTTPError SMALLINT NOT NULL, SendTiming INTEGER NOT NULL, DNSTiming INTEGER NOT NULL, ConnectTiming INTEGER NOT NULL, ResponseStartTiming INTEGER NOT NULL, ResponseEndTiming INTEGER NOT NULL, FetchTiming INTEGER NOT NULL, SocialSourceNetworkID SMALLINT NOT NULL, SocialSourcePage TEXT NOT NULL, ParamPrice BIGINT NOT NULL, ParamOrderID TEXT NOT NULL, ParamCurrency TEXT NOT NULL, ParamCurrencyID SMALLINT NOT NULL, OpenstatServiceName TEXT NOT NULL, OpenstatCampaignID TEXT NOT NULL, OpenstatAdID TEXT NOT NULL, OpenstatSourceID TEXT NOT NULL, UTMSource TEXT NOT NULL, UTMMedium TEXT NOT NULL, UTMCampaign TEXT NOT NULL, UTMContent TEXT NOT NULL, UTMTerm TEXT NOT NULL, FromTag TEXT NOT NULL, HasGCLID SMALLINT NOT NULL, RefererHash BIGINT NOT NULL, URLHash BIGINT NOT NULL, CLID INTEGER NOT NULL, PRIMARY KEY (CounterID, EventDate, UserID, EventTime, WatchID) ) with column group (each column);
Step 2: Execute direct load
Direct load
LOAD DATA
/*+
query_timeout(10000000000)
parallel(32)
direct(true, 0) -- Enable direct load mode.
*/
INFILE '/path/to/hits.tsv'
INTO TABLE hits
FIELDS TERMINATED BY '\t'
ENCLOSED BY ''
ESCAPED BY '';
After the preceding statement is executed, you can view the execution time of direct load.
Non-direct load
LOAD DATA
/*+
query_timeout(10000000000)
parallel(32)
*/
INFILE '/path/to/hits.tsv'
INTO TABLE hits
FIELDS TERMINATED BY '\t'
ENCLOSED BY ''
ESCAPED BY '';
After the preceding statement is executed, you can view the execution time of non-direct load.
Performance comparison
| Scenario | Execution time (seconds) |
|---|---|
| Direct load | 249 |
| Non-direct load | 767 |
Note
The resource specifications of the cluster are 16 CPU cores and 32 GB of memory. The execution environment may vary, which results in different execution times. The execution times in the preceding table are for reference only.
Conclusion: Direct load improves the import speed by more than 3 times. It is suitable for scenarios where you need to import massive data, such as preparing TPC-H or TPC-DS test data.