Logo
Sharding Algorithm

Sharding Algorithm #

Auto Sharding Algorithm #

Modulo Sharding Algorithm #

Type: MOD

Attributes:

NameDataTypeDescription
sharding-countintSharding count

Hash Modulo Sharding Algorithm #

Type: HASH_MOD

Attributes:

NameDataTypeDescription
sharding-countintSharding count

Volume Based Range Sharding Algorithm #

Type: VOLUME_RANGE

Attributes:

NameDataTypeDescription
range-lowerlongRange lower bound, throw exception if lower than bound
range-upperlongRange upper bound, throw exception if upper than bound
sharding-volumelongSharding volume

Boundary Based Range Sharding Algorithm #

Type: BOUNDARY_RANGE

Attributes:

NameDataTypeDescription
sharding-rangesStringRange of sharding border, multiple boundaries separated by commas

Auto Interval Sharding Algorithm #

Type: AUTO_INTERVAL

Attributes:

NameDataTypeDescription
datetime-lowerStringShard datetime begin boundary, pattern: yyyy-MM-dd HH:mm:ss
datetime-upperStringShard datetime end boundary, pattern: yyyy-MM-dd HH:mm:ss
sharding-secondslongMax seconds for the data in one shard, allows sharding key timestamp format seconds with time precision, but time precision after seconds is automatically erased

Consistent Hash Sharding Algorithm #

Type: SphereEx:CONSISTENT_HASH

Attributes:

NameDataTypeDescription
sharding-countintRequired item, used to specify the number of sharding.
sharding-node-weightStringIt is not a required item. The weight of sharding data nodes is separated by commas, for example: “2,2,1,1”. The larger the weight, the more virtual nodes used for consistency hash calculation, and the default weight is 1.
virtual-node-countintRequired item. The number of virtual nodes corresponding to the sharding data node. The more virtual nodes, the more balanced the sharding. But too many virtual nodes will also affect the performance.
consistent-hash-seedintIt is not required. The seed parameter of consistency hash is calculated. The default value is 0.

Standard Sharding Algorithm #

Apache ShardingSphere built-in standard sharding algorithm are:

Inline Sharding Algorithm #

With Groovy expressions, InlineShardingStrategy provides single-key support for the sharding operation of = and IN in SQL. Simple sharding algorithms can be used through a simple configuration to avoid laborious Java code developments. For example, t_user_$->{u_id % 8} means table t_user is divided into 8 tables according to u_id, with table names from t_user_0 to t_user_7. Please refer to Inline Expression for more details.

Type: INLINE

Attributes:

NameDataTypeDescriptionDefault Value
algorithm-expressionStringInline expression sharding algorithm-
allow-range-query-with-inline-sharding (?)booleanWhether range query is allowed. Note: range query will ignore sharding strategy and conduct full routingfalse

Interval Sharding Algorithm #

Type: INTERVAL

Attributes:

NameDataTypeDescriptionDefault Value
datetime-patternStringTimestamp pattern of sharding value, must can be transformed to Java LocalDateTime. For example: yyyy-MM-dd HH:mm:ss-
datetime-lowerStringDatetime sharding lower boundary, pattern is defined datetime-pattern-
datetime-upper (?)StringDatetime sharding upper boundary, pattern is defined datetime-patternNow
sharding-suffix-patternStringSuffix pattern of sharding data sources or tables, must can be transformed to Java LocalDateTime, must be consistent with datetime-interval-unit. For example: yyyyMM-
datetime-interval-amount (?)intInterval of sharding value1
datetime-interval-unit (?)StringUnit of sharding value interval, must can be transformed to Java ChronoUnit’s Enum value. For example: MONTHSDAYS

Complex Sharding Algorithm #

Complex Inline Sharding Algorithm #

Please refer to Inline Expression for more details.

Type: COMPLEX_INLINE

NameDataTypeDescriptionDefault Value
sharding-columns (?)Stringsharing column names-
algorithm-expressionStringInline expression sharding algorithm-
allow-range-query-with-inline-sharding (?)booleanWhether range query is allowed. Note: range query will ignore sharding strategy and conduct full routingfalse

Hint Sharding Algorithm #

Hint Inline Sharding Algorithm #

Please refer to Inline Expression for more details.

Type: COMPLEX_INLINE

NameDataTypeDescriptionDefault Value
algorithm-expressionStringInline expression sharding algorithm${value}

Class Based Sharding Algorithm #

Realize custom extension by configuring the sharding strategy type and algorithm class name.

Type:CLASS_BASED

Attributes:

NameDataTypeDescription
strategyStringSharding strategy type, support STANDARD, COMPLEX or HINT (case insensitive)
algorithmClassNameStringFully qualified name of sharding algorithm