Skip to content

Commit 0a17f9c

Browse files
authored
sql: clarify description about SET GLOBAL (#22175)
1 parent b015405 commit 0a17f9c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sql-statements/sql-statement-set-variable.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ SELECT @myvar, @myvar + 1;
106106

107107
The following behavior differences apply:
108108

109-
* Changes made with `SET GLOBAL` will be propagated to all TiDB instances in the cluster. This differs from MySQL, where changes do not propagate to replicas.
109+
* In MySQL, changes made with `SET GLOBAL` do not apply to replicas. However in TiDB, the scope of `SET GLOBAL` depends on the specific system variable:
110+
111+
* Global variables: for most system variables (for example, those that affect cluster behavior or optimizer behavior), changes made with `SET GLOBAL` apply to all TiDB instances in the cluster.
112+
* Instance-level variables: for some system variables (for example, `max_connections`), changes made with `SET GLOBAL` apply only to the TiDB instance that the current connection is using.
113+
114+
Therefore, when using `SET GLOBAL` to modify a variable, always check the [documentation](/system-variables.md) of that variable, especially the "Persists to cluster" attribute, to confirm the scope of the change.
115+
110116
* TiDB presents several variables as both readable and settable. This is required for MySQL compatibility, because it is common for both applications and connectors to read MySQL variables. For example: JDBC connectors both read and set query cache settings, despite not relying on the behavior.
111117
* Changes made with `SET GLOBAL` will persist through TiDB server restarts. This means that `SET GLOBAL` in TiDB behaves more similar to `SET PERSIST` as available in MySQL 8.0 and above.
112118
* TiDB does not support `SET PERSIST` and `SET PERSIST_ONLY`, because TiDB persists global variables.

0 commit comments

Comments
 (0)