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

首頁 > 數據庫 > MySQL > 正文

MySQL語句加鎖的實現分析

2024-07-24 12:50:59
字體:
來源:轉載
供稿:網友

摘要: MySQL兩條SQL語句鎖的分析

看一下下面的SQL語句加什么鎖

SLQ1:select * from t1 where id = 10;SQL2:delete from t1 where id = 10;

(1)id 是不是主鍵

(2)當前系統的隔離級別是什么

(3)id列如果不是主鍵,那么id列上有索引嗎

(4)id列上如果有二級索引,那么這個索引是二級索引嗎

(5)兩個SQL的執行計劃是什么?索引掃描還是全表掃描

實際的執行計劃需要根據MySQL的輸出為準

組合一:id列是主鍵,RC隔離級別
組合二:id列是二級唯一索引,RC隔離級別
組合三:id列是二級非唯一索引,RC隔離級別
組合四:id列沒有索引,RC隔離級別
組合五:id列是主鍵,RR隔離級別
組合六:id列是二級唯一索引,RR隔離級別
組合七:id列是二級非唯一索引,RR隔離級別
組合八:id列上沒有索引,RR隔離級別

Serializable隔離級別

在RR RC隔離級別下,SQL1:select 均不加鎖,采用的是快照讀;以下僅討論SQL2:delete操作的加鎖
Percona

組合一:id主鍵+RC
Percona

---TRANSACTION 1286310, ACTIVE 9 sec2 lock struct(s), heap size 360, 1 row lock(s), undo log entries 1MySQL thread id 341, OS thread handle 0x7f4d540d0700, query id 4510972 localhost root cleaning upTABLE LOCK table `test`.`t1` trx id 1286310 lock mode IXRECORD LOCKS space id 29 page no 3 n bits 80 index `PRIMARY` of table `test`.`t1` trx id 1286310 lock_mode X locks rec but not gap

MySQL

---TRANSACTION 5936, ACTIVE 171 sec2 lock struct(s), heap size 360, 1 row lock(s), undo log entries 1MySQL thread id 2, OS thread handle 0x7f5677201700, query id 364 localhost rootTABLE LOCK table `test`.`t1` trx id 5936 lock mode IXRECORD LOCKS space id 6 page no 3 n bits 80 index `PRIMARY` of table `test`.`t1` trx id 5936 lock_mode X locks rec but not gapRecord lock, heap no 5 PHYSICAL RECORD: n_fields 4; compact format; info bits 32 0: len 4; hex 8000000a; asc ;; 1: len 6; hex 000000001730; asc 0;; 2: len 7; hex 26000001550110; asc & U ;; 3: len 1; hex 61; asc a;;

組合二:id唯一索引+RC
在唯一索引上的更新需要兩個X鎖,一個對應唯一索引id=10 記錄,一個對應于聚簇索引name='d'的記錄
Percona

---TRANSACTION 1286327, ACTIVE 3 sec3 lock struct(s), heap size 360, 2 row lock(s), undo log entries 1MySQL thread id 344, OS thread handle 0x7f4d5404e700, query id 4510986 localhost root cleaning upTABLE LOCK table `test`.`t2` trx id 1286327 lock mode IXRECORD LOCKS space id 30 page no 4 n bits 80 index `id` of table `test`.`t2` trx id 1286327 lock_mode X locks rec but not gapRECORD LOCKS space id 30 page no 3 n bits 80 index `PRIMARY` of table `test`.`t2` trx id 1286327 lock_mode X locks rec but not gap
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 民权县| 板桥市| 三明市| 南川市| 大方县| 千阳县| 德兴市| 建水县| 永宁县| 衡山县| 吴堡县| 阿勒泰市| 监利县| 吉木乃县| 衡阳市| 得荣县| 合川市| 通许县| 安义县| 绥化市| 土默特右旗| 黄梅县| 呈贡县| 湖南省| 论坛| 海门市| 韩城市| 哈尔滨市| 临武县| 儋州市| 微博| 于田县| 建平县| 怀宁县| 东阿县| 昌乐县| 治县。| 互助| 巴东县| 广东省| 十堰市|