返回介绍

数据分片

发布于 2021-09-25 22:17:11 字数 3540 浏览 992 评论 0 收藏 0

定义

Sharding Table Rule

CREATE SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...

ALTER SHARDING TABLE RULE shardingTableRuleDefinition [, shardingTableRuleDefinition] ...

DROP SHARDING TABLE RULE tableName [, tableName] ...

DROP SHARDING ALGORITHM algorithmName [, algorithmName] ...

shardingTableRuleDefinition:
    tableName(resources [, shardingColumn] [, shardingAlgorithm] [, keyGenerateStrategy])

resources:
    RESOURCES(resourceName [, resourceName] ...))

shardingColumn:
    SHARDING_COLUMN=columnName

shardingAlgorithm:
    TYPE(NAME=shardingAlgorithmType [, PROPERTIES([algorithmProperties] )] )

keyGenerateStrategy:
    GENERATED_KEY(COLUMN=columnName,strategyDefinition)

strategyDefinition:
    TYPE(NAME=keyGenerateStrategyType [, PROPERTIES([algorithmProperties] )] )

algorithmProperties:
    algorithmProperty [, algorithmProperty] ...

algorithmProperty:
    key=value                          
  • RESOURCES 需使用 RDL 管理的数据源资源
  • shardingAlgorithmType 指定自动分片算法类型,请参考 自动分片算法
  • keyGenerateStrategyType 指定分布式主键生成策略,请参考 分布式主键
  • 重复的 tableName 将无法被创建
  • shardingAlgorithm 能够被不同的 Sharding Table Rule 复用,因此在执行 DROP SHARDING TABLE RULE 时,对应的 shardingAlgorithm 不会被移除
  • 如需移除 shardingAlgorithm,请执行 DROP SHARDING ALGORITHM

Sharding Binding Table Rule

CREATE SHARDING BINDING TABLE RULES(bindTableRulesDefinition [, bindTableRulesDefinition] ...)

ALTER SHARDING BINDING TABLE RULES(bindTableRulesDefinition [, bindTableRulesDefinition] ...)

DROP SHARDING BINDING TABLE RULES

bindTableRulesDefinition:
    (tableName [, tableName] ... )
  • ALTER 会使用新的配置直接覆盖数据库内的绑定表配置

Sharding Broadcast Table Rule

CREATE SHARDING BROADCAST TABLE RULES (tableName [, tableName] ... )

ALTER SHARDING BROADCAST TABLE RULES (tableName [, tableName] ... )

DROP SHARDING BROADCAST TABLE RULES
  • ALTER 会使用新的配置直接覆盖数据库内的广播表配置

示例

Sharding Table Rule

CREATE SHARDING TABLE RULE t_order (
RESOURCES(resource_0,resource_1),
SHARDING_COLUMN=order_id,
TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=4)),
GENERATED_KEY(COLUMN=another_id,TYPE(NAME=snowflake,PROPERTIES("worker-id"=123)))
);

ALTER SHARDING TABLE RULE t_order (
RESOURCES(resource_0,resource_1),
SHARDING_COLUMN=order_id,
TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=10)),
GENERATED_KEY(COLUMN=another_id,TYPE(NAME=snowflake,PROPERTIES("worker-id"=123)))
);

DROP SHARDING TABLE RULE t_order, t_order_item;

DROP SHARDING ALGORITHM t_order_hash_mod;

Sharding Binding Table Rule

CREATE SHARDING BINDING TABLE RULES (
(t_order,t_order_item),
(t_1,t_2)
);

ALTER SHARDING BINDING TABLE RULES (
(t_order,t_order_item)
);

DROP SHARDING BINDING TABLE RULES;

Sharding Broadcast Table Rule

CREATE SHARDING BROADCAST TABLE RULES (t_b,t_a);

ALTER SHARDING BROADCAST TABLE RULES (t_b,t_a,t_3);

DROP SHARDING BROADCAST TABLE RULES;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文