From 2d0e78b565c1f7de4fb967145d823221d16243df Mon Sep 17 00:00:00 2001
From: gengliqi <gengliqiii@gmail.com>
Date: Sat, 29 Mar 2025 00:40:53 +0800
Subject: [PATCH 1/5] add tiflash_hash_join_version

Signed-off-by: gengliqi <gengliqiii@gmail.com>
---
 system-variables.md | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/system-variables.md b/system-variables.md
index 15cfe1b9be5de..1f1b289437cbe 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -6341,6 +6341,21 @@ For details, see [Identify Slow Queries](/identify-slow-queries.md).
     - `force_streaming`: TiFlash directly sends data to the next stage of HashAgg without pre-aggregation.
     - `auto`: TiFlash automatically chooses whether to perform pre-aggregation based on the current workload's aggregation degree.
 
+### tiflash_hash_join_version <span class="version-mark">New in v9.1.0</span>
+
+- Scope: SESSION | GLOBAL
+- Persists to cluster: Yes
+- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): Yes
+- Type: Enumeration
+- Default value: `legacy`.
+- Possible values: `legacy`, `optimized`
+- This variable is used to control whether TiFlash uses an optimized version of hash join. The value is `legacy` by default, which means the optimized version is not used. If it is set to `optimized`, TiFlash uses the optimized version to execute hash join for better performance.
+
+> **Note:**
+>
+> - Currently, the optimized hash join only supports inner join, so for other joins, even if `tiflash_hash_join_version` is set to `optimized`, TiFlash still uses the legacy hash join.
+> - Currently, the optimized hash join in TiFlash does not support spilling to disk when the memory is out of quota, which means TiFlash will use the legacy hash join if both [`tiflash_mem_quota_query_per_node`](/system-variables.md#tiflash_mem_quota_query_per_node-new-in-v740) and `tiflash_query_spill_ratio` are greater than 0 or [tidb_max_bytes_before_tiflash_external_join](/system-variables.md#tidb_max_bytes_before_tiflash_external_join-new-in-v700) is greater than 0.
+
 ### tikv_client_read_timeout <span class="version-mark">New in v7.4.0</span>
 
 - Scope: SESSION | GLOBAL

From 337e779931ef44a0b0c3d6a72e0cd5c75af4393d Mon Sep 17 00:00:00 2001
From: gengliqi <gengliqiii@gmail.com>
Date: Sat, 29 Mar 2025 00:48:32 +0800
Subject: [PATCH 2/5] u

Signed-off-by: gengliqi <gengliqiii@gmail.com>
---
 system-variables.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/system-variables.md b/system-variables.md
index 1f1b289437cbe..126ed6260eda2 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -6354,7 +6354,7 @@ For details, see [Identify Slow Queries](/identify-slow-queries.md).
 > **Note:**
 >
 > - Currently, the optimized hash join only supports inner join, so for other joins, even if `tiflash_hash_join_version` is set to `optimized`, TiFlash still uses the legacy hash join.
-> - Currently, the optimized hash join in TiFlash does not support spilling to disk when the memory is out of quota, which means TiFlash will use the legacy hash join if both [`tiflash_mem_quota_query_per_node`](/system-variables.md#tiflash_mem_quota_query_per_node-new-in-v740) and `tiflash_query_spill_ratio` are greater than 0 or [tidb_max_bytes_before_tiflash_external_join](/system-variables.md#tidb_max_bytes_before_tiflash_external_join-new-in-v700) is greater than 0.
+> - Currently, the optimized hash join in TiFlash does not support spilling to disk when the memory is out of quota, which means TiFlash will use the legacy hash join if both [`tiflash_mem_quota_query_per_node`](/system-variables.md#tiflash_mem_quota_query_per_node-new-in-v740) and [`tiflash_query_spill_ratio`](/system-variables.md#tiflash_query_spill_ratio-new-in-v740) are greater than 0 or [tidb_max_bytes_before_tiflash_external_join](/system-variables.md#tidb_max_bytes_before_tiflash_external_join-new-in-v700) is greater than 0.
 
 ### tikv_client_read_timeout <span class="version-mark">New in v7.4.0</span>
 

From 21f67b45b3a0abdb41669e6b54e0f2c9445cc8f8 Mon Sep 17 00:00:00 2001
From: gengliqi <gengliqiii@gmail.com>
Date: Sat, 29 Mar 2025 00:51:43 +0800
Subject: [PATCH 3/5] u

Signed-off-by: gengliqi <gengliqiii@gmail.com>
---
 system-variables.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/system-variables.md b/system-variables.md
index 126ed6260eda2..e2fe0ab568da9 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -6343,6 +6343,10 @@ For details, see [Identify Slow Queries](/identify-slow-queries.md).
 
 ### tiflash_hash_join_version <span class="version-mark">New in v9.1.0</span>
 
+> **Warning:**
+>
+> The feature controlled by this variable is experimental. It is not recommended that you use it in the production environment. This feature might be changed or removed without prior notice. If you find a bug, you can report an [issue](https://github.com/pingcap/tidb/issues) on GitHub.
+
 - Scope: SESSION | GLOBAL
 - Persists to cluster: Yes
 - Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): Yes

From 4cce3c7214e4df1ad17ec19c5e0092cdb804d724 Mon Sep 17 00:00:00 2001
From: gengliqi <gengliqiii@gmail.com>
Date: Sat, 29 Mar 2025 01:12:27 +0800
Subject: [PATCH 4/5] u

Signed-off-by: gengliqi <gengliqiii@gmail.com>
---
 system-variables.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/system-variables.md b/system-variables.md
index e2fe0ab568da9..14ec23772bbbf 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -6358,7 +6358,7 @@ For details, see [Identify Slow Queries](/identify-slow-queries.md).
 > **Note:**
 >
 > - Currently, the optimized hash join only supports inner join, so for other joins, even if `tiflash_hash_join_version` is set to `optimized`, TiFlash still uses the legacy hash join.
-> - Currently, the optimized hash join in TiFlash does not support spilling to disk when the memory is out of quota, which means TiFlash will use the legacy hash join if both [`tiflash_mem_quota_query_per_node`](/system-variables.md#tiflash_mem_quota_query_per_node-new-in-v740) and [`tiflash_query_spill_ratio`](/system-variables.md#tiflash_query_spill_ratio-new-in-v740) are greater than 0 or [tidb_max_bytes_before_tiflash_external_join](/system-variables.md#tidb_max_bytes_before_tiflash_external_join-new-in-v700) is greater than 0.
+> - Currently, the optimized hash join in TiFlash does not support spilling data to disk when the memory usage exceeds its quota. As a result, if both [`tiflash_mem_quota_query_per_node`](/system-variables.md#tiflash_mem_quota_query_per_node-new-in-v740) and [`tiflash_query_spill_ratio`](/system-variables.md#tiflash_query_spill_ratio-new-in-v740) are set to values greater than 0, or if [tidb_max_bytes_before_tiflash_external_join](/system-variables.md#tidb_max_bytes_before_tiflash_external_join-new-in-v700) is greater than 0, TiFlash will not use the optimized hash join.
 
 ### tikv_client_read_timeout <span class="version-mark">New in v7.4.0</span>
 

From 5b6b01fd3a4eb27083288d61610a06e002e27ff2 Mon Sep 17 00:00:00 2001
From: Liqi Geng <gengliqiii@gmail.com>
Date: Thu, 10 Apr 2025 16:38:03 +0800
Subject: [PATCH 5/5] Update system-variables.md

Co-authored-by: Aolin <aolinz@outlook.com>
---
 system-variables.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/system-variables.md b/system-variables.md
index 14ec23772bbbf..bf1fedd02eeaa 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -6341,7 +6341,7 @@ For details, see [Identify Slow Queries](/identify-slow-queries.md).
     - `force_streaming`: TiFlash directly sends data to the next stage of HashAgg without pre-aggregation.
     - `auto`: TiFlash automatically chooses whether to perform pre-aggregation based on the current workload's aggregation degree.
 
-### tiflash_hash_join_version <span class="version-mark">New in v9.1.0</span>
+### tiflash_hash_join_version <span class="version-mark">New in v9.0.0</span>
 
 > **Warning:**
 >