-
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
* : Multiple rows insert in a statement should have consecutive autoID if needed. #11876
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11876 +/- ##
================================================
- Coverage 79.9776% 79.8912% -0.0864%
================================================
Files 460 460
Lines 103609 103527 -82
================================================
- Hits 82864 82709 -155
- Misses 14697 14770 +73
Partials 6048 6048 |
Good job! |
executor/insert_common.go
Outdated
case AutoIDNull: | ||
// Find consecutive num. | ||
var cnt int | ||
var start int |
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.
var start int | |
var start int |
Simply start := i
is enough
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.
Cool Done! >.<
executor/insert_common.go
Outdated
var cnt int | ||
var start int | ||
start = i | ||
for i < length { |
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.
How about:
cnt := 1
for i+1 < length && e.cache[i+1].kind == AutoIDNull {
cnt++
i++
}
So you don't need to fix the index i
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.
Cool Done.
executor/insert_common.go
Outdated
if e.filterErr(err) != nil { | ||
return nil, err | ||
} | ||
// Distribute autoIDs to rows. |
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.
// Distribute autoIDs to rows. | |
// Assign autoIDs to rows. |
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.
Addressed.
executor/insert_common.go
Outdated
// Cause d may changed in HandleBadNull, do assignment here | ||
rows[rowIdx][colIdx] = d | ||
case AutoIDZero: | ||
// Don't change value 0 to auto id, if NoAutoValueOnZero SQL mode is set. |
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.
// Don't change value 0 to auto id, if NoAutoValueOnZero SQL mode is set. | |
// Don't change value 0 to auto id, if `NO_AUTO_VALUE_ON_ZERO` SQL mode is set. |
Is this a TODO?
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.
No, that means fill 0
to autoID column, just let it be.
executor/insert_common.go
Outdated
@@ -530,6 +675,98 @@ func (e *InsertValues) fillRow(ctx context.Context, row []types.Datum, hasValue | |||
return row, nil | |||
} | |||
|
|||
// fillRowLazy is quite same to fillRow() except it will cache auto increment datum for lazy batch allocation of autoID. | |||
// This case is used in insert|replace into values (row),(row),(row)... | |||
func (e *InsertValues) fillRowLazy(ctx context.Context, row []types.Datum, hasValue []bool, rowIdx int) ([]types.Datum, error) { |
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.
This function shares some codes with fillRow
, and the two functions are with same signature, can we use a flag variable of InsertValues
(for example, lazyFillAutoID
) to indicate if the filling logic is lazy, and try to combine two functions?
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.
Nice idea!
25dbe2d
to
2e4497f
Compare
/run-all-tests |
5a78aaf
to
8bc9a07
Compare
/run-all-tests |
/rebuild |
Attention!This PR need to modify mysql-test |
/run-all-tests |
e131b79
to
10a32e3
Compare
/run-all-tests |
@jackysp hi,shuaipeng,this PR is ready for review now, PTAL |
The PR is really big, is there anyone else to review together? |
/run-all-tests |
/run-all-tests |
@AilinKid merge failed. |
/run-unit-test |
cherry pick to release-2.1 failed |
cherry pick to release-3.0 failed |
cherry pick to release-3.1 failed |
Clicking the update branch button triggers the merge? (bug?) |
What problem does this PR solve?
fix issue 11696
This comes from JDBC getGeneratedKeys error in Mybatis framework
Attention Please:
This PR guarantees the consecutive autoID in a batch. (That means users should use JDBC getGeneratedKeys feature under the circumstance that the insert rows in a statement should less than the batch size. For most case, it's adequate. )
When doing multiple batch insert, keeping the consecutive autoID will cache all rows in memory for lazy autoID batch allocation.
What is changed and how it works?
1:let allocator support
AllocN(num)
to allocate consecutive sequence.2:when do insert rows, use
AllocN(num)
to make sure consecutive id allocation.Check List
Tests
Code changes
Related changes
Release note