[planner] SET_VAR(tidb_opt_join_reorder_through_sel=...) emits warning 3637 despite taking effect
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step
This reproduces on TiDB v8.5.6:
```sql
SET @@tidb_opt_join_reorder_through_sel = OFF;
SELECT /*+ SET_VAR(tidb_opt_join_reorder_through_sel=ON) */
@@tidb_opt_join_reorder_through_sel;
SHOW WARNINGS;
SELECT @@tidb_opt_join_reorder_through_sel;
```
The value returned by the hinted statement is `1`, and the value after the statement is restored to `0`.
The issue is also present in the latest master at commit `16c97eb67f9558f39535bf63b8c2ffe388fbe391`.
### 2. What did you expect to see?
The `SET_VAR` hint should take effect without a warning. The system variable documentation marks `tidb_opt_join_reorder_through_sel` as applicable to `SET_VAR`.
### 3. What did you see instead?
```text
Warning 3637 Variable 'tidb_opt_join_reorder_through_sel' might not be affected by SET_VAR hint.
```
The hint actually takes effect despite the warning. An `EXPLAIN` comparison using a Selection between joins also confirms that `SET_VAR(...=ON)` changes the join reorder result.
### 4. Root cause
`tidb_opt_join_reorder_through_sel` is registered as a session/global system variable and works with statement-scoped `SET_VAR`, but it is missing from `isHintUpdatableVerified` in `pkg/sessionctx/variable/setvar_affect.go`.
As a result, `setVarHintChecker` accepts and applies the variable but emits `ErrNotHintUpdatable` (3637).
### Proposed fix
Add `tidb_opt_join_reorder_through_sel` to `isHintUpdatableVerified` and add a regression test that verifies:
- the hinted value is visible inside the statement;
- the session value is restored afterward;
- `SHOW WARNINGS` is empty.
Contributor guide
Research direction
Start in pkg/sessionctx/variable/setvar_affect.go, especially isHintUpdatableVerified and the setVarHintChecker path. Read nearby SET_VAR regression tests and run the SQL reproducer from the issue. Done means the hint changes the value during the statement, the session value is restored afterward, and SHOW WARNINGS returns no warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100