MySQL InnoDB 锁 - For Update 加锁分析:

1. InnoDB锁 简单介绍

2. 当前读加锁分析:REPEATABLE-READ 可重复读、READ-COMMITTED 读已提交

3. 锁模式说明及8.0的data_locks表

一、InnoDB锁

1、全局锁

全局读锁,flush tables with read lock,整库处于只读状态。全局锁的一个典型场景:全库逻辑备份,--single-transaction实现一致性读。

2、表级锁

表锁,lock tables…read/write,主动在表上加读锁或写锁;

元数据锁(meta data lock,MDL),访问表时自动加上,防止DDL和DML并发的冲突,保证读写正确性;

自增锁,表中auto_increment字段的自增值生成控制,内存自增计数器,8.0之后通过redo进行持久化;

意向锁,只会和表级锁发生冲突,不会阻止除表锁请求之外的锁,表明有事务即将、或正锁定某N行;

  1. 意向共享锁(IS):SELECT ... LOCK IN SHARE MODE,在对应记录行上加锁之前,在表上加意向共享锁;

  2. 意向排它锁(IX):SELECT .. FOR UPDATE,悲观锁,对表所有扫描过的行都会被加上意向排它锁,若扫描行其中有行锁,则会被阻塞;对SELECT索引加排它锁,阻塞其他事务修改或SELECT ... FOR SHARE(在8.0新增的方式);

3、行锁

行锁,事务锁,只有发生行锁冲突,才会出现事务锁的排队等待。

两阶段锁协议:行锁在需要时加上,事务结束时释放。

