pingcap / pingcap/tidb

why tidb-server receive 1000 rows from tikv,it‘s used 26.4GiB memory?

Open
#33,594 2 comments 0 reactions 0 assignees View on GitHub
severity/moderate sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

exec sql:
```
SELECT
*
FROM
pay_iap_receipt_detail
WHERE
createTime < '2022-03-30 14:52:52.986'
AND preOrderFlag IS false
AND exchangeFlag IS false
LIMIT
1000;
```
```
id task estRows operator info actRows execution info memory disk
Limit_9 root 1000 offset:0, count:1000 1000 time:4.02s, loops:2 N/A N/A
└─IndexLookUp_18 root 1000 1000 time:4.02s, loops:1, index_task: {total_time: 34.5s, fetch_handle: 171.2ms, build: 119.8µs, wait: 34.3s}, table_task: {total_time: 1h0m25.7s, num: 15, concurrency: 5} 26.4 GB N/A
├─IndexRangeScan_14 cop[tikv] 1000 table:pay_iap_receipt_detail, index:idx_create_time(createTime), range:[-inf,2022-03-30 14:52:53), keep order:false 1145764 time:15.5ms, loops:252, cop_task: {num: 1, max: 2.43ms, proc_keys: 0, rpc_num: 1, rpc_time: 2.38ms, copr_cache_hit_ratio: 1.00}, tikv_task:{time:769ms, loops:1123} N/A N/A
└─Limit_17 cop[tikv] 1000 offset:0, count:1000 237536 time:59m10s, loops:247, cop_task: {num: 1417, max: 1m32s, min: 5.68ms, avg: 2.55s, p95: 11.7s, max_proc_keys: 520, p95_proc_keys: 404, tot_proc: 2m50.1s, tot_wait: 1.5s, rpc_num: 1578, rpc_time: 1h42m56.2s, copr_cache_hit_ratio: 0.00}, backoff{tikvRPC: 57s, pdRPC: 1.28s, regionMiss: 946ms}, tikv_task:{proc max:237ms, min:0s, p80:97ms, p95:148ms, iters:3944, tasks:1417}, scan_detail: {total_process_keys: 237536, total_process_keys_size: 25185374639, total_keys: 244848, rocksdb: {delete_skipped_count: 26047, key_skipped_count: 22360, block: {cache_hit_count: 1458748, read_count: 149524, read_byte: 1.80 GB}}} N/A N/A
└─Selection_16 cop[tikv] 1000 isfalse(u7pay.pay_iap_receipt_detail.exchangeflag), isfalse(u7pay.pay_iap_receipt_detail.preorderflag) 237536 tikv_task:{proc max:237ms, min:0s, p80:97ms, p95:148ms, iters:3944, tasks:1417} N/A N/A
└─TableRowIDScan_15 cop[tikv] 1000 table:pay_iap_receipt_detail, keep order:false 237536 tikv_task:{proc max:237ms, min:0s, p80:97ms, p95:148ms, iters:3944, tasks:1417} N/A N/A
```
![image](https://user-images.githubusercontent.com/27006237/160787528-2e11f7ea-f1c9-4f53-9d21-91c216b370d1.png)

problem:
1. this sql used much memory
2. when i kill this sql, but tidb-server free memory very slow(6MB/s) and swap can't be freed

### 1. Minimal reproduce step (Required)
no

### 2. What did you expect to see? (Required)
tidb-server used little memory when only get free rows
tidb-server could free memory fast when kill sql which used large memory

### 3. What did you see instead (Required)
26.4GiB memory used
free memory very slow

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

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.