diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index d75bb4b947e21..2cdbbe01fd7cf 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -840,15 +840,15 @@ func HelperTestAdminShowNextID(c *C, s *seqTestSuite, str string) { tk.MustExec("create table t3(id bigint primary key auto_random(5), c int)") // Start handle is 1. r = tk.MustQuery(str + " t3 next_row_id") - r.Check(testkit.Rows("test1 t3 _tidb_rowid 1 AUTO_INCREMENT", "test1 t3 id 1 AUTO_RANDOM")) + r.Check(testkit.Rows("test1 t3 id 1 AUTO_RANDOM")) // Insert some rows. tk.MustExec("insert into t3 (c) values (1), (2);") r = tk.MustQuery(str + " t3 next_row_id") - r.Check(testkit.Rows("test1 t3 _tidb_rowid 1 AUTO_INCREMENT", "test1 t3 id 11 AUTO_RANDOM")) + r.Check(testkit.Rows("test1 t3 id 11 AUTO_RANDOM")) // Rebase. tk.MustExec("insert into t3 (id, c) values (103, 3);") r = tk.MustQuery(str + " t3 next_row_id") - r.Check(testkit.Rows("test1 t3 _tidb_rowid 1 AUTO_INCREMENT", "test1 t3 id 114 AUTO_RANDOM")) + r.Check(testkit.Rows("test1 t3 id 114 AUTO_RANDOM")) // Test for a sequence. tk.MustExec("create sequence seq1 start 15 cache 57") diff --git a/meta/autoid/autoid.go b/meta/autoid/autoid.go index db7d07ae4565f..0ec326908e7f5 100755 --- a/meta/autoid/autoid.go +++ b/meta/autoid/autoid.go @@ -427,10 +427,14 @@ func NewSequenceAllocator(store kv.Storage, dbID int64, info *model.SequenceInfo func NewAllocatorsFromTblInfo(store kv.Storage, schemaID int64, tblInfo *model.TableInfo) Allocators { var allocs []Allocator dbID := tblInfo.GetDBID(schemaID) - if tblInfo.AutoIdCache > 0 { - allocs = append(allocs, NewAllocator(store, dbID, tblInfo.IsAutoIncColUnsigned(), RowIDAllocType, CustomAutoIncCacheOption(tblInfo.AutoIdCache))) - } else { - allocs = append(allocs, NewAllocator(store, dbID, tblInfo.IsAutoIncColUnsigned(), RowIDAllocType)) + hasRowID := !tblInfo.PKIsHandle && !tblInfo.IsCommonHandle + hasAutoIncID := tblInfo.GetAutoIncrementColInfo() != nil + if hasRowID || hasAutoIncID { + if tblInfo.AutoIdCache > 0 { + allocs = append(allocs, NewAllocator(store, dbID, tblInfo.IsAutoIncColUnsigned(), RowIDAllocType, CustomAutoIncCacheOption(tblInfo.AutoIdCache))) + } else { + allocs = append(allocs, NewAllocator(store, dbID, tblInfo.IsAutoIncColUnsigned(), RowIDAllocType)) + } } if tblInfo.ContainsAutoRandomBits() { allocs = append(allocs, NewAllocator(store, dbID, tblInfo.IsAutoRandomBitColUnsigned(), AutoRandomType))