diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index d36e49c4d4..33f80185c0 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -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")) } diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index be9ace8ee9..a143347db6 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -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,