行锁的3种算法:record lock、gap lock、next-key lock

  1. 记录锁 record lock:添加在索引上,表中没有索引时会默认添加在默认创建的聚集索引上;

  2. 间隙锁 gap lock:锁定一个范围,可重复读 隔离级别下,行锁会变成gap锁(范围锁),降低并发性,当前读(dml、select for update),若where条件列上有索引,加gap lock在索引上,实现可重复读;

  3. Next-Key Lock:Gap Lock+Record Lock,锁定一个范围,并且锁定记录本身;

    ① 唯一索引或主键,Next-Key Lock 降为 Record Lock,即仅锁住索引本身,而不是范围。

    ② 辅助索引(二级索引),默认使用Next-Key Locking加锁,锁定范围是前一个索引到后一个索引之间范围,左开右闭。

  1. ### session 1
  2. root@test 15:51 > begin;
  3.  
  4. root@test 15:51 > show create table student;
  5. +---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  6. | Table | Create Table |
  7. +---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  8. | student | CREATE TABLE `student` (
  9. `id` int(11) NOT NULL AUTO_INCREMENT,
  10. `name` varchar(20) DEFAULT NULL,
  11. `birthday` datetime DEFAULT NULL,
  12. PRIMARY KEY (`id`),
  13. KEY `ix_name` (`name`),
  14. KEY `ix_birthday` (`birthday`)
  15. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 |
  16. +---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17.  
  18. root@test 15:52 > select * from student;
  19. +----+-------+---------------------+
  20. | id | name | birthday |
  21. +----+-------+---------------------+
  22. | 1 | abcd | 1995-06-27 00:00:00 |
  23. | 2 | abef | 1995-01-24 00:00:00 |
  24. | 3 | abg | 1995-07-26 00:00:00 |
  25. | 4 | cdmn | 1995-06-13 00:00:00 |
  26. +----+-------+---------------------+
  27.  
  28. root@test 15:52 > select * from student where birthday > '1995-06-27 00:00:00' and birthday < '1995-07-26 00:00:00' for update;
  29. Empty set (0.02 sec)
  30.  
  31. ### session 2
  32. root@test 15:51 > begin;
  33.  
  34. # 左开
  35. root@test 15:54 > update student set name = 'abcd' where birthday = "1995-06-27 00:00:00";
  36.  
  37. # 右闭(阻塞更新)
  38. root@test 15:55 > update student set name = 'abg' where birthday = '1995-07-26 00:00:00';
  39. ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

二、当前读加锁分析

分析不同隔离级别,当前读(dml、select … for update)的加锁情况

1、REPEATABLE-READ 可重复读

  1. root@test 15:06 > show global variables like "%iso%";
  2. +-----------------------+-----------------+
  3. | Variable_name | Value |
  4. +-----------------------+-----------------+
  5. | transaction_isolation | REPEATABLE-READ |
  6. | tx_isolation | REPEATABLE-READ |
  7. +-----------------------+-----------------+
1.1、表无显式主键和索引
  1. root@test 15:30 > show create table t_student;
  2. +-----------+----------------------------------------------------------------------------------------------------------------------------+
  3. | Table | Create Table |
  4. +-----------+----------------------------------------------------------------------------------------------------------------------------+
  5. | t_student | CREATE TABLE `t_student` (
  6. `id` int(11) NOT NULL,
  7. `name` varchar(10) DEFAULT NULL
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  9. +-----------+----------------------------------------------------------------------------------------------------------------------------+
  10.  
  11. root@test 15:30 > begin;
  12.  
  13. root@test 15:31 > select * from t_student for update;
  14. +----+-------+
  15. | id | name |
  16. +----+-------+
  17. | 1 | jack |
  18. | 2 | kuzma |
  19. | 3 | linda |
  20. +----+-------+

如上,可重复读,表上没有主键(会自动生成隐式主键聚集组织表),也没有索引,全表SELECT的当前读的加锁情况:

  ① 对表添加 IX 锁

  ② 在"supremum"上添加 Next-Key Lock(supremum表示高于表中任何一个索引的值),即最大索引值之后的间隙锁住

  ③ 在三条记录上分别添加 Next-Key Lock

  1. root@test 16:08 > begin;
  2.  
  3. # where上带条件 id = 3
  4. root@test 16:08 > select * from t_student where id = 3 for update;
  5. +----+-------+
  6. | id | name |
  7. +----+-------+
  8. | 3 | linda |
  9. +----+-------+
  10.  
  11. root@test 16:09 > show engine innodb status\G
  12. # 锁信息如上,表上IX,supremum 和 三条记录上添加 Next-Key Lock
  13.  
  14. # 另开一个session
  15. root@test 16:09 > begin;
  16.  
  17. root@test 16:13 > insert into t_student values(2,"tom");
  18. ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
  19. root@test 16:15 > insert into t_student values(4,"tom");
  20. ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

如上,insert为什么会被阻塞呢?delete呢?update呢?

每次插入记录时,所生成的聚集索引(DB_ROW_ID)是自增的,每次都会在表的最后插入,因此就有可能插入id=10这条记录,所以需要添加"supremum pseudo-record"防止数据插入。

  1. ---TRANSACTION 582122, ACTIVE 3874 sec inserting
  2. mysql tables in use 1, locked 1
  3. LOCK WAIT 2 lock struct(s), heap size 1136, 6 row lock(s)
  4. MySQL thread id 12529, OS thread handle 123145486712832, query id 94463 localhost root update
  5. insert into t_student values(5,"tom")
  6. Trx read view will not see trx with id >= 582123, sees < 582121
  7. ------- TRX HAS BEEN WAITING 3 SEC FOR THIS LOCK TO BE GRANTED:
  8. RECORD LOCKS space id 168 page no 3 n bits 72 index GEN_CLUST_INDEX of table `test`.`t_student` trx id 582122 lock_mode X insert intention waiting
  9. Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
  10. 0: len 8; hex 73757072656d756d; asc supremum;;
  11.  
  12. ------------------
  13. TABLE LOCK table `test`.`t_student` trx id 582122 lock mode IX
  14. RECORD LOCKS space id 168 page no 3 n bits 72 index GEN_CLUST_INDEX of table `test`.`t_student` trx id 582122 lock_mode X insert intention waiting
  15. Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
  16. 0: len 8; hex 73757072656d756d; asc supremum;;

即使是不满足where条件的记录上,也会添加Next-Key Lock,目的是为了防止幻读。因此的,其他会话事务执行delete或者update都会造成幻读,也就被阻塞的。

  1. ---TRANSACTION 582122, ACTIVE 3788 sec starting index read
  2. mysql tables in use 1, locked 1
  3. LOCK WAIT 2 lock struct(s), heap size 1136, 5 row lock(s)
  4. MySQL thread id 12529, OS thread handle 123145486712832, query id 94461 localhost root updating
  5. update t_student set name = "linda" where id = 3
  6. Trx read view will not see trx with id >= 582123, sees < 582121
  7. ------- TRX HAS BEEN WAITING 14 SEC FOR THIS LOCK TO BE GRANTED:
  8. RECORD LOCKS space id 168 page no 3 n bits 72 index GEN_CLUST_INDEX of table `test`.`t_student` trx id 582122 lock_mode X waiting
  9. Record lock, heap no 2 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
  10. 0: len 6; hex 00000000090a; asc ;;
  11. 1: len 6; hex 00000008e1c8; asc ;;
  12. 2: len 7; hex f4000001e40110; asc ;;
  13. 3: len 4; hex 80000001; asc ;;
  14. 4: len 4; hex 6a61636b; asc jack;;
  15.  
  16. ------------------
  17. TABLE LOCK table `test`.`t_student` trx id 582122 lock mode IX
  18. RECORD LOCKS space id 168 page no 3 n bits 72 index GEN_CLUST_INDEX of table `test`.`t_student` trx id 582122 lock_mode X waiting
  19. Record lock, heap no 2 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
  20. 0: len 6; hex 00000000090a; asc ;;
  21. 1: len 6; hex 00000008e1c8; asc ;;
  22. 2: len 7; hex f4000001e40110; asc ;;
  23. 3: len 4; hex 80000001; asc ;;
  24. 4: len 4; hex 6a61636b; asc jack;;
1.2、表有显式主键无索引
  1. 不带where条件,表上IX,主键最大索引值之后的间隙锁住,表所有记录对应主键加上记录锁

  2. where条件是主键,表上IX,主键添加记录锁(X,REC_NOT_GAP),并且只锁住条件记录,因为主键保证唯一,不需要间隙锁

  1. ---TRANSACTION 582139, ACTIVE 12 sec
  2. 2 lock struct(s), heap size 1136, 1 row lock(s)
  3. MySQL thread id 12528, OS thread handle 123145486434304, query id 94472 localhost root
  4. TABLE LOCK table `test`.`t_student` trx id 582139 lock mode IX
  5. RECORD LOCKS space id 169 page no 3 n bits 72 index PRIMARY of table `test`.`t_student` trx id 582139 lock_mode X locks rec but not gap
  6. Record lock, heap no 3 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
  7. 0: len 4; hex 80000002; asc ;;
  8. 1: len 6; hex 00000008e1c8; asc ;;
  9. 2: len 7; hex f4000001e4011f; asc ;;
  10. 3: len 5; hex 6b757a6d61; asc kuzma;;
1.3、表无显式主键有索引
  1. 不带where条件,表上IX,id最大索引值之后的间隙锁住,表所有记录对应索引加上记录锁

  2. where条件是普通索引字段

  1. root@test 22:01 > show create table t_student;
  2. +-----------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  3. | Table | Create Table |
  4. +-----------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  5. | t_student | CREATE TABLE `t_student` (
  6. `id` int(11) NOT NULL,
  7. `name` varchar(10) DEFAULT NULL,
  8. KEY `ix_id` (`id`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  10. +-----------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  11.  
  12. root@test 22:10 > begin;
  13.  
  14. root@test 22:11 > select * from t_student where id = 2 for update;
  15. +----+-------+
  16. | id | name |
  17. +----+-------+
  18. | 2 | kuzma |
  19. +----+-------+
  20.  
  21. root@test 22:11 > show engine innodb status\G
  22. ---TRANSACTION 582176, ACTIVE 14 sec
  23. 4 lock struct(s), heap size 1136, 3 row lock(s)
  24. MySQL thread id 12534, OS thread handle 123145487269888, query id 94485 localhost root
  25. TABLE LOCK table `test`.`t_student` trx id 582176 lock mode IX
  26. RECORD LOCKS space id 170 page no 4 n bits 72 index ix_id of table `test`.`t_student` trx id 582176 lock_mode X
  27. Record lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
  28. 0: len 4; hex 80000002; asc ;;
  29. 1: len 6; hex 000000000912; asc ;;
  30.  
  31. RECORD LOCKS space id 170 page no 3 n bits 72 index GEN_CLUST_INDEX of table `test`.`t_student` trx id 582176 lock_mode X locks rec but not gap
  32. Record lock, heap no 3 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
  33. 0: len 6; hex 000000000912; asc ;;
  34. 1: len 6; hex 00000008e200; asc ;;
  35. 2: len 7; hex be00000146011f; asc F ;;
  36. 3: len 4; hex 80000002; asc ;;
  37. 4: len 5; hex 6b757a6d61; asc kuzma;;
  38.  
  39. RECORD LOCKS space id 170 page no 4 n bits 72 index ix_id of table `test`.`t_student` trx id 582176 lock_mode X locks gap before rec
  40. Record lock, heap no 4 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
  41. 0: len 4; hex 80000003; asc ;;
  42. 1: len 6; hex 000000000913; asc ;;

如上,过滤一个普通索引时的加锁情况是:

  ① 对表添加 IX锁

  ② 对id=2对应的索引添加 Next-Key Lock锁,区间是(-∞, 2]

  ③ 对索引对应的聚集索引添加 X记录锁

  ④ 为防止幻读(因为是普通索引,可重复插入id=2的记录),对索引记录区间(2,3)添加间隙锁(lock_mode X locks gap before rec)

也就是说,(测试用例有些许不恰当)如果说放大到10~20~30测试,id直到29之间的记录插入都会被阻塞,而插入id=30因为不在间隙锁范围,不会被阻塞。

1.4、表有显式主键和索引
  1. 无where条件,如1.2.1描述

  2. 有where条件,其实,无论是主键,还是唯一键索引,只要能准确定位的,都是表上IX,主键或唯一键添加记录锁(X,REC_NOT_GAP),并且只锁住条件记录

2、READ-COMMITTED 读已提交

  1. root@test 23:57 > show global variables like "tx_isolation";
  2. +---------------+----------------+
  3. | Variable_name | Value |
  4. +---------------+----------------+
  5. | tx_isolation | READ-COMMITTED |
  6. +---------------+----------------+
2.1、表无显式主键和索引
  1. root@test 23:57 > show create table t_people;
  2. +----------+-------------------------------------------------------------------------------------------------------------------------------+
  3. | Table | Create Table |
  4. +----------+-------------------------------------------------------------------------------------------------------------------------------+
  5. | t_people | CREATE TABLE `t_people` (
  6. `id` int(11) DEFAULT NULL,
  7. `name` varchar(10) DEFAULT NULL
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  9. +----------+-------------------------------------------------------------------------------------------------------------------------------+
  10.  
  11. root@test 23:58 > select * from t_people;
  12. +------+-------+
  13. | id | name |
  14. +------+-------+
  15. | 1 | jack |
  16. | 2 | kuzma |
  17. | 3 | linda |
  18. +------+-------+

如下,表t_people上加 IX意向排它锁,表中所有行的隐藏主键上(行格式里第三个就是隐藏主键,在表中没有显示主键的时候自动生成用于组织表数据)加 X记录锁,只锁定记录本身,非范围间隙锁。

如果带上where条件呢?

  1. root@test 00:44 > begin;
  2.  
  3. root@test 00:45 > select * from t_people where id = 2 for update;
  4. +------+-------+
  5. | id | name |
  6. +------+-------+
  7. | 2 | kuzma |
  8. +------+-------+
  9.  
  10. root@test 00:45 > show engine innodb status;
  11. ......
  12. ---TRANSACTION 582053, ACTIVE 4 sec
  13. 2 lock struct(s), heap size 1136, 1 row lock(s)
  14. MySQL thread id 12521, OS thread handle 123145487269888, query id 94339 localhost root
  15. TABLE LOCK table `test`.`t_people` trx id 582053 lock mode IX
  16. RECORD LOCKS space id 166 page no 3 n bits 72 index GEN_CLUST_INDEX of table `test`.`t_people` trx id 582053 lock_mode X locks rec but not gap
  17. Record lock, heap no 3 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
  18. 0: len 6; hex 000000000908; asc ;;
  19. 1: len 6; hex 00000008e19e; asc ;;
  20. 2: len 7; hex d2000001580110; asc X ;;
  21. 3: len 4; hex 80000002; asc ;;
  22. 4: len 5; hex 6b757a6d61; asc kuzma;;
  23. ......
  24. # 只是在 id = 2 的记录上加了X记录锁
2.2、表有显式主键无索引
  1. 不带where条件,如上的,表中所有行上加 X记录锁,不锁定范围

  2. where条件是主键字段时,对表加 IX锁,对主键添加记录锁(X, REC_NOTGAP),where了主键,主键已经保证唯一,非范围锁,锁加在具体的记录上

  1. root@test 00:49 > show engine innodb status;
  2. ---TRANSACTION 582071, ACTIVE 7 sec
  3. 2 lock struct(s), heap size 1136, 1 row lock(s)
  4. MySQL thread id 12521, OS thread handle 123145487269888, query id 94353 localhost root
  5. TABLE LOCK table `test`.`t_people` trx id 582071 lock mode IX
  6. RECORD LOCKS space id 167 page no 3 n bits 72 index PRIMARY of table `test`.`t_people` trx id 582071 lock_mode X locks rec but not gap
  7. Record lock, heap no 3 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
  8. 0: len 4; hex 80000002; asc ;;
  9. 1: len 6; hex 00000008e19e; asc ;;
  10. 2: len 7; hex d2000001580110; asc X ;;
  11. 3: len 5; hex 6b757a6d61; asc kuzma;;
  1. where条件包含主键字段和非主键字段,和上面是一样的,因为主键已经定位了加锁。

2.3、表无显示主键有索引
  1. 不带where条件,同样的,表中所有行上加 X记录锁,不锁定范围

  2. where条件是普通索引字段,唯一索引亦如是

  1. root@test 20:24 > show create table t_student;
  2. +-----------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  3. | Table | Create Table |
  4. +-----------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  5. | t_student | CREATE TABLE `t_student` (
  6. `id` int(11) NOT NULL,
  7. `name` varchar(10) DEFAULT NULL,
  8. KEY `ix_name` (`name`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  10. +-----------+------------------------------------------------------------------------------------------------------------------------------------------------------+
  11.  
  12. root@test 20:25 > begin;
  13.  
  14. root@test 20:27 > select * from t_student where name = 'kuzma' for update;
  15. +----+-------+
  16. | id | name |
  17. +----+-------+
  18. | 2 | kuzma |
  19. +----+-------+
  20.  
  21. root@test 20:27 > show engine innodb status;
  22. ---TRANSACTION 582093, ACTIVE 57 sec
  23. 3 lock struct(s), heap size 1136, 2 row lock(s)
  24. MySQL thread id 12525, OS thread handle 123145486712832, query id 94388 localhost root
  25. TABLE LOCK table `test`.`t_student` trx id 582093 lock mode IX
  26. RECORD LOCKS space id 168 page no 4 n bits 72 index ix_name of table `test`.`t_student` trx id 582093 lock_mode X locks rec but not gap
  27. Record lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
  28. 0: len 5; hex 6b757a6d61; asc kuzma;;
  29. 1: len 6; hex 00000000090b; asc ;;
  30.  
  31. RECORD LOCKS space id 168 page no 3 n bits 72 index GEN_CLUST_INDEX of table `test`.`t_student` trx id 582093 lock_mode X locks rec but not gap
  32. Record lock, heap no 3 PHYSICAL RECORD: n_fields 5; compact format; info bits 0
  33. 0: len 6; hex 00000000090b; asc ;;
  34. 1: len 6; hex 00000008e1c8; asc ;;
  35. 2: len 7; hex f4000001e4011f; asc ;;
  36. 3: len 4; hex 80000002; asc ;;
  37. 4: len 5; hex 6b757a6d61; asc kuzma;;

如上,当where条件上是普通索引字段时,加锁情况如下:

  ① 表上加 IX,意向排它锁

  ② name='kuzma' 对应的索引上添加 X 记录锁

  ③ GEN_CLUST_INDEX,对应的(自动生成的)聚集索引上添加 X 记录锁

2.4、表有显式主键有索引
  1. 不带where条件,所有行记录添加记录锁,并没有间隙范围锁

  2. where条件是普通索引或主键索引,如前面的,先是表上加 IX 意向排它锁,然后在对应的普通索引上添加 X 记录锁(如果是主键则无需),最后在对应的聚集索引(主键)上添加 X 记录锁

三、锁模式说明及8.0的data_locks表

3.1、锁模式LOCK_MODE

show engine innodb status中见到的 lock_mode,如下整理说明:

锁模式 说明
IX   意向排它锁
X   Next-Key Lock锁定记录和记录之前的间隙(X)
S   Next-Key Lock锁定记录和记录之前的间隙(S)
X, REC_NOT_GAP   只锁定记录本身(X)
S, REC_NOT_GAP   只锁定记录本身(S)
X, GAP   间隙锁,不锁定记录本身(X)
S, GAP   间隙锁,不锁定记录本身(S)
X, GAP, INSERT_INTENTION   插入意向锁,间隙范围,排它

3.2、8.0的data_locks表

在8.0之前,查看锁信息可以通过设置innodb_status_output_locks=ON,然后在 show engine innodb status的输出里,看到详细的锁信息打印,如前面展示。

8.0之后,performance_schema.data_locks,新增的,记录表加锁情况,可将之前的innodb status锁信息打印更好的以表格的形式记录展示。

For Update 加锁分析的更多相关文章

  1. MySQL的并发控制与加锁分析

    本文主要是针对MySQL/InnoDB的并发控制和加锁技术做一个比较深入的剖析,并且对其中涉及到的重要的概念,如多版本并发控制(MVCC),脏读(dirty read),幻读(phantom read ...

  2. (转)mysql、innodb和加锁分析

    mysql.innodb和加锁分析 原文:https://liuzhengyang.github.io/2016/09/25/mysqlinnodb/ 介绍 本文主要介绍MySQL和InnoDB存储引 ...

  3. MySQL中一条SQL的加锁分析

    MySQL中一条SQL的加锁分析 id主键 + RC id唯一索引 + RC id非唯一索引 + RC id无索引 + RC id主键 + RR id唯一索引 + RR id非唯一索引 + RR id ...

  4. mysql InnoDB加锁分析

    文章转载自:http://www.fanyilun.me/2017/04/20/MySQL%E5%8A%A0%E9%94%81%E5%88%86%E6%9E%90/ 以下实验数据基于MySQL 5.7 ...

  5. select加锁分析(Mysql)

    [原创]惊!史上最全的select加锁分析(Mysql) 前言 大家在面试中有没遇到面试官问你下面六句Sql的区别呢 select * from table where id = ? select * ...

  6. 解决死锁之路3 - 常见 SQL 语句的加锁分析 (转)

    出处:https://www.aneasystone.com/archives/2017/12/solving-dead-locks-three.html 这篇博客将对一些常见的 SQL 语句进行加锁 ...

  7. MySQL加锁分析

    参考:MySQL 加锁处理分析.该文已经讲的很详尽了,也易懂,下面仅仅是个人做的总结. 一. 背景 1.1 隔离级别 1.2 加锁过程 逐条处理,逐条加锁. 1.3 两阶段锁2PL 1.4 gap锁 ...

  8. MyISAM加锁分析

    为什么加锁 你正在读着你喜欢的女孩递给你的信,看到一半的时候,她的好闺蜜过来瞄了一眼(假设她会隐身术,你看不到她),她想把"我很喜欢你"改成"我不喜欢你",刚把 ...

  9. 史上最全的select加锁分析(Mysql)

    引言 大家在面试中有没遇到面试官问你下面六句Sql的区别呢 select * from table where id = ? select * from table where id < ? s ...

随机推荐

  1. 【LeetCode】面试题 17.16. 按摩师 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetco ...

  2. 【九度OJ】题目1442:A sequence of numbers 解题报告

    [九度OJ]题目1442:A sequence of numbers 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1442 ...

  3. 【LeetCode】462. Minimum Moves to Equal Array Elements II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:排序 方法二:直接找中位数 日期 题目地址: ...

  4. Iptables 实操

    目录 Iptables之实操 简介 名称概念: 四表中常用的表 Nat表 Filter表 iptables表和链的工作流程图 iptables过滤图 Iptables安装 Iptables 命令说明 ...

  5. 第二十四个知识点:描述一个二进制m组的滑动窗口指数算法

    第二十四个知识点:描述一个二进制m组的滑动窗口指数算法 简单回顾一下我们知道的. 大量的密码学算法的大数是基于指数问题的安全性,例如RSA或者DH算法.因此,现代密码学需要大指数模幂算法的有效实现.我 ...

  6. Qos 0/1/2的理解

    Qos 0/1/2的理解 Qos 0 最多一次的传输 消息是基于TCP/IP网络传输的.没有回应,在协议中也没有定义重传的语义.消息可能到达服务器1次,也可能根本不会到达. Qos 1 至少一次的传输 ...

  7. 使用 arguments 对象

    arguments 对象表示参数集合,它是一个伪类数组,拥有与数组相似的结构,可以通过数组下标的形式访问函数实参值,但是没有基础 Array 的原型方法. //函数没有定义形参,但是在函数体内通过 a ...

  8. 安装Cacti-plugin

    安装pluginunzip cacti-plugin-0.8.7e-PA-v2.6.zip -d cacti-plugin-archcp -R cacti-plugin-arch/* /data/ww ...

  9. Linux上天之路(九)之文件和文件夹的权限

    主要内容 linux 基本权限 linux特殊权限 linux隐藏权限 linux file ACL 权限 1. Linux的基本权限 使用ls -l filename 命令查看文件或文件夹详细权限 ...

  10. IE8和IE9下textarea滚动选中的问题

    在IE8和IE9下如果textarea设置了样式overflow-y:auto;就不可以滚动选中了,应该样式写成overflow:auto;有了纵向滚动实际上就不会出现横向滚动的情况,也没有必要ove ...