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

executor: skip ignore check for not update indexes #23894

Merged
merged 6 commits into from
Apr 12, 2021
Merged

executor: skip ignore check for not update indexes #23894

merged 6 commits into from
Apr 12, 2021

Conversation

lysu
Copy link
Contributor

@lysu lysu commented Apr 7, 2021

What problem does this PR solve?

Issue Number: close #23892

Problem Summary:

for insert ignore on duplicate update stmt, "ignore check" should only check the index that real change

only new row value meet duplicated in indexes need be ignore, and it can continue update if new value == old value, due to old row/indexes will be removed before upsert

What is changed and how it works?

What's Changed, How it Works:

only ignore check for real changed indexes

Related changes

  • Need to cherry-pick to the release branch 5.0.x

Check List

Tests

  • Unit test

Side effects

  • n/a

Release note

  • No release note

This change is Reviewable

@lysu lysu requested a review from a team as a code owner April 7, 2021 08:54
@lysu lysu requested review from qw4990 and removed request for a team April 7, 2021 08:54
@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 7, 2021
@lysu lysu requested review from cfzjywxk, coocood and jackysp and removed request for qw4990 April 7, 2021 08:57
@lysu lysu added the type/bugfix This PR fixes a bug. label Apr 7, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Apr 7, 2021
@@ -1450,11 +1450,11 @@ func FindIndexByColName(t table.Table, name string) table.Index {

// CheckHandleOrUniqueKeyExistForUpdateIgnoreOrInsertOnDupIgnore check whether recordID key or unique index key exists. if not exists, return nil,
// otherwise return kv.ErrKeyExists error.
func CheckHandleOrUniqueKeyExistForUpdateIgnoreOrInsertOnDupIgnore(ctx context.Context, sctx sessionctx.Context, t table.Table, recordID kv.Handle, data []types.Datum) error {
func CheckHandleOrUniqueKeyExistForUpdateIgnoreOrInsertOnDupIgnore(ctx context.Context, sctx sessionctx.Context, t table.Table, recordID kv.Handle, oldRow, newRow []types.Datum) error {
Copy link
Member

@jackysp jackysp Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could use modified in updateRecord to avoid to compare once again.

@lysu
Copy link
Contributor Author

lysu commented Apr 7, 2021

/run-all-tests

@lysu lysu requested a review from jackysp April 7, 2021 11:01
}
for _, c := range idx.Meta().Columns {
if modified[c.Offset] {
return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit confused, if this index related column value is changed, should we do the check?

Copy link
Contributor Author

@lysu lysu Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😵 my fault when extract method..fixed...it only need check when value changed

@lysu
Copy link
Contributor Author

lysu commented Apr 7, 2021

/run-all-tests

@tangenta
Copy link
Contributor

tangenta commented Apr 7, 2021

/lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 7, 2021
if !IsIndexWritable(idx) {
continue
canSkipIgnoreCheck := func(idx table.Index) bool {
if !IsIndexWritable(idx) || !idx.Meta().Unique || (t.Meta().IsCommonHandle && idx.Meta().Primary) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we skip t.Meta().PKIsHandle && idx.Meta().Primary too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can skip that because

https://github.com/pingcap/tidb/pull/23894/files#diff-ccb2771ef1931990c0d0ce3703def7dd53bd21d00a8f6b40b59ca0115f776a60R1469-R1480

had check handle, primary key should be same as handle if it's clustered index

Copy link
Contributor Author

@lysu lysu Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... it seems, there are no indexInfo named Primary when table is PKIsHandle after debug

for example:

create table t4(id int primary key clustered, k int, v int, unique key uk1(k))

t.indices only contain uk1's info, so maybe can avoid this check 😄

Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • cfzjywxk
  • tangenta

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 7, 2021
@jackysp
Copy link
Member

jackysp commented Apr 7, 2021

CI failed.

@ichn-hu ichn-hu mentioned this pull request Apr 9, 2021
@lysu
Copy link
Contributor Author

lysu commented Apr 12, 2021

@coocood

@lysu
Copy link
Contributor Author

lysu commented Apr 12, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 02c28cb

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 12, 2021
@lysu
Copy link
Contributor Author

lysu commented Apr 12, 2021

/run-all-tests

@ti-srebot
Copy link
Contributor

cherry pick to release-5.0 in PR #23976

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

insert ignore on duplicate got wrong result when index value unchanged
7 participants