CREATE DEFAULT SHARDING STRATEGY

Description

The CREATE DEFAULT SHARDING STRATEGY syntax is used to create a default sharding strategy

Syntax

  1. CreateDefaultShardingStrategy ::=
  2. 'CREATE' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' '(' shardingStrategy ')'
  3. shardingStrategy ::=
  4. 'TYPE' '=' strategyType ',' ( 'SHARDING_COLUMN' '=' columnName | 'SHARDING_COLUMNS' '=' columnNames ) ',' ( 'SHARDING_ALGORITHM' '=' algorithmName | algorithmDefinition )
  5. algorithmDefinition ::=
  6. 'TYPE' '(' 'NAME' '=' algorithmType ( ',' 'PROPERTIES' '(' propertyDefinition ')' )?')'
  7. columnNames ::=
  8. columnName (',' columnName)+
  9. columnName ::=
  10. identifier
  11. algorithmName ::=
  12. identifier
  13. algorithmType ::=
  14. string

Supplement

  • When using the complex sharding algorithm, multiple sharding columns need to be specified using SHARDING_COLUMNS;
  • algorithmType is the sharding algorithm type. For detailed sharding algorithm type information, please refer to Sharding Algorithm.

Example

1.Create a default sharding strategy by using an existing sharding algorithm

  1. -- create a sharding algorithm
  2. CREATE SHARDING ALGORITHM database_inline (
  3. TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_${order_id % 2}"))
  4. );
  5. -- create a default sharding database strategy
  6. CREATE DEFAULT SHARDING DATABASE STRATEGY (
  7. TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM=database_inline
  8. );

2.Create sharding algorithm and default sharding table strategy at the same time

  1. -- create a default sharding table strategy
  2. CREATE DEFAULT SHARDING TABLE STRATEGY (
  3. TYPE="standard", SHARDING_COLUMN=user_id, SHARDING_ALGORITHM(TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_${user_id % 2}")))
  4. );

Reserved word

CREATE, DEFAULT, SHARDING, DATABASE, TABLE, STRATEGY, TYPE, SHARDING_COLUMN, SHARDING_COLUMNS, SHARDING_ALGORITHM, NAME, PROPERTIES