In the LOAD DATA statement, the direct keyword is used as a hint to indicate whether bypass import is used.
Limitations
- You cannot execute two statements to write the same table at a time because a lock is added to the table during import.
- The
LOAD DATAstatement cannot be used in triggers. - The
LOAD DATAstatement supports loading LOBs but the loading performance is poor. Therefore, LOBs are still loaded to the corresponding paths by using transactions. - The
LOAD DATAstatement cannot be executed in a multi-row transaction.
Considerations
To speed up data import, OceanBase Database adopts a parallel design for LOAD DATA operations. During the process, data to be imported is divided into multiple subtasks, which are executed in parallel. Each subtask is processed as an independent transaction in a random order. Therefore, observe the following considerations:
- The atomicity of the overall data import operation is not guaranteed.
- For a table without a primary key, data may be written to the table in an order different from that in the source file.
Syntax
LOAD DATA /*+ direct(need_sort,max_error) parallel(N) */ INFILE 'file_name' ...
For more information about the syntax of the LOAD DATA statement, see LOAD DATA.
Parameters
| Parameter | Description |
|---|---|
| direct | Specifies to use bypass import. |
| need_sort | Specifies whether OceanBase Database needs to sort the data. The value is of the Boolean type.
|
| max_error | The maximum number of erroneous rows allowed. The value is of the INT type. If this value is exceeded, the LOAD DATA statement returns an error. |
| parallel(N) | The degree of parallelism (DOP) for loading data. The default value of N is 4. |
Examples
Note
The following example shows how to import data from a file on the server. You can also use the LOAD DATA LOCAL INFILE statement to import data by loading a local file in bypass mode in OceanBase Database. For more information about the LOAD DATA LOCAL INFILE statement, see Import data by using the LOAD DATA statement.
Log on to the server where the target OBServer node resides and create test data in the
/home/admindirectory.Note
In OceanBase Database, the
LOAD DATAstatement can load only local input files on OBServer nodes. Therefore, you must copy the to-be-imported files to an OBServer node before the import.[xxx@xxx /home/admin]# ssh admin@10.10.10.1 [admin@xxx /home/admin]# vi tbl1.csv 1,11 2,22 3,33Set the path where the file to be imported is located.
Set the system variable
secure_file_privto specify the path that can be accessed for file import or export.Notice
For security reasons, when you set the system variable
secure_file_priv, you can connect to the database only through a local socket to execute the SQL statement that modifies the global variable. For more information, see secure_file_priv.Log on to the server where the OBServer node to connect to resides.
[xxx@xxx /home/admin]# ssh admin@10.10.10.1Execute the following statement to connect to the
mysql001tenant through a local Unix socket:obclient -S /home/admin/oceanbase/run/sql.sock -uroot@mysql001 -p******Set the import path to
/home/admin.obclient [(none)]> SET GLOBAL secure_file_priv = "/home/admin"; Query OK, 0 rows affected
After you reconnect to the database, execute the
LOAD /*+ APPEND */ DATAstatement to import data.obclient [test]> CREATE TABLE tbl1(col1 INT PRIMARY KEY,col2 INT); Query OK, 0 rows affected obclient [test]> SELECT * FROM tbl1; Empty set obclient [test]> LOAD DATA /*+ direct(true,1024) parallel(16) */ INFILE '/home/admin/tbl1.csv' INTO TABLE tbl1 FIELDS TERMINATED BY ','; Query OK, 3 rows affected Records: 3 Deleted: 0 Skipped: 0 Warnings: 0 obclient [test]> SELECT * FROM tbl1; +------+------+ | col1 | col2 | +------+------+ | 1 | 11 | | 2 | 22 | | 3 | 33 | +------+------+ 3 rows in set
References
- For more information about the
LOAD DATAstatement, see Import data by using the LOAD DATA statement. - For more information about how to connect to OceanBase Database, see Overview.
- For more information about how to drop a table, see Drop a table.