{"id":5452,"date":"2021-04-19T17:14:39","date_gmt":"2021-04-19T09:14:39","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=5452"},"modified":"2021-06-30T16:35:42","modified_gmt":"2021-06-30T08:35:42","slug":"gbase-8a-%e8%87%aa%e5%ae%9a%e4%b9%89%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e6%9f%a5%e7%9c%8b%e8%a1%a8%e5%88%86%e7%89%87%e6%95%b0%e6%8d%ae%e9%87%8f%e3%80%81%e8%a1%8c%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/5452","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a \u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u67e5\u770b\u8868\u5206\u7247\u6570\u636e\u91cf\u3001\u884c\u6570"},"content":{"rendered":"<p>GBase 8a\u63d0\u4f9b\u4e86\u67e5\u770b\u5206\u5e03\u8868\u5404\u5206\u7247\u6570\u636e\u91cf\u7684\u529f\u80fd\uff0c\u5728\u65b0\u72489.5\u91cc\u53c8\u63d0\u4f9b\u4e86segment_id\u6765\u67e5\u770b\u5206\u7247\u5206\u7247\u6570\u636e\uff0c\u672c\u6587\u63d0\u4f9b\u4e862\u4e2a\u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6765\u65b9\u4fbf\u8bd5\u7528\u3002<\/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-6a2aea093c2e4\" 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-6a2aea093c2e4\"  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\/5452\/#%E5%8F%82%E8%80%83\" >\u53c2\u8003<\/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\/5452\/#%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B\" >Stored procedure<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/5452\/#%E5%85%AC%E5%85%B1%E5%87%BD%E6%95%B0%E5%92%8C%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B\" >\u516c\u5171\u51fd\u6570\u548c\u5b58\u50a8\u8fc7\u7a0b<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/5452\/#executeSQL%E9%80%9A%E7%94%A8%E5%8A%A8%E6%80%81SQL\" >executeSQL\u901a\u7528\u52a8\u6001SQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/5452\/#check_version_%E6%A3%80%E6%9F%A5%E7%89%88%E6%9C%AC\" >check_version \u68c0\u67e5\u7248\u672c<\/a><\/li><\/ul><\/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\/5452\/#sp_table_segment_size_%E5%88%86%E7%89%87%E6%95%B0%E6%8D%AE%E9%87%8F\" >sp_table_segment_size \u5206\u7247\u6570\u636e\u91cf<\/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\/5452\/#sp_table_segment_count_%E5%88%86%E7%89%87%E8%A1%8C%E6%95%B0\" >sp_table_segment_count \u5206\u7247\u884c\u6570<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%82%E8%80%83\"><\/span>\u53c2\u8003<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.gbase8.cn\/en\/5190\/\">GBase 8a \u4ece\u96c6\u7fa4\u5c42\u901a\u8fc7segment_id\u76f4\u63a5\u67e5\u8be2\u5206\u7247\u6570\u636e\u6392\u67e5\u503e\u659c<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.gbase8.cn\/en\/75\/\">GBase8a \u96c6\u7fa4\u67e5\u770b\u67d0\u5f20\u8868\u5360\u7528\u7684\u78c1\u76d8\u7a7a\u95f4\u5927\u5c0f<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.gbase8.cn\/en\/226\/\">GBase 8a\u96c6\u7fa4\u5b58\u50a8\u8fc7\u7a0b\u6837\u4f8b\uff0c\u52a8\u6001\u5b58\u50a8\u8fc7\u7a0b<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B\"><\/span>Stored procedure<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%85%AC%E5%85%B1%E5%87%BD%E6%95%B0%E5%92%8C%E5%AD%98%E5%82%A8%E8%BF%87%E7%A8%8B\"><\/span>\u516c\u5171\u51fd\u6570\u548c\u5b58\u50a8\u8fc7\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"executeSQL%E9%80%9A%E7%94%A8%E5%8A%A8%E6%80%81SQL\"><\/span>executeSQL\u901a\u7528\u52a8\u6001SQL<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u56e0\u4e3a\u662f\u901a\u7528\u7684\uff0c\u6240\u4ee5\u65e0\u9700\u6bcf\u6b21\u90fd\u5220\u9664\u8001\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>delimiter \/\/\ncreate procedure executeSQL(\n S_SQL_TMP VARCHAR(21000)\n)\nBEGIN\n  set @executeSQL_sql = S_SQL_TMP;\n  PREPARE executeSQL_s1 FROM @executeSQL_sql ;\n  EXECUTE executeSQL_s1;\n  DEALLOCATE PREPARE executeSQL_s1;\nEND \/\/\ndelimiter ;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"check_version_%E6%A3%80%E6%9F%A5%E7%89%88%E6%9C%AC\"><\/span>check_version \u68c0\u67e5\u7248\u672c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>drop function if exists check_version;\ndelimiter \/\/\ncreate function check_version(ver varchar) returns boolean\nbegin\n  select instr(version(),ver) into @rtn;\n  return @rtn;\nend \/\/ \ndelimiter ;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"sp_table_segment_size_%E5%88%86%E7%89%87%E6%95%B0%E6%8D%AE%E9%87%8F\"><\/span>sp_table_segment_size \u5206\u7247\u6570\u636e\u91cf<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>drop procedure if exists sp_table_segment_size;\ndelimiter \/\/\ncreate procedure sp_table_segment_size(dbname varchar,tbname varchar)\nbegin\n  set @sql=concat('select SUFFIX,HOST,TABLE_DATA_SIZE,TABLE_STORAGE_SIZE,DATA_PERCENT from information_schema.CLUSTER_TABLE_SEGMENTS a where table_schema=\\''\n    ,dbname\n    ,'\\' and table_name=\\''\n    ,tbname\n    ,'\\'');\n  call executeSQL(@sql);\nend\n\/\/\ndelimiter ;\ncall sp_table_segment_size('testdb','t1');<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"sp_table_segment_count_%E5%88%86%E7%89%87%E8%A1%8C%E6%95%B0\"><\/span>sp_table_segment_count \u5206\u7247\u884c\u6570<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8981\u6c429.5+\u7248\u672c\u624d\u652f\u6301<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drop procedure if exists sp_table_segment_count;\r\ndelimiter \/\/\r\ncreate procedure sp_table_segment_count(dbname varchar,tbname varchar)\r\nmain:begin\r\n  select check_version('9.5.3') into @rtn from dual;\r\n  if !@rtn then\r\n    select 'this function need 9.5.3 +';\r\n    leave main;\r\n  end if;\r\n  \r\n  call executeSQL('set gcluster_segment_id_replace=1');\r\n\r\n  set @sql=concat('select segment_id,count(*) from '\r\n    ,dbname\r\n    ,'.'\r\n    ,tbname\r\n    ,' group by segment_id');\r\n  call executeSQL(@sql);\r\nend\r\n\/\/\r\ndelimiter ;\r\n\r\ncall sp_table_segment_count('testdb','t1');<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u63d0\u4f9b\u4e86\u67e5\u770b\u5206\u5e03\u8868\u5404\u5206\u7247\u6570\u636e\u91cf\u7684\u529f\u80fd\uff0c\u5728\u65b0\u72489.5\u91cc\u53c8\u63d0\u4f9b\u4e86segment_id\u6765\u67e5\u770b\u5206\u7247\u5206\u7247\u6570\u636e\uff0c\u672c\u6587\u63d0\u4f9b\u4e862\u4e2a\u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6765\u65b9\u4fbf\u8bd5\u7528\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[92],"class_list":["post-5452","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-92"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5452","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=5452"}],"version-history":[{"count":8,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5452\/revisions"}],"predecessor-version":[{"id":6847,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5452\/revisions\/6847"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=5452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=5452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=5452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}