数据分片

定义

Sharding Table Rule

  1. CREATE SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
  2. ALTER SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...
  3. DROP SHARDING TABLE RULE tableName [, tableName] ...
  4. shardingTableRuleDefinition:
  5. tableName(resources [, shardingColumn] [, shardingAlgorithm] [, keyGenerateStrategy])
  6. resources:
  7. RESOURCES(resourceName [, resourceName] ...))
  8. shardingColumn:
  9. SHARDING_COLUMN=columnName
  10. shardingAlgorithm:
  11. TYPE(NAME=shardingAlgorithmType [, PROPERTIES([algorithmProperties] )] )
  12. keyGenerateStrategy:
  13. GENERATED_KEY(COLUMN=columnName,strategyDefinition)
  14. strategyDefinition:
  15. TYPE(NAME=keyGenerateStrategyType [, PROPERTIES([algorithmProperties] )] )
  16. algorithmProperties:
  17. algorithmProperty [, algorithmProperty] ...
  18. algorithmProperty:
  19. key=value
  • RESOURCES 需使用 RDL 管理的数据源资源
  • shardingAlgorithmType 指定自动分片算法类型,请参考 自动分片算法
  • keyGenerateStrategyType 指定分布式主键生成策略,请参考 分布式主键
  • 重复的 tableName 将无法被创建

Sharding Binding Table Rule

  1. CREATE SHARDING BINDING TABLE RULES(bindTableRulesDefinition [, bindTableRulesDefinition] ...)
  2. ALTER SHARDING BINDING TABLE RULES(bindTableRulesDefinition [, bindTableRulesDefinition] ...)
  3. DROP SHARDING BINDING TABLE RULES
  4. bindTableRulesDefinition:
  5. (tableName [, tableName] ... )
  • ALTER 会使用新的配置直接覆盖数据库内的绑定表配置

Sharding Broadcast Table Rule

  1. CREATE SHARDING BROADCAST TABLE RULES (tableName [, tableName] ... )
  2. ALTER SHARDING BROADCAST TABLE RULES (tableName [, tableName] ... )
  3. DROP SHARDING BROADCAST TABLE RULES
  • ALTER 会使用新的配置直接覆盖数据库内的广播表配置

示例

Sharding Table Rule

  1. CREATE SHARDING TABLE RULE t_order (
  2. RESOURCES(resource_0,resource_1),
  3. SHARDING_COLUMN=order_id,
  4. TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=4)),
  5. GENERATED_KEY(COLUMN=another_id,TYPE(NAME=snowflake,PROPERTIES("worker-id"=123)))
  6. );
  7. ALTER SHARDING TABLE RULE t_order (
  8. RESOURCES(resource_0,resource_1),
  9. SHARDING_COLUMN=order_id,
  10. TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=10)),
  11. GENERATED_KEY(COLUMN=another_id,TYPE(NAME=snowflake,PROPERTIES("worker-id"=123)))
  12. );
  13. DROP SHARDING TABLE RULE t_order, t_order_item;

Sharding Binding Table Rule

  1. CREATE SHARDING BINDING TABLE RULES (
  2. (t_order,t_order_item),
  3. (t_1,t_2)
  4. );
  5. ALTER SHARDING BINDING TABLE RULES (
  6. (t_order,t_order_item)
  7. );
  8. DROP SHARDING BINDING TABLE RULES;

Sharding Broadcast Table Rule

  1. CREATE SHARDING BROADCAST TABLE RULES (t_b,t_a);
  2. ALTER SHARDING BROADCAST TABLE RULES (t_b,t_a,t_3);
  3. DROP SHARDING BROADCAST TABLE RULES;