复古 护眼 海天 深邃 暗黑 默认

ALTER DEFAULT SHARDING STRATEGY

描述

ALTER DEFAULT SHARDING STRATEGY 语法用于修改默认的分片策略

语法定义

AlterDefaultShardingStrategy ::=
  'ALTER' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' '(' shardingStrategy ')'

shardingStrategy ::=
  'TYPE' '=' strategyType ',' ('SHARDING_COLUMN' '=' columnName | 'SHARDING_COLUMNS' '=' columnNames) ',' 'SHARDING_ALGORITHM' '=' algorithmDefinition

strategyType ::=
  string

algorithmDefinition ::=
  'TYPE' '(' 'NAME' '=' algorithmType ',' propertiesDefinition ')'  

columnNames ::=
  columnName (',' columnName)+

columnName ::=
  identifier

algorithmType ::=
  string

propertiesDefinition ::=
  'PROPERTIES' '(' key '=' value (',' key '=' value)* ')'

key ::=
  string

value ::=
  literal

补充说明

  • 当使用复合分片算法时,需要通过 SHARDING_COLUMNS 指定多个分片键;
  • algorithmType 为分片算法类型,详细的分片算法类型信息请参考分片算法

示例

  • 修改默认分表策略
ALTER DEFAULT SHARDING TABLE STRATEGY (
    TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM(TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${user_id % 2}")))
);

保留字

ALTERDEFAULTSHARDINGDATABASETABLESTRATEGYTYPESHARDING_COLUMNSHARDING_COLUMNSSHARDING_ALGORITHMNAMEPROPERTIES

相关链接