You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* *: add more doc for slow log
* Apply suggestions from code review
Co-authored-by: Keke Yi <[email protected]>
Co-authored-by: Keke Yi <[email protected]>
*`Cop_backoff_{backoff-type}_avg_time`: The average time of backoff caused by an error.
110
110
*`Cop_backoff_{backoff-type}_p90_time`: The P90 percentile backoff time caused by an error.
111
111
112
+
## Related system variables
113
+
114
+
*[`tidb_slow_log_threshold`](/system-variables.md#tidb_slow_log_threshold): Sets the threshold for the slow log. The SQL statement whose execution time exceeds this threshold is recorded in the slow log. The default value is 300 (ms).
115
+
*[`tidb_query_log_max_len`](/system-variables.md#tidb_query_log_max_len): Sets the maximum length of the SQL statement recorded in the slow log. The default value is 4096 (byte).
116
+
*[`tidb_log_desensitization`](/system-variables.md#tidb_log_desensitization): Determines whether to desensitize user data using `?` in the SQL statement recorded in the slow log. The default value is `0`, which means to disable the feature.
117
+
*[`tidb_enable_collect_execution_info`](/system-variables.md#tidb_enable_collect_execution_info): Determines whether to record the execution information of each operator in the execution plan. The default value is `1`. This feature impacts the performance by approximately 3%. After enabling this feature, you can view the `Plan` information as follows:
If you are conducting a performance test, you can disable the feature of automatically collecting the execution information of operators:
133
+
134
+
{{< copyable "sql" >}}
135
+
136
+
```sql
137
+
set @@tidb_enable_collect_execution_info=0;
138
+
```
139
+
140
+
The returned result of the `Plan` field has roughly the same format with that of `EXPLAIN` or `EXPLAIN ANALYZE`. For more details of the execution plan, see [`EXPLAIN`](/sql-statements/sql-statement-explain.md) or [`EXPLAIN ANALYZE`](/sql-statements/sql-statement-explain-analyze.md).
141
+
142
+
For more information, see [TiDB specific variables and syntax](/system-variables.md).
143
+
112
144
## Memory mapping in slow log
113
145
114
146
You can query the content of the slow query log by querying the `INFORMATION_SCHEMA.SLOW_QUERY` table. Each column name in the table corresponds to one field name in the slow log. For table structure, see the introduction to the `SLOW_QUERY` table in [Information Schema](/information-schema/information-schema-slow-query.md).
TiDB system variables behave similar to MySQL, in that settings may apply on a `SESSION`, `GLOBAL` or both `SESSION` and `GLOBAL` scope. Changes to `GLOBAL` scoped variables **only apply** to new connections to TiDB. Variables can be set with the [`SET` statement](/sql-statements/sql-statement-set-variable.md) on a per-session or global basis:
9
+
TiDB system variables behave similar to MySQL with some differences, in that settings might apply on a `SESSION`, `INSTANCE`, or `GLOBAL` scope, or on a scope that combines `SESSION`, `INSTANCE`, or `GLOBAL`.
10
+
11
+
- Changes to `GLOBAL` scoped variables **only apply to new connection sessions with TiDB**. Currently active connection sessions are not affected. These changes are persisted and valid after restarts.
12
+
- Changes to `INSTANCE` scoped variables apply to all active or new connection sessions with the current TiDB instance immediately after the changes are made. Other TiDB instances are not affected. These changes are not persisted and become invalid after TiDB restarts.
13
+
14
+
Variables can be set with the [`SET` statement](/sql-statements/sql-statement-set-variable.md) on a per-session, instance or global basis:
10
15
11
16
```sql
12
17
# These two identical statements change a session variable
@@ -39,7 +44,7 @@ SET GLOBAL tidb_distsql_scan_concurrency = 10;
39
44
40
45
### ddl_slow_threshold
41
46
42
-
- Scope: SESSION
47
+
- Scope: INSTANCE
43
48
- Default value: 300
44
49
- DDL operations whose execution time exceeds the threshold value are output to the log. The unit is millisecond.
45
50
@@ -171,7 +176,7 @@ SET GLOBAL tidb_distsql_scan_concurrency = 10;
171
176
172
177
### tidb_check_mb4_value_in_utf8
173
178
174
-
- Scope: SERVER
179
+
- Scope: INSTANCE
175
180
- Default value: 1, indicating check the validity of UTF-8 data. This default behavior is compatible with MySQL.
176
181
- This variable is used to set whether to check the validity of UTF-8 data.
177
182
- To upgrade an earlier version (TiDB v2.1.1 or earlier), you may need to disable this option. Otherwise, you can successfully write invalid strings in an earlier version but fail to do this in a later version, because there is no data validity check in the earlier version. For details, see [FAQs After Upgrade](/faq/upgrade-faq.md).
@@ -336,7 +341,7 @@ Constraint checking is always performed in place for pessimistic transactions (d
336
341
337
342
### tidb_enable_slow_log
338
343
339
-
- Scope: SESSION
344
+
- Scope: INSTANCE
340
345
- Default value: `1`
341
346
- This variable is used to control whether to enable the slow log feature. It is enabled by default.
342
347
@@ -410,22 +415,22 @@ Constraint checking is always performed in place for pessimistic transactions (d
410
415
411
416
### tidb_expensive_query_time_threshold
412
417
413
-
- Scope: SERVER
418
+
- Scope: INSTANCE
414
419
- Default value: 60
415
420
- This variable is used to set the threshold value that determines whether to print expensive query logs. The unit is second. The difference between expensive query logs and slow query logs is:
416
421
- Slow logs are printed after the statement is executed.
417
422
- Expensive query logs print the statements that are being executed, with execution time exceeding the threshold value, and their related information.
418
423
419
424
### tidb_force_priority
420
425
421
-
- Scope: SESSION
426
+
- Scope: INSTANCE
422
427
- Default value: `NO_PRIORITY`
423
428
- This variable is used to change the default priority for statements executed on a TiDB server. A use case is to ensure that a particular user that is performing OLAP queries receives lower priority than users performing OLTP queries.
424
429
- You can set the value of this variable to `NO_PRIORITY`, `LOW_PRIORITY`, `DELAYED`or`HIGH_PRIORITY`.
425
430
426
431
### tidb_general_log
427
432
428
-
- Scope: SERVER
433
+
- Scope: INSTANCE
429
434
- Default value: 0
430
435
- This variable is used to set whether to record all the SQL statements in the log.
431
436
@@ -679,7 +684,7 @@ mysql> desc select count(distinct a) from test.t;
679
684
680
685
### tidb_query_log_max_len
681
686
682
-
- Scope: SESSION
687
+
- Scope: INSTANCE
683
688
- Default value: 4096 (bytes)
684
689
- The maximum length of the SQL statement output. When the output length of a statement is larger than the `tidb_query-log-max-len` value, the statement is truncated to output.
685
690
@@ -691,13 +696,13 @@ set tidb_query_log_max_len = 20
691
696
692
697
### tidb_pprof_sql_cpu <span class="version-mark">New in v4.0</span>
693
698
694
-
- Scope: SESSION
699
+
- Scope: INSTANCE
695
700
- Default value: 0
696
701
- This variable is used to control whether to mark the corresponding SQL statement in the profile output to identify and troubleshoot performance issues.
697
702
698
703
### tidb_record_plan_in_slow_log
699
704
700
-
- Scope: SESSION
705
+
- Scope: INSTANCE
701
706
- Default value: `1`
702
707
- This variable is used to control whether to include the execution plan of slow queries in the slow log.
- This variable is used to output the threshold value of the time consumed by the slow log. When the time consumed by a query is larger than this value, this query is considered as a slow log and its log is output to the slow query log.
762
767
@@ -766,6 +771,19 @@ Usage example:
766
771
SET tidb_slow_log_threshold = 200;
767
772
```
768
773
774
+
### tidb_enable_collect_execution_info
775
+
776
+
- Scope: INSTANCE
777
+
- Default value: 1
778
+
- This variable controls whether to record the execution information of each operator in the slow query log.
779
+
780
+
### tidb_log_desensitization
781
+
782
+
- Scope: GLOBAL
783
+
- Default value: 0
784
+
- This variable controls whether to hide user information in the SQL statement being recorded into the TiDB log and slow log.
785
+
- When you set the variable to `1`, user information is hidden. For example, if the executed SQL statement is `insert into t values (1,2)`, the statement is recorded as `insert into t values (?,?)` in the log.
786
+
769
787
### tidb_slow_query_file
770
788
771
789
- Scope: SESSION
@@ -810,7 +828,7 @@ SET tidb_slow_log_threshold = 200;
810
828
811
829
### tidb_store_limit <span class="version-mark">New in v3.0.4 and v4.0</span>
812
830
813
-
- Scope: SESSION | GLOBAL
831
+
- Scope: INSTANCE | GLOBAL
814
832
- Default value: 0
815
833
- This variable is used to limit the maximum number of requests TiDB can send to TiKV at the same time. 0 means no limit.
816
834
@@ -845,7 +863,7 @@ SET tidb_slow_log_threshold = 200;
845
863
846
864
- Scope: SESSION | GLOBAL
847
865
- Default value: 4
848
-
- This variable is used to set the concurrency degree of the window operator.
866
+
- This variable is used to set the concurrency degree of the window operator.
0 commit comments