-
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: Fix a bug in 'INSERT ... ON DUPLICATE KEY UPDATE' #7675
Conversation
/run-all-tests |
LGTM |
@jackysp PTAL |
executor/insert.go
Outdated
// There is only one row per update. | ||
fillBackKeysInRows, err := e.getKeysNeedCheck(e.ctx, e.Table, [][]types.Datum{updatedRow}) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
// Delete old keys and fill back new key-values of the updated row. | ||
e.deleteDupKeys(row) | ||
cleanupRows, err := e.getKeysNeedCheck(e.ctx, e.Table, [][]types.Datum{oldRow}) |
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.
We could use a function to handle this part and
Line 73 in 9070bb6
// Cleanup keys map, because the record was removed. |
together.
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.
Thanks for the review @jackysp, I plan to define a function for this and put it in the base struct InsertValues
, what do u think?
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 think to put it into batchChecker
is better. Thanks for your contribution, @bb7133 !
ea2cdd8
to
0a478c2
Compare
Comments addressed, PTAL @jackysp , thanks! |
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.
LGTM
Thanks @bb7133 !
/run-all-tests |
Thank you @jackysp |
What problem does this PR solve?
Fix a bug in 'INSERT ... ON DUPLICATE KEY UPDATE' when unique key are updated, for example:
, which is incorrect. We should expect the following result instead:
After this PR, it will be fixed.
What is changed and how it works?
In
InsertExec
'supdateDupKeyValues
function,dupKVs
(amap
that holds existing primary keys and unique keys for duplication detection) is updated by removing keys from the inserting row first, then adding keys from the updated row. But we should remove keys from the old row instead, because old row is the one that to be replaced.Check List
Tests
Code changes
Side effects
Related changes