dbpack icon indicating copy to clipboard operation
dbpack copied to clipboard

feature: `MonthMod` shard algorithm

Open dk-lockdown opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

implement ShardingAlgorithm interface.

type ShardingAlgorithm interface {
	HasShardingKey(key string) bool
	Shard(condition *KeyCondition) (Condition, error)
	ShardRange(cond1, cond2 *KeyCondition) (Condition, error)
	AllShards() Condition
	AllowFullScan() bool
}

https://github.com/CECTC/dbpack/blob/0ae8c774106b58f5dbbfa045d4a8591fb913c929/pkg/cond/sharding_algorithm.go#L226

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

dk-lockdown avatar May 31 '22 08:05 dk-lockdown

@dk-lockdown could you please explain with more details? 🙏 I was not clear for me, please man

tanryberdi avatar Jun 01 '22 08:06 tanryberdi

@dk-lockdown could you please explain with more details? 🙏 I was not clear for me, please man

If a column of the table is of type date, and the sharding algorithm is sharded by month. When execute select * from t where day > 2020-01-05 and day < 2020-05-05, and the sharding key is day, the sharding algorithm is Month(day) mod 12, the sharding result will be calculated for January to May, so the sql will be rewritten as:

select * from t_1 where day > 2020-01-05 and day < 2020-05-05;
select * from t_2 where day > 2020-01-05 and day < 2020-05-05;
select * from t_3 where day > 2020-01-05 and day < 2020-05-05;
select * from t_4 where day > 2020-01-05 and day < 2020-05-05;
select * from t_5 where day > 2020-01-05 and day < 2020-05-05;

Then aggregate the query results.

dk-lockdown avatar Jun 01 '22 13:06 dk-lockdown