mysql - InnoDB中的锁
问题描述
问题解答
回答1:------- TRX HAS BEEN WAITING 28 SEC FOR THIS LOCK TO BE GRANTED:RECORD LOCKS space id 6 page no 4 n bits 80 index idx_a of table `test`.`t` trx id 637972 lock_mode X locks gap before rec insert intention waitingRecord lock, heap no 4 PHYSICAL RECORD: n_fields 2; compact format; info bits 32 0: len 4; hex 8000000b; asc ;; 1: len 6; hex 000000000414; asc ;;
这里说的很清楚啊 lock_mode X意味着是排它锁 gap代表是区间锁也就是说在insert之前该表加入了区间排他锁,为什么呢?因为之前执行的这句delete from t where a = 11;会在(negative infinity,11]这个区间加上排他锁,为什么是排他锁而不是Record Lock呢,因为你这里的a并非唯一索引,只是一个普通的索引,具体的看http://dev.mysql.com/doc/refman/5.7/en/innodb-locking.html
回答2:mysql默认的会话隔离级别是repeated read,会产生更多的gap锁,如果可以接受幻读,可以考虑降为read commit级别,减少锁冲突的概率。
相关文章:
1. javascript - 移动端 点击弹出遮罩层 加断点调试就行 不加断点就不行2. docker-machine添加一个已有的docker主机问题3. nignx - docker内nginx 80端口被占用4. angular.js使用$resource服务把数据存入mongodb的问题。5. dockerfile - 为什么docker容器启动不了?6. docker容器呢SSH为什么连不通呢?7. 关于docker下的nginx压力测试8. javascript - 正则匹配字符串特定语句后的数字9. docker安装后出现Cannot connect to the Docker daemon.10. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?

网公网安备