planner: allow `tidb_request_source_type` and `tidb_low_resolution_tso` in `SET_VAR` hints
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Feature Request
**Is your feature request related to a problem? Please describe:**
`tidb_request_source_type` and `tidb_low_resolution_tso` can only be changed with `SET`, so they apply to the whole session. Applications that share connections (for example through a connection pool or a proxy) cannot safely tag a single query with a request source or let a single query read with a low-resolution TSO without also changing the behavior of every following statement on that connection.
**Describe the feature you'd like:**
Allow both variables in the `SET_VAR` optimizer hint so they can be scoped to one statement, the same way `MAX_EXECUTION_TIME` and `RESOURCE_GROUP` already can:
```sql
SELECT /*+ SET_VAR(tidb_request_source_type='lightning') */ ... ;
SELECT /*+ SET_VAR(tidb_low_resolution_tso=ON) */ ... ;
```
The hinted value should also reach an already active transaction (the request source is copied into the transaction when it is activated) and be restored after the statement finishes.
**Describe alternatives you've considered:**
Wrapping every such query in `SET @@tidb_request_source_type = ...; ; SET @@tidb_request_source_type = ;`. This costs extra round trips and leaks the setting to other statements if the middle statement fails or the connection is returned to the pool early.
**Teachability, Documentation, Adoption, Migration Strategy:**
Documentation only needs to list the two variables as `SET_VAR`-capable in the system variable reference. No migration is required since existing `SET` usage keeps working.
Contributor guide
Research direction
Start by tracing the existing SET_VAR handling for MAX_EXECUTION_TIME and RESOURCE_GROUP, then inspect how tidb_request_source_type and tidb_low_resolution_tso are applied to session and active-transaction state. Add coverage for both hinted variables, including restoration after the statement, and update the system variable reference to list their SET_VAR support.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100