国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > 文庫 > 正文

兩條insert 語句出現的死鎖

2024-09-07 22:12:37
字體:
來源:轉載
供稿:網友
      查看status日志發現兩條insert 出現了死鎖
      RECORD LOCKS space id 388 page no 27032 n bits 616 index `idx_svcorderserviceitem_workorderid_quantity` of table `ecejservice`.`svc_order_service_item` trx id 596252578 lock_mode X insert intention waiting
      可以確定,這個x鎖不是由于INSERT產生的,因為 INSERT可能產生的鎖包括檢查dup key時的s鎖,隱式鎖轉換為顯式鎖(not gap,要在二級索引上產生lock_mode為X的LOCK_ORDINARY類型的鎖(包括記錄及記錄前面的gap),據我所知一般是根據二級索引掃描進行記錄更新導致的。
 
      一個簡單但不完全相同的重現步驟:
     DROP TABLE t1;
     CREATE TABLE `t1` (
  `a` int(11) NOT NULL AUTO_INCREMENT,
  `b` int(11) DEFAULT NULL,
  `c` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`),
  KEY `b` (`b`)
) ENGINE=InnoDB ;
insert into t1(a, b,c) values(1,2,3),(5,4,6),(8, 7,9),(12,12,19),(15,15,11);
session1:
 
begin;
delete from t1 where b = 12;
//二級索引上lock_mode X、lock_mode X locks gap before rec以及主鍵上的lock_mode X locks rec but not gap
二級索引:heap_no=5, type_mode=3  (12上的LOCK_ORDINARY類型鎖,包括記錄和記錄前的GAP)
聚集索引:heap_no=5,type_mode=1027
二級索引:heap_no=6,type_mode=547(15上的GAP鎖)
session2:
begin;
delete from t1 where b = 7;
//二級索引上lock_mode X、lock_mode X locks gap before rec以及主鍵上的lock_mode X locks rec but not gap
二級索引:heap_no=4,type_mode=3       (7上的LOCK_ORDINARY類型鎖,包括記錄和記錄前的GAP)
聚集索引:heap_no=4,type_mode=1027
二級索引:heap_no=5,type_mode=547    (記錄12上的GAP鎖)
session1:
insert into t1 values (NULL, 6,10);
//新插入記錄聚集索引無沖突插入成功,二級索引等待插入意向鎖(lock_mode X locks gap before rec insert intention waiting)
二級索引,heap_no=4, type_mode=2819 (請求記錄7上面的插入意向鎖LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION, 需要等待session2
session2:
insert into t1 values (NULL, 7,10);
二級索引:heap_no=5,  type_mode=2819  (請求記錄12上的插入意向鎖LOCK_X | LOCK_GAP | LOCK_INSERT_INTENTION,需要等待session1)
互相等待,導致發生死鎖
從打印的死鎖信息來看,基本和線上發生的死鎖現象是一致的。
  
再舉一個例子
mysql> select * from test01;
+----+-----+
| id | app |
+----+-----+
| 1 | 01 |
| 2 | 02 |
| 5 | 03 |
| 10 | 03 |
| 6 | 04 |
| 7 | 05 |
| 8 | 06 |
| 9 | 06 |
| 11 | 06 |
| 12 | 07 |
| 13 | 08 |
| 14 | 09 |
| 15 | 09 |
+----+-----+
13 rows in set (0.00 sec)
 
session1:
mysql> select now();start TRANSACTION;      
+---------------------+
| now() |
+---------------------+
| 2018-01-25 16:08:46 |
+---------------------+
1 row in set (0.00 sec)
  
session2:
mysql> select * from test01 where app='08' for update;  --第二步 鎖住【12,07】-【13,08】以及【13,08】-【14,09】兩段區間
+----+-----+
| id | app |
+----+-----+
| 13 | 08 |
+----+-----+
1 row in set (0.00 sec)
 
mysql> insert into test01(app) values ('04');                  ----第四步 等待第一步釋放,,于是死鎖
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
 
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 64 page no 4 n bits 80 index idx_app of table `devops`.`test01` trx id 5376 lock_mode X locks gap before rec insert intention waiting
Record lock, heap no 6 PHYSICAL RECORD: n_fields 2; compact format; info bits 0
 0: len 2; hex 3035; asc 05;;
 1: len 4; hex 00000007; asc ;;
 
*** WE ROLL BACK TRANSACTION (2)
------------
 
死鎖日志是不是和上面的一樣?

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 孝感市| 手机| 伊春市| 汉阴县| 饶河县| 辛集市| 永安市| 建始县| 大港区| 盐城市| 湖南省| 大姚县| 探索| 洮南市| 丰县| 宁阳县| 镇巴县| 天峨县| 峡江县| 多伦县| 蓬莱市| 津市市| 新建县| 措美县| 林西县| 静宁县| 泰来县| 瓮安县| 新晃| 涿鹿县| 铁岭市| 平湖市| 安平县| 辽源市| 天全县| 莱芜市| 壶关县| 崇州市| 荃湾区| 五河县| 凌云县|