executor: batch point get does not track memory usage and cannot be canceled
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug / Enhancement
`BatchPointGetExec` buffers every fetched row value in `e.values` without registering it with the query memory tracker. A large batch point get — e.g. `SELECT ... WHERE pk IN ()` over wide rows or large columns — therefore holds memory that is invisible to:
1. the per-query quota `tidb_mem_quota_query`, and
2. the instance `tidb_server_memory_limit` killer, which selects the session with the highest tracked `BytesConsumed` (`MemUsageTop1Tracker`).
As a result such queries are neither canceled by the per-query OOM action nor picked as the victim by the instance memory-limit killer, so they can drive a tidb-server to OOM. In heap profiles of such an OOM, `kvrpcpb.KvPair.Unmarshal` and row decoding dominate the heap, while the queries themselves report `mem_max: 0` in the OOM `running_sql` record.
For comparison, the coprocessor read path (`TableReaderExecutor` / distsql `selectResult`) already tracks response memory via the query tracker, so only the point-get/batch-point-get path is unaccounted.
## Expected
The memory buffered by batch point get should be tracked against the statement memory tracker so the query is cancelable by `tidb_mem_quota_query` and visible to the `tidb_server_memory_limit` killer.
## Affected versions
Reproduced against `master`; the code path is also present on the release branches.
Contributor guide
Research direction
Locate BatchPointGetExec and inspect how its e.values buffer is populated and released. Compare that path with TableReaderExecutor and distsql selectResult, which already track response memory, then trace the statement memory tracker and its cancellation behavior. Done means batch point get memory contributes to tidb_mem_quota_query and is visible to the tidb_server_memory_limit killer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100