{"id":4225,"date":"2019-05-09T18:29:51","date_gmt":"2019-05-09T10:29:51","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4225"},"modified":"2019-05-09T18:29:51","modified_gmt":"2019-05-09T10:29:51","slug":"%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e4%bd%a0mysql%e4%b8%ad%e6%9f%a5%e8%af%a2%e5%9b%9e%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4225","title":{"rendered":"\u624b\u628a\u624b\u6559\u4f60MySQL\u4e2d\u67e5\u8be2\u56de\u8868"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u80fd\u4ece\u6765\u90fd\u6ca1\u6709\u542c\u8bf4\u8fc7\u56de\u8868\u4e00\u8bcd\uff0c\u4f46\u662f\u4f60\u5728\u5b9e\u9645\u5de5\u4f5c\u4e2d\u80af\u5b9a\u7528\u8fc7\u56de\u8868\u3002\u5982\u679c\u8fd8\u6ca1\u6709\u542c\u8fc7\u56de\u8868\uff0c\u90a3\u6211\u76f8\u4fe1\u4e0d\u7ba1\u4f60\u770b\u591a\u5c11 SQL \u4f18\u5316\u7684\u77e5\u8bc6\uff0c\u90fd\u8fd8\u53ea\u662f\u505c\u7559\u5728\u8868\u9762\u3002\u5373\u4f7f\u4f60\u53c2\u8003\u5b66\u4e60\u8fc7\u6211\u524d\u9762\u7684\u8fd9\u7bc7\u6587\u7ae0\u300a<a href=\"https:\/\/www.xttblog.com\/?p=3524\">MySQL \u6027\u80fd\u4f18\u5316\u795e\u5668 Explain \u4f7f\u7528\u6559\u7a0b<\/a>\u300b\u3002 <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g2v87zffkoj20jl0dbq7g.jpg\" alt=\"\" \/><figcaption>\u4e00\u6761SQL\u8bed\u53e5\u7684\u67e5\u8be2\u8fc7\u7a0b<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u5148\u6765\u770b\u770b\u4ec0\u4e48\u662f\u56de\u8868\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u4fd7\u7684\u8bb2\u5c31\u662f\uff0c\u5982\u679c\u7d22\u5f15\u7684\u5217\u5728 select \u6240\u9700\u83b7\u5f97\u7684\u5217\u4e2d\uff08\u56e0\u4e3a\u5728 mysql \u4e2d\u7d22\u5f15\u662f\u6839\u636e\u7d22\u5f15\u5217\u7684\u503c\u8fdb\u884c\u6392\u5e8f\u7684\uff0c\u6240\u4ee5\u7d22\u5f15\u8282\u70b9\u4e2d\u5b58\u5728\u8be5\u5217\u4e2d\u7684\u90e8\u5206\u503c\uff09\u6216\u8005\u6839\u636e\u4e00\u6b21\u7d22\u5f15\u67e5\u8be2\u5c31\u80fd\u83b7\u5f97\u8bb0\u5f55\u5c31\u4e0d\u9700\u8981\u56de\u8868\uff0c\u5982\u679c select \u6240\u9700\u83b7\u5f97\u5217\u4e2d\u6709\u5927\u91cf\u7684\u975e\u7d22\u5f15\u5217\uff0c\u7d22\u5f15\u5c31\u9700\u8981\u5230\u8868\u4e2d\u627e\u5230\u76f8\u5e94\u7684\u5217\u7684\u4fe1\u606f\uff0c\u8fd9\u5c31\u53eb\u56de\u8868\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u8fd9\u4e2a\u6982\u5ff5\uff0c\u5f53\u4f60\u4f7f\u7528 Explain \u6267\u884c\u67e5\u8be2\u8ba1\u5212\u65f6\uff0c\u5f53\u7ed3\u679c\u4e2d Extra \u51fa\u73b0\u4e86 using index\u3001using where\u3001using index condition \u7b49\u4f60\u5c31\u8ba4\u4e3a\u4f7f\u7528\u4e86\u8fc7\u6ee4\u6761\u4ef6\uff0c\u4f7f\u7528\u4e86\u7d22\u5f15\uff0cSQL \u4f18\u5316\u7684\u8fd8\u4e0d\u9519\u3002\u8fd9\u5176\u5b9e\u662f\u4e00\u79cd\u9519\u8bef\u7684\u8ba4\u8bc6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u4e3a\uff0c\u4f7f\u7528\u4e86\u7d22\u5f15\u5e76\u4e0d\u4ee3\u8868\u67e5\u8be2\u5c31\u6700\u4f18\u3002\u4ece using index condition\u3001using index &amp; using where \u7b49\u53ef\u4ee5\u770b\u51fa\uff0c\u8fd9\u6761 SQL \u8bed\u53e5\u5176\u5b9e\u662f\u8fdb\u884c\u4e86\u56de\u8868\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u6709\u4e9b\u65f6\u5019\uff0c\u4f60\u67e5\u770b Explain \u6267\u884c\u8ba1\u5212\u540e\uff0c\u53d1\u73b0\u660e\u660e\u8d70\u4e86\u7d22\u5f15\uff0c\u4e3a\u4ec0\u4e48\u8fd8\u662f\u6162\uff1f\u8fd9\u91cc\u9762\u53ef\u80fd\u5c31\u662f\u5b58\u5728\u56de\u8868\u4e86\u3002\u4e0b\u9762\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u8bf4\u660e\u4ec0\u4e48\u662f\u56de\u8868\u3002\u5148\u521b\u5efa\u4e00\u5f20\u8868\uff0csql \u8bed\u53e5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create table xttblog(\n    id int primary key, \n    k int not null, \n    name varchar(16),\n    index (k)\n)engine = InnoDB;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\uff0c\u6211\u4eec\u518d\u6267\u884c\u4e0b\u9762\u7684 SQL \u8bed\u53e5\uff0c\u63d2\u5165\u51e0\u6761\u6d4b\u8bd5\u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO xttblog(id, k, name) VALUES(1, 2, 'xttblog'),\n    (2, 1, '\u4e1a\u4f59\u8349'),\n    (3, 3, '\u4e1a\u4f59\u8349\u516c\u4f17\u53f7');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\uff0c\u73b0\u5728\u6211\u4eec\u8981\u67e5\u8be2\u51fa id \u4e3a 2 \u7684\u6570\u636e\u3002\u90a3\u4e48\u6267\u884c select * from xttblog where ID = 2; \u8fd9\u6761 SQL \u8bed\u53e5\u5c31\u4e0d\u9700\u8981\u56de\u8868\u3002\u539f\u56e0\u662f\u6839\u636e\u4e3b\u952e\u7684\u67e5\u8be2\u65b9\u5f0f\uff0c\u5219\u53ea\u9700\u8981\u641c\u7d22 ID \u8fd9\u68f5 B+ \u6811\u3002\u4e3b\u952e\u662f\u552f\u4e00\u7684\uff0c\u6839\u636e\u8fd9\u4e2a\u552f\u4e00\u7684\u7d22\u5f15\uff0cMySQL \u5c31\u80fd\u786e\u5b9a\u641c\u7d22\u7684\u8bb0\u5f55\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u5f53\u6211\u4eec\u4f7f\u7528 k \u8fd9\u4e2a\u7d22\u5f15\u6765\u67e5\u8be2 k = 2 \u7684\u8bb0\u5f55\u65f6\u5c31\u8981\u7528\u5230\u56de\u8868\u3002select * from xttblog where k = 2; \u539f\u56e0\u662f\u901a\u8fc7 k \u8fd9\u4e2a\u666e\u901a\u7d22\u5f15\u67e5\u8be2\u65b9\u5f0f\uff0c\u5219\u9700\u8981\u5148\u641c\u7d22 k \u7d22\u5f15\u6811\uff0c\u7136\u540e\u5f97\u5230\u4e3b\u952e ID \u7684\u503c\u4e3a 1\uff0c\u518d\u5230 ID \u7d22\u5f15\u6811\u641c\u7d22\u4e00\u6b21\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u867d\u7136\u7528\u4e86\u7d22\u5f15\uff0c\u4f46\u5b9e\u9645\u4e0a\u5e95\u5c42\u8fdb\u884c\u4e86\u4e24\u6b21\u7d22\u5f15\u67e5\u8be2\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u79f0\u4e3a\u56de\u8868\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e5f\u5c31\u662f\u8bf4\uff0c\u57fa\u4e8e\u975e\u4e3b\u952e\u7d22\u5f15\u7684\u67e5\u8be2\u9700\u8981\u591a\u626b\u63cf\u4e00\u68f5\u7d22\u5f15\u6811\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5728\u5e94\u7528\u4e2d\u5e94\u8be5\u5c3d\u91cf\u4f7f\u7528\u4e3b\u952e\u67e5\u8be2\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u8fd9\u91cc\u8868\u91cc\u7684\u6570\u636e\u91cf\u6bd4\u8f83\u5c11\uff0c\u5982\u679c\u6570\u636e\u91cf\u5927\u7684\u8bdd\uff0c\u4f60\u80fd\u5f88\u660e\u663e\u7684\u770b\u51fa\u4e24\u6b21\u67e5\u8be2\u6240\u7528\u7684\u65f6\u95f4\uff0c\u5f88\u660e\u663e\u4f7f\u7528\u4e3b\u952e\u67e5\u8be2\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g2v8qr0itbj20ey0300t5.jpg\" alt=\"\" \/><figcaption>SQL \u56de\u8868<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u8fd9\u4e9b\u5185\u5bb9\uff0c\u6211\u5f88\u5c11\u6709\u770b\u5230 SQL \u4f18\u5316\u89c4\u5219\u4e2d\u6709\u63d0\u5230\uff01\u5e0c\u671b\u80fd\u591f\u5e2e\u52a9\u5230\u5927\u5bb6\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=4225\">\u624b\u628a\u624b\u6559\u4f60MySQL\u4e2d\u67e5\u8be2\u56de\u8868<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u4f60\u53ef\u80fd\u4ece\u6765\u90fd\u6ca1\u6709\u542c\u8bf4\u8fc7\u56de\u8868\u4e00\u8bcd\uff0c\u4f46\u662f\u4f60\u5728\u5b9e\u9645\u5de5\u4f5c\u4e2d\u80af\u5b9a\u7528\u8fc7\u56de\u8868\u3002\u5982\u679c\u8fd8\u6ca1\u6709\u542c\u8fc7\u56de\u8868\uff0c\u90a3\u6211\u76f8\u4fe1\u4e0d\u7ba1\u4f60\u770b\u591a\u5c11 SQ [&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":[83,947,106,917,681],"class_list":["post-4225","post","type-post","status-publish","format-standard","hentry","category-sql","tag-mysql","tag-947","tag-106","tag-917","tag-681"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4225","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=4225"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4225\/revisions"}],"predecessor-version":[{"id":4226,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4225\/revisions\/4226"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}