{"id":4933,"date":"2020-03-26T18:55:21","date_gmt":"2020-03-26T10:55:21","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4933"},"modified":"2020-03-26T18:55:21","modified_gmt":"2020-03-26T10:55:21","slug":"mysql-mvcc-%e8%ae%be%e8%ae%a1%e7%bc%ba%e9%99%b7","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4933","title":{"rendered":"MySQL MVCC \u8bbe\u8ba1\u7f3a\u9677"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u719f\u6089 Oracle \u7684\u90fd\u77e5\u9053 Oracle mvcc \u91cc\u6709\u4e00\u4e2a\u6982\u5ff5\uff1aquery restart\uff0c\u56e0\u6b64\u6211 3 \u6708\u4efd\u7684\u65f6\u5019\u53d1\u4e86\u4e00\u4e2a\u5fae\u535a\uff01<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/gitee.com\/xmtblog\/img\/raw\/master\/WX20200326-184056.png\" alt=\"MySQL query restart\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u7684\u56de\u7b54\uff1a\u8fd9\u662f MySQL MVCC \u7684\u4e00\u4e2a\u8bbe\u8ba1\u7f3a\u9677\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136 SQL-92 \u89c4\u5b9a\u4e86\u56db\u79cd\u9694\u79bb\u7ea7\u522b\uff0c\u4f46\u662f\u5728\u5f15\u5165 MVCC \u540e\uff0cRC\/RR \u90fd\u662f snapshot isolation \u4e0b\u7684\u53d8\u4f53\u3002\u81f3\u4e8e\u5bf9\u9694\u79bb\u6027\u548c\u4e00\u81f4\u6027\u7684\u5410\u69fd\uff0c\u5f15\u7528\u6c88\u6d35\u7684\u8bdd\uff1a\u201c\u5feb\u7167\u8bfb\u4ee5\u66f4\u4f4e\u7684\u4ee3\u4ef7\u5b9e\u73b0\u4e86\u66f4\u9ad8\u7684\u5e76\u53d1\u5ea6\uff0c\u5374\u4e0d\u5f97\u4e0d\u59d4\u8eab\u5728\u539f\u6709\u4e8b\u52a1\u6846\u67b6\u5185\u3002\u5176\u5b9e ACID \u4e5f\u53ea\u662f\u4e00\u4e2a\u6807\u51c6,\u5e76\u975e\u771f\u7406\u3002\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e2\u7136\u662f snapshot isolation\uff0cMySQL \u6709\u4ec0\u4e48\u95ee\u9898\u5462\uff0c\u76f4\u63a5\u4e0a\u6848\u4f8b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u51c6\u5907\u5de5\u4f5c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>create table mvcc(x int auto_increment primary key,y int default 1);<\/code><code>insert into mvcc(y)  select 1 from mvcc; -- many times<\/code><code>Query OK, 2097152 rows affected (13.24 sec)<\/code><code>Records: 2097152  Duplicates: 0  Warnings: 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">RC\/RR &amp;&amp; autocommit = 0<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/gitee.com\/xmtblog\/img\/raw\/master\/WX20200326-184139.png\" alt=\"MySQL query restart\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6309\u7167 snapshot isolation \u6765\u8bf4 session2 \u7684 trx<em>id \u5927\u4e8e session1 \u7684 trx<\/em>id\uff0c\u4ece\u800c session2 \u7684\u4fee\u6539\u5bf9 session1 \u5e94\u8be5\u662f\u4e0d\u53ef\u89c1\u7684\uff1a\u5373 session1 \u5e94\u8be5\u66f4\u65b0 0 \u884c\uff0c\u4f46\u662f MySQL \u5728\u8fd9\u91cc\u5374\u5bf9 y=2 \u8fdb\u884c\u4e86\u66f4\u65b0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL \u5b98\u65b9\u5728 5.5+ \u7684\u6587\u6863\u4e5f\u9488\u5bf9\u8be5\u95ee\u9898\u505a\u51fa\u4e86 Note\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The snapshot of the database state applies to SELECT statements within a transaction, not necessarily to DML statements. If you insert or modify some rows and then commit that transaction, a DELETE or UPDATE statement issued from another concurrent REPEATABLE READ transaction could affect those just-committed rows, even though the session could not query them. If a transaction does update or delete rows committed by a different transaction, those changes do become visible to the current transaction.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u672c\u539f\u56e0\u5728\u4e8e MySQL \u5728 update\/delete\/insert\/select for update\/select lock in share mode \u65f6\u8fdb\u884c\u7684\u662f current read(select<em>lock<\/em>type != LOCK_NONE) \u800c\u975e consistent read\u3002\u800c Oracle \u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u65b9\u5f0f\u662f\u5bf9\u6bd4 current read \u548c consistent read \u6765\u51b3\u5b9a\u662f\u5426\u8fdb\u884c query restart(\u7ec6\u8282\u53c2\u8003 tom oracle \u827a\u672f)\uff1b\u5bf9\u4e8e\u8be5\u6848\u4f8b\uff0csession1 \u5728 T2 \u65f6\u66f4\u65b0\u5230 x=3000000 \u65f6\u53d1\u73b0 y \u53d1\u751f\u4e86\u53d8\u5316\u4ece\u800c\u56de\u6eda\u4e86\u8fd9\u4e2a\u53d8\u66f4\u5e76\u8fdb\u5165 query restart\uff0c\u6700\u7ec8\u7ed3\u679c\u5c31\u662f\u5728 T3 \u65f6\u66f4\u65b0\u4e86 0 \u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u6b64\uff0c\u5982\u679c\u4e1a\u52a1\u4f9d\u8d56\u4e8b\u52a1\u4f46\u662f\u53c8\u4e0d\u6e05\u695a\u5177\u4f53\u6570\u636e\u5e93\u7684\u5b9e\u73b0\u7ec6\u8282\uff0c\u5f88\u5bb9\u6613\u5c31\u6389\u5230\u5751\u91cc\u4e86\uff1b\u6bd4\u5982\u8fd9\u4e2a\u6848\u4f8b\uff0c\u5c31\u4ea7\u751f\u4e86&#8221;\u9519\u8bef\u7684&#8221;\u66f4\u65b0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u9488\u5bf9 MySQL RR \u7ed9\u51fa\u4e00\u4e2a\u975e\u8c13\u8bcd\u66f4\u65b0\u7684\u4e00\u4e2a\u6848\u4f8b\uff1a\u5982\u679c\u4e0d\u7406\u89e3\u8fd9\u5757\u4e8b\u52a1\uff0c\u5728T3\u65f6\u60f3\u5f53\u7136\u5c31\u4f1a\u89c9\u5f97\u7ed3\u679c\u5e94\u8be5\u662f 6000\uff0c\u53ef\u80fd\u5c31\u72af\u9519\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RR &amp;&amp; autocommit=0<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/gitee.com\/xmtblog\/img\/raw\/master\/WX20200326-184231.png\" alt=\"MySQL query restart\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u603b\u7684\u6765\u8bf4\u4e8b\u52a1\u7684\u6c34\u8fd8\u662f\u6bd4\u8f83\u6df1\u7684\uff0c\u5f53\u9762\u5bf9\u5206\u5e03\u5f0f\u65f6\uff0c\u53c8\u662f\u53e6\u5916\u4e00\u756a\u70e7\u8111\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4933\">MySQL MVCC \u8bbe\u8ba1\u7f3a\u9677<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u719f\u6089 Oracle \u7684\u90fd\u77e5\u9053 Oracle mvcc \u91cc\u6709\u4e00\u4e2a\u6982\u5ff5\uff1aquery restart\uff0c\u56e0\u6b64\u6211 3 \u6708 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[1968,83,580,391,722],"class_list":["post-4933","post","type-post","status-publish","format-standard","hentry","category-sql","tag-mvcc","tag-mysql","tag-mysql----dba","tag-722"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4933"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4933\/revisions"}],"predecessor-version":[{"id":4934,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4933\/revisions\/4934"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}