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

autoid: only initialize rowid allocator if necessary #18326

Merged
merged 4 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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