{"id":246909,"date":"2020-12-21T02:35:09","date_gmt":"2020-12-20T18:35:09","guid":{"rendered":"http:\/\/4563.org\/?p=246909"},"modified":"2020-12-21T02:35:09","modified_gmt":"2020-12-20T18:35:09","slug":"hash-join-%e7%9a%84%e4%b8%80%e4%b8%aa%e7%96%91%e9%97%ae","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=246909","title":{"rendered":"hash join \u7684\u4e00\u4e2a\u7591\u95ee"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  hash join \u7684\u4e00\u4e2a\u7591\u95ee               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : RudyC <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>MySQL \u5728 8.0.18 \u652f\u6301\u4e86 hash join\uff0c\u8fd9\u4e2a\u7248\u672c\u4e2d\u53ea\u652f\u6301 join \u7684\u7b49\u503c\u6761\u4ef6\u3002\u6b64\u65f6\u662f\u4ee5 hash join \u662f\u4ee5\u7b49\u503c\u6761\u4ef6\u505a hash table\uff0c\u518d\u8fdb\u884c\u5339\u914d\uff08 build \u548c probe \uff09\u3002<\/p>\n<p>MySQL 8.0.20 \u540e\u5c31\u4e0d\u518d\u9650\u5236\u7b49\u503c\u6761\u4ef6\u4e86\uff0c\u90a3\u8fd9\u4e2a\u7248\u672c\u4e2d\u662f\u600e\u4e48\u8fdb\u884c build \u548c probe \u7684\u5462\uff1f<\/p>\n<p>\u4f8b\u5982\u5b98\u65b9\u6587\u6863\u4e2d\uff1a \u00b7\u00b7\u00b7 mysql&gt; EXPLAIN FORMAT=TREE SELECT * FROM t1 JOIN t2 ON t1.c1 &lt; t2.c1G *************************** 1. row *************************** EXPLAIN: -&gt; Filter: (t1.c1 &lt; t2.c1) (cost=4.70 rows=12) -&gt; Inner hash join (no condition) (cost=4.70 rows=12) -&gt; Table scan on t2 (cost=0.08 rows=6) -&gt; Hash -&gt; Table scan on t1 (cost=0.85 rows=6) \u00b7\u00b7\u00b7<\/p>\n<p>https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/hash-joins.html<br \/> https:\/\/mysqlserverteam.com\/hash-join-in-mysql-8\/<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4803428\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lpts007 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             non-equi-join\uff0c\u54c8\u5e0c\u51fd\u6570\u76f4\u63a5\u8fd4\u56de\u539f\u503c\u6216\u524d\u7f00\u5c31\u884c\u4e86\u3002<br \/>\u5e94\u8be5\u5c31\u662f\u628a\u6570\u636e\u4ece engine \u90a3\u91cc\u5168\u8981\u8fc7\u6765\uff08\u533a\u522b\u4e8e BNJ \u7684\u4f20\u4e2a block \u8fdb\u5165 engine \u8fdb\u884c\u5339\u914d\uff09\uff0cserver \u81ea\u5df1\u5e72\uff0c\u914d\u7684 buffer \u4e0d\u591f\u5c31\u7528\u4e34\u65f6\u6587\u4ef6\u3002<\/p>\n<p>\u53c8\u60f3\u5230\u4e86 5.6 \u7684\u7d22\u5f15\u4e0b\u63a8\uff0c\u8fd9\u4e0d\u5c31\u662f\u4e00\u4e2a bug \u4fee\u590d\u5417\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4803429\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : RudyC <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lpts007 \u611f\u8c22\u56de\u590d\uff0c\u4f46\u8fd8\u662f\u6709\u51e0\u5904\u4e0d\u660e\u767d\u7684\u5730\u65b9\u3002<\/p>\n<p>1. \u5728 non-equi-join \u7684\u65f6\uff0c\u56e0\u4e3a\u6ca1\u6709\u6761\u4ef6\uff0cbuild \u8fd9\u4e2a\u9636\u6bb5\u662f\u4ee5\u54ea\u4e2a\u5b57\u6bb5\u4f5c\u4e3a hash table \u7684 key \u5462\uff1f<br \/>2. \u540c\u6837\u5728 probe \u9636\u6bb5\u4e2d\uff0c\u7531\u4e8e\u6ca1\u6709\u6761\u4ef6\u9650\u5236\uff0c\u6b64\u5904\u662f\u5426\u4e0d\u9700\u8981\u8fdb\u884c key exist \u800c\u662f\u76f4\u63a5\u904d\u5386 hash table \u7684 buffer \u4ee5\u53ca\u6587\u4ef6\u5462\uff1f\u5982\u679c\u9700\u8981\u8fdb\u884c key exist\uff0c\u90a3\u4e48\u662f\u9009\u53d6\u7684\u54ea\u4e2a\u5b57\u6bb5\u5462\uff1f\u6211\u6d4b\u8bd5\u4e24\u4efd\u540c\u6837\u7684\u8868\u6570\u636e\uff0c\u5728 5.7 \u548c 8.0.22 \u4e2d\u5206\u522b\u8fdb\u884c join\uff0c5.7 \u5219\u662f\u4ee5\u9884\u671f\u7684\u7b1b\u5361\u5c14\u79ef\u7684\u7ed3\u679c\u96c6\uff08 BNL \uff09\uff0c8.0.22 \u4e2d\u867d\u7136\u7ed3\u679c\u96c6\u4e5f\u662f\u4e00\u6837\uff0c\u4e0d\u8fc7\u987a\u5e8f\u5219\u662f\u4ee5\u5c0f\u8868\uff08\u5373\u7528\u4f5c hash table \u7684\u8868\uff09\u8fdb\u884c\u5012\u5e8f\u6392\u5e8f\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>hash join \u7684\u4e00\u4e2a\u7591\u95ee \u8cc7&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\/246909"}],"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=246909"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/246909\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=246909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=246909"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=246909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}