MySQL??Innodb?е?????????????????
???????????? ???????[ 2016/11/2 10:38:17 ] ????????????? MySQL ??
???????:
??????????????????????????????????????Щ????????????????????????????ü?????????????????????????????????????????д???????????????????????????????????????????????????????????????????????????????????????????????????????MySQL??InnoDB???????????????????????????????????????????????????????????
????#??η???or????????
????????д?????????????????????????????????????????η????????????????????Σ?????????????????Щ???????????????????????????????????????????????????Ч?????????????????????????????????????????????Σ??????????????????Щ?????
??????????????????????Э?飬??????????????Σ???????κ??????Σ??????????????
??????????Σ???y?ο?????м?????????????κ???????ж???????????????S?????????????????????????????????????????????????????????д??????????????X???????????????????????????κ??????????????????????????????????????????????????С???????Σ??????????????????????????????????Σ???y???????н???????????????м????????? ???? ????/???????? begin?? insert into test ..... ??insert??????? update test set... ??update??????? delete from test .... ??delete??????? commit; ??????????????insert??update??delete???????
????????????????????????????????????Э???????????????????????л??????л??????????????????????????????????
????#?????е???????
????##??????????????
???????????????У??????Ч????????????????????????????????????????????????????????????Щ???????????
?????????? ?????Dirty Read?? ???????????NonRepeatable Read?? ?????Phantom Read?? δ??????Read uncommitted?? ???? ???? ???? ????????Read committed?? ?????? ???? ???? ?????????Repeatable read?? ?????? ?????? ???? ????л???Serializable ?? ?????? ?????? ?????? δ????(Read Uncommitted)?????????????????????????????δ??????????????????(Read Committed)?????????????????????Oracle????????????????ü??? (???????)???????(Repeated Read)????????????????????????????????????????μ??InnoDB????????SQL????У????????????????????????????????????????ж?(Serializable)????????л????????ζ?????????????????????д??????????
????Read Uncommitted???????????????????????????κβ?????????????????????????
????##MySQL??????????
????MySQL?????????????г?????????????????????????Metadata Lock???????????????????????????????????д???????????????????????2???????????????????ddl???????á?
????????????????????У???????????????????????????????????????????????????????????????????????????MySQL?????????????????????????????????????????????
????###Read Committed????????????
??????RC?????У?????????????????????????????д?????????????????????Ч??????
????MySQL> show create table class_teacher G
????Table: class_teacher
????Create Table: CREATE TABLE `class_teacher` (
????`id` int(11) NOT NULL AUTO_INCREMENT??
????`class_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL??
????`teacher_id` int(11) NOT NULL??
????PRIMARY KEY (`id`)??
????KEY `idx_teacher_id` (`teacher_id`)
????) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
????1 row in set (0.02 sec)
????MySQL> select * from class_teacher;
????+----+--------------+------------+
????| id | class_name | teacher_id |
????+----+--------------+------------+
????| 1 | ??????? | 1 |
????| 3 | ??????? | 2 |
????| 4 | ???????? | 2 |
????+----+--------------+------------+
????????MySQL??InnoDB?????????RR???????????????????session?????RC????????????binlog????
????SET session transaction isolation level read committed;
????SET SESSION binlog_format = 'ROW';????????MIXED??
????????A ????B begin; begin; update class_teacher set class_name='????????' where teacher_id=1; update class_teacher set class_name='????????' where teacher_id=1; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction commit;
??????????????????е????????????A??MySQL??teacher_id=1???????м???????????commit??????????????????B????ò???????????wait????????
?????????????????teacher_id?????????????????????????class_name???update class_teacher set teacher_id=3 where class_name = '???????';
???????MySQL??????????????????е???????????????????е?????飬?????sql???е?????У?MySQL?????????Щ???????? class_name = '???????'???????????????????????????????????????????洢???????????м???????????????MySQL Server????й????
?????????????ù?????У?MySQL?????Щ???????MySQL Server?????????????????????????unlock_row?????????????????????????? (Υ?????????Э??????)???????????????????????????????????????????????????????????????????????????????MySQL?????Ч??????Υ???淶??????μ?????????MySQL???????????p181??
????????????????????MySQL??????????RR??????????????????????????????????????????????????????MySQL Server???????????????????????????????????Щ?е????????????????????????????
????###Repeatable Read?????????
????????MySQL??InnoDB?????????????????“??”??“д”?????????????
????####??
????????????????????????????????????????????????????????????????????У??е???????????????Ч????
????RC??????????????μ????
????????A ????B begin;
????begin;
????select id??class_name??teacher_id from class_teacher where teacher_id=1;
????id class_name teacher_id 1 ???????? 1 2 ??????? 1
????update class_teacher set class_name='????????' where id=1;
????commit;
????select id??class_name??teacher_id from class_teacher where teacher_id=1;
????id class_name teacher_id 1 ???????? 1 2 ??????? 1
??????????????B??????????????β????????????????????????
????commit;
????????B???id=1???????????????A?????????????κ????ε???????????????????????????????????????????????????????Щ???????????????????RR??????MySQL??????
????????A ????B ????C begin;
????begin;
????begin;
????select id??class_name??teacher_id from class_teacher whereteacher_id=1;
????id class_name teacher_id 1 ???????? 1 2 ??????? 1
????update class_teacher set class_name='????????' where id=1;
????commit;
????insert into class_teacher values (null??'????????'??1);
????commit;
????select id??class_name??teacher_id from class_teacher whereteacher_id=1;
????id class_name teacher_id 1 ???????? 1 2 ??????? 1
??????ж???????B???????????????sql?????????????????????
??????ж???????C???????????
????commit;
???????????????teacher_id=1???????A????????ζ????????B?м??????id=1?????????commit???????A????ζ?????????????????????????????????????????MySQL????????????????????????????????????????
????####???????????????????####
??????????????????????????????????????Щ???????????????????????update??delete????????????????insert??
?????????????????????????????????????????У???sql????ζ?????????????Щ?????????????????????????Щ?????????????????????????????????????insert????????????????A??????????????????????????????????B???????insert???????????????A????ī????????????????е??????????????????????????????????Serializable?????? ???????????д??д??????????д?????????????????Ч??????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????
??????????????????????????????????????????????MySQL??ORACLE??PostgreSQL?????????????????????????????????????????????????MVCC????汾?????????????????????????
????####?????????????####
??????????
?????????????????????????????磨?????????????????????????????????????????????????????????????????????????У???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????????£?????????????????????????????????????????????????????????????????Щ????????????????????????????????????????Щ?????
?????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????汾?? Version ???????????????ν????汾?????????????????汾?????????????????汾????????У??????????????????????? “version” ?????????????????????????汾??????????????????????汾????????????????????汾??????????????????????汾??????б??????????????汾??????????????汾???????????£??????????????????
?????????????MVCC???????й????淶?????????????в??????????????????????InnoDB??MVCC??
????####MVCC??MySQL??InnoDB?е????
??????InnoDB?У????????????????????????????????????MVCC?????????????????????????????????????????????????????????????????????? ?????????У??洢???????????????????汾??????????????????????汾???????? ??????Repeatable reads??????????£?
????SELECT???????????汾??<=???????汾???????汾??????>???????汾???INSERT??????浱?????汾????е?????汾??DELETE??????浱?????汾????е?????汾??UPDATE???????????????????浱?????汾????д????汾????????浱?????汾?????????????
???????MVCC???????м????????????洢?????????м?鶴??????Щ???????????????????????????????????????????????ü???????????????????????????????????????????????????У??????????С?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11