From fcb4c21f513d1097a53d135910a0b82b2530e77d Mon Sep 17 00:00:00 2001 From: toutdesuite Date: Fri, 28 Feb 2020 17:51:14 +0800 Subject: [PATCH 1/2] cherry pick #1896 to release-3.1 Signed-off-by: sre-bot --- reference/performance/optimizer-hints.md | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/reference/performance/optimizer-hints.md b/reference/performance/optimizer-hints.md index c7e9ae58959ee..d470ad7a73484 100644 --- a/reference/performance/optimizer-hints.md +++ b/reference/performance/optimizer-hints.md @@ -172,6 +172,47 @@ The `READ_FROM_STORAGE(TIFLASH[t1_name [, tl_name ...]], TIKV[t2_name [, tl_name select /*+ READ_FROM_STORAGE(TIFLASH[t1], TIKV[t2]) */ t1.a from t t1, t t2 where t1.a = t2.a; ``` +<<<<<<< HEAD +======= +### USE_INDEX_MERGE(t1_name, idx1_name [, idx2_name ...]) + +The `USE_INDEX_MERGE(t1_name, idx1_name [, idx2_name ...])` hint tells the optimizer to access a specific table with the index merge method. The given list of indexes are optional parameters. If you explicitly specify the list, TiDB selects indexes from the list to build index merge; if you do not give the list of indexes, TiDB selects indexes from all available indexes to build index merge. For example: + +{{< copyable "sql" >}} + +```sql +select /*+ USE_INDEX_MERGE(t1, idx_a, idx_b, idx_c) */ * from t t1 where t1.a > 10 or t1.b > 10; +``` + +### NO_INDEX_MERGE() + +The `NO_INDEX_MERGE()` hint disables the index merge feature of the optimizer. + +For example, the following query will not use index merge: + +{{< copyable "sql" >}} + +```sql +select /*+ NO_INDEX_MERGE() */ * from t where t.a > 0 or t.b > 0; +``` + +In addition to this hint, setting the `tidb_enable_index_merge` environment variable also controls whether to enable this feature. + +### USE_TOJA(boolean_value) + +The `boolean_value` parameter can be `TRUE` or `FALSE`. The `USE_TOJA(TRUE)` hint enables the optimizer to convert an `in` condition (containing a sub-query) to join and aggregation operations. Comparatively, the `USE_TOJA(FALSE)` hint disables this feature. + +For example, the following query will convert `in (select t2.a from t2) subq` to corresponding join and aggregation operations: + +{{< copyable "sql" >}} + +```sql +select /*+ USE_TOJA(TRUE) */ t1.a, t1.b from t1 where t1.a in (select t2.a from t2) subq; +``` + +In addition to this hint, setting the `tidb_opt_insubq_to_join_and_agg` environment variable also controls whether to enable this feature. + +>>>>>>> 743bf5b... Update optimizer-hints.md (#1896) ## Hints for setting operation parameters A hint for setting operation parameters follows behind **the first** `SELECT`, `UPDATE` or `DELETE` keyword in a SQL statement. A hint of this category modifies the operation parameter of the query to which this hint applies. @@ -215,6 +256,7 @@ select /*+ READ_FROM_REPLICA() */ * from t; ``` In addition to this hint, setting the `tidb_replica_read` environment variable to `'follower'` or `'leader'` also controls whether to enable this feature. +<<<<<<< HEAD ### USE_TOJA(boolean_value) @@ -229,3 +271,5 @@ select /*+ USE_TOJA(TRUE) */ t1.a, t1.b from t1 where t1.a in (select t2.a from ``` In addition to this hint, setting the `tidb_opt_insubq_to_join_and_agg` environment variable also controls whether to enable this feature. +======= +>>>>>>> 743bf5b... Update optimizer-hints.md (#1896) From 971afb4e8e91c8f02bdf366c45187fa506ef4134 Mon Sep 17 00:00:00 2001 From: yikeke Date: Fri, 28 Feb 2020 18:31:40 +0800 Subject: [PATCH 2/2] apply the original changes to v3.1 --- reference/performance/optimizer-hints.md | 44 ------------------------ 1 file changed, 44 deletions(-) diff --git a/reference/performance/optimizer-hints.md b/reference/performance/optimizer-hints.md index d470ad7a73484..448ba2981ef4b 100644 --- a/reference/performance/optimizer-hints.md +++ b/reference/performance/optimizer-hints.md @@ -172,32 +172,6 @@ The `READ_FROM_STORAGE(TIFLASH[t1_name [, tl_name ...]], TIKV[t2_name [, tl_name select /*+ READ_FROM_STORAGE(TIFLASH[t1], TIKV[t2]) */ t1.a from t t1, t t2 where t1.a = t2.a; ``` -<<<<<<< HEAD -======= -### USE_INDEX_MERGE(t1_name, idx1_name [, idx2_name ...]) - -The `USE_INDEX_MERGE(t1_name, idx1_name [, idx2_name ...])` hint tells the optimizer to access a specific table with the index merge method. The given list of indexes are optional parameters. If you explicitly specify the list, TiDB selects indexes from the list to build index merge; if you do not give the list of indexes, TiDB selects indexes from all available indexes to build index merge. For example: - -{{< copyable "sql" >}} - -```sql -select /*+ USE_INDEX_MERGE(t1, idx_a, idx_b, idx_c) */ * from t t1 where t1.a > 10 or t1.b > 10; -``` - -### NO_INDEX_MERGE() - -The `NO_INDEX_MERGE()` hint disables the index merge feature of the optimizer. - -For example, the following query will not use index merge: - -{{< copyable "sql" >}} - -```sql -select /*+ NO_INDEX_MERGE() */ * from t where t.a > 0 or t.b > 0; -``` - -In addition to this hint, setting the `tidb_enable_index_merge` environment variable also controls whether to enable this feature. - ### USE_TOJA(boolean_value) The `boolean_value` parameter can be `TRUE` or `FALSE`. The `USE_TOJA(TRUE)` hint enables the optimizer to convert an `in` condition (containing a sub-query) to join and aggregation operations. Comparatively, the `USE_TOJA(FALSE)` hint disables this feature. @@ -212,7 +186,6 @@ select /*+ USE_TOJA(TRUE) */ t1.a, t1.b from t1 where t1.a in (select t2.a from In addition to this hint, setting the `tidb_opt_insubq_to_join_and_agg` environment variable also controls whether to enable this feature. ->>>>>>> 743bf5b... Update optimizer-hints.md (#1896) ## Hints for setting operation parameters A hint for setting operation parameters follows behind **the first** `SELECT`, `UPDATE` or `DELETE` keyword in a SQL statement. A hint of this category modifies the operation parameter of the query to which this hint applies. @@ -256,20 +229,3 @@ select /*+ READ_FROM_REPLICA() */ * from t; ``` In addition to this hint, setting the `tidb_replica_read` environment variable to `'follower'` or `'leader'` also controls whether to enable this feature. -<<<<<<< HEAD - -### USE_TOJA(boolean_value) - -The `boolean_value` parameter can be `TRUE` or `FALSE`. The `USE_TOJA(TRUE)` hint enables the optimizer to convert an `in` condition (containing a sub-query) to join and aggregation operations. Comparatively, the `USE_TOJA(FALSE)` hint disables this feature. - -For example, the following query will convert `in (select t2.a from t2) subq` to corresponding join and aggregation operations: - -{{< copyable "sql" >}} - -```sql -select /*+ USE_TOJA(TRUE) */ t1.a, t1.b from t1 where t1.a in (select t2.a from t2) subq; -``` - -In addition to this hint, setting the `tidb_opt_insubq_to_join_and_agg` environment variable also controls whether to enable this feature. -======= ->>>>>>> 743bf5b... Update optimizer-hints.md (#1896)