diff --git a/optimizer-hints.md b/optimizer-hints.md index 1dcff3340ed72..3c4bccc714f5e 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -928,3 +928,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`](/system-variables.md#tidb_opt_enable_hash_join-new-in-v656) 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 927207fe5a4df..dbed0a28cf792 100644 --- a/system-variables.md +++ b/system-variables.md @@ -2958,6 +2958,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 New in v6.5.6 + +- Scope: SESSION | GLOBAL +- Persists to cluster: Yes +- 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_force_inline_cte New in v6.3.0 - Scope: SESSION | GLOBAL