mirror of
https://github.com/MariaDB/server.git
synced 2025-12-13 20:03:16 +03:00
weakens the locks for this session similarly like the option innodb_locks_unsafe_for_binlog. This patch removes almost all gap locking (used in next-key locking) and makes MySQL to release the row locks on the rows which does not belong to result set. Additionally, nonlocking selects on INSERT INTO SELECT, UPDATE ... (SELECT ...), and CREATE ... SELECT ... use a nonlocking consistent read. If a binlog is used, then binlog format should be set to row based binloging to make the execution of the complex SQL statements.
247 lines
6.5 KiB
Plaintext
247 lines
6.5 KiB
Plaintext
drop table if exists t1,t2;
|
|
create table t1 (id int not null, f_id int not null, f int not null,
|
|
primary key(f_id, id)) engine=innodb;
|
|
create table t2 (id int not null,s_id int not null,s varchar(200),
|
|
primary key(id)) engine=innodb;
|
|
INSERT INTO t1 VALUES (8, 1, 3);
|
|
INSERT INTO t1 VALUES (1, 2, 1);
|
|
INSERT INTO t2 VALUES (1, 0, '');
|
|
INSERT INTO t2 VALUES (8, 1, '');
|
|
commit;
|
|
DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
|
|
WHERE mm.id IS NULL;
|
|
select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
|
|
where mm.id is null lock in share mode;
|
|
id f_id f
|
|
drop table t1,t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t1 lock in share mode;
|
|
a b
|
|
1 1
|
|
2 2
|
|
3 1
|
|
4 2
|
|
5 1
|
|
6 2
|
|
7 3
|
|
update t1 set b = 5 where b = 1;
|
|
set autocommit = 0;
|
|
select * from t1 where a = 2 and b = 2 for update;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t1;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
|
|
commit;
|
|
set autocommit = 0;
|
|
update t1 set b = 5 where b = 1;
|
|
set autocommit = 0;
|
|
select * from t1 where a = 7 and b = 3 for update;
|
|
a b
|
|
7 3
|
|
commit;
|
|
commit;
|
|
drop table t1;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (8,6),(12,1),(3,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
3 1
|
|
8 6
|
|
12 1
|
|
set autocommit = 0;
|
|
insert into t1 select * from t2;
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(d int not null, e int, primary key(d)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
d e
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
update t1 set b = (select e from t2 where a = d);
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb
|
|
select * from t2;
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (8,6),(12,1),(3,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
3 1
|
|
8 6
|
|
12 1
|
|
set autocommit = 0;
|
|
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
|
|
insert into t1 select * from t2;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(d int not null, e int, primary key(d)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
d e
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
|
|
update t1 set b = (select e from t2 where a = d);
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb
|
|
select * from t2;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (8,6),(12,1),(3,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
3 1
|
|
8 6
|
|
12 1
|
|
set autocommit = 0;
|
|
insert into t1 select * from t2 lock in share mode;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(d int not null, e int, primary key(d)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
d e
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
update t1 set b = (select e from t2 where a = d lock in share mode);
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (8,6),(12,1),(3,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
3 1
|
|
8 6
|
|
12 1
|
|
set autocommit = 0;
|
|
insert into t1 select * from t2 for update;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t1 values (1,2),(5,3),(4,2);
|
|
create table t2(d int not null, e int, primary key(d)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
d e
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
update t1 set b = (select e from t2 where a = d for update);
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t1, t2;
|
|
create table t2(a int not null, b int, primary key(a)) engine=innodb;
|
|
insert into t2 values (1,6),(5,1),(4,1);
|
|
commit;
|
|
set autocommit = 0;
|
|
select * from t2 for update;
|
|
a b
|
|
1 6
|
|
4 1
|
|
5 1
|
|
set autocommit = 0;
|
|
create table t1(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
commit;
|
|
drop table t2;
|