CREATE SHARDING ALGORITHM

Description

The CREATE SHARDING ALGORITHM syntax is used to create a sharding algorithm for the currently selected database.

Syntax

  1. CreateShardingAlgorithm ::=
  2. 'CREATE' 'SHARDING' 'ALGORITHM' shardingAlgorithmName '(' algorithmDefinition ')'
  3. algorithmDefinition ::=
  4. 'TYPE' '(' 'NAME' '=' algorithmType ( ',' 'PROPERTIES' '(' propertyDefinition ')' )?')'
  5. propertyDefinition ::=
  6. ( key '=' value ) ( ',' key '=' value )*
  7. shardingAlgorithmName ::=
  8. identifier
  9. algorithmType ::=
  10. string

Supplement

  • algorithmType is the sharding algorithm type. For detailed sharding algorithm type information, please refer to Sharding Algorithm.

Example

1.Create sharding algorithms

  1. -- create a sharding algorithm of type INLINE
  2. CREATE SHARDING ALGORITHM inline_algorithm (
  3. TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_${user_id % 2}"))
  4. );
  5. -- create a sharding algorithm of type AUTO_INTERVAL
  6. CREATE SHARDING ALGORITHM interval_algorithm (
  7. TYPE(NAME="auto_interval", PROPERTIES("datetime-lower"="2022-01-01 00:00:00", "datetime-upper"="2022-01-03 00:00:00", "sharding-seconds"="86400"))
  8. );

Reserved word

CREATE, SHARDING, ALGORITHM, TYPE, NAME, PROPERTIES