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

alter integer primary key to auto_random with certain auto_random_base #19724

Open
zz-jason opened this issue Sep 2, 2020 · 1 comment
Open
Labels
feature/reviewing This feature request is reviewing by product managers sig/sql-infra SIG: SQL Infra type/feature-request Categorizes issue or PR as related to a new feature.

Comments

@zz-jason
Copy link
Member

zz-jason commented Sep 2, 2020

Feature Request

Is your feature request related to a problem? Please describe:

Let's say we have the following table whose primary key is an integer:

create table t (
	a bigint auto_increment primary key,
	b bigint
);

or column a is defined without auto_increment:

create table t(
	a bigint primary key,
	b bigint
);

After inserting some data to table t, users may detect that there is a hot write region in the table t. Currently, users have to rebuild the table like the following:

  • define a new table whose primary column is defined as auto_random
  • rewrite all the data from the old table to the new table
  • continue to insert data to the new table, which may not have the hot write region issue

Describe the feature you'd like:

Since TiDB has auto_random property for an int primary key, it would be great to support altering the int primary column to auto_random without rebuilding the whole table. Since there is existing data in the table, it's better to set the auto_random_base to be larger than a certain value.

This issue requests to support a certain alter table statement like the following:

alter table t modify a bigint auto_random auto_random_base=?;

Describe alternatives you've considered:

N/A

Teachability, Documentation, Adoption, Migration Strategy:

N/A

@zz-jason zz-jason added the type/feature-request Categorizes issue or PR as related to a new feature. label Sep 2, 2020
@tangenta
Copy link
Contributor

tangenta commented Sep 3, 2020

If the performance of this DDL does not matter, it is possible to internally select max(a) from t and rebase to the value. So the syntax will be

alter table t modify a bigint auto_random;

@AilinKid AilinKid added the sig/sql-infra SIG: SQL Infra label Sep 4, 2020
@zz-jason zz-jason added the feature/reviewing This feature request is reviewing by product managers label Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/reviewing This feature request is reviewing by product managers sig/sql-infra SIG: SQL Infra type/feature-request Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants