{"id":890,"date":"2017-08-29T22:15:24","date_gmt":"2017-08-29T14:15:24","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=890"},"modified":"2017-08-29T22:15:24","modified_gmt":"2017-08-29T14:15:24","slug":"mysql%e5%88%86%e5%8c%ba%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=890","title":{"rendered":"mysql\u5206\u533a\u7c7b\u578b"},"content":{"rendered":"<p>MySQL5.7\u5206\u533a\u7c7b\u578b\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>RANGE\u5206\u533a<\/strong>\u3002\u8fd9\u7c7b\u5206\u533a\u57fa\u4e8e\u67d0\u4e00\u5217\u7684\u503c\u5728\u7ed9\u4e88\u7684\u8303\u56f4\u5185\uff0c\u5206\u914d\u884c\u5230\u5206\u533a\u4e2d\u3002<\/li>\n<li><strong>LIST\u5206\u533a<\/strong>\u3002\u7c7b\u4f3c\u4e8eRANGE\uff0c\u9664\u4e86\u8fd9\u79cd\u5206\u533a\u9009\u62e9\u7684\u5217\u503c\u662f\u57fa\u4e8e\u4e00\u7ec4\u4e0d\u8fde\u7eed\u7684\u503c\u4e2d\u7684\u4e00\u4e2a\u3002\uff08Similar to partitioning by RANGE, except that the partition is selected based on columns matching on of a set of discrete values.\uff09<\/li>\n<li><strong>HASH\u5206\u533a<\/strong>\u3002\u8fd9\u79cd\u7c7b\u578b\u7684\u5206\u533a\uff0c\u4e00\u4e2a\u5206\u533a\u57fa\u4e8e\u7528\u6237\u5b9a\u4e49\u7684\u8868\u8fbe\u5f0f\u4f5c\u7528\u5230\u88ab\u9009\u62e9\u7684\u5217\u4e0a\u3002\u8fd9\u4e2a\u51fd\u6570\u7531MYSQL\u6709\u6548\u8868\u8fbe\u5f0f\u7ec4\u6210\uff0c\u5b83\u4ea7\u751f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002<\/li>\n<li><strong>KEY\u5206\u533a<\/strong>\u3002\u8fd9\u7c7b\u5206\u533a\u7c7b\u4f3c\u4e8eHASH\u5206\u533a\uff0c\u9664\u4e86\u5b83\u662f\u5bf9\u4e00\u5217\u6216\u51e0\u5217\u8fdb\u884c\u8bc4\u4f30\uff0c\u5e76\u4e14\u662f\u7531MYSQL\u670d\u52a1\u5668\u63d0\u4f9b\u5b83\u81ea\u5df1\u7684\u54c8\u5e0c\u51fd\u6570\u3002\u800c\u8fd9\u4e9b\u5217\u53ef\u4ee5\u5305\u542b\u9664\u4e86\u6574\u6570\u4e4b\u5916\u7684\u7c7b\u578b\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u7531MYSQL\u63d0\u4f9b\u7684\u54c8\u5e0c\u51fd\u6570\u53ef\u4ee5\u6839\u636e\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u90fd\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u3002<\/li>\n<\/ul>\n<p>\u6700\u5e38\u89c1\u7684\u5206\u533a\u65b9\u6cd5\u662f\u6839\u636e\u65e5\u671f\u3002\u867d\u7136MYSQL5.7\u5e76\u6ca1\u6709\u663e\u793a\u7684\u652f\u6301\u4ee5\u65e5\u671f\u5206\u533a\uff0c\u4f46\u5728MYSQL\u4e2d\u5b9e\u73b0\u57fa\u4e8eDATE,TIME\u6216DATETIME\u5217\u7684\u5206\u533a\u5e76\u4e0d\u96be\u3002<\/p>\n<p>\u5f53\u5206\u533a\u662f\u57fa\u4e8ekey\u6216linear key\u65f6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528DATE\u3001TIME\u6216DATATIME\u5217\u505a\u4e3a\u5206\u533a\u5217\uff0c\u800c\u4e0d\u9700\u8981\u5bf9\u5217\u4e0a\u7684\u503c\u505a\u4efb\u4f55\u4fee\u6539\u3002<\/p>\n<p>\u5728MYSQL5.7\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528DATE\u6216DATETIME\u5217\u505a\u4e3aRANGE\u548cLIST\u5206\u533a\u3002MYSQL\u5176\u5b83\u5206\u533a\u7c7b\u578b\uff0c\u65e0\u8bba\u5982\u4f55\u90fd\u9700\u8981\u5206\u533a\u8868\u8fbe\u5f0f\u4ea7\u751f\u4e00\u4e2a\u6574\u6570\u503c\u6216NULL\u3002\u5982\u679c\u5e0c\u671b\u4f7f\u7528RANGE\u3001LIST\u3001HASH\u6216LINEAR HASH\u7c7b\u578b\u7684\u5206\u533a\u5728\u57fa\u4e8e\u65f6\u95f4\u7684\u5217\u4e0a\uff0c\u4f60\u53ef\u4ee5\u7b80\u5355\u7684\u4f7f\u7528\u67d0\u4e00\u51fd\u6570\u64cd\u4f5c\u5728DATE\u3001TIME\u6216DATETIME\u5217\u4e0a\uff0c\u5e76\u8ba9\u5176\u8fd4\u56de\u4e00\u4e2a\u503c\uff0c\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n<pre>CREATE TABLE members (\r\n    firstname VARCHAR(25) NOT NULL,\r\n    lastname VARCHAR(25) NOT NULL,\r\n    username VARCHAR(16) NOT NULL,\r\n    email VARCHAR(35),\r\n    joined DATE NOT NULL\r\n)\r\nPARTITION BY RANGE( YEAR(joined) ) (\r\n    PARTITION p0 VALUES LESS THAN (1960),\r\n    PARTITION p1 VALUES LESS THAN (1970),\r\n    PARTITION p2 VALUES LESS THAN (1980),\r\n    PARTITION p3 VALUES LESS THAN (1990),\r\n    PARTITION p4 VALUES LESS THAN MAXVALUE\r\n);\r\n<\/pre>\n<p>MYSQL\u5206\u533a\u53ef\u4ee5\u901a\u8fc7to days()\u3001year()\u548cto seconds()\u51fd\u6570\u4f18\u5316\u3002\u5f53\u7136\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u5b83\u65f6\u95f4\u51fd\u6570\u5c31\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u6216NULL\uff0c\u50cfweekday(), dayofyear()\u6216month()\u3002<\/p>\n<p>\u6709\u4e00\u70b9\u5f88\u91cd\u8981\u2014\u2014\u65e0\u8bba\u4f60\u4f7f\u7528\u4ec0\u4e48\u7c7b\u578b\u7684\u5206\u533a\uff0c\u5206\u533a\u7684\u7f16\u53f7\u90fd\u662f\u81ea\u52a8\u751f\u6210\u5e76\u987a\u5e8f\u6392\u5217\u7684\uff0c\u7f16\u53f7\u4ee50\u5f00\u59cb\u3002\u5f53\u4e00\u4e2a\u65b0\u884c\u63d2\u5165\u5230\u88ab\u5206\u533a\u7684\u8868\u4e2d\uff0c\u5206\u533a\u53f7\u7528\u6765\u6b63\u786e\u6307\u51fa\u8981\u63d2\u5230\u54ea\u4e2a\u5206\u533a\u4e2d\u3002<\/p>\n<p>\u5206\u533a\u540d\u662f\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u7684\u3002<\/p>\n<p>\u5f53\u4f60\u4e3a\u8868\u6307\u5b9a\u5206\u533a\u53f7\u65f6\uff0c\u5fc5\u987b\u88ab\u8868\u8fbe\u6210\u4e00\u4e2a\u6b63\u6570\u3001\u975e\u96f6\u6574\u6570\u3001\u4e0d\u4ee50\u5f00\u5934\uff0c\u5c0f\u6570\u3001\u5206\u6570\u662f\u4e0d\u88ab\u5141\u8bb8\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL5.7\u5206\u533a\u7c7b\u578b\u5305\u62ec\uff1a RANGE\u5206\u533a\u3002\u8fd9\u7c7b\u5206\u533a\u57fa\u4e8e\u67d0\u4e00\u5217\u7684\u503c\u5728\u7ed9\u4e88\u7684\u8303\u56f4\u5185\uff0c\u5206\u914d\u884c\u5230\u5206\u533a\u4e2d\u3002 LIST\u5206\u533a\u3002\u7c7b\u4f3c\u4e8eRANGE\uff0c\u9664\u4e86\u8fd9\u79cd\u5206\u533a\u9009\u62e9\u7684\u5217\u503c\u662f&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=890\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-890","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=890"}],"version-history":[{"count":4,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/890\/revisions"}],"predecessor-version":[{"id":894,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/890\/revisions\/894"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}