-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
executor: only rebase auto increment ID when needed #7515
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1a3841a
Only rebase auto ID when needed.
jackysp 455b37b
add a test case
jackysp 4a9a6ae
fix CI
jackysp 908193d
Address comments.
jackysp c9e10da
Merge branch 'master' into rebase-if-needed
lysu 220689c
merge master
jackysp 61c7e11
address comments
jackysp ff9d03a
Merge branch 'master' into rebase-if-needed
jackysp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2021,3 +2021,36 @@ func (s *testSuite) TestReplaceLog(c *C) { | |
|
||
tk.MustQuery(`admin cleanup index testLog b;`).Check(testkit.Rows("1")) | ||
} | ||
|
||
// For issue 7422. | ||
// There is no need to do the rebase when updating a record if the auto-increment ID not changed. | ||
// This could make the auto ID increasing speed slower. | ||
func (s *testSuite) TestRebaseIfNeeded(c *C) { | ||
tk := testkit.NewTestKit(c, s.store) | ||
tk.MustExec("use test") | ||
tk.MustExec(`create table t (a int not null primary key auto_increment, b int unique key);`) | ||
tk.MustExec(`insert into t (b) values (1);`) | ||
|
||
s.ctx = mock.NewContext() | ||
s.ctx.Store = s.store | ||
tbl, err := s.domain.InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("t")) | ||
c.Assert(err, IsNil) | ||
c.Assert(s.ctx.NewTxn(), IsNil) | ||
// AddRecord directly here will skip to rebase the auto ID in the insert statement, | ||
// which could simulate another TiDB adds a large auto ID. | ||
_, err = tbl.AddRecord(s.ctx, types.MakeDatums(30001, 2), false) | ||
c.Assert(err, IsNil) | ||
c.Assert(s.ctx.Txn().Commit(context.Background()), IsNil) | ||
|
||
tk.MustExec(`update t set b = 3 where a = 30001;`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comments to this case, |
||
tk.MustExec(`insert into t (b) values (4);`) | ||
tk.MustQuery(`select a from t where b = 4;`).Check(testkit.Rows("2")) | ||
|
||
tk.MustExec(`insert into t set b = 3 on duplicate key update a = a;`) | ||
tk.MustExec(`insert into t (b) values (5);`) | ||
tk.MustQuery(`select a from t where b = 5;`).Check(testkit.Rows("4")) | ||
|
||
tk.MustExec(`insert into t set b = 3 on duplicate key update a = a + 1;`) | ||
tk.MustExec(`insert into t (b) values (6);`) | ||
tk.MustQuery(`select a from t where b = 6;`).Check(testkit.Rows("30003")) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe need add
insert on duplicate key update
testcase, and checklast_insert_id()
value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already have the cases at line 595 to 627.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I means rebase auto_increment in
on duplicate key update
, current case seems not update id? e.g. use duplicate on second unique index then update primary key...