-
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 the incorrect untouch used in optimistic transactions #30447
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,8 +169,22 @@ func (c *index) Create(sctx sessionctx.Context, txn kv.Transaction, indexedValue | |
// should not overwrite the key with un-commit flag. | ||
// So if the key exists, just do nothing and return. | ||
v, err := txn.GetMemBuffer().Get(ctx, key) | ||
if err == nil && len(v) != 0 { | ||
return nil, nil | ||
if err == nil { | ||
if len(v) != 0 { | ||
return nil, nil | ||
} | ||
// The key is marked as deleted in the memory buffer, as the existence check is done lazily | ||
// for optimistic transactions by default. The "untouched" key could still exist in the store, | ||
// it's needed to commit this key to do the existence check so unset the untouched flag. | ||
if !txn.IsPessimistic() { | ||
keyFlags, err := txn.GetMemBuffer().GetFlags(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if keyFlags.HasPresumeKeyNotExists() { | ||
opt.Untouched = false | ||
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. This will recover the deleted /* t */ delete from t where c1 is null;
-- t >> 1 rows affected
/* t */ select * from t force index(c0);
-- t >> +----+----+----+
-- t | C0 | C1 | C2 |
-- t +----+----+----+
-- t +----+----+----+
/* t */ update t set c2 = 'green' where c2 between 'purple' and 'white';
-- t >> 1 rows affected
/* t */ select * from t force index(c0);
-- t >> +----+-----+-------+
-- t | C0 | C1 | C2 |
-- t +----+-----+-------+
-- t | 1 | red | green |
-- t +----+-----+-------+
/* t */ commit;
-- t >> E1062: Duplicate entry '1' for key 'c0' A risky fix is to return this function directly here since the presume-not-exist keys will be checked when committing. 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. Do you mean the current fix will recover the 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. Yes. 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. It's caused by the same situation that
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.
Yes, however, the index
Actually, the ideal solution will be not to delete |
||
} | ||
} | ||
} | ||
} | ||
|
||
|
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.
The key is filtered by it before
tidb/store/driver/txn/txn_driver.go
Lines 290 to 292 in d83ee8c
How about changing
TiDBKVFilter.IsUnnecessaryKeyValue()
? TiDB should commit the key as long as it hasflagPresumeKNE
.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.
Ah, the value can't be recognized in this case.
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.
Should we add an assertion at
tidb/store/driver/txn/txn_driver.go
Lines 290 to 292 in d83ee8c
unnecessary
format it should not contain certain flags likeflagPresumeKNE
?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.
Good idea!