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

ddl: support alter table auto_increment #5472

Merged
merged 12 commits into from
Dec 27, 2017
Merged

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Dec 22, 2017

Fix #5034 PTAL @zimulala

@shenli
Copy link
Member

shenli commented Dec 22, 2017

/run-all-tests

ddl/ddl_api.go Outdated
case ast.AlterTableOption:
for _, opt := range spec.Options {
if opt.Tp == ast.TableOptionAutoIncrement {
err = d.RebaseAutoID(ctx, ident, int64(opt.UintValue-1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is opt.UintValue-1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is compatible with MySQL, if we set auto_increment = 10, the next auto increment insert column should take 10.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int64(opt.UintValue)-1 should be better. I'll fix it.

ddl/ddl_api.go Outdated
if err != nil {
return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name))
}
return t.RebaseAutoID(ctx, newBase, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd better clear all TiDBs' cache.
So you can add a DDL Job likes https://github.com/pingcap/tidb/blob/master/ddl/ddl_api.go#L72
Then you can clear cache when we load the schema.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. PTAL @zimulala

@jackysp
Copy link
Member Author

jackysp commented Dec 25, 2017

/run-all-tests

job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}
tblInfo.AutoIncID = newBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check that if the new auto-id is not less than current id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, though it will be checked in storage, it should set a more properly info here. Fixed.

if err != nil {
return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ident.Schema, ident.Name))
}
autoIncID, err := t.Allocator(ctx).NextGlobalAutoID(t.Meta().ID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd can put this logical to onRebaseAutoID。Because now autoIncID is n,its value may change when you rebase the global auto ID in onRebaseAutoID

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another check in storage node to guarantee the value be set properly. The comparison here is trying to set a more reasonable value in table info.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that the global auto-id is not the current max id, for example, if the current max id is 1, the new base is 1000, then the next id inserted will be 5001. Is it desirable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is our expected result. I'll add a test for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. PTAL @lamxTyler

{"alter table t add column c int auto_increment key, auto_increment=10", true,
errors.New("[autoid:3]No support for setting auto_increment using alter_table")},
{"alter table t auto_increment=1", true, nil},
{"alter table t add column c int auto_increment key, auto_increment=10", true, nil},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SQL is different with SQL in 78. Should we add tests in ddl_db_test.go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! PTAL @zimulala

@zimulala
Copy link
Contributor

LGTM

@jackysp
Copy link
Member Author

jackysp commented Dec 26, 2017

/run-all-tests

@jackysp jackysp added all-tests-passed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 26, 2017
Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alivxxx
Copy link
Contributor

alivxxx commented Dec 27, 2017

/run-all-tests

@alivxxx
Copy link
Contributor

alivxxx commented Dec 27, 2017

/run-sqllogic-test

1 similar comment
@jackysp
Copy link
Member Author

jackysp commented Dec 27, 2017

/run-sqllogic-test

@alivxxx alivxxx merged commit 427b02e into pingcap:master Dec 27, 2017
@jackysp jackysp deleted the auto_increment branch December 27, 2017 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support change auto_increment definition using alter table ... change/modify
4 participants