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. python - django 里自定義的 login 方法,如何使用 login_required()2. python如何不改動文件的情況下修改文件的 修改日期3. angular.js - angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性4. angular.js - 不適用其他構建工具,怎么搭建angular1項目5. mysql優化 - mysql count(id)查詢速度如何優化?6. 主從備份 - 跪求mysql 高可用主從方案7. css3 - [CSS] 動畫效果 3D翻轉bug8. node.js - node_moduls太多了9. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應用上有什么區別?10. java8中,邏輯與 & 符號用在接口類上代表什么意思
![css3 - [CSS] 動畫效果 3D翻轉bug](http://www.cgvv.com.cn/attached/image/news/202304/110831f073.png)