Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: MonthMod shard algorithm #122

Open
dk-lockdown opened this issue May 31, 2022 · 2 comments
Open

feature: MonthMod shard algorithm #122

dk-lockdown opened this issue May 31, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@dk-lockdown
Copy link
Collaborator

dk-lockdown commented May 31, 2022

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
}

type MonthMod struct {

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 dk-lockdown added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels May 31, 2022
@tanryberdi
Copy link
Contributor

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

@dk-lockdown
Copy link
Collaborator Author

dk-lockdown commented Jun 1, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants