ddl: allow altering auto_increment to a large number (#19241)
* ddl: allow altering auto_increment to a large number * fix the edge case problem of auto_inc option * revert last commit Co-authored-by: Arenatlx <ailinsilence4@gmail.com> Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
This commit is contained in:
@ -2401,16 +2401,26 @@ func (s *testIntegrationSuite5) TestDropColumnsWithMultiIndex(c *C) {
|
||||
tk.MustQuery(query).Check(testkit.Rows())
|
||||
}
|
||||
|
||||
func (s *testIntegrationSuite7) TestAutoIncrementAllocator(c *C) {
|
||||
func (s *testIntegrationSuite7) TestAutoIncrementTableOption(c *C) {
|
||||
tk := testkit.NewTestKit(c, s.store)
|
||||
defer config.RestoreFunc()()
|
||||
config.UpdateGlobal(func(conf *config.Config) {
|
||||
// Make sure the integer primary key is the handle(PkIsHandle).
|
||||
conf.AlterPrimaryKey = false
|
||||
})
|
||||
tk.MustExec("drop database if exists test_create_table_option_auto_inc;")
|
||||
tk.MustExec("create database test_create_table_option_auto_inc;")
|
||||
tk.MustExec("use test_create_table_option_auto_inc;")
|
||||
tk.MustExec("drop database if exists test_auto_inc_table_opt;")
|
||||
tk.MustExec("create database test_auto_inc_table_opt;")
|
||||
tk.MustExec("use test_auto_inc_table_opt;")
|
||||
|
||||
// Empty auto_inc allocator should not cause error.
|
||||
tk.MustExec("create table t (a bigint primary key) auto_increment = 10;")
|
||||
tk.MustExec("alter table t auto_increment = 10;")
|
||||
tk.MustExec("alter table t auto_increment = 12345678901234567890;")
|
||||
|
||||
// Rebase the auto_inc allocator to a large integer should work.
|
||||
tk.MustExec("drop table t;")
|
||||
tk.MustExec("create table t (a bigint unsigned auto_increment, unique key idx(a));")
|
||||
tk.MustExec("alter table t auto_increment = 12345678901234567890;")
|
||||
tk.MustExec("insert into t values ();")
|
||||
tk.MustQuery("select * from t;").Check(testkit.Rows("12345678901234567890"))
|
||||
}
|
||||
|
||||
@ -2392,7 +2392,7 @@ func (d *ddl) RebaseAutoID(ctx sessionctx.Context, ident ast.Ident, newBase int6
|
||||
// If the user sends SQL `alter table t1 auto_increment = 100` to TiDB-B,
|
||||
// and TiDB-B finds 100 < 30001 but returns without any handling,
|
||||
// then TiDB-A may still allocate 99 for auto_increment column. This doesn't make sense for the user.
|
||||
newBase = mathutil.MaxInt64(newBase, autoID)
|
||||
newBase = int64(mathutil.MaxUint64(uint64(newBase), uint64(autoID)))
|
||||
}
|
||||
job := &model.Job{
|
||||
SchemaID: schema.ID,
|
||||
|
||||
Reference in New Issue
Block a user