{"id":17870,"date":"2025-06-21T17:15:38","date_gmt":"2025-06-21T09:15:38","guid":{"rendered":"https:\/\/92it.top\/?p=17870"},"modified":"2025-06-21T17:15:38","modified_gmt":"2025-06-21T09:15:38","slug":"mysql%e5%88%86%e5%8c%ba%e8%a1%a8%ef%bc%8c%e8%af%a5%e4%b8%8d%e4%bc%9a%e8%bf%98%e6%9c%89%e4%ba%ba%e4%b8%8d%e7%9f%a5%e9%81%93%e7%9a%84%e5%90%a7%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=17870","title":{"rendered":"MySQL\u5206\u533a\u8868\uff0c\u8be5\u4e0d\u4f1a\u8fd8\u6709\u4eba\u4e0d\u77e5\u9053\u7684\u5427\uff1f"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"http:\/\/edisonz.cn\/archives\/mysql-partition\">MySQL\u5206\u533a\u8868\uff0c\u8be5\u4e0d\u4f1a\u8fd8\u6709\u4eba\u4e0d\u77e5\u9053\u7684\u5427\uff1f<\/a><\/p>\n\n\n\n<p><strong>\u80cc\u666f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5206\u5e93\u5206\u8868\uff0c\u76f8\u4fe1\u5927\u5bb6\u591a\u5c11\u90fd\u6709\u4e86\u89e3\u8fc7\u5176\u4e2d\u7684\u4e00\u4e9b\u65b9\u6848\u8bbe\u8ba1\u4e0e\u539f\u7406\u3002<\/p>\n\n\n\n<p>\u800c\u4eca\u5929\u8bb2\u7684\u662f\u5206\u533a\uff0c\u5bf9\u4e8e<strong>\u5206\u533a<\/strong>\u53c8\u6709\u591a\u5c11\u5c0f\u4f19\u4f34\u4e86\u89e3\u8fc7\u5462\uff1f<\/p>\n\n\n\n<p>\u5c0f\u5e74\u6700\u8fd1\u662f\u78b0\u5230\u8fd9\u4e48\u4e00\u4e2a\u4e1a\u52a1\u80cc\u666f\uff1a\u5728\u7528\u6237\u8fdb\u5165\u8d2d\u4e70\u4e3b\u9875\u9762\uff0c\u9700\u8981\u5c55\u793a\u7528\u6237\u6700\u8fd1\u51e0\u4e2a\u6708\u8d2d\u4e70\u8bb0\u5f55\u7684\u5546\u54c1\u5217\u8868\u3002<\/p>\n\n\n\n<p>\u5b9e\u73b0\u7684\u65b9\u6848\u6709\u5f88\u591a\uff0c\u8fd9\u91cc\u7b80\u5355\u5217\u4e3e\u51e0\u4e2a\u5e38\u89c1\u7684\uff1a<\/p>\n\n\n\n<ol>\n<li>\u76f4\u63a5\u67e5\u8be2\u7528\u6237\u4ea4\u6613\u8ba2\u5355\u8868\uff0c\u83b7\u53d6\u8fd1\u51e0\u4e2a\u6708\u5185\u7684\u4ea4\u6613\u8bb0\u5f55\uff08\u8ba2\u5355\u8868\u8bb0\u5f55\u5546\u54c1\uff09<\/li>\n\n\n\n<li>\u589e\u52a0\u4e00\u4e2a\u7528\u6237\u8d2d\u4e70\u5546\u54c1\u6d41\u6c34\u8868\uff0c\u8fd9\u4e2a\u8868\u53ea\u9700\u8bb0\u5f55\u7528\u6237\u6700\u8fd1\u51e0\u4e2a\u6708\u7684\u6d41\u6c34<\/li>\n<\/ol>\n\n\n\n<p>\uff08\u5f53\u7136\uff0c\u5927\u5bb6\u6709\u66f4\u597d\u7684\u65b9\u6848\u6b22\u8fce\u7559\u8a00\uff09<\/p>\n\n\n\n<p>\u65b9\u68481\uff0c\u8fd9\u662f\u5927\u5bb6\u6700\u4e3a\u5bb9\u6613\u60f3\u5230\u548c\u5b9e\u73b0\u7b80\u5355\u7684\u4e00\u79cd\u3002\u4f46\u662f\u8003\u8651\u5230\u8ba2\u5355\u8868\u7684\u6570\u636e\u91cf\u4f1a\u8d8a\u6765\u8d8a\u591a\uff0c\u800c\u4e14\u7528\u6237\u8d2d\u4e70\u76f8\u540c\u7684\u5546\u54c1\u4f1a\u91cd\u590d\uff0c\u67e5\u8be2\u9700\u8981\u57fa\u4e8e\u5546\u54c1\u3001\u65f6\u95f4\u7b49\u8fc7\u6ee4\uff0cSQL \u5c42\u9762\u4f1a\u7a0d\u5fae\u590d\u6742\u4e00\u4e9b\u3002\u5f53\u7136\u91cd\u8981\u7684\u4e00\u70b9\u8fd8\u662f\u4f1a\u5bf9\u8ba2\u5355\u8868\u6709\u5f71\u54cd\uff0c\u5982\u679c\u51fa\u73b0\u6027\u80fd\u95ee\u9898\u7684\u8bdd\u3002<\/p>\n\n\n\n<p>\u65b9\u68482\uff0c\u65b0\u589e\u4e00\u4e2a\u7528\u6237\u8d2d\u4e70\u5546\u54c1\u6d41\u6c34\u8868\uff0c\u53ea\u9700\u8981\u8bb0\u5f55\u8fd1\u51e0\u4e2a\u6708\u7684\u6570\u636e\uff0c\u5728\u6d41\u7a0b\u662f\u5b9e\u73b0\u4e0a\uff0c\u53ea\u9700\u8981\u5728\u5199\u5165\u8ba2\u5355\u8868\u540e\uff0c\u540c\u65f6\u8bb0\u5f55\u4e00\u6761\u5546\u54c1\u6d41\u6c34\u3002\u6570\u636e\u91cf\u76f8\u6bd4\u8ba2\u5355\u8868\u6765\u8bf4\u80af\u5b9a\u662f\u5c11\u4e86\u4e0d\u5c11\uff0c \u6d41\u6c34\u8868\u7684\u5b57\u6bb5\u4e5f\u53ea\u4fdd\u7559\u5546\u54c1\u4fe1\u606f\uff0c\u5173\u952e\u662f\u8bfb\u5199\u90fd\u4e0d\u4f1a\u5f71\u54cd\u8ba2\u5355\u8868\u7684\u6027\u80fd\u3002<\/p>\n\n\n\n<p>\u7ecf\u8fc7\u4e00\u756a\u5bf9\u6bd4\uff0c\u6700\u7ec8\u5c0f\u5e74\u9009\u62e9\u4e86\u65b9\u68482\u3002<\/p>\n\n\n\n<p>\u65e2\u7136\u662f\u4fdd\u7559\u7528\u6237\u6700\u8fd1\u8fd1\u4e2a\u6708\u7684\u6570\u636e\uff0c\u90a3\u4e48\u600e\u4e48\u5b9e\u73b0\u5462\uff1f<\/p>\n\n\n\n<ul>\n<li>\u5b9a\u65f6\u5220\u9664\u6570\u636e\uff1f<\/li>\n\n\n\n<li>\u5206\u533a\u8868\uff1f<\/li>\n<\/ul>\n\n\n\n<p>\u5b9a\u65f6\u5220\u9664\uff0c\u53ef\u4ee5\u901a\u8fc7\u5e94\u7528\u7a0b\u5e8f\u7684\u5b9a\u65f6\u4efb\u52a1\uff0c\u6216\u8005\u6570\u636e\u5e93\u7684\u811a\u672c\u6bd4\u5982\u5b58\u50a8\u8fc7\u7a0b\u4e4b\u7c7b\u3002<\/p>\n\n\n\n<p>\u5206\u533a\u8868\uff0c\u901a\u8fc7\u6570\u636e\u5e93\u7269\u7406\u5b58\u50a8\u5c42\u7684\u5b9e\u73b0\uff0c\u6309\u7167\u65f6\u95f4\u6761\u4ef6\u5c06\u6570\u636e\u5b58\u50a8\u4e8e\u4e0d\u540c\u7684\u5206\u533a\uff0c\u628a\u4e0d\u9700\u8981\u7684\u5206\u533a\u6570\u636e\u5220\u6389\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u662f\u8868\u5206\u533a\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u7b80\u5355\u6982\u8ff0\u4e00\u4e0b\u5206\u5e93\/\u5206\u8868\/\u5206\u533a \u8fd9\u51e0\u4e2a\u6982\u5ff5\uff1a<\/p>\n\n\n\n<ul>\n<li><strong>\u5206\u5e93<\/strong>\uff1a\u628a\u4e00\u4e2a\u6570\u636e\u5e93\u62c6\u5206\u6210\u591a\u4e2a\u5e93\uff0c\u4e5f\u5c31\u662f\u6570\u636e\u5206\u6563\u5728\u591a\u4e2a\u6570\u636e\u5e93\u5b9e\u4f8b\u4e0a\u3002<\/li>\n\n\n\n<li><strong>\u5206\u8868<\/strong>\uff1a\u628a\u4e00\u5f20\u8868\u6309\u7167\u4e00\u5b9a\u7684\u89c4\u5219\uff0c\u5206\u6210\u591a\u4e2a\u72ec\u7acb\u5b58\u50a8\u7a7a\u95f4\u7684\u5b9e\u4f53\u8868\u3002\u5bf9\u6570\u636e\u7684\u8bfb\u5199\u90fd\u5fc5\u987b\u6309\u7167\u89c4\u5219\uff0c\u8def\u7531\u5230\u76f8\u5e94\u7684\u5b9e\u4f53\u8868\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><strong>\u5206\u533a<\/strong>\uff1a\u628a\u4e00\u5f20\u8868\u7684\u6570\u636e\u5206\u6210\u591a\u4e2a\u533a\u5757\uff0c\u5728\u903b\u8f91\u4e0a\u770b\u8fd8\u662f\u4e00\u5f20\u8868\uff0c\u4f46\u662f\u5728\u7269\u7406\u5b58\u50a8\u4e0a\uff0c\u6570\u636e\u662f\u5b58\u50a8\u5728\u4e0d\u540c\u7684\u533a\u5757\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5047\u8bbe\u6709\u4e00\u5f20\u8ba2\u5355\u8bb0\u5f55\u8868\uff08\u7b80\u7565\u7248\uff09\uff0c\u7528\u4e8e\u8bb0\u5f55\u7528\u6237\u7684\u5546\u54c1\u8d2d\u4e70\u5386\u53f2\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TABLE `order_history` (\n  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '\u4e3b\u952e',\n  `order_no` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '\u8ba2\u5355\u53f7',\n  `member_id` varchar(64) COLLATE utf8mb4_bin NOT NULL COMMENT '\u7528\u6237ID',\n  `product_id` varchar(64) COLLATE utf8mb4_bin NOT NULL COMMENT '\u5546\u54c1ID',\n  `create_time` datetime DEFAULT NULL COMMENT '\u8ba2\u5355\u521b\u5efa\u65f6\u95f4',\n  PRIMARY KEY (`id`),\n  KEY `idx_member_id` (`member_id`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;<\/pre>\n\n\n\n<p>\u5728\u672a\u5206\u533a\u4e4b\u524d\uff0c\u6240\u6709\u7684\u6570\u636e\u90fd\u662f\u5b58\u50a8\u5728\u4e00\u4e2a <code>.ibd<\/code> \u6587\u4ef6<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"714\" height=\"102\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-232.png\" alt=\"\" class=\"wp-image-17871\" style=\"width:424px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-232.png 714w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-232-300x43.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-232-230x33.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-232-350x50.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-232-480x69.png 480w\" sizes=\"(max-width: 714px) 100vw, 714px\" \/><\/figure><\/div>\n\n\n<p>\u6539\u6210\u5206\u533a\u8868\u4e4b\u540e\uff08\u6309\u7167\u65f6\u95f4\u505a\u5206\u533a\uff09\uff0c\u5c31\u4f1a\u751f\u6210\u4e0d\u540c\u7684\u65f6\u95f4\u5206\u533a\uff0c\u6570\u636e\u662f\u5206\u522b\u5b58\u50a8\u5728\u4e0d\u540c\u7684 <code>.ibd<\/code> \u6587\u4ef6\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"211\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-1024x211.png\" alt=\"\" class=\"wp-image-17872\" style=\"width:502px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-1024x211.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-300x62.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-768x158.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-830x171.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-230x47.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-350x72.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233-480x99.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2025\/06\/image-233.png 1264w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u73b0\u5728\u5e94\u8be5\u53ef\u4ee5\u66f4\u597d\u7406\u89e3\uff0c\u5206\u533a\uff0c\u5728\u7269\u7406\u5b58\u50a8\u4e0a\uff0c\u5c31\u662f\u5c06\u540c\u4e00\u4e2a\u8868\u4e2d\u7684\u884c\u6570\u636e\u5b58\u50a8\u5230\u4e0d\u540c\u7684\u7269\u7406\u6587\u4ef6\u4e2d\uff0c\u6709\u51e0\u4e2a\u5206\u533a\u5c31\u6709\u51e0\u4e2a <code>.ibd<\/code> \u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u5728\u903b\u8f91\u5c42\u9762\u4e0a\u6211\u4eec\u64cd\u4f5c\u7684\u8fd8\u662f\u540c\u4e00\u4e2a\u8868\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u5206\u533a\u7c7b\u578b<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>1. RANGE<\/strong><\/p>\n\n\n\n<p>\u57fa\u4e8e\u884c\u6570\u636e\u7684\u5217\u503c\uff0c\u5212\u5206\u4e0d\u540c\u7684\u8303\u56f4\u5206\u533a\u3002\u4e3b\u8981\u7528\u4e8e\u65e5\u671f\u5217\u7684\u5206\u533a\uff0c\u53ef\u4ee5\u6839\u636e\u5e74\u6708\u6765\u5b58\u653e\u6570\u636e\uff0c\u6bd4\u5982\u4ea4\u6613\u8868\uff0c\u6d41\u6c34\u8868\u7b49\u3002<\/p>\n\n\n\n<p>\u50cf\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\u7684 <code>order_history<\/code> \u8868\uff0c\u7528\u7684\u5c31\u662f RANGE \u5206\u533a\uff0c\u6309\u7167<strong>\u5e74\u6708<\/strong>\u6765\u505a\u5206\u533a\u3002\u628a\u6570\u636e\u6309\u5e74\u6708\u5206\u533a\uff0c\u5982\u679c\u53ea\u60f3\u4fdd\u7559\u8fd1\u51e0\u4e2a\u6708\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u76f4\u63a5\u5220\u6389\u5386\u53f2\u6708\u4efd\u7684\u6570\u636e\u6587\u4ef6\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TABLE `order_history` (\n  `id` bigint NOT NULL AUTO_INCREMENT,\n  `member_id` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL,\n  `order_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,\n  `create_time` datetime NOT NULL,\n  PRIMARY KEY (`id`,`create_time`),\n  KEY `idx_member_id` (`member_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\nPARTITION BY RANGE (to_days(create_time))\n(\n     PARTITION p202301 VALUES LESS THAN (to_days('2023-02-01')),\n     PARTITION p202302 VALUES LESS THAN (to_days('2023-03-01')),\n     PARTITION p202303 VALUES LESS THAN (to_days('2023-04-01')),\n  \t PARTITION pmax VALUES LESS THAN MAXVALUE\n);<\/pre>\n\n\n\n<p>\u5173\u952e\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<ul>\n<li>`PARTITION BY RANGE&#8220;<\/li>\n\n\n\n<li>&#8220;VALUES LESS THAN`<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u91cc\u662f\u6839\u636e\u5b57\u6bb5 <code>create_time<\/code> \u6309\u7167\u5e74\u6708\u6765\u505a\u5206\u533a\uff0c\u5199\u5165\u7684\u6bcf\u4e00\u6761\u6570\u636e\uff0c\u90fd\u4f1a\u9884\u5148\u5224\u65ad\u8981\u5206\u914d\u54ea\u4e2a\u5206\u533a\uff0c\u5982\u679c\u4e0d\u5b58\u5728 MySQL \u4f1a\u76f4\u63a5\u62a5\u9519\u3002\u6bd4\u5982\u63d2\u5165\u4e00\u6761 <code>2023-06-01<\/code> \u7684\u6570\u636e\uff0c\u5728\u8fd9\u91cc\u627e\u4e0d\u5230\u5339\u914d\u7684\u5206\u533a\uff0c\u4f1a\u76f4\u63a5\u62a5\u9519\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6709\u4e00\u70b9\u9ebb\u70e6\u7684\u662f\uff0c\u9700\u8981\u624b\u52a8\u9884\u5148\u5206\u914d\u5206\u533a\u3002\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u50cf\u4e0a\u9762\u4e00\u6837\uff0c\u589e\u52a0\u4e00\u4e2a <code>PARTITION pmax VALUES LESS THAN MAXVALUE<\/code>\uff0c\u5728\u627e\u4e0d\u5230\u5339\u914d\u4e0d\u5230\u5177\u4f53\u7684\u5206\u533a\u65f6\uff0c\u90fd\u653e\u5230 <code>pmax<\/code> \u7684\u5206\u533a\u4e2d\uff0c\u4e0d\u8fc7\u4e0d\u5efa\u8bae\u8fd9\u4e48\u7528\uff0c\u8fd9\u6837\u7684\u8bdd\u5206\u533a\u5c31\u6ca1\u4ec0\u4e48\u610f\u4e49\u4e86\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u589e\u52a0\u5206\u533a\nalter table `tr` add partition(PARTITION p6 VALUES LESS THAN (2020));\n \n#\u5220\u9664\u5206\u533a\nalter table `tr` drop partition p1;\n \n#\u67e5\u770b\u5206\u533a\nSELECT PARTITION_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 'tr';\n \n# \u67e5\u770b\u67d0\u4e2a\u5206\u533a\u7684\u6570\u636e\nSELECT * FROM `tr` PARTITION (p2);\n \n# \u6e05\u7a7a\u67d0\u5206\u533a\u7684\u6570\u636e\nalter table `tr` truncate partition p0;<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>2. LIST<\/strong><\/p>\n\n\n\n<p>LIST \u5206\u533a\u4e0e RANGE \u5206\u533a\u6709\u70b9\u76f8\u4f3c\uff0c\u4e0d\u8fc7 LIST \u5206\u533a\u5b57\u6bb5\u7684\u662f\u57fa\u4e8e\u660e\u786e\u7684\u679a\u4e3e\u8303\u56f4\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TABLE product (\n    `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '\u4e3b\u952e',\n    `product_name` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '\u5546\u54c1\u540d\u79f0',\n    `type` INT(2) NOT NULL COMMENT '1-\u6570\u7801 2-\u96f6\u98df 3-\u65e5\u7528',\n    PRIMARY KEY (`id`, `type`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\nPARTITION BY LIST(type) \n(\n    PARTITION p1 VALUES IN (1),\n    PARTITION p2 VALUES IN (2),\n    PARTITION p3 VALUES IN (3)\n);<\/pre>\n\n\n\n<p>\u5173\u952e\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<ul>\n<li><code>PARTITION BY LIST<\/code><\/li>\n\n\n\n<li><code>IN()<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u9002\u7528\u4e8e\u5206\u533a\u5b57\u6bb5\u662f\u56fa\u5b9a\u8303\u56f4\u7684\u679a\u4e3e\u503c\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>3. HSAH<\/strong><\/p>\n\n\n\n<p>\u8fd9\u4e2a\u5c31\u66f4\u5bb9\u6613\u7406\u89e3\uff0c\u5c31\u662f\u5bf9\u6307\u5b9a\u7684\u5206\u533a\u5b57\u6bb5\uff0c\u505a\u54c8\u5e0c\u5904\u7406\uff0c\u4ece\u800c\u5224\u65ad\u662f\u5206\u914d\u5230\u54ea\u4e2a\u5206\u533a\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TABLE product (\n    id INT NOT NULL,\n    product_name VARCHAR(64),\n    type INT COMMENT '1-\u6570\u7801 2-\u96f6\u98df 3-\u65e5\u7528',\n)\nPARTITION BY HASH(id)\nPARTITIONS 4\uff1b<\/pre>\n\n\n\n<p>\u5173\u952e\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<ul>\n<li><code>PARTITION BY HASH<\/code><\/li>\n\n\n\n<li><code>PARTITIONS<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u91cc\u7684 <code>PARTITIONS4<\/code> \u6307\u7684\u662f\u5206\u533a\u6570\u4e3a4<\/p>\n\n\n\n<p>\u5e38\u89c1\u7684\u5206\u533a\u7c7b\u578b\u5c31\u5927\u6982\u5c31\u8fd93\u79cd\uff0c\u8fd8\u7528\u5b50\u5206\u533a\u7684\u5d4c\u5957\u7ec4\u5408\u7528\u6cd5\uff0c\u53ef\u80fd\u5c31\u6bd4\u8f83\u7a0d\u5fae\u590d\u6742\uff0c\u8fd9\u91cc\u5c31\u4e0d\u5c55\u5f00\u4e86\u3002<\/p>\n\n\n\n<p>\u806a\u660e\u7684\u540c\u5b66\u53ef\u80fd\u4f1a\u53d1\u73b0\uff0c\u5728\u5206\u533a\u8868\u7684 DDL \u4e2d\uff0c\u4e3b\u89c1\u7d22\u5f15\u662f\u6709\u7a0d\u5fae\u4e0d\u4e00\u6837\u7684\u3002\u6bd4\u5982\u4f8b\u5b50\u4e2d\u7684 <code>order_history<\/code> \u8868\uff0c\u5206\u533a\u540e\u4e3b\u952e\u53d8\u4e3a <code>PRIMARY KEY (<\/code>id<code>,<\/code>create_time<code>)<\/code>\u3002<\/p>\n\n\n\n<p>\u8fd9\u662f\u56e0\u4e3a MySQL \u7684\u5206\u533a\u5b57\u6bb5\uff0c\u5fc5\u987b\u5305\u542b\u5728\u4e3b\u952e\u5b57\u6bb5\u6216\u8005\u552f\u4e00\u7d22\u5f15\u5217\u4e2d\uff0c\u4e5f\u5c31\u662f\u5206\u533a\u7684\u5b57\u6bb5\u5fc5\u987b\u5168\u90e8\u90fd\u5c5e\u4e8e\u4e3b\u952e\u6216\u8005\u552f\u4e00\u7d22\u5f15\u5217\u7684\u4e00\u90e8\u5206\u6216\u8005\u5168\u90e8\uff0c\u5426\u5219\u521b\u5efa\u5206\u533a\u5c06\u76f4\u63a5\u62a5\u9519\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>Pros VS Cons<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Pros<\/strong><\/p>\n\n\n\n<ol>\n<li>\u5355\u8868\u5b58\u50a8\u66f4\u591a\u7684\u6570\u636e\u3002\u56e0\u4e3a\u5c06\u6570\u636e\u5206\u644a\u5230\u4e0d\u540c\u7684\u7269\u7406\u6587\u4ef6\u4e2d\uff0c\u6240\u4ee5\u5bf9\u6bd4\u672a\u5206\u533a\u8868\u6765\u8bf4\uff0c\u5206\u533a\u8868\u7684\u7269\u7406\u6587\u4ef6\u4f1a\u66f4\u5c0f\u3002<\/li>\n\n\n\n<li>\u67e5\u8be2\u6027\u80fd\u9ad8\uff0c\u63d0\u9ad8\u68c0\u7d22\u901f\u5ea6\u3002\u53ef\u4ee5\u6307\u5b9a\u5fc5\u8981\u7684\u5206\u533a\u6765\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\u3002<\/li>\n\n\n\n<li>\u4fbf\u4e8e\u7ef4\u62a4\uff0c\u53ef\u7528\u6027\u9ad8\n<ul>\n<li>\u6bd4\u5982\u5386\u53f2\u6570\u636e\u9700\u8981\u5b9a\u65f6\u6e05\u7406\uff0c\u901a\u8fc7\u6e05\u9664\u6574\u4e2a\u5206\u533a\u5feb\u901f\u5b9e\u73b0\u3002\u4e5f\u53ef\u4ee5\u589e\u52a0\u65b0\u7684\u5206\u533a\u6765\u652f\u6301\u65b0\u63d2\u5165\u7684\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u8868\u7684\u67d0\u4e2a\u5206\u533a\u51fa\u73b0\u6545\u969c\uff0c\u9700\u8981\u4fee\u590d\u6570\u636e\uff0c\u53ea\u4fee\u590d\u8be5\u5206\u533a\u5373\u53ef\uff0c\u4e0d\u5f71\u54cd\u5176\u4ed6\u5206\u533a\uff0c\u53ef\u7528\u6027\u76f8\u5bf9\u8f83\u9ad8\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5747\u8861I\/O\uff1a\u53ef\u4ee5\u628a\u4e0d\u540c\u7684\u5206\u533a\u6620\u5c04\u5230\u78c1\u76d8\u4ee5\u5e73\u8861I\/O\uff0c\u6539\u5584\u6574\u4e2a\u7cfb\u7edf\u6027\u80fd\u3002<\/li>\n<\/ol>\n\n\n\n<p>PS\uff1a\u5206\u533a\u4e5f\u662f\u5927\u8868\u4f18\u5316\u7684\u4e00\u4e2a\u4e0d\u9519\u65b9\u6848\u54e6\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>Cons<\/strong><\/p>\n\n\n\n<ol>\n<li>\u5206\u533a\u6570\u9650\u5236\uff0c\u4e00\u4e2a\u8868\u6700\u591a\u53ea\u80fd\u67091024\u4e2a\u5206\u533a\uff08mysql5.6\u4e4b\u540e\u652f\u63018192\u4e2a\u5206\u533a\uff09<\/li>\n\n\n\n<li>\u5206\u533a\u7684\u5b57\u6bb5\uff0c\u5fc5\u987b\u662f\u8868\u4e0a\u6240\u6709\u7684\u552f\u4e00\u7d22\u5f15\uff08\u6216\u8005\u4e3b\u952e\u7d22\u5f15\uff09\u5305\u542b\u7684\u5b57\u6bb5\u7684\u5b50\u96c6<\/li>\n\n\n\n<li>\u5206\u533a\u8868\u4e2d\u65e0\u6cd5\u4f7f\u7528\u5916\u952e\u7ea6\u675f<\/li>\n\n\n\n<li>\u7ef4\u62a4\u5206\u533a\u7684\u6210\u672c\u53ef\u80fd\u5f88\u9ad8\u3002\u5982\u679c\u6570\u636e\u66f4\u65b0\u9891\u7387\u6bd4\u8f83\u9ad8\uff0c\u8fd9\u4e2a\u4f1a\u5bfc\u81f4\u884c\u6570\u636e\u7684\u91cd\u65b0\u5206\u914d\u5206\u533a\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5728\u4ec0\u4e48\u573a\u666f\u4e2d\u4f1a\u9002\u5408\u7528\u5206\u533a\u5462\uff1f<\/p>\n\n\n\n<ul>\n<li>\u4e1a\u52a1\u7b80\u5355\uff0c\u5355\u8868\u67e5\u8be2\uff0c\u4e14\u90fd\u8ddf\u65f6\u95f4\u8303\u56f4\u67e5\u8be2\u76f8\u5173<\/li>\n\n\n\n<li>\u6570\u636e\u9700\u8981\u5b9a\u671f\u6e05\u7406\u6570\u636e\uff0c\u65e0\u9700\u4fdd\u7559\u5168\u90e8\u6570\u636e<\/li>\n\n\n\n<li>\u6570\u636e\u66f4\u65b0\u9891\u7387\u8f83\u4f4e\uff0c\u53ea\u6709\u5199\u5165\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1aMySQL\u5206\u533a\u8868\uff0c\u8be5\u4e0d\u4f1a\u8fd8\u6709\u4eba\u4e0d\u77e5\u9053\u7684\u5427\uff1f \u80cc\u666f \u5206\u5e93\u5206\u8868\uff0c\u76f8\u4fe1\u5927\u5bb6\u591a\u5c11\u90fd\u6709\u4e86\u89e3\u8fc7\u5176\u4e2d\u7684\u4e00\u4e9b\u65b9\u6848\u8bbe\u8ba1\u4e0e\u539f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17870"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17870"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17870\/revisions"}],"predecessor-version":[{"id":17873,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/17870\/revisions\/17873"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}