﻿{"id":361,"date":"2017-07-28T21:54:47","date_gmt":"2017-07-28T13:54:47","guid":{"rendered":"http:\/\/www.chenweikang.top\/?p=361"},"modified":"2017-09-19T11:36:43","modified_gmt":"2017-09-19T03:36:43","slug":"mysql%e7%b4%a2%e5%bc%95%e5%8e%9f%e7%90%86%e5%8f%8a%e6%85%a2%e6%9f%a5%e8%af%a2%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/www.chenweikang.top\/?p=361","title":{"rendered":"MySQL\u7d22\u5f15\u539f\u7406\u53ca\u6162\u67e5\u8be2\u4f18\u5316"},"content":{"rendered":"<p>MySQL\u51ed\u501f\u7740\u51fa\u8272\u7684\u6027\u80fd\u3001\u4f4e\u5ec9\u7684\u6210\u672c\u3001\u4e30\u5bcc\u7684\u8d44\u6e90\uff0c\u5df2\u7ecf\u6210\u4e3a\u7edd\u5927\u591a\u6570\u4e92\u8054\u7f51\u516c\u53f8\u7684\u9996\u9009\u5173\u7cfb\u578b\u6570\u636e\u5e93\u3002\u867d\u7136\u6027\u80fd\u51fa\u8272\uff0c\u4f46\u6240\u8c13\u201c\u597d\u9a6c\u914d\u597d\u978d\u201d\uff0c\u5982\u4f55\u80fd\u591f\u66f4\u597d\u7684\u4f7f\u7528\u5b83\uff0c\u5df2\u7ecf\u6210\u4e3a\u5f00\u53d1\u5de5\u7a0b\u5e08\u7684\u5fc5\u4fee\u8bfe\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u4ece\u804c\u4f4d\u63cf\u8ff0\u4e0a\u770b\u5230\u8bf8\u5982\u201c\u7cbe\u901aMySQL\u201d\u3001\u201cSQL\u8bed\u53e5\u4f18\u5316\u201d\u3001\u201c\u4e86\u89e3\u6570\u636e\u5e93\u539f\u7406\u201d\u7b49\u8981\u6c42\u3002\u6211\u4eec\u77e5\u9053\u4e00\u822c\u7684\u5e94\u7528\u7cfb\u7edf\uff0c\u8bfb\u5199\u6bd4\u4f8b\u572810:1\u5de6\u53f3\uff0c\u800c\u4e14\u63d2\u5165\u64cd\u4f5c\u548c\u4e00\u822c\u7684\u66f4\u65b0\u64cd\u4f5c\u5f88\u5c11\u51fa\u73b0\u6027\u80fd\u95ee\u9898\uff0c\u9047\u5230\u6700\u591a\u7684\uff0c\u4e5f\u662f\u6700\u5bb9\u6613\u51fa\u95ee\u9898\u7684\uff0c\u8fd8\u662f\u4e00\u4e9b\u590d\u6742\u7684\u67e5\u8be2\u64cd\u4f5c\uff0c\u6240\u4ee5\u67e5\u8be2\u8bed\u53e5\u7684\u4f18\u5316\u663e\u7136\u662f\u91cd\u4e2d\u4e4b\u91cd\u3002<br \/>\n\u672c\u4eba\u4ece13\u5e747\u6708\u4efd\u8d77\uff0c\u4e00\u76f4\u5728\u7f8e\u56e2\u6838\u5fc3\u4e1a\u52a1\u7cfb\u7edf\u90e8\u505a\u6162\u67e5\u8be2\u7684\u4f18\u5316\u5de5\u4f5c\uff0c\u5171\u8ba1\u5341\u4f59\u4e2a\u7cfb\u7edf\uff0c\u7d2f\u8ba1\u89e3\u51b3\u548c\u79ef\u7d2f\u4e86\u4e0a\u767e\u4e2a\u6162\u67e5\u8be2\u6848\u4f8b\u3002\u968f\u7740\u4e1a\u52a1\u7684\u590d\u6742\u6027\u63d0\u5347\uff0c\u9047\u5230\u7684\u95ee\u9898\u5343\u5947\u767e\u602a\uff0c\u4e94\u82b1\u516b\u95e8\uff0c\u532a\u5937\u6240\u601d\u3002\u672c\u6587\u65e8\u5728\u4ee5\u5f00\u53d1\u5de5\u7a0b\u5e08\u7684\u89d2\u5ea6\u6765\u89e3\u91ca\u6570\u636e\u5e93\u7d22\u5f15\u7684\u539f\u7406\u548c\u5982\u4f55\u4f18\u5316\u6162\u67e5\u8be2\u3002<\/p>\n<h1 id=\"-\">\u4e00\u4e2a\u6162\u67e5\u8be2\u5f15\u53d1\u7684\u601d\u8003<\/h1>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span>\r\n   <span class=\"keyword\">count<\/span>(*) \r\n<span class=\"keyword\">from<\/span>\r\n   task \r\n<span class=\"keyword\">where<\/span>\r\n   <span class=\"keyword\">status<\/span>=<span class=\"number\">2<\/span> \r\n   <span class=\"keyword\">and<\/span> operator_id=<span class=\"number\">20839<\/span> \r\n   <span class=\"keyword\">and<\/span> operate_time&gt;<span class=\"number\">1371169729<\/span> \r\n   <span class=\"keyword\">and<\/span> operate_time&lt;<span class=\"number\">1371174603<\/span> \r\n   <span class=\"keyword\">and<\/span> <span class=\"keyword\">type<\/span>=<span class=\"number\">2<\/span>;<\/span>\r\n<\/code><\/pre>\n<p>\u7cfb\u7edf\u4f7f\u7528\u8005\u53cd\u5e94\u6709\u4e00\u4e2a\u529f\u80fd\u8d8a\u6765\u8d8a\u6162\uff0c\u4e8e\u662f\u5de5\u7a0b\u5e08\u627e\u5230\u4e86\u4e0a\u9762\u7684SQL\u3002<br \/>\n\u5e76\u4e14\u5174\u81f4\u51b2\u51b2\u7684\u627e\u5230\u4e86\u6211\uff0c\u201c\u8fd9\u4e2aSQL\u9700\u8981\u4f18\u5316\uff0c\u7ed9\u6211\u628a\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u52a0\u4e0a\u7d22\u5f15\u201d<br \/>\n\u6211\u5f88\u60ca\u8bb6\uff0c\u95ee\u9053\u201c\u4e3a\u4ec0\u4e48\u9700\u8981\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u52a0\u4e0a\u7d22\u5f15\uff1f\u201d<br \/>\n\u201c\u628a\u67e5\u8be2\u7684\u5b57\u6bb5\u90fd\u52a0\u4e0a\u7d22\u5f15\u4f1a\u66f4\u5feb\u201d\u5de5\u7a0b\u5e08\u4fe1\u5fc3\u6ee1\u6ee1<br \/>\n\u201c\u8fd9\u79cd\u60c5\u51b5\u5b8c\u5168\u53ef\u4ee5\u5efa\u4e00\u4e2a\u8054\u5408\u7d22\u5f15\uff0c\u56e0\u4e3a\u662f\u6700\u5de6\u524d\u7f00\u5339\u914d\uff0c\u6240\u4ee5operate_time\u9700\u8981\u653e\u5230\u6700\u540e\uff0c\u800c\u4e14\u8fd8\u9700\u8981\u628a\u5176\u4ed6\u76f8\u5173\u7684\u67e5\u8be2\u90fd\u62ff\u6765\uff0c\u9700\u8981\u505a\u4e00\u4e2a\u7efc\u5408\u8bc4\u4f30\u3002\u201d<br \/>\n\u201c\u8054\u5408\u7d22\u5f15\uff1f\u6700\u5de6\u524d\u7f00\u5339\u914d\uff1f\u7efc\u5408\u8bc4\u4f30\uff1f\u201d\u5de5\u7a0b\u5e08\u4e0d\u7981\u9677\u5165\u4e86\u6c89\u601d\u3002<br \/>\n\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u77e5\u9053\u7d22\u5f15\u80fd\u591f\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u4f46\u5e94\u8be5\u5982\u4f55\u5efa\u7acb\u7d22\u5f15\uff1f\u7d22\u5f15\u7684\u987a\u5e8f\u5982\u4f55\uff1f\u8bb8\u591a\u4eba\u5374\u53ea\u77e5\u9053\u5927\u6982\u3002\u5176\u5b9e\u7406\u89e3\u8fd9\u4e9b\u6982\u5ff5\u5e76\u4e0d\u96be\uff0c\u800c\u4e14\u7d22\u5f15\u7684\u539f\u7406\u8fdc\u6ca1\u6709\u60f3\u8c61\u7684\u90a3\u4e48\u590d\u6742\u3002<\/p>\n<h1 id=\"mysql-\">MySQL\u7d22\u5f15\u539f\u7406<\/h1>\n<p>##\u7d22\u5f15\u76ee\u7684<br \/>\n\u7d22\u5f15\u7684\u76ee\u7684\u5728\u4e8e\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u53ef\u4ee5\u7c7b\u6bd4\u5b57\u5178\uff0c\u5982\u679c\u8981\u67e5\u201cmysql\u201d\u8fd9\u4e2a\u5355\u8bcd\uff0c\u6211\u4eec\u80af\u5b9a\u9700\u8981\u5b9a\u4f4d\u5230m\u5b57\u6bcd\uff0c\u7136\u540e\u4ece\u4e0b\u5f80\u4e0b\u627e\u5230y\u5b57\u6bcd\uff0c\u518d\u627e\u5230\u5269\u4e0b\u7684sql\u3002\u5982\u679c\u6ca1\u6709\u7d22\u5f15\uff0c\u90a3\u4e48\u4f60\u53ef\u80fd\u9700\u8981\u628a\u6240\u6709\u5355\u8bcd\u770b\u4e00\u904d\u624d\u80fd\u627e\u5230\u4f60\u60f3\u8981\u7684\uff0c\u5982\u679c\u6211\u60f3\u627e\u5230m\u5f00\u5934\u7684\u5355\u8bcd\u5462\uff1f\u6216\u8005ze\u5f00\u5934\u7684\u5355\u8bcd\u5462\uff1f\u662f\u4e0d\u662f\u89c9\u5f97\u5982\u679c\u6ca1\u6709\u7d22\u5f15\uff0c\u8fd9\u4e2a\u4e8b\u60c5\u6839\u672c\u65e0\u6cd5\u5b8c\u6210\uff1f<\/p>\n<p>##\u7d22\u5f15\u539f\u7406<br \/>\n\u9664\u4e86\u8bcd\u5178\uff0c\u751f\u6d3b\u4e2d\u968f\u5904\u53ef\u89c1\u7d22\u5f15\u7684\u4f8b\u5b50\uff0c\u5982\u706b\u8f66\u7ad9\u7684\u8f66\u6b21\u8868\u3001\u56fe\u4e66\u7684\u76ee\u5f55\u7b49\u3002\u5b83\u4eec\u7684\u539f\u7406\u90fd\u662f\u4e00\u6837\u7684\uff0c\u901a\u8fc7\u4e0d\u65ad\u7684\u7f29\u5c0f\u60f3\u8981\u83b7\u5f97\u6570\u636e\u7684\u8303\u56f4\u6765\u7b5b\u9009\u51fa\u6700\u7ec8\u60f3\u8981\u7684\u7ed3\u679c\uff0c\u540c\u65f6\u628a\u968f\u673a\u7684\u4e8b\u4ef6\u53d8\u6210\u987a\u5e8f\u7684\u4e8b\u4ef6\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u603b\u662f\u901a\u8fc7\u540c\u4e00\u79cd\u67e5\u627e\u65b9\u5f0f\u6765\u9501\u5b9a\u6570\u636e\u3002<br \/>\n\u6570\u636e\u5e93\u4e5f\u662f\u4e00\u6837\uff0c\u4f46\u663e\u7136\u8981\u590d\u6742\u8bb8\u591a\uff0c\u56e0\u4e3a\u4e0d\u4ec5\u9762\u4e34\u7740\u7b49\u503c\u67e5\u8be2\uff0c\u8fd8\u6709\u8303\u56f4\u67e5\u8be2(&gt;\u3001&lt;\u3001between\u3001in)\u3001\u6a21\u7cca\u67e5\u8be2(like)\u3001\u5e76\u96c6\u67e5\u8be2(or)\u7b49\u7b49\u3002\u6570\u636e\u5e93\u5e94\u8be5\u9009\u62e9\u600e\u4e48\u6837\u7684\u65b9\u5f0f\u6765\u5e94\u5bf9\u6240\u6709\u7684\u95ee\u9898\u5462\uff1f\u6211\u4eec\u56de\u60f3\u5b57\u5178\u7684\u4f8b\u5b50\uff0c\u80fd\u4e0d\u80fd\u628a\u6570\u636e\u5206\u6210\u6bb5\uff0c\u7136\u540e\u5206\u6bb5\u67e5\u8be2\u5462\uff1f\u6700\u7b80\u5355\u7684\u5982\u679c1000\u6761\u6570\u636e\uff0c1\u5230100\u5206\u6210\u7b2c\u4e00\u6bb5\uff0c101\u5230200\u5206\u6210\u7b2c\u4e8c\u6bb5\uff0c201\u5230300\u5206\u6210\u7b2c\u4e09\u6bb5......\u8fd9\u6837\u67e5\u7b2c250\u6761\u6570\u636e\uff0c\u53ea\u8981\u627e\u7b2c\u4e09\u6bb5\u5c31\u53ef\u4ee5\u4e86\uff0c\u4e00\u4e0b\u5b50\u53bb\u9664\u4e8690%\u7684\u65e0\u6548\u6570\u636e\u3002\u4f46\u5982\u679c\u662f1\u5343\u4e07\u7684\u8bb0\u5f55\u5462\uff0c\u5206\u6210\u51e0\u6bb5\u6bd4\u8f83\u597d\uff1f\u7a0d\u6709\u7b97\u6cd5\u57fa\u7840\u7684\u540c\u5b66\u4f1a\u60f3\u5230\u641c\u7d22\u6811\uff0c\u5176\u5e73\u5747\u590d\u6742\u5ea6\u662flgN\uff0c\u5177\u6709\u4e0d\u9519\u7684\u67e5\u8be2\u6027\u80fd\u3002\u4f46\u8fd9\u91cc\u6211\u4eec\u5ffd\u7565\u4e86\u4e00\u4e2a\u5173\u952e\u7684\u95ee\u9898\uff0c\u590d\u6742\u5ea6\u6a21\u578b\u662f\u57fa\u4e8e\u6bcf\u6b21\u76f8\u540c\u7684\u64cd\u4f5c\u6210\u672c\u6765\u8003\u8651\u7684\uff0c\u6570\u636e\u5e93\u5b9e\u73b0\u6bd4\u8f83\u590d\u6742\uff0c\u6570\u636e\u4fdd\u5b58\u5728\u78c1\u76d8\u4e0a\uff0c\u800c\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u6bcf\u6b21\u53c8\u53ef\u4ee5\u628a\u90e8\u5206\u6570\u636e\u8bfb\u5165\u5185\u5b58\u6765\u8ba1\u7b97\uff0c\u56e0\u4e3a\u6211\u4eec\u77e5\u9053\u8bbf\u95ee\u78c1\u76d8\u7684\u6210\u672c\u5927\u6982\u662f\u8bbf\u95ee\u5185\u5b58\u7684\u5341\u4e07\u500d\u5de6\u53f3\uff0c\u6240\u4ee5\u7b80\u5355\u7684\u641c\u7d22\u6811\u96be\u4ee5\u6ee1\u8db3\u590d\u6742\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<p>###\u78c1\u76d8IO\u4e0e\u9884\u8bfb<br \/>\n\u524d\u9762\u63d0\u5230\u4e86\u8bbf\u95ee\u78c1\u76d8\uff0c\u90a3\u4e48\u8fd9\u91cc\u5148\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u78c1\u76d8IO\u548c\u9884\u8bfb\uff0c\u78c1\u76d8\u8bfb\u53d6\u6570\u636e\u9760\u7684\u662f\u673a\u68b0\u8fd0\u52a8\uff0c\u6bcf\u6b21\u8bfb\u53d6\u6570\u636e\u82b1\u8d39\u7684\u65f6\u95f4\u53ef\u4ee5\u5206\u4e3a\u5bfb\u9053\u65f6\u95f4\u3001\u65cb\u8f6c\u5ef6\u8fdf\u3001\u4f20\u8f93\u65f6\u95f4\u4e09\u4e2a\u90e8\u5206\uff0c\u5bfb\u9053\u65f6\u95f4\u6307\u7684\u662f\u78c1\u81c2\u79fb\u52a8\u5230\u6307\u5b9a\u78c1\u9053\u6240\u9700\u8981\u7684\u65f6\u95f4\uff0c\u4e3b\u6d41\u78c1\u76d8\u4e00\u822c\u57285ms\u4ee5\u4e0b\uff1b\u65cb\u8f6c\u5ef6\u8fdf\u5c31\u662f\u6211\u4eec\u7ecf\u5e38\u542c\u8bf4\u7684\u78c1\u76d8\u8f6c\u901f\uff0c\u6bd4\u5982\u4e00\u4e2a\u78c1\u76d87200\u8f6c\uff0c\u8868\u793a\u6bcf\u5206\u949f\u80fd\u8f6c7200\u6b21\uff0c\u4e5f\u5c31\u662f\u8bf41\u79d2\u949f\u80fd\u8f6c120\u6b21\uff0c\u65cb\u8f6c\u5ef6\u8fdf\u5c31\u662f1\/120\/2 = 4.17ms\uff1b\u4f20\u8f93\u65f6\u95f4\u6307\u7684\u662f\u4ece\u78c1\u76d8\u8bfb\u51fa\u6216\u5c06\u6570\u636e\u5199\u5165\u78c1\u76d8\u7684\u65f6\u95f4\uff0c\u4e00\u822c\u5728\u96f6\u70b9\u51e0\u6beb\u79d2\uff0c\u76f8\u5bf9\u4e8e\u524d\u4e24\u4e2a\u65f6\u95f4\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\u3002\u90a3\u4e48\u8bbf\u95ee\u4e00\u6b21\u78c1\u76d8\u7684\u65f6\u95f4\uff0c\u5373\u4e00\u6b21\u78c1\u76d8IO\u7684\u65f6\u95f4\u7ea6\u7b49\u4e8e5+4.17 = 9ms\u5de6\u53f3\uff0c\u542c\u8d77\u6765\u8fd8\u633a\u4e0d\u9519\u7684\uff0c\u4f46\u8981\u77e5\u9053\u4e00\u53f0500 -MIPS\u7684\u673a\u5668\u6bcf\u79d2\u53ef\u4ee5\u6267\u884c5\u4ebf\u6761\u6307\u4ee4\uff0c\u56e0\u4e3a\u6307\u4ee4\u4f9d\u9760\u7684\u662f\u7535\u7684\u6027\u8d28\uff0c\u6362\u53e5\u8bdd\u8bf4\u6267\u884c\u4e00\u6b21IO\u7684\u65f6\u95f4\u53ef\u4ee5\u6267\u884c40\u4e07\u6761\u6307\u4ee4\uff0c\u6570\u636e\u5e93\u52a8\u8f84\u5341\u4e07\u767e\u4e07\u4e43\u81f3\u5343\u4e07\u7ea7\u6570\u636e\uff0c\u6bcf\u6b219\u6beb\u79d2\u7684\u65f6\u95f4\uff0c\u663e\u7136\u662f\u4e2a\u707e\u96be\u3002\u4e0b\u56fe\u662f\u8ba1\u7b97\u673a\u786c\u4ef6\u5ef6\u8fdf\u7684\u5bf9\u6bd4\u56fe\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/tech.meituan.com\/img\/mysql_index\/various-system-software-hardware-latencies.png\" alt=\"various-system-software-hardware-latencies\" \/><br \/>\n\u8003\u8651\u5230\u78c1\u76d8IO\u662f\u975e\u5e38\u9ad8\u6602\u7684\u64cd\u4f5c\uff0c\u8ba1\u7b97\u673a\u64cd\u4f5c\u7cfb\u7edf\u505a\u4e86\u4e00\u4e9b\u4f18\u5316\uff0c\u5f53\u4e00\u6b21IO\u65f6\uff0c\u4e0d\u5149\u628a\u5f53\u524d\u78c1\u76d8\u5730\u5740\u7684\u6570\u636e\uff0c\u800c\u662f\u628a\u76f8\u90bb\u7684\u6570\u636e\u4e5f\u90fd\u8bfb\u53d6\u5230\u5185\u5b58\u7f13\u51b2\u533a\u5185\uff0c\u56e0\u4e3a\u5c40\u90e8\u9884\u8bfb\u6027\u539f\u7406\u544a\u8bc9\u6211\u4eec\uff0c\u5f53\u8ba1\u7b97\u673a\u8bbf\u95ee\u4e00\u4e2a\u5730\u5740\u7684\u6570\u636e\u7684\u65f6\u5019\uff0c\u4e0e\u5176\u76f8\u90bb\u7684\u6570\u636e\u4e5f\u4f1a\u5f88\u5feb\u88ab\u8bbf\u95ee\u5230\u3002\u6bcf\u4e00\u6b21IO\u8bfb\u53d6\u7684\u6570\u636e\u6211\u4eec\u79f0\u4e4b\u4e3a\u4e00\u9875(page)\u3002\u5177\u4f53\u4e00\u9875\u6709\u591a\u5927\u6570\u636e\u8ddf\u64cd\u4f5c\u7cfb\u7edf\u6709\u5173\uff0c\u4e00\u822c\u4e3a4k\u62168k\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u8bfb\u53d6\u4e00\u9875\u5185\u7684\u6570\u636e\u65f6\u5019\uff0c\u5b9e\u9645\u4e0a\u624d\u53d1\u751f\u4e86\u4e00\u6b21IO\uff0c\u8fd9\u4e2a\u7406\u8bba\u5bf9\u4e8e\u7d22\u5f15\u7684\u6570\u636e\u7ed3\u6784\u8bbe\u8ba1\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/p>\n<p>###\u7d22\u5f15\u7684\u6570\u636e\u7ed3\u6784<br \/>\n\u524d\u9762\u8bb2\u4e86\u751f\u6d3b\u4e2d\u7d22\u5f15\u7684\u4f8b\u5b50\uff0c\u7d22\u5f15\u7684\u57fa\u672c\u539f\u7406\uff0c\u6570\u636e\u5e93\u7684\u590d\u6742\u6027\uff0c\u53c8\u8bb2\u4e86\u64cd\u4f5c\u7cfb\u7edf\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u76ee\u7684\u5c31\u662f\u8ba9\u5927\u5bb6\u4e86\u89e3\uff0c\u4efb\u4f55\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u90fd\u4e0d\u662f\u51ed\u7a7a\u4ea7\u751f\u7684\uff0c\u4e00\u5b9a\u4f1a\u6709\u5b83\u7684\u80cc\u666f\u548c\u4f7f\u7528\u573a\u666f\uff0c\u6211\u4eec\u73b0\u5728\u603b\u7ed3\u4e00\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u80fd\u591f\u505a\u4e9b\u4ec0\u4e48\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u90a3\u5c31\u662f\uff1a\u6bcf\u6b21\u67e5\u627e\u6570\u636e\u65f6\u628a\u78c1\u76d8IO\u6b21\u6570\u63a7\u5236\u5728\u4e00\u4e2a\u5f88\u5c0f\u7684\u6570\u91cf\u7ea7\uff0c\u6700\u597d\u662f\u5e38\u6570\u6570\u91cf\u7ea7\u3002\u90a3\u4e48\u6211\u4eec\u5c31\u60f3\u5230\u5982\u679c\u4e00\u4e2a\u9ad8\u5ea6\u53ef\u63a7\u7684\u591a\u8def\u641c\u7d22\u6811\u662f\u5426\u80fd\u6ee1\u8db3\u9700\u6c42\u5462\uff1f\u5c31\u8fd9\u6837\uff0cb+\u6811\u5e94\u8fd0\u800c\u751f\u3002<\/p>\n<p>###\u8be6\u89e3b+\u6811<br \/>\n<img decoding=\"async\" src=\"https:\/\/tech.meituan.com\/img\/mysql_index\/btree.jpg\" alt=\"b+\u6811\" \/><br \/>\n\u5982\u4e0a\u56fe\uff0c\u662f\u4e00\u9897b+\u6811\uff0c\u5173\u4e8eb+\u6811\u7684\u5b9a\u4e49\u53ef\u4ee5\u53c2\u89c1<a href=\"http:\/\/zh.wikipedia.org\/wiki\/B%2B%E6%A0%91\">B+\u6811<\/a>\uff0c\u8fd9\u91cc\u53ea\u8bf4\u4e00\u4e9b\u91cd\u70b9\uff0c\u6d45\u84dd\u8272\u7684\u5757\u6211\u4eec\u79f0\u4e4b\u4e3a\u4e00\u4e2a\u78c1\u76d8\u5757\uff0c\u53ef\u4ee5\u770b\u5230\u6bcf\u4e2a\u78c1\u76d8\u5757\u5305\u542b\u51e0\u4e2a\u6570\u636e\u9879\uff08\u6df1\u84dd\u8272\u6240\u793a\uff09\u548c\u6307\u9488\uff08\u9ec4\u8272\u6240\u793a\uff09\uff0c\u5982\u78c1\u76d8\u57571\u5305\u542b\u6570\u636e\u987917\u548c35\uff0c\u5305\u542b\u6307\u9488P1\u3001P2\u3001P3\uff0cP1\u8868\u793a\u5c0f\u4e8e17\u7684\u78c1\u76d8\u5757\uff0cP2\u8868\u793a\u572817\u548c35\u4e4b\u95f4\u7684\u78c1\u76d8\u5757\uff0cP3\u8868\u793a\u5927\u4e8e35\u7684\u78c1\u76d8\u5757\u3002\u771f\u5b9e\u7684\u6570\u636e\u5b58\u5728\u4e8e\u53f6\u5b50\u8282\u70b9\u53733\u30015\u30019\u300110\u300113\u300115\u300128\u300129\u300136\u300160\u300175\u300179\u300190\u300199\u3002\u975e\u53f6\u5b50\u8282\u70b9\u53ea\u4e0d\u5b58\u50a8\u771f\u5b9e\u7684\u6570\u636e\uff0c\u53ea\u5b58\u50a8\u6307\u5f15\u641c\u7d22\u65b9\u5411\u7684\u6570\u636e\u9879\uff0c\u598217\u300135\u5e76\u4e0d\u771f\u5b9e\u5b58\u5728\u4e8e\u6570\u636e\u8868\u4e2d\u3002<\/p>\n<p>###b+\u6811\u7684\u67e5\u627e\u8fc7\u7a0b<br \/>\n\u5982\u56fe\u6240\u793a\uff0c\u5982\u679c\u8981\u67e5\u627e\u6570\u636e\u987929\uff0c\u90a3\u4e48\u9996\u5148\u4f1a\u628a\u78c1\u76d8\u57571\u7531\u78c1\u76d8\u52a0\u8f7d\u5230\u5185\u5b58\uff0c\u6b64\u65f6\u53d1\u751f\u4e00\u6b21IO\uff0c\u5728\u5185\u5b58\u4e2d\u7528\u4e8c\u5206\u67e5\u627e\u786e\u5b9a29\u572817\u548c35\u4e4b\u95f4\uff0c\u9501\u5b9a\u78c1\u76d8\u57571\u7684P2\u6307\u9488\uff0c\u5185\u5b58\u65f6\u95f4\u56e0\u4e3a\u975e\u5e38\u77ed\uff08\u76f8\u6bd4\u78c1\u76d8\u7684IO\uff09\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\uff0c\u901a\u8fc7\u78c1\u76d8\u57571\u7684P2\u6307\u9488\u7684\u78c1\u76d8\u5730\u5740\u628a\u78c1\u76d8\u57573\u7531\u78c1\u76d8\u52a0\u8f7d\u5230\u5185\u5b58\uff0c\u53d1\u751f\u7b2c\u4e8c\u6b21IO\uff0c29\u572826\u548c30\u4e4b\u95f4\uff0c\u9501\u5b9a\u78c1\u76d8\u57573\u7684P2\u6307\u9488\uff0c\u901a\u8fc7\u6307\u9488\u52a0\u8f7d\u78c1\u76d8\u57578\u5230\u5185\u5b58\uff0c\u53d1\u751f\u7b2c\u4e09\u6b21IO\uff0c\u540c\u65f6\u5185\u5b58\u4e2d\u505a\u4e8c\u5206\u67e5\u627e\u627e\u523029\uff0c\u7ed3\u675f\u67e5\u8be2\uff0c\u603b\u8ba1\u4e09\u6b21IO\u3002\u771f\u5b9e\u7684\u60c5\u51b5\u662f\uff0c3\u5c42\u7684b+\u6811\u53ef\u4ee5\u8868\u793a\u4e0a\u767e\u4e07\u7684\u6570\u636e\uff0c\u5982\u679c\u4e0a\u767e\u4e07\u7684\u6570\u636e\u67e5\u627e\u53ea\u9700\u8981\u4e09\u6b21IO\uff0c\u6027\u80fd\u63d0\u9ad8\u5c06\u662f\u5de8\u5927\u7684\uff0c\u5982\u679c\u6ca1\u6709\u7d22\u5f15\uff0c\u6bcf\u4e2a\u6570\u636e\u9879\u90fd\u8981\u53d1\u751f\u4e00\u6b21IO\uff0c\u90a3\u4e48\u603b\u5171\u9700\u8981\u767e\u4e07\u6b21\u7684IO\uff0c\u663e\u7136\u6210\u672c\u975e\u5e38\u975e\u5e38\u9ad8\u3002<\/p>\n<p>###b+\u6811\u6027\u8d28<br \/>\n1.\u901a\u8fc7\u4e0a\u9762\u7684\u5206\u6790\uff0c\u6211\u4eec\u77e5\u9053IO\u6b21\u6570\u53d6\u51b3\u4e8eb+\u6570\u7684\u9ad8\u5ea6h\uff0c\u5047\u8bbe\u5f53\u524d\u6570\u636e\u8868\u7684\u6570\u636e\u4e3aN\uff0c\u6bcf\u4e2a\u78c1\u76d8\u5757\u7684\u6570\u636e\u9879\u7684\u6570\u91cf\u662fm\uff0c\u5219\u6709h=\u33d2(m+1)N\uff0c\u5f53\u6570\u636e\u91cfN\u4e00\u5b9a\u7684\u60c5\u51b5\u4e0b\uff0cm\u8d8a\u5927\uff0ch\u8d8a\u5c0f\uff1b\u800cm = \u78c1\u76d8\u5757\u7684\u5927\u5c0f \/ \u6570\u636e\u9879\u7684\u5927\u5c0f\uff0c\u78c1\u76d8\u5757\u7684\u5927\u5c0f\u4e5f\u5c31\u662f\u4e00\u4e2a\u6570\u636e\u9875\u7684\u5927\u5c0f\uff0c\u662f\u56fa\u5b9a\u7684\uff0c\u5982\u679c\u6570\u636e\u9879\u5360\u7684\u7a7a\u95f4\u8d8a\u5c0f\uff0c\u6570\u636e\u9879\u7684\u6570\u91cf\u8d8a\u591a\uff0c\u6811\u7684\u9ad8\u5ea6\u8d8a\u4f4e\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u6bcf\u4e2a\u6570\u636e\u9879\uff0c\u5373\u7d22\u5f15\u5b57\u6bb5\u8981\u5c3d\u91cf\u7684\u5c0f\uff0c\u6bd4\u5982int\u53604\u5b57\u8282\uff0c\u8981\u6bd4bigint8\u5b57\u8282\u5c11\u4e00\u534a\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48b+\u6811\u8981\u6c42\u628a\u771f\u5b9e\u7684\u6570\u636e\u653e\u5230\u53f6\u5b50\u8282\u70b9\u800c\u4e0d\u662f\u5185\u5c42\u8282\u70b9\uff0c\u4e00\u65e6\u653e\u5230\u5185\u5c42\u8282\u70b9\uff0c\u78c1\u76d8\u5757\u7684\u6570\u636e\u9879\u4f1a\u5927\u5e45\u5ea6\u4e0b\u964d\uff0c\u5bfc\u81f4\u6811\u589e\u9ad8\u3002\u5f53\u6570\u636e\u9879\u7b49\u4e8e1\u65f6\u5c06\u4f1a\u9000\u5316\u6210\u7ebf\u6027\u8868\u3002<br \/>\n2.\u5f53b+\u6811\u7684\u6570\u636e\u9879\u662f\u590d\u5408\u7684\u6570\u636e\u7ed3\u6784\uff0c\u6bd4\u5982(name,age,sex)\u7684\u65f6\u5019\uff0cb+\u6570\u662f\u6309\u7167\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u6765\u5efa\u7acb\u641c\u7d22\u6811\u7684\uff0c\u6bd4\u5982\u5f53(\u5f20\u4e09,20,F)\u8fd9\u6837\u7684\u6570\u636e\u6765\u68c0\u7d22\u7684\u65f6\u5019\uff0cb+\u6811\u4f1a\u4f18\u5148\u6bd4\u8f83name\u6765\u786e\u5b9a\u4e0b\u4e00\u6b65\u7684\u6240\u641c\u65b9\u5411\uff0c\u5982\u679cname\u76f8\u540c\u518d\u4f9d\u6b21\u6bd4\u8f83age\u548csex\uff0c\u6700\u540e\u5f97\u5230\u68c0\u7d22\u7684\u6570\u636e\uff1b\u4f46\u5f53(20,F)\u8fd9\u6837\u7684\u6ca1\u6709name\u7684\u6570\u636e\u6765\u7684\u65f6\u5019\uff0cb+\u6811\u5c31\u4e0d\u77e5\u9053\u4e0b\u4e00\u6b65\u8be5\u67e5\u54ea\u4e2a\u8282\u70b9\uff0c\u56e0\u4e3a\u5efa\u7acb\u641c\u7d22\u6811\u7684\u65f6\u5019name\u5c31\u662f\u7b2c\u4e00\u4e2a\u6bd4\u8f83\u56e0\u5b50\uff0c\u5fc5\u987b\u8981\u5148\u6839\u636ename\u6765\u641c\u7d22\u624d\u80fd\u77e5\u9053\u4e0b\u4e00\u6b65\u53bb\u54ea\u91cc\u67e5\u8be2\u3002\u6bd4\u5982\u5f53(\u5f20\u4e09,F)\u8fd9\u6837\u7684\u6570\u636e\u6765\u68c0\u7d22\u65f6\uff0cb+\u6811\u53ef\u4ee5\u7528name\u6765\u6307\u5b9a\u641c\u7d22\u65b9\u5411\uff0c\u4f46\u4e0b\u4e00\u4e2a\u5b57\u6bb5age\u7684\u7f3a\u5931\uff0c\u6240\u4ee5\u53ea\u80fd\u628a\u540d\u5b57\u7b49\u4e8e\u5f20\u4e09\u7684\u6570\u636e\u90fd\u627e\u5230\uff0c\u7136\u540e\u518d\u5339\u914d\u6027\u522b\u662fF\u7684\u6570\u636e\u4e86\uff0c \u8fd9\u4e2a\u662f\u975e\u5e38\u91cd\u8981\u7684\u6027\u8d28\uff0c\u5373\u7d22\u5f15\u7684\u6700\u5de6\u5339\u914d\u7279\u6027\u3002<\/p>\n<h1 id=\"-\">\u6162\u67e5\u8be2\u4f18\u5316<\/h1>\n<p>\u5173\u4e8eMySQL\u7d22\u5f15\u539f\u7406\u662f\u6bd4\u8f83\u67af\u71e5\u7684\u4e1c\u897f\uff0c\u5927\u5bb6\u53ea\u9700\u8981\u6709\u4e00\u4e2a\u611f\u6027\u7684\u8ba4\u8bc6\uff0c\u5e76\u4e0d\u9700\u8981\u7406\u89e3\u5f97\u975e\u5e38\u900f\u5f7b\u548c\u6df1\u5165\u3002\u6211\u4eec\u56de\u5934\u6765\u770b\u770b\u4e00\u5f00\u59cb\u6211\u4eec\u8bf4\u7684\u6162\u67e5\u8be2\uff0c\u4e86\u89e3\u5b8c\u7d22\u5f15\u539f\u7406\u4e4b\u540e\uff0c\u5927\u5bb6\u662f\u4e0d\u662f\u6709\u4ec0\u4e48\u60f3\u6cd5\u5462\uff1f\u5148\u603b\u7ed3\u4e00\u4e0b\u7d22\u5f15\u7684\u51e0\u5927\u57fa\u672c\u539f\u5219<\/p>\n<h2 id=\"-\">\u5efa\u7d22\u5f15\u7684\u51e0\u5927\u539f\u5219<\/h2>\n<p>1.\u6700\u5de6\u524d\u7f00\u5339\u914d\u539f\u5219\uff0c\u975e\u5e38\u91cd\u8981\u7684\u539f\u5219\uff0cmysql\u4f1a\u4e00\u76f4\u5411\u53f3\u5339\u914d\u76f4\u5230\u9047\u5230\u8303\u56f4\u67e5\u8be2(&gt;\u3001&lt;\u3001between\u3001like)\u5c31\u505c\u6b62\u5339\u914d\uff0c\u6bd4\u5982a = 1 and b = 2 and c &gt; 3 and d = 4 \u5982\u679c\u5efa\u7acb(a,b,c,d)\u987a\u5e8f\u7684\u7d22\u5f15\uff0cd\u662f\u7528\u4e0d\u5230\u7d22\u5f15\u7684\uff0c\u5982\u679c\u5efa\u7acb(a,b,d,c)\u7684\u7d22\u5f15\u5219\u90fd\u53ef\u4ee5\u7528\u5230\uff0ca,b,d\u7684\u987a\u5e8f\u53ef\u4ee5\u4efb\u610f\u8c03\u6574\u3002<br \/>\n2.=\u548cin\u53ef\u4ee5\u4e71\u5e8f\uff0c\u6bd4\u5982a = 1 and b = 2 and c = 3 \u5efa\u7acb(a,b,c)\u7d22\u5f15\u53ef\u4ee5\u4efb\u610f\u987a\u5e8f\uff0cmysql\u7684\u67e5\u8be2\u4f18\u5316\u5668\u4f1a\u5e2e\u4f60\u4f18\u5316\u6210\u7d22\u5f15\u53ef\u4ee5\u8bc6\u522b\u7684\u5f62\u5f0f<br \/>\n3.\u5c3d\u91cf\u9009\u62e9\u533a\u5206\u5ea6\u9ad8\u7684\u5217\u4f5c\u4e3a\u7d22\u5f15,\u533a\u5206\u5ea6\u7684\u516c\u5f0f\u662fcount(distinct col)\/count(*)\uff0c\u8868\u793a\u5b57\u6bb5\u4e0d\u91cd\u590d\u7684\u6bd4\u4f8b\uff0c\u6bd4\u4f8b\u8d8a\u5927\u6211\u4eec\u626b\u63cf\u7684\u8bb0\u5f55\u6570\u8d8a\u5c11\uff0c\u552f\u4e00\u952e\u7684\u533a\u5206\u5ea6\u662f1\uff0c\u800c\u4e00\u4e9b\u72b6\u6001\u3001\u6027\u522b\u5b57\u6bb5\u53ef\u80fd\u5728\u5927\u6570\u636e\u9762\u524d\u533a\u5206\u5ea6\u5c31\u662f0\uff0c\u90a3\u53ef\u80fd\u6709\u4eba\u4f1a\u95ee\uff0c\u8fd9\u4e2a\u6bd4\u4f8b\u6709\u4ec0\u4e48\u7ecf\u9a8c\u503c\u5417\uff1f\u4f7f\u7528\u573a\u666f\u4e0d\u540c\uff0c\u8fd9\u4e2a\u503c\u4e5f\u5f88\u96be\u786e\u5b9a\uff0c\u4e00\u822c\u9700\u8981join\u7684\u5b57\u6bb5\u6211\u4eec\u90fd\u8981\u6c42\u662f0.1\u4ee5\u4e0a\uff0c\u5373\u5e73\u57471\u6761\u626b\u63cf10\u6761\u8bb0\u5f55<br \/>\n4.\u7d22\u5f15\u5217\u4e0d\u80fd\u53c2\u4e0e\u8ba1\u7b97\uff0c\u4fdd\u6301\u5217\u201c\u5e72\u51c0\u201d\uff0c\u6bd4\u5982from_unixtime(create_time) = \u20192014-05-29\u2019\u5c31\u4e0d\u80fd\u4f7f\u7528\u5230\u7d22\u5f15\uff0c\u539f\u56e0\u5f88\u7b80\u5355\uff0cb+\u6811\u4e2d\u5b58\u7684\u90fd\u662f\u6570\u636e\u8868\u4e2d\u7684\u5b57\u6bb5\u503c\uff0c\u4f46\u8fdb\u884c\u68c0\u7d22\u65f6\uff0c\u9700\u8981\u628a\u6240\u6709\u5143\u7d20\u90fd\u5e94\u7528\u51fd\u6570\u624d\u80fd\u6bd4\u8f83\uff0c\u663e\u7136\u6210\u672c\u592a\u5927\u3002\u6240\u4ee5\u8bed\u53e5\u5e94\u8be5\u5199\u6210create_time = unix_timestamp(\u20192014-05-29\u2019);<br \/>\n5.\u5c3d\u91cf\u7684\u6269\u5c55\u7d22\u5f15\uff0c\u4e0d\u8981\u65b0\u5efa\u7d22\u5f15\u3002\u6bd4\u5982\u8868\u4e2d\u5df2\u7ecf\u6709a\u7684\u7d22\u5f15\uff0c\u73b0\u5728\u8981\u52a0(a,b)\u7684\u7d22\u5f15\uff0c\u90a3\u4e48\u53ea\u9700\u8981\u4fee\u6539\u539f\u6765\u7684\u7d22\u5f15\u5373\u53ef<\/p>\n<h2 id=\"-\">\u56de\u5230\u5f00\u59cb\u7684\u6162\u67e5\u8be2<\/h2>\n<p>\u6839\u636e\u6700\u5de6\u5339\u914d\u539f\u5219\uff0c\u6700\u5f00\u59cb\u7684sql\u8bed\u53e5\u7684\u7d22\u5f15\u5e94\u8be5\u662fstatus\u3001operator_id\u3001type\u3001operate_time\u7684\u8054\u5408\u7d22\u5f15\uff1b\u5176\u4e2dstatus\u3001operator_id\u3001type\u7684\u987a\u5e8f\u53ef\u4ee5\u98a0\u5012\uff0c\u6240\u4ee5\u6211\u624d\u4f1a\u8bf4\uff0c\u628a\u8fd9\u4e2a\u8868\u7684\u6240\u6709\u76f8\u5173\u67e5\u8be2\u90fd\u627e\u5230\uff0c\u4f1a\u7efc\u5408\u5206\u6790\uff1b<br \/>\n\u6bd4\u5982\u8fd8\u6709\u5982\u4e0b\u67e5\u8be2<\/p>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span> * <span class=\"keyword\">from<\/span> task <span class=\"keyword\">where<\/span> <span class=\"keyword\">status<\/span> = <span class=\"number\">0<\/span> <span class=\"keyword\">and<\/span> <span class=\"keyword\">type<\/span> = <span class=\"number\">12<\/span> <span class=\"keyword\">limit<\/span> <span class=\"number\">10<\/span>;<\/span>\r\n<\/code><\/pre>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span> <span class=\"keyword\">count<\/span>(*) <span class=\"keyword\">from<\/span> task <span class=\"keyword\">where<\/span> <span class=\"keyword\">status<\/span> = <span class=\"number\">0<\/span> ;<\/span>\r\n<\/code><\/pre>\n<p>\u90a3\u4e48\u7d22\u5f15\u5efa\u7acb\u6210(status,type,operator_id,operate_time)\u5c31\u662f\u975e\u5e38\u6b63\u786e\u7684\uff0c\u56e0\u4e3a\u53ef\u4ee5\u8986\u76d6\u5230\u6240\u6709\u60c5\u51b5\u3002\u8fd9\u4e2a\u5c31\u662f\u5229\u7528\u4e86\u7d22\u5f15\u7684\u6700\u5de6\u5339\u914d\u7684\u539f\u5219<\/p>\n<h2 id=\"-explain-\">\u67e5\u8be2\u4f18\u5316\u795e\u5668 - explain\u547d\u4ee4<\/h2>\n<p>\u5173\u4e8eexplain\u547d\u4ee4\u76f8\u4fe1\u5927\u5bb6\u5e76\u4e0d\u964c\u751f\uff0c\u5177\u4f53\u7528\u6cd5\u548c\u5b57\u6bb5\u542b\u4e49\u53ef\u4ee5\u53c2\u8003\u5b98\u7f51<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/explain-output.html\">explain-output<\/a>\uff0c\u8fd9\u91cc\u9700\u8981\u5f3a\u8c03rows\u662f\u6838\u5fc3\u6307\u6807\uff0c\u7edd\u5927\u90e8\u5206rows\u5c0f\u7684\u8bed\u53e5\u6267\u884c\u4e00\u5b9a\u5f88\u5feb\uff08\u6709\u4f8b\u5916\uff0c\u4e0b\u9762\u4f1a\u8bb2\u5230\uff09\u3002\u6240\u4ee5\u4f18\u5316\u8bed\u53e5\u57fa\u672c\u4e0a\u90fd\u662f\u5728\u4f18\u5316rows\u3002<\/p>\n<h2 id=\"-\">\u6162\u67e5\u8be2\u4f18\u5316\u57fa\u672c\u6b65\u9aa4<\/h2>\n<p>0.\u5148\u8fd0\u884c\u770b\u770b\u662f\u5426\u771f\u7684\u5f88\u6162\uff0c\u6ce8\u610f\u8bbe\u7f6eSQL_NO_CACHE<br \/>\n1.where\u6761\u4ef6\u5355\u8868\u67e5\uff0c\u9501\u5b9a\u6700\u5c0f\u8fd4\u56de\u8bb0\u5f55\u8868\u3002\u8fd9\u53e5\u8bdd\u7684\u610f\u601d\u662f\u628a\u67e5\u8be2\u8bed\u53e5\u7684where\u90fd\u5e94\u7528\u5230\u8868\u4e2d\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u6700\u5c0f\u7684\u8868\u5f00\u59cb\u67e5\u8d77\uff0c\u5355\u8868\u6bcf\u4e2a\u5b57\u6bb5\u5206\u522b\u67e5\u8be2\uff0c\u770b\u54ea\u4e2a\u5b57\u6bb5\u7684\u533a\u5206\u5ea6\u6700\u9ad8<br \/>\n2.explain\u67e5\u770b\u6267\u884c\u8ba1\u5212\uff0c\u662f\u5426\u4e0e1\u9884\u671f\u4e00\u81f4\uff08\u4ece\u9501\u5b9a\u8bb0\u5f55\u8f83\u5c11\u7684\u8868\u5f00\u59cb\u67e5\u8be2\uff09<br \/>\n3.order by limit \u5f62\u5f0f\u7684sql\u8bed\u53e5\u8ba9\u6392\u5e8f\u7684\u8868\u4f18\u5148\u67e5<br \/>\n4.\u4e86\u89e3\u4e1a\u52a1\u65b9\u4f7f\u7528\u573a\u666f<br \/>\n5.\u52a0\u7d22\u5f15\u65f6\u53c2\u7167\u5efa\u7d22\u5f15\u7684\u51e0\u5927\u539f\u5219<br \/>\n6.\u89c2\u5bdf\u7ed3\u679c\uff0c\u4e0d\u7b26\u5408\u9884\u671f\u7ee7\u7eed\u4ece0\u5206\u6790<\/p>\n<h2 id=\"-\">\u51e0\u4e2a\u6162\u67e5\u8be2\u6848\u4f8b<\/h2>\n<p>\u4e0b\u9762\u51e0\u4e2a\u4f8b\u5b50\u8be6\u7ec6\u89e3\u91ca\u4e86\u5982\u4f55\u5206\u6790\u548c\u4f18\u5316\u6162\u67e5\u8be2<\/p>\n<h3 id=\"-\">\u590d\u6742\u8bed\u53e5\u5199\u6cd5<\/h3>\n<p>\u5f88\u591a\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5199SQL\u53ea\u662f\u4e3a\u4e86\u5b9e\u73b0\u529f\u80fd\uff0c\u8fd9\u53ea\u662f\u7b2c\u4e00\u6b65\uff0c\u4e0d\u540c\u7684\u8bed\u53e5\u4e66\u5199\u65b9\u5f0f\u5bf9\u4e8e\u6548\u7387\u5f80\u5f80\u6709\u672c\u8d28\u7684\u5dee\u522b\uff0c\u8fd9\u8981\u6c42\u6211\u4eec\u5bf9mysql\u7684\u6267\u884c\u8ba1\u5212\u548c\u7d22\u5f15\u539f\u5219\u6709\u975e\u5e38\u6e05\u695a\u7684\u8ba4\u8bc6\uff0c\u8bf7\u770b\u4e0b\u9762\u7684\u8bed\u53e5<\/p>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span>\r\n   <span class=\"keyword\">distinct<\/span> cert.emp_id \r\n<span class=\"keyword\">from<\/span>\r\n   cm_log cl \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   (\r\n      <span class=\"keyword\">select<\/span>\r\n         emp.<span class=\"keyword\">id<\/span> <span class=\"keyword\">as<\/span> emp_id,\r\n         emp_cert.<span class=\"keyword\">id<\/span> <span class=\"keyword\">as<\/span> cert_id \r\n      <span class=\"keyword\">from<\/span>\r\n         employee emp \r\n      <span class=\"keyword\">left<\/span> <span class=\"keyword\">join<\/span>\r\n         emp_certificate emp_cert \r\n            <span class=\"keyword\">on<\/span> emp.<span class=\"keyword\">id<\/span> = emp_cert.emp_id \r\n      <span class=\"keyword\">where<\/span>\r\n         emp.is_deleted=<span class=\"number\">0<\/span>\r\n   ) cert \r\n      <span class=\"keyword\">on<\/span> (\r\n         cl.ref_table=<span class=\"string\">'Employee'<\/span> \r\n         <span class=\"keyword\">and<\/span> cl.ref_oid= cert.emp_id\r\n      ) \r\n      <span class=\"keyword\">or<\/span> (\r\n         cl.ref_table=<span class=\"string\">'EmpCertificate'<\/span> \r\n         <span class=\"keyword\">and<\/span> cl.ref_oid= cert.cert_id\r\n      ) \r\n<span class=\"keyword\">where<\/span>\r\n   cl.last_upd_date &gt;=<span class=\"string\">'2013-11-07 15:03:00'<\/span> \r\n   <span class=\"keyword\">and<\/span> cl.last_upd_date&lt;=<span class=\"string\">'2013-11-08 16:00:00'<\/span>;<\/span>\r\n<\/code><\/pre>\n<p>0.\u5148\u8fd0\u884c\u4e00\u4e0b\uff0c53\u6761\u8bb0\u5f55 1.87\u79d2\uff0c\u53c8\u6ca1\u6709\u7528\u805a\u5408\u8bed\u53e5\uff0c\u6bd4\u8f83\u6162<\/p>\n<pre><code class=\"sql\">53 rows in <span class=\"operator\"><span class=\"keyword\">set<\/span> (<span class=\"number\">1.87<\/span> sec)<\/span>\r\n<\/code><\/pre>\n<p>1.explain<\/p>\n<pre><code class=\"sql\">+----+-------------+------------+-------+---------------------------------+-----------------------+---------+-------------------+-------+--------------------------------+\r\n| id | select_type | table      | type  | possible_keys                   | key                   | key_len | ref               | rows  | Extra                          |\r\n+----+-------------+------------+-------+---------------------------------+-----------------------+---------+-------------------+-------+--------------------------------+\r\n|  1 | PRIMARY     | cl         | range | cm_log_cls_id,idx_last_upd_date | idx_last_upd_date     | 8       | NULL              |   379 | Using where; Using temporary   |\r\n|  1 | PRIMARY     | &lt;derived2&gt; | ALL   | NULL                            | NULL                  | NULL    | NULL              | 63727 | Using where; Using join buffer |\r\n|  2 | DERIVED     | emp        | ALL   | NULL                            | NULL                  | NULL    | NULL              | 13317 | Using where                    |\r\n|  2 | DERIVED     | emp_cert   | ref   | emp_certificate_empid           | emp_certificate_empid | 4       | meituanorg.emp.id |     1 | Using index                    |\r\n+----+-------------+------------+-------+---------------------------------+-----------------------+---------+-------------------+-------+--------------------------------+\r\n<\/code><\/pre>\n<p>\u7b80\u8ff0\u4e00\u4e0b\u6267\u884c\u8ba1\u5212\uff0c\u9996\u5148mysql\u6839\u636eidx_last_upd_date\u7d22\u5f15\u626b\u63cfcm_log\u8868\u83b7\u5f97379\u6761\u8bb0\u5f55\uff1b\u7136\u540e\u67e5\u8868\u626b\u63cf\u4e8663727\u6761\u8bb0\u5f55\uff0c\u5206\u4e3a\u4e24\u90e8\u5206\uff0cderived\u8868\u793a\u6784\u9020\u8868\uff0c\u4e5f\u5c31\u662f\u4e0d\u5b58\u5728\u7684\u8868\uff0c\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u6210\u662f\u4e00\u4e2a\u8bed\u53e5\u5f62\u6210\u7684\u7ed3\u679c\u96c6\uff0c\u540e\u9762\u7684\u6570\u5b57\u8868\u793a\u8bed\u53e5\u7684ID\u3002derived2\u8868\u793a\u7684\u662fID = 2\u7684\u67e5\u8be2\u6784\u9020\u4e86\u865a\u62df\u8868\uff0c\u5e76\u4e14\u8fd4\u56de\u4e8663727\u6761\u8bb0\u5f55\u3002\u6211\u4eec\u518d\u6765\u770b\u770bID = 2\u7684\u8bed\u53e5\u7a76\u7adf\u505a\u4e86\u5199\u4ec0\u4e48\u8fd4\u56de\u4e86\u8fd9\u4e48\u5927\u91cf\u7684\u6570\u636e\uff0c\u9996\u5148\u5168\u8868\u626b\u63cfemployee\u886813317\u6761\u8bb0\u5f55\uff0c\u7136\u540e\u6839\u636e\u7d22\u5f15emp_certificate_empid\u5173\u8054emp_certificate\u8868\uff0crows = 1\u8868\u793a\uff0c\u6bcf\u4e2a\u5173\u8054\u90fd\u53ea\u9501\u5b9a\u4e86\u4e00\u6761\u8bb0\u5f55\uff0c\u6548\u7387\u6bd4\u8f83\u9ad8\u3002\u83b7\u5f97\u540e\uff0c\u518d\u548ccm_log\u7684379\u6761\u8bb0\u5f55\u6839\u636e\u89c4\u5219\u5173\u8054\u3002\u4ece\u6267\u884c\u8fc7\u7a0b\u4e0a\u53ef\u4ee5\u770b\u51fa\u8fd4\u56de\u4e86\u592a\u591a\u7684\u6570\u636e\uff0c\u8fd4\u56de\u7684\u6570\u636e\u7edd\u5927\u90e8\u5206cm_log\u90fd\u7528\u4e0d\u5230\uff0c\u56e0\u4e3acm_log\u53ea\u9501\u5b9a\u4e86379\u6761\u8bb0\u5f55\u3002<br \/>\n\u5982\u4f55\u4f18\u5316\u5462\uff1f\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u5728\u8fd0\u884c\u5b8c\u540e\u8fd8\u662f\u8981\u548ccm_log\u505ajoin,\u90a3\u4e48\u6211\u4eec\u80fd\u4e0d\u80fd\u4e4b\u524d\u548ccm_log\u505ajoin\u5462\uff1f\u4ed4\u7ec6\u5206\u6790\u8bed\u53e5\u4e0d\u96be\u53d1\u73b0\uff0c\u5176\u57fa\u672c\u601d\u60f3\u662f\u5982\u679ccm_log\u7684ref_table\u662fEmpCertificate\u5c31\u5173\u8054emp_certificate\u8868\uff0c\u5982\u679cref_table\u662fEmployee\u5c31\u5173\u8054employee\u8868\uff0c\u6211\u4eec\u5b8c\u5168\u53ef\u4ee5\u62c6\u6210\u4e24\u90e8\u5206\uff0c\u5e76\u7528union\u8fde\u63a5\u8d77\u6765\uff0c\u6ce8\u610f\u8fd9\u91cc\u7528union\uff0c\u800c\u4e0d\u7528union all\u662f\u56e0\u4e3a\u539f\u8bed\u53e5\u6709\u201cdistinct\u201d\u6765\u5f97\u5230\u552f\u4e00\u7684\u8bb0\u5f55\uff0c\u800cunion\u6070\u597d\u5177\u5907\u4e86\u8fd9\u79cd\u529f\u80fd\u3002\u5982\u679c\u539f\u8bed\u53e5\u4e2d\u6ca1\u6709distinct\u4e0d\u9700\u8981\u53bb\u91cd\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528union all\u4e86\uff0c\u56e0\u4e3a\u4f7f\u7528union\u9700\u8981\u53bb\u91cd\u7684\u52a8\u4f5c\uff0c\u4f1a\u5f71\u54cdSQL\u6027\u80fd\u3002<br \/>\n\u4f18\u5316\u8fc7\u7684\u8bed\u53e5\u5982\u4e0b<\/p>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span>\r\n   emp.<span class=\"keyword\">id<\/span> \r\n<span class=\"keyword\">from<\/span>\r\n   cm_log cl \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   employee emp \r\n      <span class=\"keyword\">on<\/span> cl.ref_table = <span class=\"string\">'Employee'<\/span> \r\n      <span class=\"keyword\">and<\/span> cl.ref_oid = emp.<span class=\"keyword\">id<\/span>  \r\n<span class=\"keyword\">where<\/span>\r\n   cl.last_upd_date &gt;=<span class=\"string\">'2013-11-07 15:03:00'<\/span> \r\n   <span class=\"keyword\">and<\/span> cl.last_upd_date&lt;=<span class=\"string\">'2013-11-08 16:00:00'<\/span> \r\n   <span class=\"keyword\">and<\/span> emp.is_deleted = <span class=\"number\">0<\/span>  \r\n<span class=\"keyword\">union<\/span>\r\n<span class=\"keyword\">select<\/span>\r\n   emp.<span class=\"keyword\">id<\/span> \r\n<span class=\"keyword\">from<\/span>\r\n   cm_log cl \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   emp_certificate ec \r\n      <span class=\"keyword\">on<\/span> cl.ref_table = <span class=\"string\">'EmpCertificate'<\/span> \r\n      <span class=\"keyword\">and<\/span> cl.ref_oid = ec.<span class=\"keyword\">id<\/span>  \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   employee emp \r\n      <span class=\"keyword\">on<\/span> emp.<span class=\"keyword\">id<\/span> = ec.emp_id  \r\n<span class=\"keyword\">where<\/span>\r\n   cl.last_upd_date &gt;=<span class=\"string\">'2013-11-07 15:03:00'<\/span> \r\n   <span class=\"keyword\">and<\/span> cl.last_upd_date&lt;=<span class=\"string\">'2013-11-08 16:00:00'<\/span> \r\n   <span class=\"keyword\">and<\/span> emp.is_deleted = <span class=\"number\">0<\/span><\/span>\r\n<\/code><\/pre>\n<p>4.\u4e0d\u9700\u8981\u4e86\u89e3\u4e1a\u52a1\u573a\u666f\uff0c\u53ea\u9700\u8981\u6539\u9020\u7684\u8bed\u53e5\u548c\u6539\u9020\u4e4b\u524d\u7684\u8bed\u53e5\u4fdd\u6301\u7ed3\u679c\u4e00\u81f4<\/p>\n<p>5.\u73b0\u6709\u7d22\u5f15\u53ef\u4ee5\u6ee1\u8db3\uff0c\u4e0d\u9700\u8981\u5efa\u7d22\u5f15<\/p>\n<p>6.\u7528\u6539\u9020\u540e\u7684\u8bed\u53e5\u5b9e\u9a8c\u4e00\u4e0b\uff0c\u53ea\u9700\u898110ms \u964d\u4f4e\u4e86\u8fd1200\u500d\uff01<\/p>\n<pre><code class=\"sql\">+----+--------------+------------+--------+---------------------------------+-------------------+---------+-----------------------+------+-------------+\r\n| id | select_type  | table      | type   | possible_keys                   | key               | key_len | ref                   | rows | Extra       |\r\n+----+--------------+------------+--------+---------------------------------+-------------------+---------+-----------------------+------+-------------+\r\n|  1 | PRIMARY      | cl         | range  | cm_log_cls_id,idx_last_upd_date | idx_last_upd_date | 8       | NULL                  |  379 | Using where |\r\n|  1 | PRIMARY      | emp        | eq_ref | PRIMARY                         | PRIMARY           | 4       | meituanorg.cl.ref_oid |    1 | Using where |\r\n|  2 | UNION        | cl         | range  | cm_log_cls_id,idx_last_upd_date | idx_last_upd_date | 8       | NULL                  |  379 | Using where |\r\n|  2 | UNION        | ec         | eq_ref | PRIMARY,emp_certificate_empid   | PRIMARY           | 4       | meituanorg.cl.ref_oid |    1 |             |\r\n|  2 | UNION        | emp        | eq_ref | PRIMARY                         | PRIMARY           | 4       | meituanorg.ec.emp_id  |    1 | Using where |\r\n| NULL | UNION RESULT | &lt;union1,2&gt; | ALL    | NULL                            | NULL              | NULL    | NULL                  | NULL |             |\r\n+----+--------------+------------+--------+---------------------------------+-------------------+---------+-----------------------+------+-------------+\r\n53 rows in set (0.01 sec)\r\n<\/code><\/pre>\n<h3 id=\"-\">\u660e\u786e\u5e94\u7528\u573a\u666f<\/h3>\n<p>\u4e3e\u8fd9\u4e2a\u4f8b\u5b50\u7684\u76ee\u7684\u5728\u4e8e\u98a0\u8986\u6211\u4eec\u5bf9\u5217\u7684\u533a\u5206\u5ea6\u7684\u8ba4\u77e5\uff0c\u4e00\u822c\u4e0a\u6211\u4eec\u8ba4\u4e3a\u533a\u5206\u5ea6\u8d8a\u9ad8\u7684\u5217\uff0c\u8d8a\u5bb9\u6613\u9501\u5b9a\u66f4\u5c11\u7684\u8bb0\u5f55\uff0c\u4f46\u5728\u4e00\u4e9b\u7279\u6b8a\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u79cd\u7406\u8bba\u662f\u6709\u5c40\u9650\u6027\u7684<\/p>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span>\r\n   * \r\n<span class=\"keyword\">from<\/span>\r\n   stage_poi sp \r\n<span class=\"keyword\">where<\/span>\r\n   sp.accurate_result=<span class=\"number\">1<\/span> \r\n   <span class=\"keyword\">and<\/span> (\r\n      sp.sync_status=<span class=\"number\">0<\/span> \r\n      <span class=\"keyword\">or<\/span> sp.sync_status=<span class=\"number\">2<\/span> \r\n      <span class=\"keyword\">or<\/span> sp.sync_status=<span class=\"number\">4<\/span>\r\n   );<\/span>\r\n<\/code><\/pre>\n<p>0.\u5148\u770b\u770b\u8fd0\u884c\u591a\u957f\u65f6\u95f4,951\u6761\u6570\u636e6.22\u79d2\uff0c\u771f\u7684\u5f88\u6162<\/p>\n<pre><code class=\"sql\">951 rows in <span class=\"operator\"><span class=\"keyword\">set<\/span> (<span class=\"number\">6.22<\/span> sec)<\/span>\r\n<\/code><\/pre>\n<p>1.\u5148explain\uff0crows\u8fbe\u5230\u4e86361\u4e07\uff0ctype = ALL\u8868\u660e\u662f\u5168\u8868\u626b\u63cf<\/p>\n<pre><code class=\"sql\">+<span class=\"comment\">----+-------------+-------+------+---------------+------+---------+------+---------+-------------+<\/span>\r\n| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows    | Extra       |\r\n+<span class=\"comment\">----+-------------+-------+------+---------------+------+---------+------+---------+-------------+<\/span>\r\n|  1 | SIMPLE      | sp    | ALL  | NULL          | NULL | NULL    | NULL | 3613155 | Using where |\r\n+<span class=\"comment\">----+-------------+-------+------+---------------+------+---------+------+---------+-------------+<\/span>\r\n<\/code><\/pre>\n<p>2.\u6240\u6709\u5b57\u6bb5\u90fd\u5e94\u7528\u67e5\u8be2\u8fd4\u56de\u8bb0\u5f55\u6570\uff0c\u56e0\u4e3a\u662f\u5355\u8868\u67e5\u8be2 0\u5df2\u7ecf\u505a\u8fc7\u4e86951\u6761<\/p>\n<p>3.\u8ba9explain\u7684rows \u5c3d\u91cf\u903c\u8fd1951<\/p>\n<p>\u770b\u4e00\u4e0baccurate_result = 1\u7684\u8bb0\u5f55\u6570<\/p>\n<pre><code class=\"sql\">select count(*),accurate_result from stage_poi  group by accurate_result;\r\n+----------+-----------------+\r\n| count(*) | accurate_result |\r\n+----------+-----------------+\r\n|     1023 |              -1 |\r\n|  2114655 |               0 |\r\n|   972815 |               1 |\r\n+----------+-----------------+\r\n<\/code><\/pre>\n<p>\u6211\u4eec\u770b\u5230accurate_result\u8fd9\u4e2a\u5b57\u6bb5\u7684\u533a\u5206\u5ea6\u975e\u5e38\u4f4e\uff0c\u6574\u4e2a\u8868\u53ea\u6709-1,0,1\u4e09\u4e2a\u503c\uff0c\u52a0\u4e0a\u7d22\u5f15\u4e5f\u65e0\u6cd5\u9501\u5b9a\u7279\u522b\u5c11\u91cf\u7684\u6570\u636e<\/p>\n<p>\u518d\u770b\u4e00\u4e0bsync_status\u5b57\u6bb5\u7684\u60c5\u51b5<\/p>\n<pre><code class=\"sql\">select count(*),sync_status from stage_poi  group by sync_status;\r\n+----------+-------------+\r\n| count(*) | sync_status |\r\n+----------+-------------+\r\n|     3080 |           0 |\r\n|  3085413 |           3 |\r\n+----------+-------------+\r\n<\/code><\/pre>\n<p>\u540c\u6837\u7684\u533a\u5206\u5ea6\u4e5f\u5f88\u4f4e\uff0c\u6839\u636e\u7406\u8bba\uff0c\u4e5f\u4e0d\u9002\u5408\u5efa\u7acb\u7d22\u5f15<\/p>\n<p>\u95ee\u9898\u5206\u6790\u5230\u8fd9\uff0c\u597d\u50cf\u5f97\u51fa\u4e86\u8fd9\u4e2a\u8868\u65e0\u6cd5\u4f18\u5316\u7684\u7ed3\u8bba\uff0c\u4e24\u4e2a\u5217\u7684\u533a\u5206\u5ea6\u90fd\u5f88\u4f4e\uff0c\u5373\u4fbf\u52a0\u4e0a\u7d22\u5f15\u4e5f\u53ea\u80fd\u9002\u5e94\u8fd9\u79cd\u60c5\u51b5\uff0c\u5f88\u96be\u505a\u666e\u904d\u6027\u7684\u4f18\u5316\uff0c\u6bd4\u5982\u5f53sync_status 0\u30013\u5206\u5e03\u7684\u5f88\u5e73\u5747\uff0c\u90a3\u4e48\u9501\u5b9a\u8bb0\u5f55\u4e5f\u662f\u767e\u4e07\u7ea7\u522b\u7684<\/p>\n<p>4.\u627e\u4e1a\u52a1\u65b9\u53bb\u6c9f\u901a\uff0c\u770b\u770b\u4f7f\u7528\u573a\u666f\u3002\u4e1a\u52a1\u65b9\u662f\u8fd9\u4e48\u6765\u4f7f\u7528\u8fd9\u4e2aSQL\u8bed\u53e5\u7684\uff0c\u6bcf\u9694\u4e94\u5206\u949f\u4f1a\u626b\u63cf\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\uff0c\u5904\u7406\u5b8c\u6210\u540e\u628async_status\u8fd9\u4e2a\u5b57\u6bb5\u53d8\u62101,\u4e94\u5206\u949f\u7b26\u5408\u6761\u4ef6\u7684\u8bb0\u5f55\u6570\u5e76\u4e0d\u4f1a\u592a\u591a\uff0c1000\u4e2a\u5de6\u53f3\u3002\u4e86\u89e3\u4e86\u4e1a\u52a1\u65b9\u7684\u4f7f\u7528\u573a\u666f\u540e\uff0c\u4f18\u5316\u8fd9\u4e2aSQL\u5c31\u53d8\u5f97\u7b80\u5355\u4e86\uff0c\u56e0\u4e3a\u4e1a\u52a1\u65b9\u4fdd\u8bc1\u4e86\u6570\u636e\u7684\u4e0d\u5e73\u8861\uff0c\u5982\u679c\u52a0\u4e0a\u7d22\u5f15\u53ef\u4ee5\u8fc7\u6ee4\u6389\u7edd\u5927\u90e8\u5206\u4e0d\u9700\u8981\u7684\u6570\u636e<\/p>\n<p>5.\u6839\u636e\u5efa\u7acb\u7d22\u5f15\u89c4\u5219\uff0c\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\u5efa\u7acb\u7d22\u5f15<\/p>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">alter<\/span> <span class=\"keyword\">table<\/span> stage_poi <span class=\"keyword\">add<\/span> <span class=\"keyword\">index<\/span> idx_acc_status(accurate_result,sync_status);<\/span>\r\n<\/code><\/pre>\n<p>6.\u89c2\u5bdf\u9884\u671f\u7ed3\u679c,\u53d1\u73b0\u53ea\u9700\u8981200ms\uff0c\u5feb\u4e8630\u591a\u500d\u3002<\/p>\n<pre><code class=\"sql\">952 rows in <span class=\"operator\"><span class=\"keyword\">set<\/span> (<span class=\"number\">0.20<\/span> sec)<\/span>\r\n<\/code><\/pre>\n<p>\u6211\u4eec\u518d\u6765\u56de\u987e\u4e00\u4e0b\u5206\u6790\u95ee\u9898\u7684\u8fc7\u7a0b\uff0c\u5355\u8868\u67e5\u8be2\u76f8\u5bf9\u6765\u8bf4\u6bd4\u8f83\u597d\u4f18\u5316\uff0c\u5927\u90e8\u5206\u65f6\u5019\u53ea\u9700\u8981\u628awhere\u6761\u4ef6\u91cc\u9762\u7684\u5b57\u6bb5\u4f9d\u7167\u89c4\u5219\u52a0\u4e0a\u7d22\u5f15\u5c31\u597d\uff0c\u5982\u679c\u53ea\u662f\u8fd9\u79cd\u201c\u65e0\u8111\u201d\u4f18\u5316\u7684\u8bdd\uff0c\u663e\u7136\u4e00\u4e9b\u533a\u5206\u5ea6\u975e\u5e38\u4f4e\u7684\u5217\uff0c\u4e0d\u5e94\u8be5\u52a0\u7d22\u5f15\u7684\u5217\u4e5f\u4f1a\u88ab\u52a0\u4e0a\u7d22\u5f15\uff0c\u8fd9\u6837\u4f1a\u5bf9\u63d2\u5165\u3001\u66f4\u65b0\u6027\u80fd\u9020\u6210\u4e25\u91cd\u7684\u5f71\u54cd\uff0c\u540c\u65f6\u4e5f\u6709\u53ef\u80fd\u5f71\u54cd\u5176\u5b83\u7684\u67e5\u8be2\u8bed\u53e5\u3002\u6240\u4ee5\u6211\u4eec\u7b2c4\u6b65\u8c03\u5deeSQL\u7684\u4f7f\u7528\u573a\u666f\u975e\u5e38\u5173\u952e\uff0c\u6211\u4eec\u53ea\u6709\u77e5\u9053\u8fd9\u4e2a\u4e1a\u52a1\u573a\u666f\uff0c\u624d\u80fd\u66f4\u597d\u5730\u8f85\u52a9\u6211\u4eec\u66f4\u597d\u7684\u5206\u6790\u548c\u4f18\u5316\u67e5\u8be2\u8bed\u53e5\u3002<\/p>\n<h3 id=\"-\">\u65e0\u6cd5\u4f18\u5316\u7684\u8bed\u53e5<\/h3>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span>\r\n   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">id<\/span>,\r\n   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">name<\/span>,\r\n   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">position<\/span>,\r\n   <span class=\"keyword\">c<\/span>.sex,\r\n   <span class=\"keyword\">c<\/span>.phone,\r\n   <span class=\"keyword\">c<\/span>.office_phone,\r\n   <span class=\"keyword\">c<\/span>.feature_info,\r\n   <span class=\"keyword\">c<\/span>.birthday,\r\n   <span class=\"keyword\">c<\/span>.creator_id,\r\n   <span class=\"keyword\">c<\/span>.is_keyperson,\r\n   <span class=\"keyword\">c<\/span>.giveup_reason,\r\n   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">status<\/span>,\r\n   <span class=\"keyword\">c<\/span>.data_source,\r\n   from_unixtime(<span class=\"keyword\">c<\/span>.created_time) <span class=\"keyword\">as<\/span> created_time,\r\n   from_unixtime(<span class=\"keyword\">c<\/span>.last_modified) <span class=\"keyword\">as<\/span> last_modified,\r\n   <span class=\"keyword\">c<\/span>.last_modified_user_id  \r\n<span class=\"keyword\">from<\/span>\r\n   contact <span class=\"keyword\">c<\/span>  \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   contact_branch cb \r\n      <span class=\"keyword\">on<\/span>  <span class=\"keyword\">c<\/span>.<span class=\"keyword\">id<\/span> = cb.contact_id  \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   branch_user bu \r\n      <span class=\"keyword\">on<\/span>  cb.branch_id = bu.branch_id \r\n      <span class=\"keyword\">and<\/span> bu.<span class=\"keyword\">status<\/span> <span class=\"keyword\">in<\/span> (\r\n         <span class=\"number\">1<\/span>,\r\n      <span class=\"number\">2<\/span>)  \r\n   <span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n      org_emp_info oei \r\n         <span class=\"keyword\">on<\/span>  oei.data_id = bu.user_id \r\n         <span class=\"keyword\">and<\/span> oei.node_left &gt;= <span class=\"number\">2875<\/span> \r\n         <span class=\"keyword\">and<\/span> oei.node_right &lt;= <span class=\"number\">10802<\/span> \r\n         <span class=\"keyword\">and<\/span> oei.org_category = - <span class=\"number\">1<\/span>  \r\n   <span class=\"keyword\">order<\/span> <span class=\"keyword\">by<\/span>\r\n      <span class=\"keyword\">c<\/span>.created_time <span class=\"keyword\">desc<\/span>  <span class=\"keyword\">limit<\/span> <span class=\"number\">0<\/span> ,\r\n      <span class=\"number\">10<\/span>;<\/span>\r\n<\/code><\/pre>\n<p>\u8fd8\u662f\u51e0\u4e2a\u6b65\u9aa4<br \/>\n0.\u5148\u770b\u8bed\u53e5\u8fd0\u884c\u591a\u957f\u65f6\u95f4\uff0c10\u6761\u8bb0\u5f55\u7528\u4e8613\u79d2\uff0c\u5df2\u7ecf\u4e0d\u53ef\u5fcd\u53d7<\/p>\n<pre><code class=\"sql\">10 rows in <span class=\"operator\"><span class=\"keyword\">set<\/span> (<span class=\"number\">13.06<\/span> sec)<\/span>\r\n<\/code><\/pre>\n<p>1.explain<\/p>\n<pre><code class=\"sql\">+<span class=\"comment\">----+-------------+-------+--------+-------------------------------------+-------------------------+---------+--------------------------+------+----------------------------------------------+<\/span>\r\n| id | select_type | table | type   | possible_keys                       | key                     | key_len | ref                      | rows | Extra                                        |\r\n+<span class=\"comment\">----+-------------+-------+--------+-------------------------------------+-------------------------+---------+--------------------------+------+----------------------------------------------+<\/span>\r\n|  1 | SIMPLE      | oei   | ref    | idx_category_left_right,idx_data_id | idx_category_left_right | 5       | const                    | 8849 | Using where; Using temporary; Using filesort |\r\n|  1 | SIMPLE      | bu    | ref    | PRIMARY,idx_userid_status           | idx_userid_status       | 4       | meituancrm.oei.data_id   |   76 | Using where; Using index                     |\r\n|  1 | SIMPLE      | cb    | ref    | idx_branch_id,idx_contact_branch_id | idx_branch_id           | 4       | meituancrm.bu.branch_id  |    1 |                                              |\r\n|  1 | SIMPLE      | c     | eq_ref | PRIMARY                             | PRIMARY                 | 108     | meituancrm.cb.contact_id |    1 |                                              |\r\n+<span class=\"comment\">----+-------------+-------+--------+-------------------------------------+-------------------------+---------+--------------------------+------+----------------------------------------------+<\/span>\r\n<\/code><\/pre>\n<p>\u4ece\u6267\u884c\u8ba1\u5212\u4e0a\u770b\uff0cmysql\u5148\u67e5org_emp_info\u8868\u626b\u63cf8849\u8bb0\u5f55\uff0c\u518d\u7528\u7d22\u5f15idx_userid_status\u5173\u8054branch_user\u8868\uff0c\u518d\u7528\u7d22\u5f15idx_branch_id\u5173\u8054contact_branch\u8868\uff0c\u6700\u540e\u4e3b\u952e\u5173\u8054contact\u8868\u3002<br \/>\nrows\u8fd4\u56de\u7684\u90fd\u975e\u5e38\u5c11\uff0c\u770b\u4e0d\u5230\u6709\u4ec0\u4e48\u5f02\u5e38\u60c5\u51b5\u3002\u6211\u4eec\u5728\u770b\u4e00\u4e0b\u8bed\u53e5\uff0c\u53d1\u73b0\u540e\u9762\u6709order by + limit\u7ec4\u5408\uff0c\u4f1a\u4e0d\u4f1a\u662f\u6392\u5e8f\u91cf\u592a\u5927\u641e\u7684\uff1f\u4e8e\u662f\u6211\u4eec\u7b80\u5316SQL\uff0c\u53bb\u6389\u540e\u9762\u7684order by \u548c limit\uff0c\u770b\u770b\u5230\u5e95\u7528\u4e86\u591a\u5c11\u8bb0\u5f55\u6765\u6392\u5e8f<\/p>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span>\r\n  <span class=\"keyword\">count<\/span>(*)\r\n<span class=\"keyword\">from<\/span>\r\n   contact <span class=\"keyword\">c<\/span>  \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   contact_branch cb \r\n      <span class=\"keyword\">on<\/span>  <span class=\"keyword\">c<\/span>.<span class=\"keyword\">id<\/span> = cb.contact_id  \r\n<span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n   branch_user bu \r\n      <span class=\"keyword\">on<\/span>  cb.branch_id = bu.branch_id \r\n      <span class=\"keyword\">and<\/span> bu.<span class=\"keyword\">status<\/span> <span class=\"keyword\">in<\/span> (\r\n         <span class=\"number\">1<\/span>,\r\n      <span class=\"number\">2<\/span>)  \r\n   <span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n      org_emp_info oei \r\n         <span class=\"keyword\">on<\/span>  oei.data_id = bu.user_id \r\n         <span class=\"keyword\">and<\/span> oei.node_left &gt;= <span class=\"number\">2875<\/span> \r\n         <span class=\"keyword\">and<\/span> oei.node_right &lt;= <span class=\"number\">10802<\/span> \r\n         <span class=\"keyword\">and<\/span> oei.org_category = - <span class=\"number\">1<\/span>  \r\n+<span class=\"comment\">----------+<\/span>\r\n| <span class=\"keyword\">count<\/span>(*) |\r\n+<span class=\"comment\">----------+<\/span>\r\n|   <span class=\"number\">778878<\/span> |\r\n+<span class=\"comment\">----------+<\/span>\r\n<span class=\"number\">1<\/span> <span class=\"keyword\">row<\/span> <span class=\"keyword\">in<\/span> <span class=\"keyword\">set<\/span> (<span class=\"number\">5.19<\/span> sec)<\/span>\r\n<\/code><\/pre>\n<p>\u53d1\u73b0\u6392\u5e8f\u4e4b\u524d\u5c45\u7136\u9501\u5b9a\u4e86778878\u6761\u8bb0\u5f55\uff0c\u5982\u679c\u9488\u5bf970\u4e07\u7684\u7ed3\u679c\u96c6\u6392\u5e8f\uff0c\u5c06\u662f\u707e\u96be\u6027\u7684\uff0c\u602a\u4e0d\u5f97\u8fd9\u4e48\u6162\uff0c\u90a3\u6211\u4eec\u80fd\u4e0d\u80fd\u6362\u4e2a\u601d\u8def\uff0c\u5148\u6839\u636econtact\u7684created_time\u6392\u5e8f\uff0c\u518d\u6765join\u4f1a\u4e0d\u4f1a\u6bd4\u8f83\u5feb\u5462\uff1f<br \/>\n\u4e8e\u662f\u6539\u9020\u6210\u4e0b\u9762\u7684\u8bed\u53e5\uff0c\u4e5f\u53ef\u4ee5\u7528straight_join\u6765\u4f18\u5316<br \/>\nselect<br \/>\nc.id,<br \/>\nc.name,<br \/>\nc.position,<br \/>\nc.sex,<br \/>\nc.phone,<br \/>\nc.office_phone,<br \/>\nc.feature_info,<br \/>\nc.birthday,<br \/>\nc.creator_id,<br \/>\nc.is_keyperson,<br \/>\nc.giveup_reason,<br \/>\nc.status,<br \/>\nc.data_source,<br \/>\nfrom_unixtime(c.created_time) as created_time,<br \/>\nfrom_unixtime(c.last_modified) as last_modified,<br \/>\nc.last_modified_user_id<br \/>\nfrom<br \/>\ncontact c<br \/>\nwhere<br \/>\nexists (<br \/>\nselect<br \/>\n1<br \/>\nfrom<br \/>\ncontact_branch cb<br \/>\ninner join<br \/>\nbranch_user bu<br \/>\non cb.branch_id = bu.branch_id<br \/>\nand bu.status in (<br \/>\n1,<br \/>\n2)<br \/>\ninner join<br \/>\norg_emp_info oei<br \/>\non oei.data_id = bu.user_id<br \/>\nand oei.node_left &gt;= 2875<br \/>\nand oei.node_right &lt;= 10802<br \/>\nand oei.org_category = - 1<br \/>\nwhere<br \/>\nc.id = cb.contact_id<br \/>\n)<br \/>\norder by<br \/>\nc.created_time desc limit 0 ,<br \/>\n10;<\/p>\n<pre><code>\u9a8c\u8bc1\u4e00\u4e0b\u6548\u679c \u9884\u8ba1\u57281ms\u5185\uff0c\u63d0\u5347\u4e8613000\u591a\u500d\uff01\r\n```sql\r\n10 rows in set (0.00 sec)\r\n<\/code><\/pre>\n<p>\u672c\u4ee5\u4e3a\u81f3\u6b64\u5927\u5de5\u544a\u6210\uff0c\u4f46\u6211\u4eec\u5728\u524d\u9762\u7684\u5206\u6790\u4e2d\u6f0f\u4e86\u4e00\u4e2a\u7ec6\u8282\uff0c\u5148\u6392\u5e8f\u518djoin\u548c\u5148join\u518d\u6392\u5e8f\u7406\u8bba\u4e0a\u5f00\u9500\u662f\u4e00\u6837\u7684\uff0c\u4e3a\u4f55\u63d0\u5347\u8fd9\u4e48\u591a\u662f\u56e0\u4e3a\u6709\u4e00\u4e2alimit\uff01\u5927\u81f4\u6267\u884c\u8fc7\u7a0b\u662f\uff1amysql\u5148\u6309\u7d22\u5f15\u6392\u5e8f\u5f97\u5230\u524d10\u6761\u8bb0\u5f55\uff0c\u7136\u540e\u518d\u53bbjoin\u8fc7\u6ee4\uff0c\u5f53\u53d1\u73b0\u4e0d\u591f10\u6761\u7684\u65f6\u5019\uff0c\u518d\u6b21\u53bb10\u6761\uff0c\u518d\u6b21join\uff0c\u8fd9\u663e\u7136\u5728\u5185\u5c42join\u8fc7\u6ee4\u7684\u6570\u636e\u975e\u5e38\u591a\u7684\u65f6\u5019\uff0c\u5c06\u662f\u707e\u96be\u7684\uff0c\u6781\u7aef\u60c5\u51b5\uff0c\u5185\u5c42\u4e00\u6761\u6570\u636e\u90fd\u627e\u4e0d\u5230\uff0cmysql\u8fd8\u50bb\u4e4e\u4e4e\u7684\u6bcf\u6b21\u53d610\u6761\uff0c\u51e0\u4e4e\u904d\u5386\u4e86\u8fd9\u4e2a\u6570\u636e\u8868\uff01<br \/>\n\u7528\u4e0d\u540c\u53c2\u6570\u7684SQL\u8bd5\u9a8c\u4e0b<\/p>\n<pre><code class=\"sql\"><span class=\"operator\"><span class=\"keyword\">select<\/span>\r\n   sql_no_cache   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">id<\/span>,\r\n   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">name<\/span>,\r\n   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">position<\/span>,\r\n   <span class=\"keyword\">c<\/span>.sex,\r\n   <span class=\"keyword\">c<\/span>.phone,\r\n   <span class=\"keyword\">c<\/span>.office_phone,\r\n   <span class=\"keyword\">c<\/span>.feature_info,\r\n   <span class=\"keyword\">c<\/span>.birthday,\r\n   <span class=\"keyword\">c<\/span>.creator_id,\r\n   <span class=\"keyword\">c<\/span>.is_keyperson,\r\n   <span class=\"keyword\">c<\/span>.giveup_reason,\r\n   <span class=\"keyword\">c<\/span>.<span class=\"keyword\">status<\/span>,\r\n   <span class=\"keyword\">c<\/span>.data_source,\r\n   from_unixtime(<span class=\"keyword\">c<\/span>.created_time) <span class=\"keyword\">as<\/span> created_time,\r\n   from_unixtime(<span class=\"keyword\">c<\/span>.last_modified) <span class=\"keyword\">as<\/span> last_modified,\r\n   <span class=\"keyword\">c<\/span>.last_modified_user_id    \r\n<span class=\"keyword\">from<\/span>\r\n   contact <span class=\"keyword\">c<\/span>   \r\n<span class=\"keyword\">where<\/span>\r\n   <span class=\"keyword\">exists<\/span> (\r\n      <span class=\"keyword\">select<\/span>\r\n         <span class=\"number\">1<\/span>        \r\n      <span class=\"keyword\">from<\/span>\r\n         contact_branch cb         \r\n      <span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n         branch_user bu                     \r\n            <span class=\"keyword\">on<\/span>  cb.branch_id = bu.branch_id                     \r\n            <span class=\"keyword\">and<\/span> bu.<span class=\"keyword\">status<\/span> <span class=\"keyword\">in<\/span> (\r\n               <span class=\"number\">1<\/span>,\r\n            <span class=\"number\">2<\/span>)                \r\n         <span class=\"keyword\">inner<\/span> <span class=\"keyword\">join<\/span>\r\n            org_emp_info oei                           \r\n               <span class=\"keyword\">on<\/span>  oei.data_id = bu.user_id                           \r\n               <span class=\"keyword\">and<\/span> oei.node_left &gt;= <span class=\"number\">2875<\/span>                           \r\n               <span class=\"keyword\">and<\/span> oei.node_right &lt;= <span class=\"number\">2875<\/span>                           \r\n               <span class=\"keyword\">and<\/span> oei.org_category = - <span class=\"number\">1<\/span>                \r\n         <span class=\"keyword\">where<\/span>\r\n            <span class=\"keyword\">c<\/span>.<span class=\"keyword\">id<\/span> = cb.contact_id           \r\n      )        \r\n   <span class=\"keyword\">order<\/span> <span class=\"keyword\">by<\/span>\r\n      <span class=\"keyword\">c<\/span>.created_time <span class=\"keyword\">desc<\/span>  <span class=\"keyword\">limit<\/span> <span class=\"number\">0<\/span> ,\r\n      <span class=\"number\">10<\/span>;<\/span>\r\nEmpty <span class=\"operator\"><span class=\"keyword\">set<\/span> (<span class=\"number\">2<\/span> <span class=\"keyword\">min<\/span> <span class=\"number\">18.99<\/span> sec)<\/span>\r\n<\/code><\/pre>\n<p>2 min 18.99 sec\uff01\u6bd4\u4e4b\u524d\u7684\u60c5\u51b5\u8fd8\u7cdf\u7cd5\u5f88\u591a\u3002\u7531\u4e8emysql\u7684nested loop\u673a\u5236\uff0c\u9047\u5230\u8fd9\u79cd\u60c5\u51b5\uff0c\u57fa\u672c\u662f\u65e0\u6cd5\u4f18\u5316\u7684\u3002\u8fd9\u6761\u8bed\u53e5\u6700\u7ec8\u4e5f\u53ea\u80fd\u4ea4\u7ed9\u5e94\u7528\u7cfb\u7edf\u53bb\u4f18\u5316\u81ea\u5df1\u7684\u903b\u8f91\u4e86\u3002<br \/>\n\u901a\u8fc7\u8fd9\u4e2a\u4f8b\u5b50\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u8bed\u53e5\u90fd\u80fd\u4f18\u5316\uff0c\u800c\u5f80\u5f80\u6211\u4eec\u4f18\u5316\u65f6\uff0c\u7531\u4e8eSQL\u7528\u4f8b\u56de\u5f52\u65f6\u843d\u6389\u4e00\u4e9b\u6781\u7aef\u60c5\u51b5\uff0c\u4f1a\u9020\u6210\u6bd4\u539f\u6765\u8fd8\u4e25\u91cd\u7684\u540e\u679c\u3002\u6240\u4ee5\uff0c\u7b2c\u4e00\uff1a\u4e0d\u8981\u6307\u671b\u6240\u6709\u8bed\u53e5\u90fd\u80fd\u901a\u8fc7SQL\u4f18\u5316\uff0c\u7b2c\u4e8c\uff1a\u4e0d\u8981\u8fc7\u4e8e\u81ea\u4fe1\uff0c\u53ea\u9488\u5bf9\u5177\u4f53case\u6765\u4f18\u5316\uff0c\u800c\u5ffd\u7565\u4e86\u66f4\u590d\u6742\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u6162\u67e5\u8be2\u7684\u6848\u4f8b\u5c31\u5206\u6790\u5230\u8fd9\u513f\uff0c\u4ee5\u4e0a\u53ea\u662f\u4e00\u4e9b\u6bd4\u8f83\u5178\u578b\u7684\u6848\u4f8b\u3002\u6211\u4eec\u5728\u4f18\u5316\u8fc7\u7a0b\u4e2d\u9047\u5230\u8fc7\u8d85\u8fc71000\u884c\uff0c\u6d89\u53ca\u523016\u4e2a\u8868join\u7684\u201c\u5783\u573eSQL\u201d\uff0c\u4e5f\u9047\u5230\u8fc7\u7ebf\u4e0a\u7ebf\u4e0b\u6570\u636e\u5e93\u5dee\u5f02\u5bfc\u81f4\u5e94\u7528\u76f4\u63a5\u88ab\u6162\u67e5\u8be2\u62d6\u6b7b\uff0c\u4e5f\u9047\u5230\u8fc7varchar\u7b49\u503c\u6bd4\u8f83\u6ca1\u6709\u5199\u5355\u5f15\u53f7\uff0c\u8fd8\u9047\u5230\u8fc7\u7b1b\u5361\u5c14\u79ef\u67e5\u8be2\u76f4\u63a5\u628a\u4ece\u5e93\u641e\u6b7b\u3002\u518d\u591a\u7684\u6848\u4f8b\u5176\u5b9e\u4e5f\u53ea\u662f\u4e00\u4e9b\u7ecf\u9a8c\u7684\u79ef\u7d2f\uff0c\u5982\u679c\u6211\u4eec\u719f\u6089\u67e5\u8be2\u4f18\u5316\u5668\u3001\u7d22\u5f15\u7684\u5185\u90e8\u539f\u7406\uff0c\u90a3\u4e48\u5206\u6790\u8fd9\u4e9b\u6848\u4f8b\u5c31\u53d8\u5f97\u7279\u522b\u7b80\u5355\u4e86\u3002<\/p>\n<h1 id=\"-\">\u5199\u5728\u540e\u9762\u7684\u8bdd<\/h1>\n<p>\u672c\u6587\u4ee5\u4e00\u4e2a\u6162\u67e5\u8be2\u6848\u4f8b\u5f15\u5165\u4e86MySQL\u7d22\u5f15\u539f\u7406\u3001\u4f18\u5316\u6162\u67e5\u8be2\u7684\u4e00\u4e9b\u65b9\u6cd5\u8bba;\u5e76\u9488\u5bf9\u9047\u5230\u7684\u5178\u578b\u6848\u4f8b\u505a\u4e86\u8be6\u7ec6\u7684\u5206\u6790\u3002\u5176\u5b9e\u505a\u4e86\u8fd9\u4e48\u957f\u65f6\u95f4\u7684\u8bed\u53e5\u4f18\u5316\u540e\u624d\u53d1\u73b0\uff0c\u4efb\u4f55\u6570\u636e\u5e93\u5c42\u9762\u7684\u4f18\u5316\u90fd\u62b5\u4e0d\u4e0a\u5e94\u7528\u7cfb\u7edf\u7684\u4f18\u5316\uff0c\u540c\u6837\u662fMySQL\uff0c\u53ef\u4ee5\u7528\u6765\u652f\u6491Google\/FaceBook\/Taobao\u5e94\u7528\uff0c\u4f46\u53ef\u80fd\u8fde\u4f60\u7684\u4e2a\u4eba\u7f51\u7ad9\u90fd\u6491\u4e0d\u4f4f\u3002\u5957\u7528\u6700\u8fd1\u6bd4\u8f83\u6d41\u884c\u7684\u8bdd\uff1a\u201c\u67e5\u8be2\u5bb9\u6613\uff0c\u4f18\u5316\u4e0d\u6613\uff0c\u4e14\u5199\u4e14\u73cd\u60dc\uff01\u201d<\/p>\n<h1 id=\"-\">\u53c2\u8003<\/h1>\n<p>\u53c2\u8003\u6587\u732e\u5982\u4e0b\uff1a<br \/>\n1.\u300a\u9ad8\u6027\u80fdMySQL\u300b<br \/>\n2.\u300a\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u5206\u6790\u300b<\/p>\n<p>\u539f\u6587\uff1a\u7f8e\u56e2\u70b9\u8bc4\u6280\u672f\u56e2\u961f<a href=\"https:\/\/tech.meituan.com\/mysql-index.html\">\u00a0https:\/\/tech.meituan.com\/mysql-index.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.chenweikang.top\">\u5de6\u624b\u4ee3\u7801\u53f3\u624b\u8bd7<\/a> &raquo; <a href=\"https:\/\/www.chenweikang.top\/?p=361\">MySQL\u7d22\u5f15\u539f\u7406\u53ca\u6162\u67e5\u8be2\u4f18\u5316<\/a><\/p><div class=\"__youshang\">\r\n            <div id=\"__youshang_popup\" class=\"wechat popup\" style=\"display: none;\">\r\n                <div class=\"head\">~\u8c22\u8c22\u6253\u8d4f~<\/div>\r\n                <div class=\"qrcode\"><div class=\"qrcode-li wechat\" ><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/wexin.png\" \/><\/div><div class=\"qrcode-li alipay\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-pay.png\" \/><\/div><div class=\"qrcode-li hongbao\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-hongbao.png\" \/><\/div><\/div>\r\n                <ul class=\"platform\"><li class=\"icon-wechat active\" data-bg-color=\"#05af4e\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-alipay \" data-bg-color=\"#00a2ea\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-hongbao \" data-bg-color=\"#dd5746\" data-thanks=\"<p>\u626b\u7801\u9886\u7ea2\u5305<\/p><p style='margin-top: 24px;'>\uff08\u4f59\u989d\u5b9d\u652f\u4ed8\u65f6\u53ef\u62b5\u73b0\uff09<\/p>\"><\/li><\/ul>\r\n            <\/div>\r\n            <a href=\"javascript:void(0);\" id=\"__youshang_btn\">\u8d4f<\/a>\r\n        <\/div>","protected":false},"excerpt":{"rendered":"<p>MySQL\u51ed\u501f\u7740\u51fa\u8272\u7684\u6027\u80fd\u3001\u4f4e\u5ec9\u7684\u6210\u672c\u3001\u4e30\u5bcc\u7684\u8d44\u6e90\uff0c\u5df2\u7ecf\u6210\u4e3a\u7edd\u5927\u591a\u6570\u4e92\u8054\u7f51\u516c\u53f8\u7684\u9996\u9009\u5173\u7cfb\u578b\u6570\u636e\u5e93\u3002\u867d\u7136\u6027\u80fd\u51fa\u8272 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":363,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[45],"class_list":["post-361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database","tag-45"],"_links":{"self":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=361"}],"version-history":[{"count":0,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/361\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/media\/363"}],"wp:attachment":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}