暂无图片
MariaDB 行锁测试研究
最近更新:2022-08-15 17:46:09

适用范围

数据库版本:Mariadb 10.2.25
root@localhost[(none)] 08:28:13>select user(),@@version,database(),@@innodb_version,@@port,@@autocommit,@@tx_isolation;
+----------------+---------------------+------------+------------------+--------+--------------+----------------+
| user()         | @@version           | database() | @@innodb_version | @@port | @@autocommit | @@tx_isolation |
+----------------+---------------------+------------+------------------+--------+--------------+----------------+
| root@localhost | 10.2.25-MariaDB-log | NULL       | 5.7.26           |   3306 |            1 | READ-COMMITTED |
+----------------+---------------------+------------+------------------+--------+--------------+----------------+
1 row in set (0.00 sec)

测试概述

MariaDB行锁测试研究

测试过程

准备工作

use test;
drop table test_tc;
create table test_tc(id int,name varchar(30)) engine=innodb;
insert into test_tc values(11,'tc1'),(12,'tc2'),(13,'tc3'),(14,'tc4');
-- session_1:
set autocommit=0;
select * from test_tc where id = 11 ;
select * from test_tc where id = 11  for update;
-- session_2:
set autocommit=0;
select * from test_tc where id = 12 ;
select * from test_tc where id = 12  for update;

1.表没有索引的情况

session_1:操作记录
root@localhost[test] 11:17:48>-- session_1:
root@localhost[test] 11:18:15>set autocommit=0;
Query OK, 0 rows affected (0.00 sec)

root@localhost[test] 11:18:15>select * from test_tc where id = 11 ;
+------+------+
| id   | name |
+------+------+
|   11 | tc1  |
......