Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 删除数据transaction is too large,size:104857608
[TiDB Usage Environment] Production Environment
[TiDB Version]
[Reproduction Path] /
[Encountered Problem: Problem Phenomenon and Impact]
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachment: Screenshot/Log/Monitoring] Deleting data transaction is too large, size: 104857608
Transactions cannot be too large; there are limitations. If the data to be deleted is too large, perform the operation in batches.
You can use a for loop to execute each delete limit 10000 in the background.
The image you provided is not visible. Please provide the text you need translated.
BATCH | PingCAP 文档中心 Automatic batch processing
It’s best to add a WHERE clause to the DELETE statement and split it into multiple statements executed by primary key.
Splitting large transactions into smaller ones is part of database optimization. It also prevents large transactions from causing the database to hang and block other transactions.
The delete operation has exceeded the default maximum value for transactions.
Deleting like this will get slower and slower, it’s better to do it in batches.
I also have a table with 4 billion records and need to delete 3 billion of them. The deletion process gets slower and slower with each iteration, which is not very feasible.
BATCH ON test.t2.id LIMIT 1 delete FROM t2;
Supported in version 7. Still using my version 5.
If it’s not real-time data writing, create a new table to write the valid data, then delete the old table, rename the new one, and it will be faster.
Break it into smaller transactions and delete in a loop.
Split the transactions, commit around 5000 each time.