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

CREATE DEFAULT SHARDING STRATEGY

描述

CREATE DEFAULT SHARDING STRATEGY 语法用于创建默认的分片策略

语法定义

CreateDefaultShardingStrategy ::=
  'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' '(' shardingStrategy ')'

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

algorithmDefinition ::=
  'TYPE' '(' 'NAME' '=' algorithmType ',' 'PROPERTIES'  '(' propertyDefinition ')' ')'  

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

columnName ::=
  identifier

algorithmName ::=
  identifier
  
algorithmType ::=
  string

补充说明

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

示例

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

保留字

CREATEDEFAULTSHARDINGDATABASETABLESTRATEGYTYPESHARDING_COLUMNSHARDING_COLUMNSSHARDING_ALGORITHMNAMEPROPERTIES

相关链接