pingcap / pingcap/tidb

sql_log_off=1 is accepted but TiDB still writes the session to the general query log

Open
#70,981 2 comments 0 reactions 0 assignees View on GitHub
affects-25.10 affects-26.3 affects-7.5 affects-8.1 affects-8.5 affects-9.0 component/server found-by-ai severity/major sig/sql-infra type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```sql
-- TiDB, server started with tidb_general_log=ON:
SET GLOBAL tidb_general_log=ON;
-- session with sql_log_off=0:
SELECT 'MARKER_ON';
-- session with sql_log_off=1:
SET SESSION sql_log_off=1;
SELECT 'MARKER_OFF';
```

Probe output:

```text
MYSQL_OFF_COUNT=0
MYSQL_ON_COUNT=1
MYSQL_SQL_LOG_OFF_SUPPRESSES

TIDB_ON_COUNT=1
TIDB_GENERAL_LOG_LOGS_WHEN_SQL_LOG_OFF_OFF

TIDB_OFF_COUNT=1
TIDB_SQL_LOG_OFF_IGNORED
```

MySQL suppresses the `sql_log_off=1` marker and logs the `sql_log_off=0` marker. TiDB logs both markers, including the one from the session that set `sql_log_off=1`.

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

`SET SESSION sql_log_off=1` must suppress the session's general-query-log entries, matching MySQL. If TiDB does not implement the switch, `SET sql_log_off=1` must be rejected instead of accepted and ignored.

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

MySQL: with general_log=ON, sql_log_off=1 marker count 0 and sql_log_off=0 marker count 1. TiDB: with tidb_general_log=ON, sql_log_off=1 marker count 1 in the general log file.

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

```text
Release Version: v8.4.0-this-is-a-placeholder
Edition: Community
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: go1.25.12
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Kernel Type: Classic
```

Built from source commit `a514a92784c9654502686e6ee6efc9e0aeda8afa` (pingcap/tidb master, 2026-09-07).

### 5. Root cause (optional)

- pkg/sessionctx/variable/noop.go:496 registers sql_log_off as a noop variable
- pkg/session/session.go:5374 logGeneralQuery checks only ProcessGeneralLog and InRestrictedSQL
- pkg/session/session.go:5403 writes GENERAL_LOG without consulting sql_log_off
- pkg/sessionctx/variable/sysvar.go:550-554 maps tidb_general_log to ProcessGeneralLog
- repo-wide grep for sql_log_off finds no consumer outside noop.go

Contributor guide

Open the contributing guide

Research direction

Read pkg/sessionctx/variable/noop.go around the sql_log_off registration, then trace pkg/session/session.go at logGeneralQuery and the GENERAL_LOG write. Reproduce the SQL sequence with tidb_general_log enabled and inspect the general log. Done means sql_log_off=1 suppresses that session's entries while sql_log_off=0 remains logged, or the setting is rejected if unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.