{"id":5409,"date":"2024-11-14T13:03:42","date_gmt":"2024-11-14T05:03:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5409\/"},"modified":"2024-11-14T13:03:42","modified_gmt":"2024-11-14T05:03:42","slug":"mysql%e6%89%a7%e8%a1%8c%e8%ae%a1%e5%88%92%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5409\/","title":{"rendered":"mysql\u6267\u884c\u8ba1\u5212\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  mysql \u6267\u884c\u8ba1\u5212\u662f\u4e00\u5f20\u56fe\u8868\uff0c\u8be6\u7ec6\u8bf4\u660e\u4e86 mysql \u5982\u4f55\u6267\u884c\u67e5\u8be2\uff0c\u5305\u62ec\u6b65\u9aa4\u548c\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u3002\u53ef\u4ee5\u901a\u8fc7 explain \u5173\u952e\u5b57\u6216 mysql workbench gui \u67e5\u770b\u6267\u884c\u8ba1\u5212\u3002\u6267\u884c\u8ba1\u5212\u901a\u5e38\u5305\u62ec\u5757 id\u3001\u67e5\u8be2\u7c7b\u578b\u3001\u6d89\u53ca\u8868\u3001\u8bbf\u95ee\u65b9\u5f0f\u3001\u53ef\u80fd\/\u5b9e\u9645\u4f7f\u7528\u7684\u7d22\u5f15\u3001\u4f30\u8ba1\u884c\u6570\u3001\u8fc7\u6ee4\u767e\u5206\u6bd4\u548c\u9644\u52a0\u4fe1\u606f\u3002\u89e3\u91ca\u6267\u884c\u8ba1\u5212\u65f6\uff0c\u5e94\u5173\u6ce8\u8bbf\u95ee\u65b9\u5f0f\uff08type\uff09\u3001\u4f30\u8ba1\u884c\u6570\uff08rows\uff09\u548c\u9644\u52a0\u4fe1\u606f\uff08extra\uff09\u3002\u53ef\u4ee5\u9075\u5faa\u5efa\u8bae\uff08\u4f8b\u5982\u521b\u5efa\u9002\u5f53\u7d22\u5f15\u3001\u4f7f\u7528\u8986\u76d6\u7d22\u5f15\u3001\u907f\u514d select * \u548c\u4f18\u5316 where \u5b50\u53e5\uff09\u6765\u4f18\u5316\u6267\u884c\u8ba1\u5212\uff0c\u4ece\u800c\u63d0\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052811304526490.jpg\" class=\"aligncenter\" title=\"mysql\u6267\u884c\u8ba1\u5212\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"mysql\u6267\u884c\u8ba1\u5212\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u6267\u884c\u8ba1\u5212<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f MySQL \u6267\u884c\u8ba1\u5212\uff1f<\/strong><\/p>\n<p>MySQL \u6267\u884c\u8ba1\u5212\u662f\u4e00\u4e2a\u8bf4\u660e MySQL \u5c06\u5982\u4f55\u6267\u884c\u67e5\u8be2\u7684\u56fe\u8868\u3002\u5b83\u663e\u793a\u4e86 MySQL \u4f30\u8ba1\u7684\u6b65\u9aa4\u548c\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\uff0c\u4ee5\u5e2e\u52a9\u7528\u6237\u4e86\u89e3\u67e5\u8be2\u7684\u6027\u80fd\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b\u6267\u884c\u8ba1\u5212<\/strong><\/p>\n<p>\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u67e5\u770b\u6267\u884c\u8ba1\u5212\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 EXPLAIN \u5173\u952e\u5b57\uff1aEXPLAIN <\/li>\n<li>\u4f7f\u7528 MySQL Workbench GUI<\/li>\n<\/ul>\n<p><strong>\u6267\u884c\u8ba1\u5212\u7684\u7ed3\u6784<\/strong><\/p>\n<p>\u6267\u884c\u8ba1\u5212\u901a\u5e38\u5305\u542b\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li> <strong>id\uff1a<\/strong>\u67e5\u8be2\u5757\u7684\u6807\u8bc6\u7b26\u3002<\/li>\n<li> <strong>select_type\uff1a<\/strong>\u67e5\u8be2\u7c7b\u578b\uff0c\u4f8b\u5982 SIMPLE \u6216 DEPENDENT SUBQUERY\u3002<\/li>\n<li> <strong>table\uff1a<\/strong>\u6d89\u53ca\u7684\u8868\u6216\u89c6\u56fe\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>type\uff1a<\/strong>MySQL \u5c06\u5982\u4f55\u8bbf\u95ee\u8868\uff0c\u4f8b\u5982 ALL\uff08\u5168\u8868\u626b\u63cf\uff09\u6216 index\uff08\u7d22\u5f15\u626b\u63cf\uff09\u3002<\/li>\n<li> <strong>possible_keys\uff1a<\/strong>\u67e5\u8be2\u4e2d\u53ef\u80fd\u4f7f\u7528\u7684\u7d22\u5f15\u3002<\/li>\n<li> <strong>key\uff1a<\/strong>\u5b9e\u9645\u4e0a\u4f7f\u7528\u7684\u7d22\u5f15\u3002<\/li>\n<li> <strong>rows\uff1a<\/strong>MySQL \u4f30\u8ba1\u7684\u8981\u626b\u63cf\u7684\u884c\u6570\u3002<\/li>\n<li> <strong>filtered\uff1a<\/strong>MySQL \u4f30\u8ba1\u7684\u88ab WHERE \u5b50\u53e5\u8fc7\u6ee4\u7684\u884c\u767e\u5206\u6bd4\u3002<\/li>\n<li> <strong>Extra\uff1a<\/strong>\u6709\u5173\u67e5\u8be2\u6267\u884c\u7684\u9644\u52a0\u4fe1\u606f\uff0c\u4f8b\u5982 Using index \u6216 Using temporary\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u89e3\u91ca\u6267\u884c\u8ba1\u5212<\/strong><\/p>\n<p>\u89e3\u91ca\u6267\u884c\u8ba1\u5212\u65f6\uff0c\u8bf7\u5173\u6ce8\u4ee5\u4e0b\u5173\u952e\u70b9\uff1a<\/p>\n<ul>\n<li> <strong>type\uff1a<\/strong>\u8fd9\u8868\u793a MySQL \u8bbf\u95ee\u8868\u7684\u6548\u7387\u3002ALL \u662f\u6700\u6162\u7684\uff0cindex \u662f\u6700\u5feb\u7684\u3002<\/li>\n<li> <strong>rows\uff1a<\/strong>\u8f83\u9ad8\u7684\u884c\u6570\u4f30\u8ba1\u503c\u8868\u660e\u67e5\u8be2\u53ef\u80fd\u9700\u8981\u66f4\u957f\u7684\u65f6\u95f4\u3002<\/li>\n<li> <strong>Extra\uff1a<\/strong>\u8fd9\u63d0\u4f9b\u4e86\u6709\u5173\u67e5\u8be2\u6267\u884c\u7684\u5176\u4ed6\u89c1\u89e3\uff0c\u4f8b\u5982\u662f\u5426\u4f7f\u7528\u4e86\u4e34\u65f6\u8868\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u4f18\u5316\u6267\u884c\u8ba1\u5212<\/strong><\/p>\n<p>\u901a\u8fc7\u9075\u5faa\u4ee5\u4e0b\u5efa\u8bae\uff0c\u53ef\u4ee5\u4f18\u5316\u6267\u884c\u8ba1\u5212\uff1a<\/p>\n<ul>\n<li>\u786e\u4fdd\u8868\u4e0a\u6709\u9002\u5f53\u7684\u7d22\u5f15\u3002<\/li>\n<li>\u4f7f\u7528\u8986\u76d6\u7d22\u5f15\u4ee5\u4ece\u7d22\u5f15\u4e2d\u68c0\u7d22\u6240\u6709\u6570\u636e\u3002<\/li>\n<li>\u907f\u514d\u4f7f\u7528 SELECT *\uff0c\u800c\u662f\u4ec5\u9009\u62e9\u6240\u9700\u7684\u5217\u3002<\/li>\n<li>\u4f18\u5316 WHERE \u5b50\u53e5\uff0c\u4f7f\u7528\u7d22\u5f15\u6765\u8fc7\u6ee4\u6570\u636e\u3002<\/li>\n<li>\u8003\u8651\u91cd\u5199\u67e5\u8be2\u4ee5\u4f7f\u5176\u66f4\u6709\u6548\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6267\u884c\u8ba1\u5212\u600e\u4e48\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql \u6267\u884c\u8ba1\u5212\u662f\u4e00\u5f20\u56fe\u8868\uff0c\u8be6\u7ec6\u8bf4\u660e\u4e86 mysql \u5982\u4f55\u6267\u884c\u67e5\u8be2\uff0c\u5305\u62ec\u6b65\u9aa4\u548c\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u3002\u53ef\u4ee5\u901a\u8fc7 explain \u5173\u952e\u5b57\u6216 mysql workbench gui \u67e5\u770b\u6267\u884c\u8ba1\u5212\u3002\u6267\u884c\u8ba1\u5212\u901a\u5e38\u5305\u62ec\u5757 id\u3001\u67e5\u8be2\u7c7b\u578b\u3001\u6d89\u53ca\u8868\u3001\u8bbf\u95ee\u65b9\u5f0f\u3001\u53ef\u80fd\/\u5b9e\u9645\u4f7f\u7528\u7684\u7d22\u5f15\u3001\u4f30\u8ba1\u884c\u6570\u3001\u8fc7\u6ee4\u767e\u5206\u6bd4\u548c\u9644\u52a0\u4fe1\u606f\u3002\u89e3\u91ca\u6267\u884c\u8ba1\u5212\u65f6\uff0c\u5e94\u5173\u6ce8\u8bbf\u95ee\u65b9\u5f0f\uff08type\uff09\u3001\u4f30\u8ba1\u884c\u6570\uff08rows\uff09\u548c\u9644\u52a0\u4fe1\u606f\uff08extra\uff09\u3002\u53ef\u4ee5\u9075\u5faa\u5efa\u8bae\uff08\u4f8b\u5982\u521b\u5efa\u9002\u5f53\u7d22\u5f15\u3001\u4f7f\u7528\u8986\u76d6\u7d22\u5f15\u3001\u907f\u514d select * \u548c\u4f18\u5316 where \u5b50\u53e5\uff09\u6765\u4f18\u5316\u6267\u884c\u8ba1\u5212\uff0c\u4ece\u800c\u63d0 \u5982\u4f55\u4f7f\u7528 MySQL \u6267\u884c\u8ba1\u5212 \u4ec0\u4e48\u662f MySQL \u6267\u884c\u8ba1\u5212\uff1f MySQL \u6267\u884c\u8ba1\u5212\u662f\u4e00\u4e2a\u8bf4\u660e MySQL \u5c06\u5982\u4f55\u6267\u884c\u67e5\u8be2\u7684\u56fe\u8868\u3002\u5b83\u663e\u793a\u4e86 MySQL \u4f30\u8ba1\u7684\u6b65\u9aa4\u548c\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\uff0c\u4ee5\u5e2e\u52a9\u7528\u6237\u4e86\u89e3\u67e5\u8be2\u7684\u6027\u80fd\u3002 \u5982\u4f55\u67e5\u770b\u6267\u884c\u8ba1\u5212 \u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u67e5\u770b\u6267\u884c\u8ba1\u5212\uff1a \u4f7f\u7528 EXPLAIN \u5173\u952e\u5b57\uff1aEXPLAIN \u4f7f\u7528 MySQL Workbench GUI \u6267\u884c\u8ba1\u5212\u7684\u7ed3\u6784 \u6267\u884c\u8ba1\u5212\u901a\u5e38\u5305\u542b\u4ee5\u4e0b\u4fe1\u606f\uff1a id\uff1a\u67e5\u8be2\u5757\u7684\u6807\u8bc6\u7b26\u3002 select_type\uff1a\u67e5\u8be2\u7c7b\u578b\uff0c\u4f8b\u5982 SIMPLE \u6216 DEPENDENT SUBQUERY\u3002 table\uff1a\u6d89\u53ca\u7684\u8868\u6216\u89c6\u56fe\u7684\u540d\u79f0\u3002 type\uff1aMySQL \u5c06\u5982\u4f55\u8bbf\u95ee\u8868\uff0c\u4f8b\u5982 ALL\uff08\u5168\u8868\u626b\u63cf\uff09\u6216 index\uff08\u7d22\u5f15\u626b\u63cf\uff09\u3002 possible_keys\uff1a\u67e5\u8be2\u4e2d\u53ef\u80fd\u4f7f\u7528\u7684\u7d22\u5f15\u3002 key\uff1a\u5b9e\u9645\u4e0a\u4f7f\u7528\u7684\u7d22\u5f15\u3002 rows\uff1aMySQL \u4f30\u8ba1\u7684\u8981\u626b\u63cf\u7684\u884c\u6570\u3002 filtered\uff1aMySQL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5409","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5409"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5409\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}