session: make tidb_paging_size_bytes updates apply to existing sessions
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
### Background
`tidb_paging_size_bytes` currently has both GLOBAL and SESSION scope. Each session copies the global default into its own `SessionVars.PagingSizeBytes`, and DistSQL execution reads that session value. Consequently, `SET GLOBAL tidb_paging_size_bytes = ...` does not update sessions that have already loaded their variables. Long-lived connections and connection pools keep using the old byte budget until they reconnect or receive an explicit session update.
This makes it difficult to enable, disable, or tune byte-budget paging consistently during Resource Control operations.
### Proposed behavior
Make `tidb_paging_size_bytes` a GLOBAL-only variable backed by an instance-local atomic value. Reuse the existing sysvar update, persistence, and cache-refresh hooks, and read the value when initializing each statement's DistSQL context.
- After a successful update on one TiDB instance, subsequent statements on its existing sessions use the new value without reconnecting, including statements in an existing transaction.
- Enabling (`0` to a positive value), disabling (a positive value to `0`), and changing the byte budget follow the same update boundary.
- An initialized execution context and its existing requests retain their captured value. This does not promise immediate changes to in-flight paging RPCs. A statement retry that rebuilds the context can pick up a newer value.
- Other TiDB instances adopt the persisted value through the existing asynchronous sysvar notification and refresh mechanism.
- Keep the default of `0`, the accepted numeric range, and existing Resource Control, resource-group, and request-path eligibility checks.
For example, if connection B already exists on the same instance, connection A can execute `SET GLOBAL tidb_paging_size_bytes = 4194304`; B's next eligible query uses a 4 MiB byte budget. Setting the value back to `0` disables byte-budget paging for subsequent queries, while queries whose execution contexts were already initialized finish with their captured setting.
### Compatibility
Remove SESSION scope and `SET_VAR(tidb_paging_size_bytes=...)` hint support so sessions cannot override the instance's effective global configuration. Users must migrate session assignments and hints to `SET GLOBAL`. Setting the byte budget to `0` does not disable independently configured row-count paging.
### Validation
Cover updates across already-initialized sessions, the captured value of an existing DistSQL context, changes within a transaction, global readback and validation, cache refresh, and the retained paging eligibility checks. Update SQL integration coverage for the GLOBAL-only scope and unsupported hint behavior.
Contributor guide
Research direction
Trace SessionVars.PagingSizeBytes into DistSQL execution, then inspect the existing sysvar update, persistence, and cache-refresh hooks. Use the validation list to cover initialized sessions, captured execution-context values, transactions, global readback, and eligibility checks, along with SQL integration coverage for GLOBAL-only scope and unsupported hints. Done means subsequent eligible statements use the refreshed value while already initialized contexts retain theirs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases, distributed-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100