Sharding

    • needs to use data source resources managed by RDL
    • shardingAlgorithmType specifies the type of automatic sharding algorithm, please refer to Auto Sharding Algorithm
    • keyGenerateStrategyType specifies the distributed primary key generation strategy, please refer to
    • auditorAlgorithmType specifies the sharding audit strategy, please refer to Sharding Audit Algorithm
    • Duplicate tableName will not be created
    • shardingAlgorithm can be reused by different Sharding Table Rule, so when executing DROP SHARDING TABLE RULE, the corresponding shardingAlgorithm will not be removed
    • To remove shardingAlgorithm, please execute DROP SHARDING ALGORITHM
    • strategyType specifies the sharding strategy, please refer to
    • Sharding Table Rule supports both Auto Table and Table at the same time. The two types are different in syntax. For the corresponding configuration file, please refer to Sharding
    • When using the autoCreativeAlgorithm way to specify shardingStrategy, a new sharding algorithm will be created automatically. The algorithm naming rule is tableName_strategyType_shardingAlgorithmType, such as t_order_database_inline

    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 bindTableRulesDefinition [, bindTableRulesDefinition] ...
    4. bindTableRulesDefinition:
    5. (tableName [, tableName] ... )
    • ALTER will overwrite the binding table configuration in the database with the new configuration
    1. CREATE SHARDING BROADCAST TABLE RULES (tableName [, tableName] ... )
    2. ALTER SHARDING BROADCAST TABLE RULES (tableName [, tableName] ... )
    3. DROP SHARDING BROADCAST TABLE RULES
    • ALTER will overwrite the broadcast table configuration in the database with the new configuration

    Example

    Sharding Table Rule

    1. CREATE SHARDING AUDITOR sharding_key_required_auditor (
    2. TYPE(NAME="DML_SHARDING_CONDITIONS")
    3. );
    4. ALTER SHARDING AUDITOR sharding_key_required_auditor (
    5. TYPE(NAME="DML_SHARDING_CONDITIONS")
    6. );
    7. DROP SHARDING AUDITOR IF EXISTS sharding_key_required_auditor;
    1. CREATE SHARDING TABLE RULE t_order (
    2. RESOURCES(resource_0,resource_1),
    3. SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="4")),
    4. KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
    5. AUDIT_STRATEGY(AUDITORS=[auditor1,auditor2],ALLOW_HINT_DISABLE=true)
    6. ALTER SHARDING TABLE RULE t_order (
    7. RESOURCES(resource_0,resource_1,resource_2,resource_3),
    8. SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="16")),
    9. KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
    10. AUDIT_STRATEGY(AUDITORS=[auditor1,auditor2],ALLOW_HINT_DISABLE=true)
    11. );
    12. DROP SHARDING TABLE RULE t_order;
    13. DROP SHARDING ALGORITHM t_order_hash_mod;
    1. CREATE SHARDING BINDING TABLE RULES (t_order,t_order_item),(t_1,t_2);
    2. ALTER SHARDING BINDING TABLE RULES (t_order,t_order_item);
    3. DROP SHARDING BINDING TABLE RULES;
    4. DROP SHARDING BINDING TABLE RULES (t_order,t_order_item);

    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;