pingcap / pingcap/tidb

Slow-query tables do not expose phase-specific backoff types

Open
#70,832 5 comments 0 reactions 0 assignees View on GitHub
severity/moderate sig/diagnosis type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

`INFORMATION_SCHEMA.SLOW_QUERY` and `CLUSTER_SLOW_QUERY` expose only the legacy `BACKOFF_TYPES` column. Modern slow logs write transaction retry types as `Prewrite_Backoff_types` and `Commit_Backoff_types`, while coprocessor retry types are encoded only in `Cop_backoff__*` detail lines.

As a result, SQL queries and TiDB Dashboard cannot reliably identify which execution phase caused a backoff. For example, a read-only query can contain `txnLockFast` in `BACKOFF_DETAIL` while `BACKOFF_TYPES` is empty.

This is related to #62218, and expands its scope to define a phase-specific, backward-compatible contract for transaction and coprocessor backoff types.

### 1. Minimal reproduce step (Required)

1. Point `tidb_slow_query_file` to a slow-log file containing records such as:

```text
# Time: 2026-09-02T10:00:00+08:00
# Prewrite_Backoff_types: [txnLock]
# Commit_Backoff_types: [regionMiss]
# Cop_backoff_txnLockFast_total_times: 2 Cop_backoff_txnLockFast_total_time: 0.2
select 1;
```

2. Query the record through `INFORMATION_SCHEMA.SLOW_QUERY`:

```sql
SELECT backoff_types, backoff_detail
FROM information_schema.slow_query
WHERE query = 'select 1;';

SELECT prewrite_backoff_types, commit_backoff_types, cop_backoff_types
FROM information_schema.slow_query
WHERE query = 'select 1;';
```

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

The slow-query tables should expose the retry types by phase:

- `PREWRITE_BACKOFF_TYPES = '[txnLock]'`
- `COMMIT_BACKOFF_TYPES = '[regionMiss]'`
- `COP_BACKOFF_TYPES = '[txnLockFast]'`

Historical `Backoff_types` log lines should continue to populate the existing `BACKOFF_TYPES` column without changing its semantics. Cop backoff types should be sorted and deduplicated so the result is stable.

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

- `Prewrite_Backoff_types` and `Commit_Backoff_types` are ignored because the tables do not define matching columns.
- Querying the expected phase-specific columns fails with `Unknown column`.
- Cop backoff types are available only inside the opaque `BACKOFF_DETAIL` text.
- The legacy `BACKOFF_TYPES` column is empty for modern records that no longer contain a `Backoff_types` field.

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

Reproduced on `master` at commit `78cac443a4` on September 2, 2026. The field-name mismatch is also described in #62218, which notes that branches after the slow-log field split are affected.

### Analysis

The slow-log writer and table parser no longer share a complete set of field names. The transaction fields can be mapped directly, while cop backoff types can be derived from existing `Cop_backoff__total_times` lines. Adding separate columns preserves the legacy `BACKOFF_TYPES` behavior and avoids conflating retries from different execution phases.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the INFORMATION_SCHEMA.SLOW_QUERY and CLUSTER_SLOW_QUERY table definitions and the slow-log parser that handles BACKOFF_TYPES and BACKOFF_DETAIL. Verify the supplied sample through the shown SQL queries, then ensure phase-specific transaction and coprocessor columns expose the expected values while legacy BACKOFF_TYPES behavior remains unchanged and cop types are stable and deduplicated.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.