ALTER DEFAULT SHARDING STRATEGY

Description

The ALTER DEFAULT SHARDING STRATEGY syntax is used to alter a default sharding strategy

Syntax

Grammar Railroad diagram

  1. AlterDefaultShardingStrategy ::=
  2. 'ALTER' 'DEFAULT' 'SHARDING' ('DATABASE' | 'TABLE') 'STRATEGY' '(' shardingStrategy ')'
  3. shardingStrategy ::=
  4. 'TYPE' '=' strategyType ',' ('SHARDING_COLUMN' '=' columnName | 'SHARDING_COLUMNS' '=' columnNames) ',' 'SHARDING_ALGORITHM' '=' algorithmDefinition
  5. strategyType ::=
  6. string
  7. algorithmDefinition ::=
  8. 'TYPE' '(' 'NAME' '=' algorithmType ',' propertiesDefinition ')'
  9. columnNames ::=
  10. columnName (',' columnName)+
  11. columnName ::=
  12. identifier
  13. algorithmType ::=
  14. string
  15. propertiesDefinition ::=
  16. 'PROPERTIES' '(' key '=' value (',' key '=' value)* ')'
  17. key ::=
  18. string
  19. value ::=
  20. literal

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

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

Reserved word

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