Replacing Atomic Table
Doris supports atomic replacement operations between two tables, applicable only to OLAP tables.
Applicable Scenariosβ
Sometimes, users need to rewrite table data, but deleting and then importing the data would result in a period of unavailability. In such cases, users can create a new table with the same structure using the CREATE TABLE LIKE
statement, import the new data into the new table, and then perform an atomic replacement of the old table. For partition-level atomic overwrite operations, refer to the temporary partition documentation.
Syntaxβ
ALTER TABLE [db.]tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')];
Replace table tbl1
with table tbl2
.
If the swap
parameter is true
, after the replacement, the data in tbl1
will be the original data in tbl2
, and the data in tbl2
will be the original data in tbl1
, meaning the data in the two tables will be swapped.
If the swap
parameter is false
, after the replacement, the data in tbl1
will be the original data in tbl2
, and tbl2
will be deleted.
Principleβ
The table replacement function turns the following set of operations into an atomic operation.
Assuming table A is replaced with table B, and swap
is true
, the operations are as follows:
- Rename table B to table A.
- Rename table A to table B.
If swap
is false
, the operations are as follows:
- Delete table A.
- Rename table B to table A.
Notesβ
- If the
swap
parameter isfalse
, the replaced table (table A) will be deleted and cannot be recovered. - The replacement operation can only occur between two OLAP tables and does not check if the table structures are consistent.
- The replacement operation will not change the original permission settings, as permission checks are based on table names.