- 当你设置了下面的内容,启动shardingsphere的时候,会提示你无法使用auto算法
autoTables:
tb_order:
actualDataSources: ds_${0..1}
shardingStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: mod
shardingAlgorithms:
mod:
type: MOD
props:
sharding-count: 2
- 这是因为autoTables字面意思就是自动表,是针对表的,当我们指定了datasources之后,此时它会自动识别sharding-count和actualDataSources
- 上面actual是ds_${0..1},sharding-count为2,那么它就能匹配到下面几种可能,也就意味着我们的数据库表名也要变成mytable_0,之所以无法使用auto算法,就是我们的实际数据库的表名没有加后面的后缀
ds_0.mytable_0 ds_1.mytable_1
sharding-count: 4
ds_0.mytable_0 ds_0.mytable_1 ds_1.mytable_0 ds_1.mytable_1
- 当我们使用shard去创建表的时候,也是如此,创建mytable_3就会放到数据库ds_1里