pingcap / pingcap/tidb

enhancement: Record auto-increment ID allocation time in slow log

Open
#66,723 0 comments 0 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement
When diagnosing slow INSERT queries via TiDB slow log, the Query_time can sometimes be significantly higher than the sum of all other recorded fields (e.g., Compile_time, Wait_TS, Cop_time, Prewrite_time, Commit_time, etc.), leaving an unexplained latency gap.
One common but currently invisible contributor to this gap is the time spent allocating AUTO_INCREMENT IDs. In certain scenarios, ID allocation involves a remote RPC call to the autoid service (e.g., when the local cache is exhausted, when AUTO_ID_CACHE=1 is configured, or during autoid service leader failover). This can add tens to hundreds of milliseconds to a query, yet it is entirely absent from the slow log.
Describe the solution you'd like
Add a new field Auto_id_alloc_time (or similar) to TiDB slow log, which records the cumulative time spent in autoid.Allocator.Alloc() during statement execution.
Example slow log output:
```
# Auto_id_alloc_time: 0.08s
```
related issue: https://github.com/pingcap/tidb/issues/34487

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.