{"id":187790,"date":"2024-11-11T17:12:20","date_gmt":"2024-11-11T09:12:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/187790\/"},"modified":"2024-11-11T17:12:21","modified_gmt":"2024-11-11T09:12:21","slug":"%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e9%96%93%e4%bb%b6-mycat%e6%ba%90%e7%a2%bc%e5%88%86%e6%9e%90-%e8%b7%a8%e5%ba%ab%e5%85%a9%e8%a1%a8join","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/187790\/","title":{"rendered":"\u6578\u64da\u5eab\u4e2d\u9593\u4ef6 MyCAT\u6e90\u78bc\u5206\u6790\u2014\u2014\u8de8\u5eab\u5169\u8868Join"},"content":{"rendered":"<h1 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e9%96%93%e4%bb%b6-mycat%e6%ba%90%e7%a2%bc%e5%88%86%e6%9e%90-%e8%b7%a8%e5%ba%ab%e5%85%a9%e8%a1%a8join-BFHqcTfzhg\">\u6578\u64da\u5eab\u4e2d\u9593\u4ef6 MyCAT\u6e90\u78bc\u5206\u6790\u2014\u2014\u8de8\u5eab\u5169\u8868Join<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u6578\u64da\u5eab\u4e2d\u9593\u4ef6\u7684\u4f7f\u7528\u8d8a\u4f86\u8d8a\u666e\u904d\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u9032\u884c\u8de8\u5eab\u64cd\u4f5c\u7684\u60c5\u6cc1\u4e0b\u3002MyCAT\u4f5c\u70ba\u4e00\u6b3e\u958b\u6e90\u7684\u6578\u64da\u5eab\u4e2d\u9593\u4ef6\uff0c\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u529f\u80fd\u4f86\u652f\u6301\u5206\u4f48\u5f0f\u6578\u64da\u5eab\u7684\u7ba1\u7406\u3002\u672c\u6587\u5c07\u6df1\u5165\u5206\u6790MyCAT\u7684\u6e90\u78bc\uff0c\u7279\u5225\u662f\u5176\u5728\u8de8\u5eab\u5169\u8868Join\u64cd\u4f5c\u4e2d\u7684\u5be6\u73fe\u65b9\u5f0f\u3002<\/p>\n<h2 id=\"mycat%e7%b0%a1%e4%bb%8b-BFHqcTfzhg\">MyCAT\u7c21\u4ecb<\/h2>\n<p>MyCAT\u662f\u4e00\u6b3e\u57fa\u65bcJava\u7684\u6578\u64da\u5eab\u4e2d\u9593\u4ef6\uff0c\u65e8\u5728\u89e3\u6c7a\u50b3\u7d71\u6578\u64da\u5eab\u5728\u64f4\u5c55\u6027\u548c\u6027\u80fd\u4e0a\u7684\u4e0d\u8db3\u3002\u5b83\u652f\u6301\u591a\u7a2e\u6578\u64da\u5eab\u985e\u578b\uff0c\u5305\u62ecMySQL\u3001Oracle\u7b49\uff0c\u4e26\u4e14\u80fd\u5920\u5be6\u73fe\u6578\u64da\u7684\u5206\u7247\u3001\u8def\u7531\u548c\u805a\u5408\u7b49\u529f\u80fd\u3002MyCAT\u7684\u67b6\u69cb\u8a2d\u8a08\u4f7f\u5176\u80fd\u5920\u5728\u591a\u500b\u6578\u64da\u5eab\u4e4b\u9593\u9032\u884c\u9ad8\u6548\u7684\u6578\u64da\u64cd\u4f5c\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u9032\u884cJoin\u64cd\u4f5c\u6642\u3002<\/p>\n<h2 id=\"%e8%b7%a8%e5%ba%ab%e5%85%a9%e8%a1%a8join%e7%9a%84%e6%8c%91%e6%88%b0-BFHqcTfzhg\">\u8de8\u5eab\u5169\u8868Join\u7684\u6311\u6230<\/h2>\n<p>\u5728\u9032\u884c\u8de8\u5eab\u5169\u8868Join\u6642\uff0c\u4e3b\u8981\u9762\u81e8\u4ee5\u4e0b\u5e7e\u500b\u6311\u6230\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u4e00\u81f4\u6027\uff1a<\/strong>\u4e0d\u540c\u6578\u64da\u5eab\u4e4b\u9593\u7684\u6578\u64da\u53ef\u80fd\u5b58\u5728\u4e0d\u4e00\u81f4\u7684\u60c5\u6cc1\uff0c\u9019\u9700\u8981\u4e2d\u9593\u4ef6\u9032\u884c\u6709\u6548\u7684\u7ba1\u7406\u3002<\/li>\n<li><strong>\u6027\u80fd\u554f\u984c\uff1a<\/strong>\u8de8\u5eab\u64cd\u4f5c\u901a\u5e38\u6703\u5c0e\u81f4\u6027\u80fd\u4e0b\u964d\uff0c\u7279\u5225\u662f\u5728\u6578\u64da\u91cf\u8f03\u5927\u7684\u60c5\u6cc1\u4e0b\u3002<\/li>\n<li><strong>\u7db2\u7d61\u5ef6\u9072\uff1a<\/strong>\u6578\u64da\u5eab\u4e4b\u9593\u7684\u7db2\u7d61\u5ef6\u9072\u53ef\u80fd\u6703\u5f71\u97ffJoin\u64cd\u4f5c\u7684\u6548\u7387\u3002<\/li>\n<\/ul>\n<h2 id=\"mycat%e7%9a%84join%e5%af%a6%e7%8f%be-BFHqcTfzhg\">MyCAT\u7684Join\u5be6\u73fe<\/h2>\n<p>MyCAT\u5728\u9032\u884c\u8de8\u5eab\u5169\u8868Join\u6642\uff0c\u4e3b\u8981\u901a\u904e\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\u4f86\u5be6\u73fe\uff1a<\/p>\n<h3 id=\"1-sql%e8%a7%a3%e6%9e%90-BFHqcTfzhg\">1. SQL\u89e3\u6790<\/h3>\n<p>\u7576\u7528\u6236\u767c\u9001\u4e00\u500b\u5305\u542bJoin\u64cd\u4f5c\u7684SQL\u67e5\u8a62\u6642\uff0cMyCAT\u9996\u5148\u6703\u5c0d\u8a72SQL\u9032\u884c\u89e3\u6790\u3002\u9019\u4e00\u904e\u7a0b\u4e2d\uff0cMyCAT\u6703\u8b58\u5225\u51fa\u9700\u8981\u9032\u884cJoin\u7684\u8868\u53ca\u5176\u6240\u5728\u7684\u6578\u64da\u5eab\u3002<\/p>\n<pre><code>public void parseSQL(String sql) {\n    \/\/ \u89e3\u6790SQL\u8a9e\u53e5\n    \/\/ \u8b58\u5225\u8868\u548c\u6578\u64da\u5eab\n}<\/code><\/pre>\n<h3 id=\"2-%e8%b7%af%e7%94%b1%e9%81%b8%e6%93%87-BFHqcTfzhg\">2. \u8def\u7531\u9078\u64c7<\/h3>\n<p>\u89e3\u6790\u5b8c\u6210\u5f8c\uff0cMyCAT\u6703\u6839\u64da\u914d\u7f6e\u7684\u8def\u7531\u898f\u5247\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u4f86\u57f7\u884c\u67e5\u8a62\u3002\u9019\u4e00\u904e\u7a0b\u4e2d\uff0cMyCAT\u6703\u8003\u616e\u5230\u6578\u64da\u7684\u5206\u7247\u7b56\u7565\uff0c\u4ee5\u78ba\u4fdd\u67e5\u8a62\u7684\u9ad8\u6548\u6027\u3002<\/p>\n<pre><code>public List routeSQL(String sql) {\n    \/\/ \u6839\u64daSQL\u9078\u64c7\u6578\u64da\u5eab\n    \/\/ \u8003\u616e\u5206\u7247\u7b56\u7565\n}<\/code><\/pre>\n<h3 id=\"3-%e6%95%b8%e6%93%9a%e6%8b%89%e5%8f%96-BFHqcTfzhg\">3. \u6578\u64da\u62c9\u53d6<\/h3>\n<p>\u5728\u78ba\u5b9a\u4e86\u9700\u8981\u8a2a\u554f\u7684\u6578\u64da\u5eab\u5f8c\uff0cMyCAT\u6703\u5411\u9019\u4e9b\u6578\u64da\u5eab\u767c\u9001\u67e5\u8a62\u8acb\u6c42\uff0c\u4e26\u62c9\u53d6\u6240\u9700\u7684\u6578\u64da\u3002\u9019\u4e00\u904e\u7a0b\u4e2d\uff0cMyCAT\u6703\u4f7f\u7528\u591a\u7dda\u7a0b\u4f86\u63d0\u9ad8\u6578\u64da\u62c9\u53d6\u7684\u6548\u7387\u3002<\/p>\n<pre><code>public List fetchData(List databases) {\n    \/\/ \u4f7f\u7528\u591a\u7dda\u7a0b\u62c9\u53d6\u6578\u64da\n}<\/code><\/pre>\n<h3 id=\"4-%e6%95%b8%e6%93%9a%e5%90%88%e4%bd%b5-BFHqcTfzhg\">4. \u6578\u64da\u5408\u4f75<\/h3>\n<p>\u6700\u5f8c\uff0cMyCAT\u6703\u5c07\u5f9e\u4e0d\u540c\u6578\u64da\u5eab\u4e2d\u62c9\u53d6\u7684\u6578\u64da\u9032\u884c\u5408\u4f75\uff0c\u4e26\u6839\u64daJoin\u689d\u4ef6\u9032\u884c\u6700\u7d42\u7684\u6578\u64da\u8655\u7406\u3002\u9019\u4e00\u904e\u7a0b\u4e2d\uff0cMyCAT\u6703\u8003\u616e\u5230\u6578\u64da\u7684\u6392\u5e8f\u548c\u904e\u6ffe\uff0c\u4ee5\u78ba\u4fdd\u6700\u7d42\u7d50\u679c\u7684\u6b63\u78ba\u6027\u3002<\/p>\n<pre><code>public ResultSet mergeData(List results) {\n    \/\/ \u5408\u4f75\u6578\u64da\u4e26\u9032\u884c\u8655\u7406\n}<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-BFHqcTfzhg\">\u7e3d\u7d50<\/h2>\n<p>MyCAT\u4f5c\u70ba\u4e00\u6b3e\u5f37\u5927\u7684\u6578\u64da\u5eab\u4e2d\u9593\u4ef6\uff0c\u80fd\u5920\u6709\u6548\u5730\u8655\u7406\u8de8\u5eab\u5169\u8868Join\u64cd\u4f5c\u3002\u901a\u904e\u5c0dSQL\u7684\u89e3\u6790\u3001\u8def\u7531\u9078\u64c7\u3001\u6578\u64da\u62c9\u53d6\u548c\u5408\u4f75\uff0cMyCAT\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u64cd\u4f5c\u7684\u6548\u7387\uff0c\u9084\u89e3\u6c7a\u4e86\u591a\u6578\u64da\u5eab\u4e4b\u9593\u7684\u6578\u64da\u4e00\u81f4\u6027\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u4e2d\u9593\u4ef6\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\u548c\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u5206\u6790MyCAT\u6e90\u78bc\uff0c\u63a2\u8a0e\u8de8\u5eab\u5169\u8868Join\u7684\u5be6\u73fe\u539f\u7406\u8207\u6027\u80fd\u512a\u5316\uff0c\u52a9\u529b\u6578\u64da\u5eab\u4e2d\u9593\u4ef6\u7684\u9ad8\u6548\u904b\u7528\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-187790","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=187790"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187790\/revisions"}],"predecessor-version":[{"id":187791,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187790\/revisions\/187791"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=187790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=187790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=187790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}