Does EXCHANGE statement on Atomic engine provide atomic capabilities for multiple tables?

162 Views Asked by At

Documentation declares Atomicity for exchanging two tables, but what about multiple tables? Following query works well and perform exchanging within tables A <=> B and C <=> D:

EXCHANGE TABLES "default"."A" AND "default"."B", "default"."C" AND "default"."D"

Does EXCHANGE statement on Atomic engine provide atomic capabilities for multiple tables? Can be situation when A <=> B exchanged but C <=> D not? Does atomicity spreads on whole EXCHANGE query?

1

There are 1 best solutions below

1
Denny Crane On

They are not atomic.

insert into a.x1 select 1;
insert into a.x1 select 2;

exchange tables a.x1 and a.x2, a.y1 and a.y2;

Received exception from server (version 22.6.1):
Code: 521. DB::Exception: Received from localhost:9000.DB::ErrnoException: Paths cannot be exchanged because /var/lib/clickhouse/store/209/209474d2-5d64-4ca0-8b45-9abf4109235a/y1.sql or /var/lib/clickhouse/store/209/209474d2-5d64-4ca0-8b45-9abf4109235a/y2.sql does not exist, errno: 2, strerror: No such file or directory. (ATOMIC_RENAME_FAIL)

select * from a.x1;
Ok.
0 rows in set. Elapsed: 0.002 sec.


select * from a.x2
┌─A─┐
│ 2 │
└───┘
┌─A─┐
│ 1 │
└───┘

Atomicy is not about DML transactions. It's about visibility for selects. That queries do not see intermediate state and do not throw table . does not exists...