2021-04-09 12:53:51 +00:00
|
|
|
drop table if exists mt1;
|
|
|
|
drop table if exists mt2;
|
|
|
|
|
|
|
|
create table mt1 (n Int64) engine=MergeTree order by n;
|
|
|
|
create table mt2 (n Int64) engine=MergeTree order by n;
|
|
|
|
|
2022-04-25 11:41:31 +00:00
|
|
|
commit; -- { serverError INVALID_TRANSACTION } -- no transaction
|
2022-03-20 21:42:26 +00:00
|
|
|
rollback; -- { serverError INVALID_TRANSACTION }
|
2021-04-09 12:53:51 +00:00
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
insert into mt1 values (1);
|
|
|
|
insert into mt2 values (10);
|
|
|
|
select 'commit', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
|
|
|
commit;
|
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
insert into mt1 values (2);
|
|
|
|
insert into mt2 values (20);
|
|
|
|
select 'rollback', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
|
|
|
rollback;
|
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
select 'no nested', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
2022-03-20 21:42:26 +00:00
|
|
|
begin transaction; -- { serverError INVALID_TRANSACTION }
|
2021-04-09 12:53:51 +00:00
|
|
|
rollback;
|
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
insert into mt1 values (3);
|
|
|
|
insert into mt2 values (30);
|
|
|
|
select 'on exception before start', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
|
|
|
-- rollback on exception before start
|
|
|
|
select functionThatDoesNotExist(); -- { serverError 46 }
|
|
|
|
-- cannot commit after exception
|
2022-04-25 11:41:31 +00:00
|
|
|
commit; -- { serverError INVALID_TRANSACTION } -- after 46
|
2022-03-20 21:42:26 +00:00
|
|
|
begin transaction; -- { serverError INVALID_TRANSACTION }
|
2021-04-09 12:53:51 +00:00
|
|
|
rollback;
|
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
insert into mt1 values (4);
|
|
|
|
insert into mt2 values (40);
|
|
|
|
select 'on exception while processing', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
|
|
|
-- rollback on exception while processing
|
|
|
|
select throwIf(100 < number) from numbers(1000); -- { serverError 395 }
|
|
|
|
-- cannot commit after exception
|
2022-04-25 11:41:31 +00:00
|
|
|
commit; -- { serverError INVALID_TRANSACTION } -- after 395
|
2022-03-20 21:42:26 +00:00
|
|
|
insert into mt1 values (5); -- { serverError INVALID_TRANSACTION }
|
|
|
|
insert into mt2 values (50); -- { serverError INVALID_TRANSACTION }
|
|
|
|
select 1; -- { serverError INVALID_TRANSACTION }
|
2021-04-09 12:53:51 +00:00
|
|
|
rollback;
|
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
insert into mt1 values (6);
|
|
|
|
insert into mt2 values (60);
|
|
|
|
select 'on session close', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
|
|
|
insert into mt1 values ([1]); -- { clientError 43 }
|
2022-04-25 11:41:31 +00:00
|
|
|
-- INSERT failures does not produce client reconnect anymore, so rollback can be done
|
|
|
|
rollback;
|
2021-04-09 12:53:51 +00:00
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
insert into mt1 values (7);
|
|
|
|
insert into mt2 values (70);
|
|
|
|
select 'commit', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
|
|
|
commit;
|
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
select 'readonly', arraySort(groupArray(n)) from (select n from mt1 union all select * from mt2);
|
|
|
|
commit;
|
|
|
|
|
2022-03-18 13:33:59 +00:00
|
|
|
begin transaction;
|
|
|
|
select 'snapshot', count(), sum(n) from mt1;
|
|
|
|
set transaction snapshot 1;
|
|
|
|
select 'snapshot1', count(), sum(n) from mt1;
|
|
|
|
set transaction snapshot 3;
|
|
|
|
set throw_on_unsupported_query_inside_transaction=0;
|
|
|
|
select 'snapshot3', count() = (select count() from system.parts where database=currentDatabase() and table='mt1' and _state in ('Active', 'Outdated')) from mt1;
|
|
|
|
set throw_on_unsupported_query_inside_transaction=1;
|
|
|
|
set transaction snapshot 1000000000000000;
|
|
|
|
select 'snapshot100500', count(), sum(n) from mt1;
|
2022-03-20 21:42:26 +00:00
|
|
|
set transaction snapshot 5; -- { serverError INVALID_TRANSACTION }
|
2022-03-18 13:33:59 +00:00
|
|
|
rollback;
|
|
|
|
|
2022-01-31 22:27:55 +00:00
|
|
|
begin transaction;
|
|
|
|
create table m (n int) engine=Memory; -- { serverError 48 }
|
2022-04-25 11:41:31 +00:00
|
|
|
commit; -- { serverError INVALID_TRANSACTION } -- after 48
|
2022-01-31 22:27:55 +00:00
|
|
|
rollback;
|
|
|
|
|
|
|
|
create table m (n int) engine=Memory;
|
|
|
|
begin transaction;
|
|
|
|
insert into m values (1); -- { serverError 48 }
|
2022-03-20 21:42:26 +00:00
|
|
|
select * from m; -- { serverError INVALID_TRANSACTION }
|
2022-04-25 11:41:31 +00:00
|
|
|
commit; -- { serverError INVALID_TRANSACTION } -- after 48
|
2022-01-31 22:27:55 +00:00
|
|
|
rollback;
|
|
|
|
|
|
|
|
begin transaction;
|
|
|
|
select * from m; -- { serverError 48 }
|
2022-04-25 11:41:31 +00:00
|
|
|
commit; -- { serverError INVALID_TRANSACTION } -- after 48
|
2022-01-31 22:27:55 +00:00
|
|
|
rollback;
|
|
|
|
|
|
|
|
drop table m;
|
2021-04-09 12:53:51 +00:00
|
|
|
drop table mt1;
|
|
|
|
drop table mt2;
|