The CREATE DEFAULT SHARDING STRATEGY
syntax is used to create a default sharding strategy
CreateDefaultShardingStrategy ::=
'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' ifNotExists? '(' shardingStrategy ')'
ifNotExists ::=
'IF' 'NOT' 'EXISTS'
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
is the sharding algorithm type. For detailed sharding algorithm type information, please refer
to Sharding Algorithm;ifNotExists
clause is used for avoid Duplicate default sharding strategy
error.-- 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}")))
);
ifNotExists
clauseCREATE 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}")))
);
CREATE
, DEFAULT
, SHARDING
, DATABASE
, TABLE
, STRATEGY
, TYPE
, SHARDING_COLUMN
, SHARDING_COLUMNS
, SHARDING_ALGORITHM
, NAME
, PROPERTIES