{"id":166861,"date":"2020-10-02T15:14:32","date_gmt":"2020-10-02T07:14:32","guid":{"rendered":"http:\/\/4563.org\/?p=166861"},"modified":"2020-10-02T15:14:32","modified_gmt":"2020-10-02T07:14:32","slug":"%e6%9c%89%e4%b8%a4%e4%b8%aa-mysql-%e4%bc%98%e5%8c%96%e7%9a%84%e9%97%ae%e9%a2%98%e6%b1%82%e6%8c%87%e5%af%bc","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=166861","title":{"rendered":"\u6709\u4e24\u4e2a mysql \u4f18\u5316\u7684\u95ee\u9898\u6c42\u6307\u5bfc"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6709\u4e24\u4e2a mysql \u4f18\u5316\u7684\u95ee\u9898\u6c42\u6307\u5bfc               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : enjoychen0318 <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>create table t1( id int primary key,  a int, b int ); create table t2( id int primary key,  a int, b int );  select t1.*, t2.* from t1     left join t2 on t1.a = t2.b where XXXX order by t1.id desc limit 1,10 <\/code><\/pre>\n<p>\u95ee\u9898:<\/p>\n<ol>\n<li>\n<p>t1 \u548c t2 \u7684\u6570\u636e\u91cf\u90fd\u662f 100w\uff0c\u6709\u65f6\u5019\u56e0\u4e3a where \u6761\u4ef6\u7684\u4e0d\u540c\uff0c\u5bfc\u81f4 join \u7684\u65f6\u5019\u9a71\u52a8\u8868\u4f1a\u53d8\u5316\uff0c\u5f53 t2 \u4f5c\u4e3a\u9a71\u52a8\u8868\u7684\u65f6\u5019 t1 \u6392\u5e8f\u5c31\u4f7f\u7528\u4e0d\u5230\u7d22\u5f15\u4e86\u3002\u5728\u4e0d\u5f3a\u5236\u9009\u62e9\u9a71\u52a8\u8868\u7684\u60c5\u51b5\u4e0b\uff0c\u6709\u5565\u4f18\u5316\u65b9\u6848\u4e48\uff1f<\/p>\n<\/li>\n<li>\n<p>\u73b0\u5728\u6211\u4eec\u516c\u53f8\u540e\u53f0\u7ba1\u7406\u6709\u4e2a\u5217\u8868\u9875\u67e5\u8be2\u5173\u8054\u7684\u8868\u6709\u70b9\u591a\uff0c\u7b5b\u9009\u6761\u4ef6\u4e5f\u6bd4\u8f83\u591a\uff0ccount \u548c\u67e5\u8be2\u90fd\u6709\u70b9\u6162\uff0c\u4f46\u662f\u5173\u8054\u7684\u8868\u5e94\u8be5\u662f\u4e0d\u80fd\u5c11\u3002\u8fd9\u4e2a\u65f6\u5019\u8be5\u600e\u4e48\u4f18\u5316\uff1f\u505a\u7f13\u5b58\u53ef\u884c\u4e48\uff0c\u6bd4\u5982\u8bf4\u5c06\u7b5b\u9009\u6761\u4ef6\u4f5c\u4e3a key \u7f13\u5b58\u8d77\u6765\u3002\u4f46\u6570\u636e\u66f4\u65b0\u5feb\uff0c\u611f\u89c9\u7f13\u5b58\u5931\u6548\u7684\u60c5\u51b5\u592a\u591a\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u592a\u53ef\u884c<\/p>\n<\/li>\n<\/ol>\n<p>\u6709\u5927\u4f6c\u80fd\u5e2e\u5e2e\u5fd9\u4e48<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3680855\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : PonysDad <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u628a\u67e5\u8be2\u8ba1\u5212\u8d34\u4e0a\u6765\u770b\u770b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3680856\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : enjoychen0318 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @PonysDad <br \/>\u6709 t2 \u7684 where \u65f6\uff0cmysql \u4f18\u5316\u5668\u8ba4\u4e3a t2 \u662f\u5c0f\u8868\uff0c\u9009\u62e9 t2 \u505a\u9a71\u52a8\u8868\u7684\u65f6\u5019\u4f1a Using temporary; Using filesort                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3680857\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : XDJI <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1.\u9996\u5148\u4f60\u8fd9\u4e2a left join t2 on t1.a = t2.b \u7528 join buffer \u4e86 \u76f4\u63a5 t1 \u5355\u6b21 t2 \u591a\u6b21\u5168\u8868\u626b\u63cf\u4e86<br \/>\u7ed9 t1.a t2.b \u52a0\u4e2a\u7d22\u5f15\u8bd5\u4e0b\u5462 <br \/>2.\u5f97\u770b\u4f60\u7684\u8bed\u53e5 explain \u51fa\u6765\u770b\u4e0b\u5462 \u5982\u679c\u4e0d\u662f\u5f3a\u4e00\u81f4\u7f13\u5b58\u5012\u662f\u4e00\u4e2a\u65b9\u6cd5\uff0c\u66f4\u65b0\u5feb\u4e0d\u662f\u95ee\u9898 \u53ef\u4ee5\u5728\u5305\u4e2a\u5185\u5b58\u7f13\u5b58\u5b9a\u65f6\u540c\u6b65\u4e0d\u8fc7\u5c31\u9ebb\u70e6\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e24\u4e2a mysql \u4f18\u5316\u7684\u95ee\u9898\u6c42\u6307&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/166861"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=166861"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/166861\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=166861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=166861"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=166861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}