From version 0.14, Doris supports atomic replacement operations between two tables. This operation is only suitable for OLAP tables. For partition-level replacement operations, refer to Temporary Partition. Syntax Description
ALTER TABLE [db.]tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')];
Replace table tbl1 with table tbl2.
If the swap
parameter is true
, after replacement, the data in the tbl1
table is the original data in the tbl2
table. The data in the tbl2
table is the original data in the tbl1
table. The data of the two tables is swapped.
If the swap
parameter is false
, after replacement, the data in the tbl1
table is the original data in the tbl2
table. The tbl2
table is deleted.
Principles
The table replacement feature, in fact, is to aggregate the following operations into one atomic operation.
Assuming table A is to be replaced with table B, and swap
is true
, the operations are as follows:
1. Rename table B to table A.
2. Rename table A to table B.
If swap
is false
, the operations are as follows:
1. Delete table A.
2. Rename table B to table A.
Notes
1. The swap
parameter defaults to true
. Replacing a table is equivalent to swapping the data of the two tables.
2. If the swap
parameter is false
, the replaced table (Table A) will be deleted and cannot be recovered.
3. The replacement operation can only occur between two OLAP tables, and it does not check whether the table structures of the two tables are the same.
4. The replacement operation does not change the original permission settings. Because permission checks are table name-based.
Best Practice
1. Atomic overwrite operation.
In some cases, users may want to overwrite the data of a table. However, if deleting first and then importing is adopted, there will be a period of time when the data cannot be viewed. At this time, users can first use the CREATE TABLE LIKE
statement to create a new table with the same structure, import the new data into the new table, and then replace the old table atomically through the replace operation to achieve the goal. For atomic overwrite operations at the partition level, refer to Temporary Partition.
Was this page helpful?