{"id":476741,"date":"2023-08-09T07:35:16","date_gmt":"2023-08-09T07:35:16","guid":{"rendered":""},"modified":"2023-09-05T11:13:20","modified_gmt":"2023-09-05T11:13:20","slug":"database-sharding","status":"publish","type":"wiki","link":"https:\/\/oneproxy.pro\/cn\/wiki\/database-sharding\/","title":{"rendered":"\u6570\u636e\u5e93\u5206\u7247"},"content":{"rendered":"<p>\u6570\u636e\u5e93\u5206\u7247\u662f\u589e\u5f3a\u5927\u89c4\u6a21\u6570\u636e\u5e93\u6027\u80fd\u3001\u53ef\u6269\u5c55\u6027\u548c\u53ef\u9760\u6027\u7684\u6709\u6548\u65b9\u6cd5\u3002\u8be5\u6280\u672f\u5c06\u8f83\u5927\u7684\u6570\u636e\u5e93\u5206\u89e3\u4e3a\u66f4\u5c0f\u3001\u66f4\u5feb\u4e14\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u90e8\u5206\u6216\u201c\u5206\u7247\u201d\uff0c\u8fd9\u4e9b\u90e8\u5206\u5206\u5e03\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<h2>\u6570\u636e\u5e93\u5206\u7247\u7684\u8d77\u6e90\u548c\u6f14\u53d8<\/h2>\n<p>\u6570\u636e\u5e93\u5206\u7247\u7684\u6982\u5ff5\u6e90\u4e8e\u5927\u6570\u636e\u548c\u9ad8\u901f\u4e92\u8054\u7f51\u65f6\u4ee3\u7ba1\u7406\u6d77\u91cf\u6570\u636e\u7684\u6311\u6218\u3002\u968f\u7740 2000 \u5e74\u4ee3\u521d\u671f\u57fa\u4e8e Web \u7684\u5e94\u7528\u7a0b\u5e8f\u548c\u670d\u52a1\u7684\u8fc5\u901f\u6269\u5c55\uff0c\u4f20\u7edf\u7684\u5173\u7cfb\u6570\u636e\u5e93\u96be\u4ee5\u5e94\u5bf9\u5de8\u5927\u7684\u6570\u636e\u91cf\u3002<\/p>\n<p>\u6570\u636e\u5e93\u5206\u7247\u9996\u6b21\u88ab\u63d0\u53ca\u662f\u5728 Google \u7684 BigTable \u548c\u4e9a\u9a6c\u900a\u7684 Dynamo \u7684\u80cc\u666f\u4e0b\u3002\u8fd9\u4e9b\u6570\u636e\u5e93\u7cfb\u7edf\u65e8\u5728\u5c06\u5927\u578b\u6570\u636e\u96c6\u5206\u5e03\u5728\u8bb8\u591a\u670d\u52a1\u5668\u4e0a\uff0c\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u53ef\u6269\u5c55\u6027\u3002\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\uff0c\u5305\u62ec MySQL \u548c PostgreSQL \u5728\u5185\u7684\u5404\u79cd\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u5f15\u5165\u4e86\u81ea\u5df1\u7684\u5206\u7247\u7248\u672c\uff0c\u589e\u5f3a\u4e86\u8be5\u6280\u672f\u5e76\u4f7f\u5176\u6210\u4e3a\u7ba1\u7406\u5927\u578b\u6570\u636e\u5e93\u7684\u6807\u51c6\u5b9e\u8df5\u3002<\/p>\n<h2>\u6570\u636e\u5e93\u5206\u7247\uff1a\u6269\u5c55\u4e3b\u9898<\/h2>\n<p>\u6570\u636e\u5e93\u5206\u7247\u662f\u4e00\u79cd\u6570\u636e\u5e93\u5206\u533a\uff0c\u5176\u4e2d\u6570\u636e\u88ab\u5206\u4e3a\u6c34\u5e73\u5206\u533a\u6216\u5206\u7247\uff0c\u5e76\u4e14\u8fd9\u4e9b\u5206\u7247\u5206\u5e03\u5728\u5355\u72ec\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e0a\u3002\u6bcf\u4e2a\u5206\u7247\u6784\u6210\u66f4\u5927\u6570\u636e\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u5e76\u4e14\u72ec\u7acb\u4e8e\u5176\u4ed6\u5206\u7247\u8fd0\u884c\u3002\u8fd9\u610f\u5473\u7740\u6bcf\u4e2a\u5206\u7247\u90fd\u53ef\u4ee5\u4e0e\u5176\u4ed6\u5206\u7247\u5206\u5f00\u8bbf\u95ee\u3001\u7ba1\u7406\u548c\u914d\u7f6e\uff0c\u4ece\u800c\u63d0\u9ad8\u4e86\u6570\u636e\u5e93\u7cfb\u7edf\u7684\u6574\u4f53\u6027\u80fd\u3002<\/p>\n<p>\u8be5\u6280\u672f\u5bf9\u4e8e\u5fc5\u987b\u5904\u7406\u6d77\u91cf\u6570\u636e\u96c6\u3001\u9ad8\u4e8b\u52a1\u7387\u6216\u4e24\u8005\u517c\u800c\u6709\u4e4b\u7684\u5e94\u7528\u7a0b\u5e8f\u7279\u522b\u6709\u76ca\u3002\u901a\u8fc7\u5c06\u6570\u636e\u5206\u5e03\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\uff0c\u5206\u7247\u53ef\u4ee5\u9632\u6b62\u4efb\u4f55\u5355\u4e2a\u670d\u52a1\u5668\u6210\u4e3a\u74f6\u9888\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u5e76\u4fdd\u8bc1\u6570\u636e\u5e93\u7cfb\u7edf\u7684\u53ef\u6269\u5c55\u6027\u3002<\/p>\n<h2>\u6570\u636e\u5e93\u5206\u7247\u7684\u5185\u90e8\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>\u5206\u7247\u7684\u5de5\u4f5c\u539f\u7406\u662f\u6839\u636e\u7279\u5b9a\u7684\u5206\u7247\u952e\u5206\u914d\u6570\u636e\u3002\u8be5\u5bc6\u94a5\u53ef\u4ee5\u662f\u4e00\u4e2a\u5c5e\u6027\uff0c\u4f8b\u5982\u5ba2\u6237\u7684\u5730\u7406\u4f4d\u7f6e\u3001\u7528\u6237\u7684 ID \u6216\u786e\u4fdd\u6570\u636e\u76f8\u5f53\u5747\u5300\u5206\u5e03\u7684\u4efb\u4f55\u5176\u4ed6\u53c2\u6570\u3002<\/p>\n<p>\u5f53\u6267\u884c\u67e5\u8be2\u65f6\uff0c\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u4f7f\u7528\u5206\u7247\u952e\u6765\u8bc6\u522b\u5305\u542b\u76f8\u5173\u6570\u636e\u7684\u5206\u7247\u3002\u7136\u540e\uff0c\u5b83\u76f4\u63a5\u4ece\u8be5\u5206\u7247\u68c0\u7d22\u6570\u636e\uff0c\u65e0\u9700\u641c\u7d22\u6574\u4e2a\u6570\u636e\u5e93\u3002\u8fd9\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u6570\u636e\u68c0\u7d22\u7684\u901f\u5ea6\u5e76\u63d0\u9ad8\u4e86\u6574\u4f53\u7cfb\u7edf\u6027\u80fd\u3002<\/p>\n<p>\u7136\u800c\uff0c\u4ed4\u7ec6\u8bbe\u8ba1\u5206\u7247\u7b56\u7565\u81f3\u5173\u91cd\u8981\u3002\u4e0d\u6b63\u786e\u7684\u5206\u7247\u952e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u5206\u5e03\u4e0d\u5747\u5300\uff0c\u5bfc\u81f4\u67d0\u4e9b\u670d\u52a1\u5668\u4e0d\u582a\u91cd\u8d1f\uff0c\u800c\u53e6\u4e00\u4e9b\u670d\u52a1\u5668\u5219\u672a\u5f97\u5230\u5145\u5206\u5229\u7528\u3002<\/p>\n<h2>\u6570\u636e\u5e93\u5206\u7247\u7684\u4e3b\u8981\u7279\u70b9<\/h2>\n<ol>\n<li><strong>\u53ef\u6269\u5c55\u6027<\/strong>\uff1a\u5206\u7247\u901a\u8fc7\u5c06\u6570\u636e\u5e93\u8d1f\u8f7d\u5206\u5e03\u5230\u591a\u4e2a\u670d\u52a1\u5668\u6765\u589e\u5f3a\u53ef\u6269\u5c55\u6027\u3002<\/li>\n<li><strong>\u8868\u73b0<\/strong>\uff1a\u7531\u4e8e\u5206\u7247\u5141\u8bb8\u67e5\u8be2\u8bbf\u95ee\u5355\u4e2a\u5206\u7247\u800c\u4e0d\u662f\u6574\u4e2a\u6570\u636e\u5e93\uff0c\u56e0\u6b64\u6570\u636e\u68c0\u7d22\u548c\u5b58\u50a8\u53d8\u5f97\u66f4\u5feb\u3002<\/li>\n<li><strong>\u53ef\u7528\u6027\u548c\u5197\u4f59<\/strong>\uff1a\u901a\u8fc7\u5206\u7247\uff0c\u4e00\u4e2a\u5206\u7247\u7684\u6545\u969c\u4e0d\u4f1a\u5bfc\u81f4\u6574\u4e2a\u6570\u636e\u5e93\u5d29\u6e83\u3002\u6b64\u5916\uff0c\u5206\u7247\u53ef\u4ee5\u8de8\u591a\u4e2a\u670d\u52a1\u5668\u590d\u5236\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u53ef\u7528\u6027\u3002<\/li>\n<li><strong>\u5730\u7406\u5206\u5e03<\/strong>\uff1a\u5206\u7247\u53ef\u4ee5\u6839\u636e\u7528\u6237\u7684\u5730\u7406\u4f4d\u7f6e\u8fdb\u884c\u5b9a\u4f4d\uff0c\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u5ef6\u8fdf\u5e76\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ol>\n<h2>\u6570\u636e\u5e93\u5206\u7247\u7684\u7c7b\u578b<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u5206\u7247\u7c7b\u578b<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u6c34\u5e73\u5206\u7247<\/strong><\/td>\n<td>\u5c06\u6570\u636e\u5e93\u5212\u5206\u4e3a\u884c\u5e76\u5c06\u5b83\u4eec\u5206\u5e03\u5728\u4e0d\u540c\u7684\u5206\u7247\u4e0a\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u5782\u76f4\u5206\u7247<\/strong><\/td>\n<td>\u5c06\u6570\u636e\u5e93\u5212\u5206\u4e3a\u5217\u6216\u76f8\u5173\u5217\u7ec4\uff0c\u5e76\u5c06\u5b83\u4eec\u5206\u5e03\u5728\u4e0d\u540c\u7684\u5206\u7247\u4e0a\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u529f\u80fd\u5206\u7247<\/strong><\/td>\n<td>\u6839\u636e\u529f\u80fd\u6216\u4e1a\u52a1\u9700\u6c42\u62c6\u5206\u6570\u636e\u5e93\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5b9e\u65bd\u548c\u7ba1\u7406\u6570\u636e\u5e93\u5206\u7247<\/h2>\n<p>\u5b9e\u65bd\u6570\u636e\u5e93\u5206\u7247\u53ef\u4ee5\u89e3\u51b3\u4e0e\u6027\u80fd\u3001\u53ef\u6269\u5c55\u6027\u548c\u5197\u4f59\u76f8\u5173\u7684\u95ee\u9898\u3002\u7136\u800c\uff0c\u5206\u7247\u4e5f\u5e26\u6765\u4e86\u65b0\u7684\u6311\u6218\uff0c\u4f8b\u5982\u7ba1\u7406\u591a\u4e2a\u5206\u7247\u3001\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\u4ee5\u53ca\u5fc5\u8981\u65f6\u91cd\u65b0\u5206\u7247\u7684\u590d\u6742\u6027\u3002<\/p>\n<p>\u5404\u79cd\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u4e3a\u8fd9\u4e9b\u6311\u6218\u63d0\u4f9b\u4e86\u89e3\u51b3\u65b9\u6848\u3002\u4f8b\u5982\uff0cMongoDB\u652f\u6301\u81ea\u52a8\u5206\u7247\u548c\u91cd\u65b0\u5206\u7247\uff0cPostgreSQL\u63d0\u4f9b\u4e86\u9ad8\u6548\u7ba1\u7406\u5206\u7247\u7684\u5de5\u5177\u3002<\/p>\n<h2>\u6570\u636e\u5e93\u5206\u7247\u4e0e\u7c7b\u4f3c\u6982\u5ff5\u7684\u6bd4\u8f83<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u5b66\u671f<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u6570\u636e\u5e93\u5206\u7247<\/strong><\/td>\n<td>\u5c06\u6570\u636e\u5e93\u62c6\u5206\u5230\u591a\u4e2a\u670d\u52a1\u5668\u4ee5\u63d0\u9ad8\u6027\u80fd\u548c\u53ef\u6269\u5c55\u6027\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u6570\u636e\u5e93\u5206\u533a<\/strong><\/td>\n<td>\u5c06\u6570\u636e\u5e93\u5212\u5206\u4e3a\u66f4\u5c0f\u3001\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u90e8\u5206\uff0c\u4f46\u8fd9\u4e9b\u90e8\u5206\u901a\u5e38\u5b58\u50a8\u5728\u540c\u4e00\u670d\u52a1\u5668\u4e0a\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u590d\u5236<\/strong><\/td>\n<td>\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\u5236\u4f5c\u6574\u4e2a\u6570\u636e\u5e93\u7684\u526f\u672c\u4ee5\u8fdb\u884c\u5907\u4efd\u548c\u53ef\u7528\u6027\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u6570\u636e\u5e93\u5206\u7247\u7684\u672a\u6765<\/h2>\n<p>\u968f\u7740\u6570\u636e\u91cf\u7ee7\u7eed\u5448\u6307\u6570\u7ea7\u589e\u957f\uff0c\u9ad8\u6548\u7684\u6570\u636e\u7ba1\u7406\u4ecd\u5c06\u662f\u9996\u8981\u4efb\u52a1\u3002\u673a\u5668\u5b66\u4e60\u548c\u4eba\u5de5\u667a\u80fd\u7684\u8fdb\u6b65\u53ef\u80fd\u4f1a\u5b8c\u5584\u5206\u7247\u7b56\u7565\u5e76\u8fdb\u4e00\u6b65\u5b9e\u73b0\u6d41\u7a0b\u81ea\u52a8\u5316\u3002\u6b64\u5916\uff0c\u5206\u7247\u4e0e\u57fa\u4e8e\u4e91\u7684\u6570\u636e\u5e93\u7684\u96c6\u6210\u5c06\u4e3a\u6570\u636e\u5e93\u53ef\u6269\u5c55\u6027\u548c\u6027\u80fd\u5f00\u8f9f\u65b0\u9014\u5f84\u3002<\/p>\n<h2>\u4ee3\u7406\u670d\u52a1\u5668\u548c\u6570\u636e\u5e93\u5206\u7247<\/h2>\n<p>\u4ee3\u7406\u670d\u52a1\u5668\u53ef\u4ee5\u4e0e\u6570\u636e\u5e93\u5206\u7247\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u589e\u5f3a\u6027\u80fd\u548c\u6570\u636e\u5b89\u5168\u6027\u3002\u4f8b\u5982\uff0c\u4ee3\u7406\u670d\u52a1\u5668\u53ef\u4ee5\u914d\u7f6e\u4e3a\u6839\u636e\u5206\u7247\u952e\u5c06\u8bf7\u6c42\u8def\u7531\u5230\u9002\u5f53\u7684\u5206\u7247\uff0c\u4ece\u800c\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002\u6b64\u5916\uff0c\u4ee3\u7406\u670d\u52a1\u5668\u53ef\u4ee5\u901a\u8fc7\u63d0\u4f9b\u989d\u5916\u7684\u5b89\u5168\u5c42\u6765\u5e2e\u52a9\u4fdd\u62a4\u6570\u636e\u5e93\u5206\u7247\uff0c\u4ece\u800c\u9632\u6b62\u76f4\u63a5\u8bbf\u95ee\u5206\u7247\u3002<\/p>\n<h2>\u76f8\u5173\u94fe\u63a5<\/h2>\n<ol>\n<li><a href=\"https:\/\/static.googleusercontent.com\/media\/research.google.com\/en\/\/archive\/bigtable-osdi06.pdf\" target=\"_new\" rel=\"noopener nofollow\">\u8c37\u6b4c\u7684\u5927\u8868<\/a><\/li>\n<li><a href=\"https:\/\/www.allthingsdistributed.com\/files\/amazon-dynamo-sosp2007.pdf\" target=\"_new\" rel=\"noopener nofollow\">\u4e9a\u9a6c\u900a\u7684\u53d1\u7535\u673a<\/a><\/li>\n<li><a href=\"https:\/\/docs.mongodb.com\/manual\/sharding\/\" target=\"_new\" rel=\"noopener nofollow\">MongoDB \u5206\u7247<\/a><\/li>\n<li><a href=\"https:\/\/www.postgresql.org\/docs\/current\/ddl-partitioning.html\" target=\"_new\" rel=\"noopener nofollow\">PostgreSQL \u5206\u7247<\/a><\/li>\n<\/ol>\n<p>\u603b\u4e4b\uff0c\u6570\u636e\u5e93\u5206\u7247\u662f\u7ba1\u7406\u5927\u578b\u6570\u636e\u5bc6\u96c6\u578b\u5e94\u7528\u7a0b\u5e8f\u7684\u5173\u952e\u7b56\u7565\u3002\u5b83\u662f\u6570\u636e\u5e93\u7ba1\u7406\u5458\u548c\u5f00\u53d1\u4eba\u5458\u624b\u4e2d\u7684\u5f3a\u5927\u5de5\u5177\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u9ad8\u7684\u6027\u80fd\u3001\u6539\u8fdb\u7684\u53ef\u6269\u5c55\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>","protected":false},"featured_media":468169,"menu_order":0,"template":"","meta":{"_acf_changed":false,"content-type":"","inline_featured_image":false,"footnotes":""},"class_list":["post-476741","wiki","type-wiki","status-publish","has-post-thumbnail","hentry"],"acf":{"faq_title":"Frequently Asked Questions about <mark>Database Sharding: An Essential Strategy for Data Management<\/mark>","faq_items":[{"question":"What is database sharding?","answer":"<p>Database sharding is a data management strategy where a large database is broken down into smaller, more manageable parts called \"shards.\" These shards are distributed across multiple servers to enhance performance, scalability, and reliability.<\/p>"},{"question":"When was database sharding first mentioned?","answer":"<p>Database sharding was first mentioned in the context of Google's BigTable and Amazon's Dynamo. These were early database systems designed to distribute large data sets across many servers for improved performance and scalability.<\/p>"},{"question":"How does database sharding work?","answer":"<p>Sharding works by dividing the data based on a specific sharding key. This key is used to determine the shard containing the relevant data when a query is executed. The data is then retrieved directly from that shard, bypassing the need to search the entire database.<\/p>"},{"question":"What are some key features of database sharding?","answer":"<p>Some key features of database sharding include scalability (as it distributes the database load across multiple servers), improved performance (as it allows queries to access a single shard rather than the entire database), availability and redundancy (with sharding, the failure of one shard doesn't impact the entire database), and geographical distribution (shards can be located based on the geographic location of users to reduce latency).<\/p>"},{"question":"What are the different types of database sharding?","answer":"<p>There are three main types of database sharding: horizontal sharding (where the database is divided into rows and distributed across different shards), vertical sharding (where the database is divided into columns or groups of related columns and distributed across different shards), and functional sharding (where the database is split based on functionality or business requirements).<\/p>"},{"question":"How can proxy servers be used with database sharding?","answer":"<p>Proxy servers can be used in conjunction with database sharding to enhance performance and data security. They can route requests to the appropriate shard based on the sharding key, improving query performance. Proxy servers can also provide an additional layer of security to the database shards by preventing direct access.<\/p>"}]},"_links":{"self":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/476741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki"}],"about":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/types\/wiki"}],"version-history":[{"count":0,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/wiki\/476741\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media\/468169"}],"wp:attachment":[{"href":"https:\/\/oneproxy.pro\/cn\/wp-json\/wp\/v2\/media?parent=476741"}],"curies":[{"name":"\u53ef\u6e7f\u6027\u7c89\u5242","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}