{"id":7148,"date":"2019-05-15T15:52:08","date_gmt":"2019-05-15T07:52:08","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=7148"},"modified":"2019-05-15T17:21:32","modified_gmt":"2019-05-15T09:21:32","slug":"mysql%e5%b7%b2%e6%9c%89%e8%a1%a8%e5%88%86%e5%8c%ba","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=7148","title":{"rendered":"mysql\u5df2\u6709\u8868\u5206\u533a"},"content":{"rendered":"\n<p>\u4e00\u3001\u8868\u7ed3\u6784\uff1a<\/p>\n\n\n\n<p>*****************************1. row **********************************<br>        Table: history_uint<br> Create Table: CREATE TABLE <code>history_uint<\/code> (<br>   <code>itemid<\/code> bigint(20) unsigned NOT NULL,<br>   <code>clock<\/code> int(11) NOT NULL DEFAULT &#8216;0&#8217;,<br>   <code>value<\/code> bigint(20) unsigned NOT NULL DEFAULT &#8216;0&#8217;,<br>   <code>ns<\/code> int(11) NOT NULL DEFAULT &#8216;0&#8217;,<br>   KEY <code>history_uint_1<\/code> (<code>itemid<\/code>,<code>clock<\/code>)<br> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin<\/p>\n\n\n\n<p>clock\u4e2d\u5b58\u50a8\u7684\u662f\u65f6\u95f4\u6233\u3002<\/p>\n\n\n\n<p>\u4e8c\u3001\u6784\u60f3<\/p>\n\n\n\n<p>1\u3001\u4f7f\u7528\u65f6\u95f4\u7684RANGE\u5206\u533a\uff0c\u6bcf\u4e2a\u5c0f\u65f6\u4e00\u4e2a\u5206\u533a\uff1a\uff08\u4ee5\u5931\u8d25\u544a\u7ec8\uff09<\/p>\n\n\n\n<p>alter table history_uint <br> partition by range( hour(from_unixtime(clock)) )(<br> partition p0 values less than (1),<br> partition p1 values less than (2),<br>&#8230;<br> partition p23 values less than (24)<br>);#\u5931\u8d25\u3002\u3002\u3002<\/p>\n\n\n\n<p>#\u9519\u8bef\u63d0\u793a\uff1a<\/p>\n\n\n\n<p>ERROR 1479 (HY000): Syntax error: RANGE PARTITIONING requires definition of VALUES LESS THAN for each partition<\/p>\n\n\n\n<p>2\u3001\u4f7f\u7528\u65f6\u95f4\u7684HASH\u5206\u533a\uff0c\u6bcf\u5c0f\u65f6\u4e00\u4e2a\u5206\u533a\uff1a\uff08\u4ee5\u5931\u8d25\u544a\u7ec8\uff09<\/p>\n\n\n\n<p> alter table history_uint <br> partition by hash( hour(from_unixtime(clock)) ) <br> partitions 24;<\/p>\n\n\n\n<p>#\u63d0\u793a\u9519\u8bef\uff1a<br> ERROR 1564 (HY000): This partition function is not allowed<\/p>\n\n\n\n<p>\u4e0b\u9762\u94fe\u63a5\u7f57\u5217\u4e86\u5728\u5206\u533a\u4e2d\u53ef\u4ee5\u4f7f\u7528\u7684\u51fd\u6570\uff1a<br>https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/partitioning-limitations-functions.html<\/p>\n\n\n\n<p>\u5206\u6790\uff1a\u6839\u636e\u5b98\u7f51\u7684\u63d0\u793afrom_unixtime()\u51fd\u6570\u4e0d\u80fd\u5728\u5206\u533a\u4e2d\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>3\u3001\u4f7f\u7528\u65e5\u671f\u7684RANGE\u5206\u533a\uff0c\u81ea\u5b9a\u4e49\u4e00\u6bb5\u65e5\u671f\u5c06\u5927\u6570\u636e\u8868\u5206\u6210\u51e0\u4e2a\u8868\uff1a\uff08\u6210\u529f\uff09<\/p>\n\n\n\n<p>alter table history_uint <br> partition by range( clock )<br> (<br>  partition p0 values less than (unix_timestamp(&#8216;2019-4-15&#8217;)), <br>  partition p1 values less than (unix_timestamp(&#8216;2019-4-20&#8217;)), <br>  partition p2 values less than (unix_timestamp(&#8216;2019-4-30&#8217;)),<br>  partition p3 values less than (MAXVALUE)<br>  );<\/p>\n\n\n\n<p>\u5982\u679c\u8868\u5f88\u5927\u7684\u8bdd\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5341\u5206\u6f2b\u957f\uff1a<\/p>\n\n\n\n<p>tage: 1 of 2 &#8216;copy to tmp table&#8217;     78% of stage done<br>####################<br>Query OK, 38753477 rows affected (1 hour 29 min 53.91 sec)<br>\nRecords: 38753477  Duplicates: 0  Warnings: 0<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u4ecb\u7ecd\u4e24\u4e2a\u51fd\u6570unix_timestamp()\u548cfrom_unixtime()\uff1a<\/p>\n\n\n\n<p>\uff081\uff09unix_timestamp()\uff1a\u53ef\u4ee5\u4ea4\u65e5\u671f\u65f6\u95f4\u8f6c\u6362\u6210\u65f6\u95f4\u6233\uff0cunix_timestamp(&#8216;2019-7-15 14:5:0&#8217;)<\/p>\n\n\n\n<p>\uff082\uff09from_unixtime(\u65f6\u95f4\u6233)\uff0c\u8f6c\u6362\u6210\u65e5\u671f\u65f6\u95f4\u3002<\/p>\n\n\n\n<p>PS\uff1aMariaDB10.0\u4e4b\u524d\u7684\u7248\u672c\u4e0d\u652f\u6301\u5206\u533a\u67e5\u8be2\uff0c\u6211\u4f7f\u7528select * from history_uint partition (p0);\u63d0\u793a\u6211\u8bed\u6cd5\u9519\u8bef\uff0c\u4f46\u662f\u5206\u533a\u662f\u652f\u6301\u7684\uff08\u6211\u7684\u7248\u672c\u662f5.5.60\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u8868\u7ed3\u6784\uff1a *****************************1. row ********************************** Ta&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=7148\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-7148","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7148","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=7148"}],"version-history":[{"count":6,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7148\/revisions"}],"predecessor-version":[{"id":7157,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/7148\/revisions\/7157"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}