Skip to content

Commit

Permalink
autoid: only initialize rowid allocator if necessary (#18326)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored Jul 13, 2020
1 parent 291bcae commit 8b856cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 8 additions & 4 deletions meta/autoid/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 8b856cc

Please sign in to comment.