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 ::=
identifier
SHARDING_COLUMNS
指定多个分片键;algorithmType
为分片算法类型,详细的分片算法类型信息请参考分片算法。-- 创建分片算法
CREATE SHARDING ALGORITHM database_inline (
TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_${order_id % 2}"))
);
-- 创建默认分库策略
CREATE DEFAULT SHARDING DATABASE STRATEGY (
TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM=database_inline
);
-- 创建默认分表策略
CREATE DEFAULT SHARDING TABLE STRATEGY (
TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM(TYPE(NAME=inline, PROPERTIES("algorithm-expression"="t_order_${user_id % 2}")))
);
CREATE
、DEFAULT
、SHARDING
、DATABASE
、TABLE
、STRATEGY
、TYPE
、SHARDING_COLUMN
、SHARDING_COLUMNS
、SHARDING_ALGORITHM
、NAME
、PROPERTIES