??????????????????????????????????????????????????????????????????????????????г????????RR???????????????????????????????????Serializable??????????????????????????????C????Ч??????????C??????????teacher_id=1??????commit??RR???????????л??????????A????teacher_id=1????????????????C??????????????????????MySQL?????????????????????????C????????A????????????????????????MySQL??RR?????У???????????????????μ????
????MySQL??Innodb?е?????????????????
???????????????????MVCC????壬?????????????????????????????ν?????????????????InnoDB??RR???????д?????????
????####“??”??“??”??????
?????????ж???????????????????????????????????壬????????????????????д???????????????????????MySQL?е????????????????е?????????????
???????????????RR?????У????MVCC???????????????????????????????????????????????????????????????????????????????????????Щ??????????Ч?????е?????У???????????
?????????????????????????????????????? (snapshot read)??????????????汾??????????е???? (current read)???????????MVCC?У?
?????????????select select * from table ....; ???????????????????????/????/????????????????????????????????????????????? select * from table where ? lock in share mode;select * from table where ? for update;insert;update ;delete;
????????????????????????????????????MySQL?????????????????????????????????????????????????????????????????select???ü???????update??insert??Щ“?????”?????????????????????
????###д??"?????"??
??????????????????????????????????????????????????д?????????????“??”?????????????????????????“д”?????????
???????????????е???????MySQL?????????Next-Key????
????####Next-Key??
????Next-Key??????????GAP??????????????????????????????????????????GAP???????
?????????????????????汾????????????????????????????????α?????????????????????????????????RR?????RC???????
????RC????
????????A ????B begin;
????begin;
????select id??class_name??teacher_id from class_teacher where teacher_id=30;
????id class_name teacher_id 2 ???????? 30
????update class_teacher set class_name='???????' where teacher_id=30;
????insert into class_teacher values (null??'????????'??30);
????commit;
????select id??class_name??teacher_id from class_teacher where teacher_id=30;
????id class_name teacher_id 2 ??????? 30 10 ???????? 30
????RR????
????????A ????B begin;
????begin;
????select id??class_name??teacher_id from class_teacher where teacher_id=30;
????id class_name teacher_id 2 ???????? 30 update class_teacher set class_name='???????' where teacher_id=30;
????insert into class_teacher values (null??'????????'??30);
????waiting....
????select id??class_name??teacher_id from class_teacher where teacher_id=30;
????id class_name teacher_id 2 ??????? 30 commit; ????Acommit??????B??insert??С?
???????????????????????RC?????У?????A?????????teacher_id=30????????????????Binsert?????????????A????ī????????????teacher_id=30?????????????б?????update?????????????“?????”??????
????RR?????У?????A??update???????????B??????????????????????A??update???????????????£????????????????????Gap????
????MySQL??????????
??????class_teacher??????У?teacher_id??????????????????????B+?????????????????????????????????????????????ν?????????????
????MySQL??Innodb?е?????????????????
????????????InnoDB??????????????teacher_id??????????????????????????κ?????id?????????????????????????????????????????С?
????Innodb????????????????????
????(negative infinity?? 5]??(5??30]??(30??positive infinity)??
????update class_teacher set class_name='???????' where teacher_id=30;???????????????????????????У?????????????????5??30]???30??positive infinity????????????gap????????????B????????????????insert?????????
?????????????????????Innodb????????????????????????????????
????????A ????B ????C begin; begin; begin;
????select id??class_name??teacher_id from class_teacher;
????id class_name teacher_id 1 ???????
????5
????2 ???????? 30 update class_teacher set class_name='??????' where teacher_id=20;
????insert into class_teacher values (null??'???????'??10);
????waiting .....
????insert into class_teacher values (null??'???????'??40); commit; ????A commit???????????????? commit; commit;
????update??teacher_id=20????(5??30]??????????????κ??????Innodb?????????????gap???????????????????????C????????
????????????????????????Σ?????update class_teacher set teacher_id=7 where class_name='?????????????????κ??????'??????????????gap?????????????????????????????????MySQL Server??????????????????????????????????????????Щ????????????????????????????????????????????????????κ??????
???????????????????????????GAP????????????????????????GAP??????γ???Next-Key??????????RR??????д?????????????
????###Serializable
??????????????????????????д????????????д???????????????????????????????????????????????????????????????????????????в?????????????????????????????????????????
??????????2???????????select?????????????Serializable??????????????????