{"id":3047,"date":"2018-09-10T12:20:15","date_gmt":"2018-09-10T04:20:15","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3047"},"modified":"2018-09-10T12:20:15","modified_gmt":"2018-09-10T04:20:15","slug":"mysql-innodb%e5%ad%98%e5%82%a8%e5%bc%95%e6%93%8eselect%e5%92%8cupdate%e6%9f%a5%e8%af%a2%e9%98%bb%e5%a1%9einsert%e8%af%ad%e5%8f%a5%e5%bd%a2%e6%88%90%e8%a1%a8%e7%ba%a7%e9%94%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3047","title":{"rendered":"MySQL InnoDB\u5b58\u50a8\u5f15\u64ceselect\u548cupdate\u67e5\u8be2\u963b\u585einsert\u8bed\u53e5,\u5f62\u6210\u8868\u7ea7\u9501"},"content":{"rendered":"<p>\n\t\u5927\u7ea6\u5728\u4e24\u4e2a\u6708\u524d\uff0c\u6709\u540c\u4e8b\u5728\u4f7f\u7528 Select \u67e5\u8be2\u8bed\u53e5\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u6574\u5f20\u8868\u88ab\u9501\u4e86\uff0c\u5bfc\u81f4\u65e5\u5fd7\u4e2d\u7ecf\u5e38\u51fa\u73b0 time out \u5f02\u5e38\u3002\u5f53\u65f6\u6211\u5224\u65ad\u662f select \u4e0d\u53ef\u80fd\u9501\u8868\u7684\uff0c\u800c\u4e14\u66f4\u4e0d\u53ef\u80fd\u9501\u6574\u5f20\u8868\u3002\u76f4\u5230\u4eca\u5929\u6211\u62bd\u51fa\u65f6\u95f4\u67e5\u8be2\u8d44\u6599\uff0c\u624d\u53d1\u73b0\u4e0d\u4ec5 Select \u4f1a\u9501\u6574\u5f20\u8868\uff0cUpdate \u548c delete \u90fd\u4f1a\u9501\u6574\u5f20\u8868\uff0c\u8fd9\u91cc\u9762\u7684\u539f\u56e0\u4e14\u542c\u672c\u6587\u5206\u89e3\uff01\n<\/p>\n<p>\n\tInnoDB \u7684\u7ec6\u7c92\u5ea6\u884c\u9501\u4ee5\u53ca\u4e8b\u52a1\u652f\u6301\u4e00\u5ea6\u662f MySQL \u6700\u5438\u5f15\u4eba\u7684\u7279\u6027\u4e4b\u4e8c\u3002\u4f46\u662f\u5728\u591a\u79cd\u60c5\u51b5\u4e0b\uff0cInnoDB \u7684\u884c\u7ea7\u9501\u4f1a\u53d8\u6210\u8868\u7ea7\u9501\u3002\u4f7f\u7528\u4e0d\u5f53\uff0c\u7ed9\u6211\u4eec\u5e26\u6765\u7684\u5371\u5bb3\u6781\u5927\uff01\n<\/p>\n<p>\n\t\u5982\u679c InnoDB \u7684\u67e5\u8be2\u6ca1\u6709\u547d\u4e2d\u7d22\u5f15\uff0c\u4e5f\u5c06\u9000\u5316\u4e3a\u8868\u9501\u3002InnoDB \u7684\u7ec6\u7c92\u5ea6\u9501\uff0c\u662f\u5b9e\u73b0\u5728\u7d22\u5f15\u8bb0\u5f55\u4e0a\u7684\u3002\n<\/p>\n<h2>\n\tInnoDB \u7684\u7d22\u5f15<br \/>\n<\/h2>\n<p>\n\tInnoDB \u7684\u7d22\u5f15\u6709\u4e24\u7c7b\u3002\u805a\u96c6\u7d22\u5f15(Clustered Index)\u4e0e\u666e\u901a\u7d22\u5f15(Secondary Index)\u3002\n<\/p>\n<p>\n\tInnoDB \u7684\u6bcf\u4e00\u4e2a\u8868\u90fd\u4f1a\u6709\u805a\u96c6\u7d22\u5f15\u3002\u5982\u679c\u4f60\u6ca1\u624b\u52a8\u521b\u5efa\uff0cInnoDB \u4e5f\u4f1a\u9ed8\u8ba4\u7684\u5e2e\u4f60\u521b\u5efa\u805a\u96c6\u7d22\u5f15\u3002\n<\/p>\n<p>\n\t\u805a\u96c6\u7d22\u5f15\u4ee5\u4e0b\u9762\u4e09\u79cd\u5f62\u5f0f\u5b58\u5728\uff1a\n<\/p>\n<ol>\n<li>\n\t\t\u5982\u679c\u8868\u5b9a\u4e49\u4e86 PK\uff0c\u5219 PK \u5c31\u662f\u805a\u96c6\u7d22\u5f15\uff1b\n\t<\/li>\n<li>\n\t\t\u5982\u679c\u8868\u6ca1\u6709\u5b9a\u4e49 PK\uff0c\u5219\u7b2c\u4e00\u4e2a\u975e\u7a7a unique \u5217\u662f\u805a\u96c6\u7d22\u5f15\uff1b\n\t<\/li>\n<li>\n\t\t\u5426\u5219\uff0cInnoDB \u4f1a\u521b\u5efa\u4e00\u4e2a\u9690\u85cf\u7684 row-id \u4f5c\u4e3a\u805a\u96c6\u7d22\u5f15\u3002\n\t<\/li>\n<\/ol>\n<p>\n\t\u6211\u4eec\u77e5\u9053\u7d22\u5f15\u7684\u7ed3\u6784\u662f B+ \u6811\uff0c\u8fd9\u91cc\u4e0d\u5c55\u5f00 B+ \u6811\u7684\u7ec6\u8282\uff0c\u5148\u8bf4\u51e0\u4e2a\u7ed3\u8bba\uff1a\n<\/p>\n<ol>\n<li>\n\t\t\u5728\u7d22\u5f15\u7ed3\u6784\u4e2d\uff0c\u975e\u53f6\u5b50\u8282\u70b9\u5b58\u50a8 key\uff0c\u53f6\u5b50\u8282\u70b9\u5b58\u50a8 value\uff1b\n\t<\/li>\n<li>\n\t\t\u805a\u96c6\u7d22\u5f15\uff0c\u53f6\u5b50\u8282\u70b9\u5b58\u50a8\u884c\u8bb0\u5f55(row)\uff1b\n\t<\/li>\n<li>\n\t\t\u666e\u901a\u7d22\u5f15\uff0c\u53f6\u5b50\u8282\u70b9\u5b58\u50a8\u4e86 PK \u7684\u503c\u3002\n\t<\/li>\n<\/ol>\n<p>\n\t\u7531\u4e8e\u4e0a\u9762\u6211\u4eec\u8bf4\u8fc7\u7684 InnoDB \u7684\u6bcf\u4e00\u4e2a\u8868\u90fd\u4f1a\u6709\u805a\u96c6\u7d22\u5f15\uff0c\u7d22\u5f15\u7ed3\u6784\u4e2d\u53f6\u5b50\u8282\u70b9\u5b58\u50a8 value\uff0c\u800c\u805a\u96c6\u7d22\u5f15\u7684\u53f6\u5b50\u8282\u70b9\u8fd8\u4f1a\u5b58\u50a8\u884c\u8bb0\u5f55(row)\u3002\u6240\u4ee5\uff0cInnoDB \u7d22\u5f15\u548c\u8bb0\u5f55\u662f\u5b58\u50a8\u5728\u4e00\u8d77\u7684\uff0c\u800c MyISAM \u7684\u7d22\u5f15\u548c\u8bb0\u5f55\u662f\u5206\u5f00\u5b58\u50a8\u7684\u3002\n<\/p>\n<p>\n\t\u6240\u4ee5\uff0cInnoDB \u7684\u666e\u901a\u7d22\u5f15\uff0c\u5b9e\u9645\u4e0a\u4f1a\u626b\u63cf\u4e24\u904d\uff1a\u7b2c\u4e00\u904d\uff0c\u7531\u666e\u901a\u7d22\u5f15\u627e\u5230 PK\uff1b\u7b2c\u4e8c\u904d\uff0c\u7531PK\u627e\u5230\u884c\u8bb0\u5f55\uff1b\n<\/p>\n<p>\n\t\u5173\u4e8e\u7d22\u5f15\u7ed3\u6784\uff0c\u6211\u8fd9\u91cc\u4e0d\u5c55\u5f00\u53bb\u8bb2\uff0c\u540e\u9762\u6211\u67e5\u8be2\u66f4\u591a\u8d44\u6599\u540e\uff0c\u5c06\u7ed9\u5927\u5bb6\u8be6\u7ec6\u7684\u8bb2\u8bb2 InnoDB\/MyISAM \u7684\u7d22\u5f15\u7ed3\u6784\uff0c\u5982\u679c\u5927\u5bb6\u611f\u5174\u8da3\u7684\u8bdd\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u8bf4\u660e\u3002\u5047\u8bbe\u5b58\u5728\u4e00\u4e2a\u4e0b\u9762\u7ed3\u6784\u7684 InnoDB \u8868\uff1a\n<\/p>\n<pre class=\"brush:sql;\">\r\nxttblog(id PK, name KEY, sex, flag);<\/pre>\n<p>\n\t\u8868\u4e2d\u6709\u56db\u6761\u8bb0\u5f55\uff1a\n<\/p>\n<pre class=\"brush:plain;\">\r\n1, shenjian, m, A\r\n3, zhangsan, m, A\r\n5, lisi, m, A\r\n9, wangwu, f, B<\/pre>\n<p>\n\t<img decoding=\"async\" alt=\"Innodb \u805a\u96c6\u7d22\u5f15\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/innodb-select-update.png\" style=\"width: 439px;height: 238px\" \/>\n<\/p>\n<p>\n\t\u4ece\u4e0a\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230\uff1a\n<\/p>\n<ul>\n<li>\n\t\t\u7b2c\u4e00\u5e45\u56fe\uff0cid PK\u7684\u805a\u96c6\u7d22\u5f15\uff0c\u53f6\u5b50\u5b58\u50a8\u4e86\u6240\u6709\u7684\u884c\u8bb0\u5f55\uff1b\n\t<\/li>\n<li>\n\t\t\u7b2c\u4e8c\u5e45\u56fe\uff0cname\u4e0a\u7684\u666e\u901a\u7d22\u5f15\uff0c\u53f6\u5b50\u5b58\u50a8\u4e86PK\u7684\u503c\uff1b\n\t<\/li>\n<\/ul>\n<p>\n\t\u5f53\u6267\u884c\u67e5\u8be2 select * from t where name=&rsquo;shenjian&rsquo;; \u8bed\u53e5\u65f6\uff0c\u4f1a\u53d1\u751f\u4e0b\u9762\u7684\u8fc7\u7a0b\uff1a\n<\/p>\n<ol>\n<li>\n\t\t\u4f1a\u5148\u5728 name \u666e\u901a\u7d22\u5f15\u4e0a\u67e5\u8be2\u5230PK=1\uff1b\n\t<\/li>\n<li>\n\t\t\u518d\u5728\u805a\u96c6\u7d22\u5f15\u886b\u67e5\u8be2\u5230(1,shenjian, m, A)\u7684\u884c\u8bb0\u5f55\uff1b\n\t<\/li>\n<\/ol>\n<p>\n\t\u518d\u56de\u5230\u6587\u7ae0\u5f00\u5934\u90e8\u5206\uff0c\u6211\u4eec\u8bf4\u8fc7&ldquo;InnoDB \u7684\u67e5\u8be2\u6ca1\u6709\u547d\u4e2d\u7d22\u5f15\uff0c\u4e5f\u5c06\u9000\u5316\u4e3a\u8868\u9501\u3002InnoDB \u7684\u7ec6\u7c92\u5ea6\u9501\uff0c\u662f\u5b9e\u73b0\u5728\u7d22\u5f15\u8bb0\u5f55\u4e0a\u7684\u3002&rdquo;\u7531\u4e8e\u8fd9\u91cc\u7684 name \u5e76\u6ca1\u6709\u521b\u5efa\u7d22\u5f15\uff0c\u6240\u4ee5\u5b83\u4f1a\u53d8\u6210\u8868\u9501\u3002\u81f3\u4e8e\u65f6\u8bfb\u9501\u548c\u5199\u9501\uff0c\u5b83\u4eec\u90fd\u662f\u9501\u3002InnoDB \u7684\u9501\uff0c\u4e0e\u7d22\u5f15\u7c7b\u578b\uff0c\u4e8b\u52a1\u7684\u9694\u79bb\u7ea7\u522b\u76f8\u5173\u3002InnoDB \u4e00\u5171\u6709 7 \u79cd\u9501\uff0c\u540e\u9762\u6709\u65f6\u95f4\u4e86\u7b49\u6211\u67e5\u8d44\u6599\uff0c\u6211\u4eec\u518d\u4e00\u8d77\u6765\u5b66\u4e60\uff01<\/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=3047\">MySQL InnoDB\u5b58\u50a8\u5f15\u64ceselect\u548cupdate\u67e5\u8be2\u963b\u585einsert\u8bed\u53e5,\u5f62\u6210\u8868\u7ea7\u9501<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5927\u7ea6\u5728\u4e24\u4e2a\u6708\u524d\uff0c\u6709\u540c\u4e8b\u5728\u4f7f\u7528 Select \u67e5\u8be2\u8bed\u53e5\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u6574\u5f20\u8868\u88ab\u9501\u4e86\uff0c\u5bfc\u81f4\u65e5\u5fd7\u4e2d\u7ecf\u5e38\u51fa\u73b0 time o [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[1674,1675,83,155,1676],"class_list":["post-3047","post","type-post","status-publish","format-standard","hentry","category-sql","tag-innodb","tag-myisam","tag-mysql","tag-sql","tag-1676"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3047","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=3047"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3047\/revisions"}],"predecessor-version":[{"id":3048,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3047\/revisions\/3048"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}