[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"site-config":3,"primary-menu":20,"cat-sharding":99,"catposts-sharding":112,"post-detail-post-sharding-shardingsphere-9d880c74":221},{"config":4,"socialLinks":19},{"title":5,"subtitle":6,"logoUrl":7,"faviconUrl":8,"footerText":9,"beianIcp":10,"beianPublicSecurity":9,"seoDescription":11,"seoKeywords":12,"homepageTitle":13,"homepageSubtitle":14,"analyticsHeadCode":15,"planetQrcodeUrl":16,"planetIntroHtml":9,"planetCtaText":17,"updatedAt":18},"编码世界","用编码改变世界","\u002Fupload\u002F2026\u002F09\u002F2f277021172f43f6bb34e1c115760b7f.png","\u002Fupload\u002F2026\u002F09\u002Fdcbad022e68c4a729a5dc4997a9bba8a.png","","苏ICP备2026073884号","编码世界（mashangan.com）是面向 Java 后端与 Go 语言的系统化编程教程站：提供\nMyBatis Plus、Lombok、Java 8、IDEA、Docker 等原创图文教程，以及 JVM、并发、\nSpring、MySQL、Redis、消息队列、计算机网络等大厂面试八股题库，另有可落地的\n项目实战系列，帮你从入门到精通。","编码世界,Java教程,Go语言教程,Docker教程,MyBatis Plus教程,Lombok教程, Java 8新特性,IDEA教程,Java面试题,八股文,JVM面试题,Java并发面试题, MySQL面试题,Redis面试题,Spring面试题,消息队列面试题,高并发,分库分表, Netty面试题,计算机网络面试题,AI Agent,RAG,程序员学习路线","Java全栈系统化编程教程","覆盖 MyBatis Plus、Lombok、Java 8、IDEA、Go、Docker 等原创图文教程，配套大厂面试八股题库，从入门到精通，持续更新","\u003Cscript>\nvar _hmt = _hmt || [];\n(function() {\n  var hm = document.createElement(\"script\");\n  hm.src = \"https:\u002F\u002Fhm.baidu.com\u002Fhm.js?f00af7e56d956c02e11efed4131379b0\";\n  var s = document.getElementsByTagName(\"script\")[0]; \n  s.parentNode.insertBefore(hm, s);\n})();\n\u003C\u002Fscript>\n","\u002Fupload\u002F2026\u002F09\u002Fc1a8f5de46584d3eb0bc762c180a5db9.png","扫码加入知识星球","2026-09-29T14:56:02.498693Z",[],{"metadata":21,"spec":24,"menuItems":34},{"name":22,"creationTimestamp":23},"primary","2026-09-12T06:13:55.024154Z",{"displayName":25,"menuItems":26},"主菜单",[27,28,29,30,31,32,33],"88c3f10b-321c-4092-86a8-70db00251b74","menu-item-izrtmxer","c4c814d1-0c2c-456b-8c96-4864965fee94","menu-item-column","menu-item-tools","menu-item-zsxq","menu-item-ocrxlczu",[35,44,54,63,72,81,90],{"displayName":36,"metadata":37,"spec":39,"status":42,"children":43},"首页",{"name":27,"creationTimestamp":38},"2026-09-12T06:13:54.422830Z",{"displayName":36,"href":40,"priority":41,"menuName":22},"\u002F",0,{"displayName":36,"href":40},[],{"displayName":45,"metadata":46,"spec":48,"status":52,"children":53},"Java面试八股",{"name":28,"creationTimestamp":47},"2026-09-13T09:42:02.854891Z",{"displayName":45,"href":49,"target":50,"priority":51,"menuName":22},"\u002Fjava-interview","_self",1,{"displayName":45,"href":49},[],{"displayName":55,"metadata":56,"spec":58,"status":61,"children":62},"文章",{"name":29,"creationTimestamp":57},"2026-09-12T06:13:54.457307Z",{"displayName":55,"href":59,"priority":60,"menuName":22},"\u002Farchives",2,{"displayName":55,"href":59},[],{"displayName":64,"metadata":65,"spec":67,"status":70,"children":71},"项目实战",{"name":30,"creationTimestamp":66},"2026-09-14T00:35:08.138170Z",{"displayName":64,"href":68,"target":50,"priority":69,"menuName":22},"\u002Fcolumn",3,{"displayName":64,"href":68},[],{"displayName":73,"metadata":74,"spec":76,"status":79,"children":80},"在线工具",{"name":31,"creationTimestamp":75},"2026-09-14T00:35:08.171474Z",{"displayName":73,"href":77,"target":50,"priority":78,"menuName":22},"\u002Ftools",4,{"displayName":73,"href":77},[],{"displayName":82,"metadata":83,"spec":85,"status":88,"children":89},"知识星球",{"name":32,"creationTimestamp":84},"2026-09-14T00:35:08.199145Z",{"displayName":82,"href":86,"target":50,"priority":87,"menuName":22},"\u002Fzsxq",5,{"displayName":82,"href":86},[],{"displayName":91,"metadata":92,"spec":94,"status":97,"children":98},"特价云服务器",{"name":33,"creationTimestamp":93},"2026-09-25T15:30:59.201614Z",{"displayName":91,"href":95,"target":50,"priority":96,"menuName":22},"\u002Fserver",6,{"displayName":91,"href":95},[],{"metadata":100,"spec":105,"status":110,"postCount":87},{"name":101,"creationTimestamp":102,"labels":103},"sharding","2026-09-13T09:13:26.020943Z",{"haloweb.section":104},"interview",{"displayName":106,"slug":101,"cover":9,"description":107,"priority":108,"hideFromList":109,"preventParentPostCascadeQuery":109},"分库分表面试题","分库分表面试题：分片策略、路由扩容、分布式主键、跨片查询与数据一致性方案。",30,false,{"permalink":111,"postCount":87,"visiblePostCount":87},"\u002Fcategories\u002Fsharding",[113,137,158,179,200],{"metadata":114,"spec":117,"status":126,"categories":131},{"name":115,"creationTimestamp":116},"post-sharding-shardingsphere-9d880c74","2026-09-13T10:01:13.510910Z",{"title":118,"slug":119,"cover":9,"excerpt":120,"publishTime":122,"categories":123,"tags":124,"priority":41,"pinned":109,"deleted":109,"visible":125,"allowComment":121},"ShardingSphere 的核心功能？","sharding-shardingsphere",{"raw":9,"autoGenerate":121},true,"2026-09-13T10:01:13.565762Z",[101],[],"PUBLIC",{"permalink":127,"excerpt":128,"lastModifyTime":129,"phase":130},"\u002Farchives\u002Fsharding-shardingsphere","一、定位 ShardingSphere 是分布式数据库中间件，提供分库分表、读写分离、数据加密等能力。 二、三种模式 ShardingSphere-JDBC：嵌入应用，JAR 包方式，性能好但只支持 Java。 ShardingSphere-Proxy：独立部署代理，支持多语言，有网络开销。 Sha","2026-09-16T09:16:37.209427Z","PUBLISHED",[132],{"metadata":133,"spec":135,"status":136,"postCount":87},{"name":101,"creationTimestamp":102,"labels":134},{"haloweb.section":104},{"displayName":106,"slug":101,"cover":9,"description":107,"priority":108,"hideFromList":109,"preventParentPostCascadeQuery":109},{"permalink":111,"postCount":87,"visiblePostCount":87},{"metadata":138,"spec":141,"status":148,"categories":152},{"name":139,"creationTimestamp":140},"post-sharding-migration-5d5ab7fd","2026-09-13T10:01:13.348573Z",{"title":142,"slug":143,"cover":9,"excerpt":144,"publishTime":145,"categories":146,"tags":147,"priority":41,"pinned":109,"deleted":109,"visible":125,"allowComment":121},"分库分表扩容如何平滑迁移？","sharding-migration",{"raw":9,"autoGenerate":121},"2026-09-13T10:01:13.392795Z",[101],[],{"permalink":149,"excerpt":150,"lastModifyTime":151,"phase":130},"\u002Farchives\u002Fsharding-migration","一、取模扩容问题 user_id % 4 改为 % 8，大部分数据需要迁移。 二、方案一：停机迁移 停机，写脚本把数据按新规则重新分配。 简单但有停机时间。 三、方案二：双写 + 迁移 新数据同时写旧分片和新分片。 后台把旧数据迁移到新分片。 校验一致后，切读到新分片。 停写旧分片。 - 不停机但复","2026-09-16T09:16:38.181057Z",[153],{"metadata":154,"spec":156,"status":157,"postCount":87},{"name":101,"creationTimestamp":102,"labels":155},{"haloweb.section":104},{"displayName":106,"slug":101,"cover":9,"description":107,"priority":108,"hideFromList":109,"preventParentPostCascadeQuery":109},{"permalink":111,"postCount":87,"visiblePostCount":87},{"metadata":159,"spec":162,"status":169,"categories":173},{"name":160,"creationTimestamp":161},"post-sharding-id-gen-2d3d5a55","2026-09-13T10:01:13.134819Z",{"title":163,"slug":164,"cover":9,"excerpt":165,"publishTime":166,"categories":167,"tags":168,"priority":41,"pinned":109,"deleted":109,"visible":125,"allowComment":121},"分布式 ID 生成方案有哪些？","sharding-id-gen",{"raw":9,"autoGenerate":121},"2026-09-13T10:01:13.220993Z",[101],[],{"permalink":170,"excerpt":171,"lastModifyTime":172,"phase":130},"\u002Farchives\u002Fsharding-id-gen","一、UUID 优点：本地生成，无网络开销，唯一。 缺点：无序，索引效率低；太长。 二、数据库自增 优点：简单，有序。 缺点：单库瓶颈；分库后不全局唯一。 三、号段模式 从数据库批量获取 ID 段（如 1-1000），在内存中使用。 优点：性能高，减少数据库压力。 缺点：服务重启可能断号。 四、Sno","2026-09-16T09:16:35.488658Z",[174],{"metadata":175,"spec":177,"status":178,"postCount":87},{"name":101,"creationTimestamp":102,"labels":176},{"haloweb.section":104},{"displayName":106,"slug":101,"cover":9,"description":107,"priority":108,"hideFromList":109,"preventParentPostCascadeQuery":109},{"permalink":111,"postCount":87,"visiblePostCount":87},{"metadata":180,"spec":183,"status":190,"categories":194},{"name":181,"creationTimestamp":182},"post-sharding-key-7d06fbdb","2026-09-13T10:01:12.933408Z",{"title":184,"slug":185,"cover":9,"excerpt":186,"publishTime":187,"categories":188,"tags":189,"priority":41,"pinned":109,"deleted":109,"visible":125,"allowComment":121},"如何选择分片键？","sharding-key",{"raw":9,"autoGenerate":121},"2026-09-13T10:01:12.988421Z",[101],[],{"permalink":191,"excerpt":192,"lastModifyTime":193,"phase":130},"\u002Farchives\u002Fsharding-key","一、选择原则 查询频率高：最常用的查询条件字段，如 user_id、order_id。 分布均匀：避免数据倾斜，如不要用性别（只有两个值）。 业务关联：关联表用相同分片键，减少跨库 join。 不可变：分片键值一旦确定不能改。 二、常见分片键 用户 ID：用户相关数据，如订单按 user_id 分片","2026-09-16T09:16:36.607917Z",[195],{"metadata":196,"spec":198,"status":199,"postCount":87},{"name":101,"creationTimestamp":102,"labels":197},{"haloweb.section":104},{"displayName":106,"slug":101,"cover":9,"description":107,"priority":108,"hideFromList":109,"preventParentPostCascadeQuery":109},{"permalink":111,"postCount":87,"visiblePostCount":87},{"metadata":201,"spec":204,"status":211,"categories":215},{"name":202,"creationTimestamp":203},"post-sharding-strategy-f725fb51","2026-09-13T10:01:12.754097Z",{"title":205,"slug":206,"cover":9,"excerpt":207,"publishTime":208,"categories":209,"tags":210,"priority":41,"pinned":109,"deleted":109,"visible":125,"allowComment":121},"分库分表有哪些策略？","sharding-strategy",{"raw":9,"autoGenerate":121},"2026-09-13T10:01:12.803252Z",[101],[],{"permalink":212,"excerpt":213,"lastModifyTime":214,"phase":130},"\u002Farchives\u002Fsharding-strategy","一、垂直拆分 垂直分库：按业务拆分库，如用户库、订单库、商品库。 垂直分表：按字段拆分表，如主表存常用字段，扩展表存大字段。 解决：单库压力、单表字段过多。 二、水平拆分 水平分库：同一张表数据按规则分到多个库。 水平分表：同一张表数据按规则分到多张表。 解决：单表数据量过大。 三、分片规则 范围：","2026-09-16T09:16:35.972485Z",[216],{"metadata":217,"spec":219,"status":220,"postCount":87},{"name":101,"creationTimestamp":102,"labels":218},{"haloweb.section":104},{"displayName":106,"slug":101,"cover":9,"description":107,"priority":108,"hideFromList":109,"preventParentPostCascadeQuery":109},{"permalink":111,"postCount":87,"visiblePostCount":87},{"metadata":222,"spec":223,"status":227,"categories":228,"content":234},{"name":115,"creationTimestamp":116},{"title":118,"slug":119,"cover":9,"excerpt":224,"publishTime":122,"categories":225,"tags":226,"priority":41,"pinned":109,"deleted":109,"visible":125,"allowComment":121},{"raw":9,"autoGenerate":121},[101],[],{"permalink":127,"excerpt":128,"lastModifyTime":129,"phase":130},[229],{"metadata":230,"spec":232,"status":233,"postCount":87},{"name":101,"creationTimestamp":102,"labels":231},{"haloweb.section":104},{"displayName":106,"slug":101,"cover":9,"description":107,"priority":108,"hideFromList":109,"preventParentPostCascadeQuery":109},{"permalink":111,"postCount":87,"visiblePostCount":87},{"content":235,"raw":235},"\u003Ch2>一、定位\u003C\u002Fh2>\n\u003Cp>ShardingSphere 是分布式数据库中间件，提供分库分表、读写分离、数据加密等能力。\u003C\u002Fp>\n\u003Ch2>二、三种模式\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>ShardingSphere-JDBC\u003C\u002Fstrong>：嵌入应用，JAR 包方式，性能好但只支持 Java。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>ShardingSphere-Proxy\u003C\u002Fstrong>：独立部署代理，支持多语言，有网络开销。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>ShardingSphere-Sidecar\u003C\u002Fstrong>：云原生，Service Mesh 模式。\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>三、核心功能\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>数据分片\u003C\u002Fstrong>：分库分表，支持多种分片算法。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>分布式事务\u003C\u002Fstrong>：XA、BASE（柔性事务）。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>读写分离\u003C\u002Fstrong>：主写从读，负载均衡。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>数据加密\u003C\u002Fstrong>：透明加解密。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>影子库\u003C\u002Fstrong>：压测数据隔离。\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>四、分片算法\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>精确分片（PreciseShardingAlgorithm）：= 和 IN。\u003C\u002Fli>\n\u003Cli>范围分片（RangeShardingAlgorithm）：BETWEEN。\u003C\u002Fli>\n\u003Cli>复合分片（ComplexKeysShardingAlgorithm）：多字段。\u003C\u002Fli>\n\u003Cli>Hint 分片：强制指定分片。\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>五、注意\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>不支持跨库事务（XA 除外，性能差）。\u003C\u002Fli>\n\u003Cli>不支持跨库 join、子查询（部分支持）。\u003C\u002Fli>\n\u003Cli>分布式主键需配置。\u003C\u002Fli>\n\u003C\u002Ful>"]