新聞中心
這篇文章主要講解了“MySQL mvcc奇怪的現(xiàn)象分析”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“MySQL mvcc奇怪的現(xiàn)象分析”吧!
創(chuàng)新互聯(lián)主營神農(nóng)架林區(qū)網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā)公司,神農(nóng)架林區(qū)h5小程序定制開發(fā)搭建,神農(nóng)架林區(qū)網(wǎng)站營銷推廣歡迎神農(nóng)架林區(qū)等地區(qū)企業(yè)咨詢
奇怪的現(xiàn)象1:
session1:
root@localhost : test 08:43:09> select * from test1;(1)
+---------+------+
| orderid | ID |
+---------+------+
| 2 | 123 |
+---------+------+
1 row in set (0.00 sec)
root@localhost : test 08:43:14> start transaction;(2)
Query OK, 0 rows affected (0.00 sec)
root@localhost : test 08:43:23> select * from test1;(3)
+---------+------+
| orderid | ID |
+---------+------+
| 2 | 123 |
+---------+------+
1 row in set (0.00 sec)
root@localhost : test 08:43:27> select * from test1;(5)
+---------+------+
| orderid | ID |
+---------+------+
| 2 | 123 |
+---------+------+
1 row in set (0.00 sec)
root@localhost : test 08:44:03> update test1 set id=234 where orderid=1;(6)
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
root@localhost : test 08:44:27> select * from test1;(7)
+---------+------+
| orderid | ID |
+---------+------+
| 1 | 234 |
| 2 | 123 |
+---------+------+
2 rows in set (0.00 sec)
session2:
root@localhost : test 08:43:48> INSERT into test1 values(1,123);(4)
Query OK, 1 row affected (0.01 sec)
奇怪的現(xiàn)象2:
session1:
root@localhost : test 08:46:57> select * from test1;(1)
+---------+------+
| orderid | ID |
+---------+------+
| 1 | 123 |
| 2 | 123 |
+---------+------+
2 rows in set (0.00 sec)
root@localhost : test 08:47:01> start transaction;(2)
Query OK, 0 rows affected (0.00 sec)
root@localhost : test 08:47:15> select * from test1;(4)
+---------+------+
| orderid | ID |
+---------+------+
| 1 | 123 |
| 2 | 123 |
| 3 | 123 |
+---------+------+
3 rows in set (0.00 sec)
session2:
insert into test1 values(3,'123');(3)
現(xiàn)象3:
root@localhost : test 08:49:26> start transaction;(1)
Query OK, 0 rows affected (0.00 sec)
root@localhost : test 08:49:28> select * from test1;(2)
+---------+------+
| orderid | ID |
+---------+------+
| 1 | 123 |
| 2 | 123 |
| 3 | 123 |
+---------+------+
3 rows in set (0.00 sec)
root@localhost : test 08:49:30> select * from test1;(4)
+---------+------+
| orderid | ID |
+---------+------+
| 1 | 123 |
| 2 | 123 |
| 3 | 123 |
+---------+------+
3 rows in set (0.00 sec)
session2:
root@localhost : test 08:47:43> insert into test1 values(4,'123');(3)
Query OK, 1 row affected (0.01 sec)
現(xiàn)象2和現(xiàn)象3中可以用mvcc中的read-view完美解釋:
1、 看不到read view創(chuàng)建時(shí)刻以后啟動(dòng)的事務(wù)
2、 看不到read view創(chuàng)建時(shí)活躍的事務(wù)
可能我們熟知的在repeatable-read的隔離級別下,是當(dāng)一個(gè)會(huì)話發(fā)起dml語句后,在當(dāng)前會(huì)話中如果沒有提交當(dāng)前會(huì)話是看不到dml語句操作的結(jié)果的!read-view的應(yīng)用可能很少注意到,像我就是這樣。
但是現(xiàn)象1怎么解釋呢?
會(huì)話1中的insert trx_id=aa 會(huì)話2 中的 trx_id=ac,session2中update之后trx_id=ab ,下面可以看得更清楚
也就是在會(huì)話一中update 會(huì)話2上的不可見的更新時(shí) 會(huì)將會(huì)話2中的trx_id變?yōu)闀?huì)話1相同的trx_id 所以會(huì)話1這個(gè)時(shí)候能看到的會(huì)話2 中不可見數(shù)據(jù)的更新之后的狀態(tài)。
感謝各位的閱讀,以上就是“MySQL mvcc奇怪的現(xiàn)象分析”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對MySQL mvcc奇怪的現(xiàn)象分析這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
文章題目:MySQLmvcc奇怪的現(xiàn)象分析
網(wǎng)站網(wǎng)址:http://www.ef60e0e.cn/article/pjscgs.html