Issues Related to Delete Within Transactions

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 事务内Delete相关问题

| username: TiDBer_U58GZgGJ

According to the official blog, DML operations are all in the local buffer of the transaction. So is delete also targeted at the buffer? It won’t actually delete from the KV before committing. Then after deleting and selecting again, wouldn’t it read the deleted data from the KV? In actual operations, this situation does not occur. How is this resolved?

| username: WinterLiu | Original post link

It is recommended to look into the implementation of distributed transactions and MVCC. TiDB ensures consistent reads of data.

| username: tidb狂热爱好者 | Original post link

Deleting within a transaction can be very slow. It is recommended to use batch mode for deletion.

| username: zhanggame1 | Original post link

The delete operation itself is also an insertion of a key-value pair. After performing a delete and then selecting, during the select operation, searching in TiKV will reveal that the original key has a delete record, indicating it has been deleted.

| username: TiDBer_U58GZgGJ | Original post link

The delete you mentioned is also an insertion of kv, so is this kv inserted into the transaction buffer before commit or directly into TiKV?

| username: yiduoyunQ | Original post link

Which blog?

| username: zhaokede | Original post link

Consistency ensures that deleted data will not be read.

| username: TiDBer_U58GZgGJ | Original post link

About transactions.

| username: TIDB-Learner | Original post link

Deletion is not a true deletion; it just marks the data as deleted. If the transaction has not yet been committed, other processes can definitely access the data. If the transaction has been committed, other processes’ transactions that were committed before the deletion transaction can read the data; otherwise, they cannot. This is due to MVCC (snapshot read) and the ACID properties of transactions. TiDB’s distributed read-write principles, timestamp, memory, and log management mechanisms. Let’s encourage each other.

| username: Soysauce520 | Original post link

When scanning kv, it will skip those with timestamps and delete markers. Your explain will have a skip execution plan.