From 1c1b1760d4832179aad8f6bc6f6184de67495374 Mon Sep 17 00:00:00 2001 From: Min Zhou Date: Fri, 6 Oct 2023 22:34:53 -0700 Subject: [PATCH 1/3] This is an automated cherry-pick of #14905 Signed-off-by: ti-chi-bot --- optimizer-hints.md | 27 +++++++++++++++++++++++++++ system-variables.md | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/optimizer-hints.md b/optimizer-hints.md index e022f8ca70299..5f8a1814da183 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -938,3 +938,30 @@ EXPLAIN SELECT /*+ leading(t1, t3), inl_join(t3) */ * FROM t1, t2, t3 WHERE t1.i +---------------------------------+----------+-----------+---------------+---------------------------------------------------------------------------------------------------------------------+ 9 rows in set (0.01 sec) ``` +<<<<<<< HEAD +======= + +### Using hints causes the `Can't find a proper physical plan for this query` error + +The `Can't find a proper physical plan for this query` error might occur in the following scenarios: + +- A query itself does not require reading indexes in order. That is, for this query, the optimizer does not generate a plan to read indexes in order in any case without using hints. In this case, if the `ORDER_INDEX` hint is specified, this error occurs. To resolve this issue, remove the corresponding `ORDER_INDEX` hint. +- A query excludes all possible join methods by using the `NO_JOIN` related hints. + +```sql +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +EXPLAIN SELECT /*+ NO_HASH_JOIN(t1), NO_MERGE_JOIN(t1) */ * FROM t1, t2 WHERE t1.a=t2.a; +ERROR 1815 (HY000): Internal : Can't find a proper physical plan for this query +``` + +- The system variable [`tidb_opt_enable_hash_join`](/system-variables.md#tidb_opt_enable_hash_join-new-in-v740) is set to `OFF`, and all other join types are also excluded. + +```sql +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +set tidb_opt_enable_hash_join=off; +EXPLAIN SELECT /*+ NO_MERGE_JOIN(t1) */ * FROM t1, t2 WHERE t1.a=t2.a; +ERROR 1815 (HY000): Internal : Can't find a proper physical plan for this query +``` +>>>>>>> b80e0c70b6 (sysvar: add system variable `tidb_opt_enable_hash_join` (#14905)) diff --git a/system-variables.md b/system-variables.md index d3c7eb989d7f9..186c2028873af 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3449,6 +3449,28 @@ mysql> desc select count(distinct a) from test.t; - Default value: `ON` - This variable is used to control whether the optimizer estimates the number of rows based on column order correlation +<<<<<<< HEAD +======= +### tidb_opt_enable_hash_join New in v7.4.0 + +- Scope: SESSION | GLOBAL +- Persists to cluster: Yes +- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No +- Type: Boolean +- Default value: `ON` +- This variable is used to control whether the optimizer selects hash joins for tables. The value is `ON` by default. If it is set to `OFF`, the optimizer avoids selecting hash joins when generating execution plans, unless no other join algorithm is available. +- If both the system variable `tidb_opt_enable_hash_join` and the `HASH_JOIN` hint are configured, the `HASH_JOIN` hint takes precedence. Even if `tidb_opt_enable_hash_join` is set to `OFF`, when you specify a `HASH_JOIN` hint in a query, the TiDB optimizer still enforces a hash join plan. + +### tidb_opt_enable_non_eval_scalar_subquery New in v7.3.0 + +- Scope: SESSION | GLOBAL +- Persists to cluster: Yes +- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No +- Type: Boolean +- Default value: `OFF` +- This variable is used to control whether the `EXPLAIN` statement disables the execution of constant subqueries that can be expanded at the optimization stage. When this variable is set to `OFF`, the `EXPLAIN` statement expands the subquery in advance at the optimization stage. When this variable is set to `ON`, the `EXPLAIN` statement does not expand the subquery at the optimization stage. For more information, see [Disable subquery expansion](/explain-walkthrough.md#disable-the-early-execution-of-subqueries). + +>>>>>>> b80e0c70b6 (sysvar: add system variable `tidb_opt_enable_hash_join` (#14905)) ### tidb_opt_enable_late_materialization New in v7.0.0 - Scope: SESSION | GLOBAL From 07633b105beaa34220df8dc98c18681e3c611ff2 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Tue, 17 Oct 2023 20:11:02 +0800 Subject: [PATCH 2/3] Apply suggestions from code review --- optimizer-hints.md | 3 --- system-variables.md | 14 +------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/optimizer-hints.md b/optimizer-hints.md index 5f8a1814da183..83ea09be28190 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -938,8 +938,6 @@ EXPLAIN SELECT /*+ leading(t1, t3), inl_join(t3) */ * FROM t1, t2, t3 WHERE t1.i +---------------------------------+----------+-----------+---------------+---------------------------------------------------------------------------------------------------------------------+ 9 rows in set (0.01 sec) ``` -<<<<<<< HEAD -======= ### Using hints causes the `Can't find a proper physical plan for this query` error @@ -964,4 +962,3 @@ set tidb_opt_enable_hash_join=off; EXPLAIN SELECT /*+ NO_MERGE_JOIN(t1) */ * FROM t1, t2 WHERE t1.a=t2.a; ERROR 1815 (HY000): Internal : Can't find a proper physical plan for this query ``` ->>>>>>> b80e0c70b6 (sysvar: add system variable `tidb_opt_enable_hash_join` (#14905)) diff --git a/system-variables.md b/system-variables.md index 186c2028873af..c4d8c743ecc97 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3449,9 +3449,7 @@ mysql> desc select count(distinct a) from test.t; - Default value: `ON` - This variable is used to control whether the optimizer estimates the number of rows based on column order correlation -<<<<<<< HEAD -======= -### tidb_opt_enable_hash_join New in v7.4.0 +### tidb_opt_enable_hash_join New in v7.1.2 - Scope: SESSION | GLOBAL - Persists to cluster: Yes @@ -3461,16 +3459,6 @@ mysql> desc select count(distinct a) from test.t; - This variable is used to control whether the optimizer selects hash joins for tables. The value is `ON` by default. If it is set to `OFF`, the optimizer avoids selecting hash joins when generating execution plans, unless no other join algorithm is available. - If both the system variable `tidb_opt_enable_hash_join` and the `HASH_JOIN` hint are configured, the `HASH_JOIN` hint takes precedence. Even if `tidb_opt_enable_hash_join` is set to `OFF`, when you specify a `HASH_JOIN` hint in a query, the TiDB optimizer still enforces a hash join plan. -### tidb_opt_enable_non_eval_scalar_subquery New in v7.3.0 - -- Scope: SESSION | GLOBAL -- Persists to cluster: Yes -- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No -- Type: Boolean -- Default value: `OFF` -- This variable is used to control whether the `EXPLAIN` statement disables the execution of constant subqueries that can be expanded at the optimization stage. When this variable is set to `OFF`, the `EXPLAIN` statement expands the subquery in advance at the optimization stage. When this variable is set to `ON`, the `EXPLAIN` statement does not expand the subquery at the optimization stage. For more information, see [Disable subquery expansion](/explain-walkthrough.md#disable-the-early-execution-of-subqueries). - ->>>>>>> b80e0c70b6 (sysvar: add system variable `tidb_opt_enable_hash_join` (#14905)) ### tidb_opt_enable_late_materialization New in v7.0.0 - Scope: SESSION | GLOBAL From c7d05ae33da03bac30c74efe7f8fbc69f652b02d Mon Sep 17 00:00:00 2001 From: xixirangrang <35301108+hfxsd@users.noreply.github.com> Date: Tue, 17 Oct 2023 20:20:55 +0800 Subject: [PATCH 3/3] fix links --- optimizer-hints.md | 2 +- system-variables.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/optimizer-hints.md b/optimizer-hints.md index 83ea09be28190..e1ac1327eeb28 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -953,7 +953,7 @@ EXPLAIN SELECT /*+ NO_HASH_JOIN(t1), NO_MERGE_JOIN(t1) */ * FROM t1, t2 WHERE t1 ERROR 1815 (HY000): Internal : Can't find a proper physical plan for this query ``` -- The system variable [`tidb_opt_enable_hash_join`](/system-variables.md#tidb_opt_enable_hash_join-new-in-v740) is set to `OFF`, and all other join types are also excluded. +- The system variable [`tidb_opt_enable_hash_join`](/system-variables.md#tidb_opt_enable_hash_join-new-in-v712) is set to `OFF`, and all other join types are also excluded. ```sql CREATE TABLE t1 (a INT); diff --git a/system-variables.md b/system-variables.md index c4d8c743ecc97..6cab19ab10d48 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3453,7 +3453,6 @@ mysql> desc select count(distinct a) from test.t; - Scope: SESSION | GLOBAL - Persists to cluster: Yes -- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No - Type: Boolean - Default value: `ON` - This variable is used to control whether the optimizer selects hash joins for tables. The value is `ON` by default. If it is set to `OFF`, the optimizer avoids selecting hash joins when generating execution plans, unless no other join algorithm is available.