-
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
Frequently updating non-index column causing too many Lock records in the unique index key #25659
Comments
Since #21229, the unique index key will be pessimistically locked, this change make the lock behaviour more reasonable but increased the possibility encountering the performance issue of the
|
@cfzjywxk To solve exactly the problem introduced by #21229, I think we can just use The index record should be small, so it does not bring too much overhead to put the index record again. With clustered index, the index can be larger, but typically it won't. |
Agree, this seems to be the plan with less changing risk, the TODOs are:
@sticnarf @MyonKeminta BTW, I'm working on the hotfix patch as there are already some customers encoutering this issue. |
We can include this in the next patch.
Currently, I don't have a very clear idea of how to achieve it in detail. I come up with some different approaches, but each of them has their own drawbacks. Approach 1Read until the latest But now prewrite does not read the latest valid record except for CDC is enabled. Reading the valid record every time introduces overhead to the hot path. Approach 2To optimize approach 1, we can record how many contiguous records need to be skipped in the latest But it is a problem to decide where to store the number. If it is added as a separate field in the To keep backward compatibility, it must be put in the Approach 3A more conservative way is to let TiDB decide the re-put. TiKV only provides hints of how many useless records are skipped in This approach does not modify the data format or introduce much overhead. But it seems complex and has limited use cases. We only re-put if we did |
@MyonKeminta @sticnarf |
Fixed in #25730 and related cherry-picks. |
Please check whether the issue should be labeled with 'affects-x.y' or 'backport-x.y.z', |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
This problem occurs if a table has:
Example table definition: (without clustered index so that the primary key is a separated unique index)
And there's frequent update operations like:
2. What did you expect to see? (Required)
Everything goes well
3. What did you see instead (Required)
The performance decreases and it can be seen that
next
operation is very high some requests likeacquire_pessimistic_lock
andkv_get
.Since this locks the unique index key, it will produce a
WriteType::Lock
record in the write cf on the unique index key. When reading value on such a key, it will need to iterate over all theseLock
records to find the latestPut
orDelete
record. Every time it iterates a Lock record, it performs anext
operation. In some bad cases, reading each key may produce over 100k+ next operations.4. What is your TiDB version? (Required)
4.0.10+, 5.x, master
The text was updated successfully, but these errors were encountered: