CREATE DEFAULT SHARDING STRATEGY
Description
The CREATE DEFAULT SHARDING STRATEGY syntax is used to create a default sharding strategy
Syntax
CreateDefaultShardingStrategy ::=
'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' ifNotExists? '(' shardingStrategy ')'
ifNotExists ::=
'IF' 'NOT' 'EXISTS'
shardingStrategy ::=
'TYPE' '=' 'NONE'
| 'TYPE' '=' 'STANDARD' ',' 'SHARDING_COLUMN' '=' columnName ',' shardingAlgorithm
| 'TYPE' '=' 'COMPLEX' ',' 'SHARDING_COLUMNS' '=' columnName ',' columnName (',' columnName)* ',' shardingAlgorithm
| 'TYPE' '=' 'HINT' ',' shardingAlgorithm
shardingAlgorithm ::=
'SHARDING_ALGORITHM' '(' algorithmDefinition ')'
algorithmDefinition ::=
'TYPE' '(' 'NAME' '=' algorithmType (',' propertiesDefinition)? ')'
columnName ::=
identifier
algorithmType ::=
string
propertiesDefinition ::=
'PROPERTIES' '(' (key '=' value (',' key '=' value)*)? ')'
key ::=
string
value ::=
literalSupplement
- When using the complex sharding algorithm, multiple sharding columns need to be specified using
SHARDING_COLUMNS; algorithmTypeis the sharding algorithm type. For detailed sharding algorithm type information, please refer to Sharding Algorithm;ifNotExistsclause is used to avoidDuplicate default sharding strategyerror.
Example
- create a default sharding table strategy
-- create a default sharding table strategy
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 a default sharding table strategy with
ifNotExistsclause
CREATE DEFAULT SHARDING TABLE STRATEGY IF NOT EXISTS (
TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM(TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_${user_id % 2}")))
);Reserved word
CREATE, DEFAULT, SHARDING, DATABASE, TABLE, STRATEGY, TYPE, SHARDING_COLUMN, SHARDING_COLUMNS, SHARDING_ALGORITHM, NAME, PROPERTIES