From 05035d6f57660607324a29ad19a3542f304bb1a3 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Thu, 18 Aug 2022 15:36:52 +0800 Subject: [PATCH 1/4] This is an automated cherry-pick of #9943 Signed-off-by: ti-chi-bot --- system-variables.md | 147 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/system-variables.md b/system-variables.md index 212a1ffd229bc..704ac408e92c8 100644 --- a/system-variables.md +++ b/system-variables.md @@ -363,6 +363,38 @@ This variable is an alias for `last_insert_id`. > > Unlike in MySQL, the `max_execution_time` system variable currently works on all kinds of statements in TiDB, not only restricted to the `SELECT` statement. The precision of the timeout value is roughly 100ms. This means the statement might not be terminated in accurate milliseconds as you specify. +### max_prepared_stmt_count + +- Scope: GLOBAL +- Persists to cluster: Yes +- Type: Integer +- Default value: `-1` +- Range: `[-1, 1048576]` +- Specifies the maximum number of [`PREPARE`](/sql-statements/sql-statement-prepare.md) statements in a session. +- The value of `-1` means no limit on the maximum number of `PREPARE` statements in a session. +- If you set the variable to a value that exceeds the upper limit `1048576`, `1048576` is used instead: + +```sql +mysql> SET GLOBAL max_prepared_stmt_count = 1048577; +Query OK, 0 rows affected, 1 warning (0.01 sec) + +mysql> SHOW WARNINGS; ++---------+------+--------------------------------------------------------------+ +| Level | Code | Message | ++---------+------+--------------------------------------------------------------+ +| Warning | 1292 | Truncated incorrect max_prepared_stmt_count value: '1048577' | ++---------+------+--------------------------------------------------------------+ +1 row in set (0.00 sec) + +mysql> SHOW GLOBAL VARIABLES LIKE 'max_prepared_stmt_count'; ++-------------------------+---------+ +| Variable_name | Value | ++-------------------------+---------+ +| max_prepared_stmt_count | 1048576 | ++-------------------------+---------+ +1 row in set (0.00 sec) +``` + ### plugin_dir - Scope: GLOBAL @@ -1174,6 +1206,14 @@ This variable is associated with a feature available since v6.2.0 and not usable - Since v6.1.0, the [Join Reorder](/join-reorder.md) algorithm of TiDB supports Outer Join. This variable controls the support behavior. The default value is `OFF`, which means the Join Reorder's support for Outer Join is disabled by default. - For a cluster upgraded from a version earlier than v6.1.0, the default value is `OFF`. For a cluster upgraded from v6.1.0, the default value is `ON`. +### tidb_enable_ordered_result_mode + +- Scope: SESSION | GLOBAL +- Persists to cluster: Yes +- Default value: `OFF` +- Specifies whether to sort the final output result automatically. +- For example, with this variable enabled, TiDB processes `SELECT a, MAX(b) FROM t GROUP BY a` as `SELECT a, MAX(b) FROM t GROUP BY a ORDER BY a, MAX(b)`. + ### tidb_enable_paging New in v5.4.0 - Scope: SESSION | GLOBAL @@ -2007,6 +2047,35 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified - This variable is used to set whether the optimizer executes the optimization operation of pushing down the aggregate function to the position before Join, Projection, and UnionAll. - When the aggregate operation is slow in query, you can set the variable value to ON. +### tidb_opt_cartesian_bcj + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Integer +- Default value: `1` +- Range: `[0, 2]` +- Indicates whether to allow the Broadcast Cartesian Join. +- `0` means that the Broadcast Cartesian Join is not allowed. `1` means that it is allowed based on [`tidb_broadcast_join_threshold_count`](#tidb_broadcast_join_threshold_count-new-in-v50). `2` means that it is always allowed even if the table size exceeds the threshold. +- This variable is internally used in TiDB, and it is **NOT** recommended to modify its value. + +### tidb_opt_concurrency_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `3.0` +- Indicates the CPU cost of starting a Golang goroutine in TiDB. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + +### tidb_opt_cop_cpu_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `3.0` +- Indicates the CPU cost for TiKV Coprocessor to process one row. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + ### tidb_opt_correlation_exp_factor - Scope: SESSION | GLOBAL @@ -2029,6 +2098,33 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified - Range: `[0, 1]` - This variable is used to set the threshold value that determines whether to enable estimating the row count by using column order correlation. If the order correlation between the current column and the `handle` column exceeds the threshold value, this method is enabled. +### tidb_opt_cpu_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `3.0` +- Indicates the CPU cost for TiDB to process one row. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + +### tidb_opt_desc_scan_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `3.0` +- Indicates the cost for TiKV to scan one row from the disk in descending order. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + +### tidb_opt_disk_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `1.5` +- Indicates the I/O cost for TiDB to read or write one byte of data from or to the temporary disk. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + ### tidb_opt_distinct_agg_push_down - Scope: SESSION @@ -2108,6 +2204,35 @@ mysql> desc select count(distinct a) from test.t; - This variable is used to set the threshold that determines whether to push the Limit or TopN operator down to TiKV. - If the value of the Limit or TopN operator is smaller than or equal to this threshold, these operators are forcibly pushed down to TiKV. This variable resolves the issue that the Limit or TopN operator cannot be pushed down to TiKV partly due to wrong estimation. +<<<<<<< HEAD +======= +### tidb_opt_memory_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `0.001` +- Indicates the memory cost for TiDB to store one row. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + +### tidb_opt_mpp_outer_join_fixed_build_side New in v5.1.0 + +- Scope: SESSION | GLOBAL +- Persists to cluster: Yes +- Type: Boolean +- Default value: `ON` +- When the variable value is `ON`, the left join operator always uses inner table as the build side and the right join operator always uses outer table as the build side. If you set the value to `OFF`, the outer join operator can use either side of the tables as the build side. + +### tidb_opt_network_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `1.0` +- Indicates the net cost of transferring 1 byte of data through the network. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + +>>>>>>> 44108aaa6 (planner: add docs for some variables (#9943)) ### tidb_opt_prefer_range_scan New in v5.0 - Scope: SESSION | GLOBAL @@ -2143,7 +2268,29 @@ explain select * from t where age=5; ### tidb_opt_write_row_id +<<<<<<< HEAD +======= +### tidb_opt_scan_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `1.5` +- Indicates the cost for TiKV to scan one row of data from the disk in ascending order. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + +### tidb_opt_seek_factor + +- Scope: SESSION | GLOBAL +- Persists to cluster: YES +- Type: Float +- Range: `[0, 2147483647]` +- Default value: `20` +- Indicates the start-up cost for TiDB to request data from TiKV. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. + +### tidb_opt_skew_distinct_agg New in v6.2.0 +>>>>>>> 44108aaa6 (planner: add docs for some variables (#9943)) > **Note:** > From 27cf012a3d6155a164c9f5262444f3a42ef76577 Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Sun, 9 Oct 2022 10:33:07 +0800 Subject: [PATCH 2/4] resolve conflicts --- system-variables.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/system-variables.md b/system-variables.md index 704ac408e92c8..7230974b9e98a 100644 --- a/system-variables.md +++ b/system-variables.md @@ -2204,8 +2204,6 @@ mysql> desc select count(distinct a) from test.t; - This variable is used to set the threshold that determines whether to push the Limit or TopN operator down to TiKV. - If the value of the Limit or TopN operator is smaller than or equal to this threshold, these operators are forcibly pushed down to TiKV. This variable resolves the issue that the Limit or TopN operator cannot be pushed down to TiKV partly due to wrong estimation. -<<<<<<< HEAD -======= ### tidb_opt_memory_factor - Scope: SESSION | GLOBAL @@ -2232,7 +2230,6 @@ mysql> desc select count(distinct a) from test.t; - Default value: `1.0` - Indicates the net cost of transferring 1 byte of data through the network. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. ->>>>>>> 44108aaa6 (planner: add docs for some variables (#9943)) ### tidb_opt_prefer_range_scan New in v5.0 - Scope: SESSION | GLOBAL @@ -2266,11 +2263,6 @@ explain select * from t where age=5; 3 rows in set (0.00 sec) ``` -### tidb_opt_write_row_id - -<<<<<<< HEAD - -======= ### tidb_opt_scan_factor - Scope: SESSION | GLOBAL @@ -2289,8 +2281,9 @@ explain select * from t where age=5; - Default value: `20` - Indicates the start-up cost for TiDB to request data from TiKV. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. -### tidb_opt_skew_distinct_agg New in v6.2.0 ->>>>>>> 44108aaa6 (planner: add docs for some variables (#9943)) +### tidb_opt_write_row_id + + > **Note:** > From 6933aec025843f762d6a235e7ab4b897873c3c38 Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Sun, 9 Oct 2022 14:45:00 +0800 Subject: [PATCH 3/4] Update sql-physical-optimization.md --- sql-physical-optimization.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sql-physical-optimization.md b/sql-physical-optimization.md index 499e7e99b5dac..52f1459f949d0 100644 --- a/sql-physical-optimization.md +++ b/sql-physical-optimization.md @@ -6,12 +6,25 @@ title: SQL Physical Optimization Physical optimization is cost-based optimization, which makes a physical execution plan for the logical execution plan generated in the previous stage. In this stage, the optimizer selects a specific physical implementation for each operator in the logical execution plan. Different physical implementations of logical operators have different time complexity, resource consumption and physical properties. In this process, the optimizer determines the cost of different physical implementations based on the statistics of the data, and selects the physical execution plan with the smallest overall cost. + + [Understand the Query Execution Plan](/explain-overview.md) has introduced some physical operators. This chapter focuses on the following aspects: - In [Index Selection](/choose-index.md), you will learn how to select the optimal index to access tables when TiDB has multiple indexes on a table. - In [Introduction to Statistics](/statistics.md), you will learn what statistics TiDB collects to obtain the data distribution of a table. - [Wrong Index Solution](/wrong-index-solution.md) introduces how to use the right index when you find the index is selected wrongly. - [Distinct Optimization](/agg-distinct-optimization.md) introduces an optimization related to the `DISTINCT` keyword during physical optimization. In this section, you will learn its advantages and disadvantages and how to use it. - - [Cost Model](/cost-model.md) introduces how to choose an optimal execution plan based on the cost model during physical optimization. + + + + + +[Understand the Query Execution Plan](/explain-overview.md) has introduced some physical operators. This chapter focuses on the following aspects: + +- In [Index Selection](/choose-index.md), you will learn how to select the optimal index to access tables when TiDB has multiple indexes on a table. +- In [Introduction to Statistics](/statistics.md), you will learn what statistics TiDB collects to obtain the data distribution of a table. +- [Wrong Index Solution](/wrong-index-solution.md) introduces how to use the right index when you find the index is selected wrongly. +- [Distinct Optimization](/agg-distinct-optimization.md) introduces an optimization related to the `DISTINCT` keyword during physical optimization. In this section, you will learn its advantages and disadvantages and how to use it. + From 12a16acc8c0eb096ef99e7656c103a9710d82b3a Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Mon, 10 Oct 2022 16:21:06 +0800 Subject: [PATCH 4/4] Apply suggestions from code review --- system-variables.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system-variables.md b/system-variables.md index 7230974b9e98a..063f96ed4d65c 100644 --- a/system-variables.md +++ b/system-variables.md @@ -2047,7 +2047,7 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified - This variable is used to set whether the optimizer executes the optimization operation of pushing down the aggregate function to the position before Join, Projection, and UnionAll. - When the aggregate operation is slow in query, you can set the variable value to ON. -### tidb_opt_cartesian_bcj +### tidb_opt_broadcast_cartesian_join - Scope: SESSION | GLOBAL - Persists to cluster: YES @@ -2067,7 +2067,7 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified - Default value: `3.0` - Indicates the CPU cost of starting a Golang goroutine in TiDB. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. -### tidb_opt_cop_cpu_factor +### tidb_opt_copcpu_factor - Scope: SESSION | GLOBAL - Persists to cluster: YES @@ -2107,7 +2107,7 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified - Default value: `3.0` - Indicates the CPU cost for TiDB to process one row. This variable is internally used in the [Cost Model](/cost-model.md), and it is **NOT** recommended to modify its value. -### tidb_opt_desc_scan_factor +### tidb_opt_desc_factor - Scope: SESSION | GLOBAL - Persists to cluster: YES @@ -2218,7 +2218,7 @@ mysql> desc select count(distinct a) from test.t; - Scope: SESSION | GLOBAL - Persists to cluster: Yes - Type: Boolean -- Default value: `ON` +- Default value: `OFF` - When the variable value is `ON`, the left join operator always uses inner table as the build side and the right join operator always uses outer table as the build side. If you set the value to `OFF`, the outer join operator can use either side of the tables as the build side. ### tidb_opt_network_factor