{"id":8096,"date":"2021-09-29T08:35:41","date_gmt":"2021-09-29T00:35:41","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=8096"},"modified":"2021-09-29T08:35:42","modified_gmt":"2021-09-29T00:35:42","slug":"gbase-8a-%e7%9a%84merge-into-%e5%8a%9f%e8%83%bd%e4%bd%bf%e7%94%a8%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/8096","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a \u7684Merge into \u529f\u80fd\u4f7f\u7528\u4ecb\u7ecd"},"content":{"rendered":"<p>GBase 8a\u652f\u6301Merge \u5408\u5e76\u529f\u80fd\uff0c\u6df7\u5408\u4e86update\u548cinsert\uff0c\u672c\u6587\u4ecb\u7ecd\u5176\u4f7f\u7528\u65b9\u6cd5\u3002\u8be5\u529f\u80fd\u6307\u9488\u5bf9Hash\u5206\u5e03\u8868\uff0c\u5426\u5219\u4f1a\u62a5\u9519ERROR 1149 (42000): (GBA-02SC-1001) Can't DO Merge when not able to build hash (redistribution) JOIN relationship between merge target and source.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2b0c4c09a8c\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2b0c4c09a8c\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/8096\/#%E8%AF%AD%E6%B3%95\" >\u8bed\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/8096\/#%E8%AF%B4%E6%98%8E\" >\u8bf4\u660e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/8096\/#%E6%A0%B7%E4%BE%8B\" >\u6837\u4f8b<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/8096\/#%E7%8E%AF%E5%A2%83\" >\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/8096\/#Merge\" >Merge<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.gbase8.cn\/en\/8096\/#%E5%8F%AA%E5%8C%85%E5%90%ABMatched%EF%BC%8C%E7%94%A8%E4%BA%8E%E6%9B%B4%E6%96%B0\" >\u53ea\u5305\u542bMatched\uff0c\u7528\u4e8e\u66f4\u65b0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.gbase8.cn\/en\/8096\/#%E5%8F%AA%E5%8C%85%E5%90%ABNOT_Matched%E7%94%A8%E4%BA%8E%E6%8F%92%E5%85%A5%E6%96%B0%E6%95%B0%E6%8D%AE\" >\u53ea\u5305\u542bNOT Matched\u7528\u4e8e\u63d2\u5165\u65b0\u6570\u636e<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%AF%AD%E6%B3%95\"><\/span>\u8bed\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Merge into TABLE1 using TABLE2 on ( match condition)\nWHEN MATCHED THEN UPDATE_CLUSE\nWHEN NOT MATCHED THEN INSERT_CLUSE<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%AF%B4%E6%98%8E\"><\/span>\u8bf4\u660e<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>match_condition \u8868\u5173\u8054\u6761\u4ef6<\/li><li>UPDATE_CLUSE \u66f4\u65b0\u64cd\u4f5c\u7684set \u90e8\u5206<\/li><li>INSERT_CLUSE \u63d2\u5165\u64cd\u4f5c\u7684\u5b57\u6bb5\u5217\u8868\u548cvalues\u503c\u5217\u8868\u90e8\u5206<\/li><\/ul>\n\n\n\n<p>\u6539\u529f\u80fd\uff0c\u53ea\u80fd\u7528\u4e8eHash\u5206\u5e03\u8868\uff0c\u4e14\u5173\u8054\u6761\u4ef6\u5305\u542bHash\u5206\u5e03\u5217\u3002\u968f\u673a\u5206\u5e03\u8868\u505amerge\u4f1a\u62a5\u9519<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ERROR 1149 (42000): (GBA-02SC-1001) Can't DO Merge when not able to build hash (redistribution) JOIN relationship between merge target and source.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A0%B7%E4%BE%8B\"><\/span>\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>t1 \u662f\u4e3b\u8868\uff0ct2\u662f\u53d8\u52a8\u8868\uff0c\u8981\u5c06t2\u7684\u6570\u636emerge\u5230\u4e3b\u8868T1<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%8E%AF%E5%A2%83\"><\/span>\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select * from t1;\r\n+------+------+------------+\r\n| id   | name | birth      |\r\n+------+------+------------+\r\n|    1 | 1111 | 2011-11-11 |\r\n|    9 | 9999 | 2011-09-09 |\r\n+------+------+------------+\r\n2 rows in set (Elapsed: 00:00:00.01)\r\n\r\ngbase> select * from t2;\r\n+------+------+------------+\r\n| id   | name | birth      |\r\n+------+------+------------+\r\n|    1 | 1212 | 2011-12-12 |\r\n|    2 | 2222 | 2022-12-12 |\r\n|    3 | 3333 | 2033-12-12 |\r\n+------+------+------------+\r\n3 rows in set (Elapsed: 00:00:00.01)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Merge\"><\/span>Merge<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5339\u914d\u4e0a\u7684id=1\u88ab\u66f4\u65b0\u4e86\uff0c\u6ca1\u5339\u914d\u4e0a\u76842\u548c3\u88abinsert\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> merge into t1 using t2 on t1.id=t2.id when matched then update set t1.name=t2.name,t1.birth=t2.birth when not matched then insert(id,name,birth)values(t2.id,t2.name,t2.birth);\r\nQuery OK, 3 rows affected (Elapsed: 00:00:00.13)\r\nRows matched: 3  Changed: 3  Warnings: 0\r\n\r\ngbase> select * from t1;\r\n+------+------+------------+\r\n| id   | name | birth      |\r\n+------+------+------------+\r\n|    9 | 9999 | 2011-09-09 |\r\n|    1 | 1212 | 2011-12-12 |\r\n|    2 | 2222 | 2022-12-12 |\r\n|    3 | 3333 | 2033-12-12 |\r\n+------+------+------------+\r\n4 rows in set (Elapsed: 00:00:00.01)\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%AA%E5%8C%85%E5%90%ABMatched%EF%BC%8C%E7%94%A8%E4%BA%8E%E6%9B%B4%E6%96%B0\"><\/span>\u53ea\u5305\u542bMatched\uff0c\u7528\u4e8e\u66f4\u65b0<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> truncate table t1;\r\nQuery OK, 4 rows affected (Elapsed: 00:00:00.21)\r\n\r\ngbase> insert into t1 values(1,'1111','2011-11-11'),(9,'9999','2011-09-09');\r\nQuery OK, 2 rows affected (Elapsed: 00:00:00.14)\r\nRecords: 2  Duplicates: 0  Warnings: 0\r\n\r\ngbase> select * from t1;\r\n+------+------+------------+\r\n| id   | name | birth      |\r\n+------+------+------------+\r\n|    1 | 1111 | 2011-11-11 |\r\n|    9 | 9999 | 2011-09-09 |\r\n+------+------+------------+\r\n2 rows in set (Elapsed: 00:00:00.01)\r\n\r\ngbase> merge into t1 using t2 on t1.id=t2.id when matched then update set t1.name=t2.name,t1.birth=t2.birth;                      Query OK, 1 row affected (Elapsed: 00:00:00.17)\r\nRows matched: 1  Changed: 1  Warnings: 0\r\n\r\ngbase> select * from t1;\r\n+------+------+------------+\r\n| id   | name | birth      |\r\n+------+------+------------+\r\n|    9 | 9999 | 2011-09-09 |\r\n|    1 | 1212 | 2011-12-12 |\r\n+------+------+------------+\r\n2 rows in set (Elapsed: 00:00:00.01)\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%AA%E5%8C%85%E5%90%ABNOT_Matched%E7%94%A8%E4%BA%8E%E6%8F%92%E5%85%A5%E6%96%B0%E6%95%B0%E6%8D%AE\"><\/span>\u53ea\u5305\u542bNOT Matched\u7528\u4e8e\u63d2\u5165\u65b0\u6570\u636e<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> truncate table t1;\r\nQuery OK, 2 rows affected (Elapsed: 00:00:00.16)\r\n\r\ngbase> insert into t1 values(1,'1111','2011-11-11'),(9,'9999','2011-09-09');\r\nQuery OK, 2 rows affected (Elapsed: 00:00:00.12)\r\nRecords: 2  Duplicates: 0  Warnings: 0\r\n\r\ngbase> merge into t1 using t2 on t1.id=t2.id when not matched then insert(id,name,birth)values(t2.id,t2.name,t2.birth);           Query OK, 2 rows affected (Elapsed: 00:00:00.17)\r\nRows matched: 2  Changed: 2  Warnings: 0\r\n\r\ngbase> select * from t1;\r\n+------+------+------------+\r\n| id   | name | birth      |\r\n+------+------+------------+\r\n|    1 | 1111 | 2011-11-11 |\r\n|    9 | 9999 | 2011-09-09 |\r\n|    2 | 2222 | 2022-12-12 |\r\n|    3 | 3333 | 2033-12-12 |\r\n+------+------+------------+\r\n4 rows in set (Elapsed: 00:00:00.00)\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u652f\u6301Merge \u5408\u5e76\u529f\u80fd\uff0c\u6df7\u5408\u4e86update\u548cinsert\uff0c\u672c\u6587\u4ecb\u7ecd\u5176\u4f7f\u7528\u65b9\u6cd5\u3002\u8be5\u529f\u80fd\u6307\u9488\u5bf9Hash\u5206\u5e03\u8868\uff0c\u5426\u5219\u4f1a\u62a5\u9519ERROR 1149 (42000): (GBA-02SC-1001) Can't DO Merge when not able to build hash (redistribution) JOIN relationship between merge target and source.<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,54],"tags":[],"class_list":["post-8096","post","type-post","status-publish","format-standard","hentry","category-gbase8a"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=8096"}],"version-history":[{"count":8,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8096\/revisions"}],"predecessor-version":[{"id":8110,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8096\/revisions\/8110"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=8096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=8096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=8096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}