DROP TABLE IF EXISTS test;
connect  con1,localhost,root,,;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
connect  con2,localhost,root,,;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
connect  con3,localhost,root,,;
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
connection con1;
create table test (id int primary key, value int) engine=rocksdb;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test;
id	value
1	10
2	20
update test set value = 101 where id = 1;
connection con2;
select * from test;
id	value
1	10
2	20
connection con1;
rollback;
connection con2;
select * from test;
id	value
1	10
2	20
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = 101 where id = 1;
connection con2;
select * from test;
id	value
1	10
2	20
connection con1;
update test set value = 11 where id = 1;
commit;
connection con2;
select * from test;
id	value
1	11
2	20
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = 11 where id = 1;
connection con2;
update test set value = 22 where id = 2;
connection con1;
select * from test where id = 2;
id	value
2	20
connection con2;
select * from test where id = 1;
id	value
1	10
connection con1;
commit;
connection con2;
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = 11 where id = 1;
update test set value = 19 where id = 2;
connection con2;
update test set value = 12 where id = 1;
connection con1;
commit;
connection con2;
connection con3;
select * from test;
id	value
1	11
2	19
connection con2;
update test set value = 18 where id = 2;
connection con3;
select * from test;
id	value
1	11
2	19
connection con2;
commit;
connection con3;
select * from test;
id	value
1	12
2	18
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where value = 30;
id	value
connection con2;
insert into test (id, value) values(3, 30);
commit;
connection con1;
select * from test where value % 3 = 0;
id	value
3	30
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = value + 10;
connection con2;
select variable_value into @a from information_schema.global_status where variable_name='rocksdb_snapshot_conflict_errors';
select * from test;
id	value
1	10
2	20
delete from test where value = 20;
connection con1;
commit;
connection con2;
select * from test;
id	value
2	30
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id = 1;
id	value
1	10
connection con2;
select * from test where id = 1;
id	value
1	10
connection con1;
update test set value = 11 where id = 1;
connection con2;
update test set value = 12 where id = 1;
connection con1;
commit;
connection con2;
select * from test;
id	value
1	12
2	20
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id = 1;
id	value
1	10
connection con2;
select * from test where id = 1;
id	value
1	10
select * from test where id = 2;
id	value
2	20
update test set value = 12 where id = 1;
update test set value = 18 where id = 2;
commit;
connection con1;
select * from test where id = 2;
id	value
2	18
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where value % 5 = 0;
id	value
1	10
2	20
connection con2;
update test set value = 12 where value = 10;
commit;
connection con1;
select * from test where value % 3 = 0;
id	value
1	12
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id = 1;
id	value
1	10
connection con2;
select * from test;
id	value
1	10
2	20
update test set value = 12 where id = 1;
update test set value = 18 where id = 2;
commit;
connection con1;
delete from test where value = 20;
select * from test where id = 2;
id	value
2	18
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id in (1,2);
id	value
1	10
2	20
connection con2;
select * from test where id in (1,2);
id	value
1	10
2	20
connection con1;
update test set value = 11 where id = 1;
connection con2;
update test set value = 21 where id = 2;
connection con1;
commit;
connection con2;
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where value % 3 = 0;
id	value
connection con2;
select * from test where value % 3 = 0;
id	value
connection con1;
insert into test (id, value) values(3, 30);
connection con2;
insert into test (id, value) values(4, 42);
connection con1;
commit;
connection con2;
commit;
select * from test where value % 3 = 0;
id	value
3	30
4	42
connection con1;
select * from test where value % 3 = 0;
id	value
3	30
4	42
connection default;
drop table test;
disconnect con1;
disconnect con2;
disconnect con3;
DROP TABLE IF EXISTS test;
connect  con1,localhost,root,,;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
connect  con2,localhost,root,,;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
connect  con3,localhost,root,,;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
connection con1;
create table test (id int primary key, value int) engine=rocksdb;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test;
id	value
1	10
2	20
update test set value = 101 where id = 1;
connection con2;
select * from test;
id	value
1	10
2	20
connection con1;
rollback;
connection con2;
select * from test;
id	value
1	10
2	20
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = 101 where id = 1;
connection con2;
select * from test;
id	value
1	10
2	20
connection con1;
update test set value = 11 where id = 1;
commit;
connection con2;
select * from test;
id	value
1	10
2	20
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = 11 where id = 1;
connection con2;
update test set value = 22 where id = 2;
connection con1;
select * from test where id = 2;
id	value
2	20
connection con2;
select * from test where id = 1;
id	value
1	10
connection con1;
commit;
connection con2;
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = 11 where id = 1;
update test set value = 19 where id = 2;
connection con2;
update test set value = 12 where id = 1;
connection con1;
commit;
connection con2;
connection con3;
select * from test;
id	value
1	11
2	19
connection con2;
update test set value = 18 where id = 2;
connection con3;
select * from test;
id	value
1	11
2	19
connection con2;
commit;
connection con3;
select * from test;
id	value
1	11
2	19
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where value = 30;
id	value
connection con2;
insert into test (id, value) values(3, 30);
commit;
connection con1;
select * from test where value % 3 = 0;
id	value
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
update test set value = value + 10;
connection con2;
select variable_value into @a from information_schema.global_status where variable_name='rocksdb_snapshot_conflict_errors';
select * from test;
id	value
1	10
2	20
delete from test where value = 20;
connection con1;
commit;
connection con2;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict)
select variable_value-@a from information_schema.global_status where variable_name='rocksdb_snapshot_conflict_errors';
variable_value-@a
1
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id = 1;
id	value
1	10
connection con2;
select * from test where id = 1;
id	value
1	10
connection con1;
update test set value = 11 where id = 1;
connection con2;
update test set value = 12 where id = 1;
connection con1;
commit;
connection con2;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict)
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id = 1;
id	value
1	10
connection con2;
select * from test where id = 1;
id	value
1	10
select * from test where id = 2;
id	value
2	20
update test set value = 12 where id = 1;
update test set value = 18 where id = 2;
commit;
connection con1;
select * from test where id = 2;
id	value
2	20
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where value % 5 = 0;
id	value
1	10
2	20
connection con2;
update test set value = 12 where value = 10;
commit;
connection con1;
select * from test where value % 3 = 0;
id	value
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id = 1;
id	value
1	10
connection con2;
select * from test;
id	value
1	10
2	20
update test set value = 12 where id = 1;
update test set value = 18 where id = 2;
commit;
connection con1;
delete from test where value = 20;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict)
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where id in (1,2);
id	value
1	10
2	20
connection con2;
select * from test where id in (1,2);
id	value
1	10
2	20
connection con1;
update test set value = 11 where id = 1;
connection con2;
update test set value = 21 where id = 2;
connection con1;
commit;
connection con2;
commit;
connection con1;
truncate table test;
insert into test (id, value) values (1, 10), (2, 20);
begin;
connection con2;
begin;
connection con3;
begin;
connection con1;
select * from test where value % 3 = 0;
id	value
connection con2;
select * from test where value % 3 = 0;
id	value
connection con1;
insert into test (id, value) values(3, 30);
connection con2;
insert into test (id, value) values(4, 42);
connection con1;
commit;
connection con2;
commit;
select * from test where value % 3 = 0;
id	value
3	30
4	42
connection con1;
select * from test where value % 3 = 0;
id	value
3	30
4	42
connection default;
drop table test;
disconnect con1;
disconnect con2;
disconnect con3;
