ALTER SHARDING TABLE RULE
语法用于修改当前所选逻辑库的分片规则。
AlterShardingTableRule ::=
'ALTER' 'SHARDING' 'TABLE' 'RULE' (tableRuleDefinition | autoTableRuleDefinition) (',' (tableRuleDefinition | autoTableRuleDefinition))*
tableRuleDefinition ::=
ruleName '(' 'DATANODES' '(' dataNode (',' dataNode)* ')' (',' 'DATABASE_STRATEGY' '(' strategyDefinition ')')? (',' 'TABLE_STRATEGY' '(' strategyDefinition ')')? (',' 'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')')? (',' 'AUDIT_STRATEGY' '(' auditStrategyDefinition ')')? ')'
autoTableRuleDefinition ::=
ruleName '(' 'STORAGE_UNITS' '(' storageUnitName (',' storageUnitName)* ')' ',' 'SHARDING_COLUMN' '=' columnName ',' algorithmDefinition (',' 'KEY_GENERATE_STRATEGY' '(' keyGenerateStrategyDefinition ')')? (',' 'AUDIT_STRATEGY' '(' auditStrategyDefinition ')')? ')'
strategyDefinition ::=
'TYPE' '=' strategyType ',' ('SHARDING_COLUMN' | 'SHARDING_COLUMNS') '=' columnName ',' algorithmDefinition
keyGenerateStrategyDefinition ::=
'KEY_GENERATE_STRATEGY' '(' 'COLUMN' '=' columnName ',' algorithmDefinition ')'
auditStrategyDefinition ::=
'AUDIT_STRATEGY' '(' algorithmDefinition (',' algorithmDefinition)* ')'
algorithmDefinition ::=
'TYPE' '(' 'NAME' '=' algorithmType (',' propertiesDefinition)?')'
propertiesDefinition ::=
'PROPERTIES' '(' key '=' value (',' key '=' value)* ')'
key ::=
string
value ::=
literal
ruleName ::=
identifier
dataNode ::=
string
storageUnitName ::=
identifier
columnName ::=
identifier
strategyType ::=
string
algorithmType ::=
string
tableRuleDefinition
为标准分片规则定义;autoTableRuleDefinition
为自动分片规则定义。标准分片规则和自动分片规则可参考数据分片;DATANODES
只能使用已经添加到当前逻辑库的资源,且只能使用 INLINE 表达式指定需要的资源;DATABASE_STRATEGY
、TABLE_STRATEGY
表示分库和分表策略,均为可选项,未配置时使用默认策略;strategyDefinition
中属性 TYPE
用于指定分片算法的类型,目前仅支持 STANDARD
、COMPLEX
。使用 COMPLEX
时需要用 SHARDING_COLUMNS
指定多个分片键。STORAGE_UNITS
只能使用已经添加到当前逻辑库的资源,可通过枚举或 INLINE 表达式指定需要的资源;algorithmType
为分片算法类型,分片算法类型请参考分片算法;tableName
_ strategyType
_ algorithmType
;tableName
_ strategyType
;KEY_GENERATE_STRATEGY
用于指定主键生成策略,为可选项,关于主键生成策略可参考分布式主键。AUDIT_STRATEGY
用于指定分配审计生成策略,为可选项,关于分片审计生成策略可参考分片审计。ALTER SHARDING TABLE RULE t_order_item (
DATANODES("ds_${0..3}.t_order_item${0..3}"),
DATABASE_STRATEGY(TYPE="standard",SHARDING_COLUMN=user_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="ds_${user_id % 4}")))),
TABLE_STRATEGY(TYPE="standard",SHARDING_COLUMN=order_id,SHARDING_ALGORITHM(TYPE(NAME="inline",PROPERTIES("algorithm-expression"="t_order_item_${order_id % 4}")))),
KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
AUDIT_STRATEGY(TYPE(NAME="dml_sharding_conditions"),ALLOW_HINT_DISABLE=true)
);
ALTER SHARDING TABLE RULE t_order (
STORAGE_UNITS(ds_0,ds_1,ds_2,ds_3),
SHARDING_COLUMN=order_id,TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="16")),
KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME="snowflake")),
AUDIT_STRATEGY(TYPE(NAME="dml_sharding_conditions"),ALLOW_HINT_DISABLE=true)
);
ALTER
、SHARDING
、TABLE
、RULE
、DATANODES
、DATABASE_STRATEGY
、TABLE_STRATEGY
、KEY_GENERATE_STRATEGY
、STORAGE_UNITS
、SHARDING_COLUMN
、TYPE
、SHARDING_COLUMN
、KEY_GENERATOR
、SHARDING_ALGORITHM
、COLUMN
、NAME
、PROPERTIES
、AUDIT_STRATEGY
、AUDITORS
、ALLOW_HINT_DISABLE