From ee6956c03d233ab126e9e9ff3d140bdc10b14a5d Mon Sep 17 00:00:00 2001 From: Min Zhou Date: Thu, 21 Sep 2023 21:31:40 -0700 Subject: [PATCH 1/9] doc for system variable tidb_opt_enable_hash_join --- optimizer-hints.md | 10 ++++++++++ system-variables.md | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/optimizer-hints.md b/optimizer-hints.md index 30486b687c516..a570ea20d59a5 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -989,3 +989,13 @@ 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` 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 +``` diff --git a/system-variables.md b/system-variables.md index a9dc140d21e30..1b59a26bbcfa7 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3517,6 +3517,15 @@ 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 +### tidb_opt_enable_hash_join + +- Scope: SESSION | GLOBAL +- Persists to cluster: Yes +- Type: Boolean +- Default value: `ON` +- With tidb_opt_enable_hash_join=off, the optimizer ignores hash join when generating execution plans. +- The `HASH_JOIN` hint takes precedence even if `tidb_opt_enable_hash_join` is set to `off`. If a `HASH_JOIN` hint is specified in a query, the TiDB optimizer will still enforce a hash join plan. + ### `tidb_opt_enable_non_eval_scalar_subquery` New in v7.3.0 - Scope: SESSION | GLOBAL From e0a8935bf422d8f1f3128a5b099bb618a3cb76cf Mon Sep 17 00:00:00 2001 From: Min Zhou Date: Tue, 26 Sep 2023 09:36:02 -0700 Subject: [PATCH 2/9] Update system-variables.md Co-authored-by: Aolin --- system-variables.md | 1 + 1 file changed, 1 insertion(+) diff --git a/system-variables.md b/system-variables.md index 1b59a26bbcfa7..7c7136554fe5b 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3521,6 +3521,7 @@ 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` - With tidb_opt_enable_hash_join=off, the optimizer ignores hash join when generating execution plans. From 18a3d7a7cd630cc605cc29b26d4f60d0627d969d Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 27 Sep 2023 10:03:35 +0800 Subject: [PATCH 3/9] Update optimizer-hints.md Co-authored-by: xixirangrang --- optimizer-hints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizer-hints.md b/optimizer-hints.md index a570ea20d59a5..7de5a2ba5cf78 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -990,7 +990,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` 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-v740) is set to `off`, and all other join types are also excluded. ```sql CREATE TABLE t1 (a INT); From 35280687634e76c92ad311c90f293be5d6064a53 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 27 Sep 2023 10:03:48 +0800 Subject: [PATCH 4/9] Update system-variables.md Co-authored-by: xixirangrang --- system-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-variables.md b/system-variables.md index 7c7136554fe5b..066e6309abedf 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3524,7 +3524,7 @@ mysql> desc select count(distinct a) from test.t; - Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No - Type: Boolean - Default value: `ON` -- With tidb_opt_enable_hash_join=off, the optimizer ignores hash join when generating execution plans. +- This variable is used to control whether the optimizer will select hash joins for tables. The value is `ON` by default. If it is set to `OFF`, the optimizer ignores hash join when generating execution plans. - The `HASH_JOIN` hint takes precedence even if `tidb_opt_enable_hash_join` is set to `off`. If a `HASH_JOIN` hint is specified in a query, the TiDB optimizer will still enforce a hash join plan. ### `tidb_opt_enable_non_eval_scalar_subquery` New in v7.3.0 From 9165081b870b1ba0edfbb886c6ff7fdde478e8b6 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Wed, 27 Sep 2023 10:04:06 +0800 Subject: [PATCH 5/9] Update system-variables.md Co-authored-by: xixirangrang --- system-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-variables.md b/system-variables.md index 066e6309abedf..cc18b23684c7b 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3517,7 +3517,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 -### tidb_opt_enable_hash_join +### `tidb_opt_enable_hash_join` New in v7.4.0 - Scope: SESSION | GLOBAL - Persists to cluster: Yes From d60b9b5ad3c71dac39986d2e3215b28e3fb39883 Mon Sep 17 00:00:00 2001 From: xixirangrang <35301108+hfxsd@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:57:11 +0800 Subject: [PATCH 6/9] Update system-variables.md --- system-variables.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system-variables.md b/system-variables.md index cc18b23684c7b..61fcfa9a1c99d 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3517,7 +3517,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 -### `tidb_opt_enable_hash_join` New in v7.4.0 +### tidb_opt_enable_hash_join New in v7.4.0 - Scope: SESSION | GLOBAL - Persists to cluster: Yes @@ -3527,7 +3527,7 @@ mysql> desc select count(distinct a) from test.t; - This variable is used to control whether the optimizer will select hash joins for tables. The value is `ON` by default. If it is set to `OFF`, the optimizer ignores hash join when generating execution plans. - The `HASH_JOIN` hint takes precedence even if `tidb_opt_enable_hash_join` is set to `off`. If a `HASH_JOIN` hint is specified in a query, the TiDB optimizer will still enforce a hash join plan. -### `tidb_opt_enable_non_eval_scalar_subquery` New in v7.3.0 +### tidb_opt_enable_non_eval_scalar_subquery New in v7.3.0 - Scope: SESSION | GLOBAL - Persists to cluster: Yes From 9660ff63d2eb2a6dd2ff71764a7628293d0722ff Mon Sep 17 00:00:00 2001 From: xixirangrang <35301108+hfxsd@users.noreply.github.com> Date: Wed, 27 Sep 2023 11:07:31 +0800 Subject: [PATCH 7/9] Update system-variables.md --- system-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-variables.md b/system-variables.md index 61fcfa9a1c99d..acca21a26e2db 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3525,7 +3525,7 @@ mysql> desc select count(distinct a) from test.t; - Type: Boolean - Default value: `ON` - This variable is used to control whether the optimizer will select hash joins for tables. The value is `ON` by default. If it is set to `OFF`, the optimizer ignores hash join when generating execution plans. -- The `HASH_JOIN` hint takes precedence even if `tidb_opt_enable_hash_join` is set to `off`. If a `HASH_JOIN` hint is specified in a query, the TiDB optimizer will still enforce a hash join plan. +- 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 From 5c5eaf67ef6e3db1dc9f308c62a63fbacf56a983 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Wed, 27 Sep 2023 11:11:45 +0800 Subject: [PATCH 8/9] Update optimizer-hints.md --- optimizer-hints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizer-hints.md b/optimizer-hints.md index 7de5a2ba5cf78..adf7196af38d0 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -990,7 +990,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-v740) is set to `OFF`, and all other join types are also excluded. ```sql CREATE TABLE t1 (a INT); From 6c8814407f1cdbd0a2d70d19a537c7332a067df0 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Sat, 7 Oct 2023 10:35:11 +0800 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: Grace Cai --- system-variables.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system-variables.md b/system-variables.md index acca21a26e2db..a18b0f0a6ed31 100644 --- a/system-variables.md +++ b/system-variables.md @@ -3524,8 +3524,8 @@ mysql> desc select count(distinct a) from test.t; - 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 will select hash joins for tables. The value is `ON` by default. If it is set to `OFF`, the optimizer ignores hash join when generating execution plans. -- 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. +- 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