pingcap / pingcap/tidb

The memory of local temporary table can only be released when current connection is shutdown

Open
#58,868 5 comments 0 reactions 1 assignee Claimed by @tiancaiamao View on GitHub
type/question
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report
In TiDB, if we create a local temporary table, and insert some data into the table, then the memory took up by the temporary table will always be kept, even if we use `truncate` or `delete from temporary_table` to delete all the data in that table. The memory can only be released when current connection is shutdown.

The root cause is when `truncate` or `delete from temporary_table`, TiDB only call `kv.MemBuffer.Delete(key)` to delete the key, but in the implementation of `kv.MemBuffer.Delete(key)`, it actually set a tombstone value to the key instead of delete it. So the memory is not free after `truncate` or `delete from temporary_table`

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

### 2. What did you expect to see? (Required)

### 3. What did you see instead (Required)

### 4. What is your TiDB version? (Required)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.