From 20867581f72d8ba87f5ae70d2bb84556e806b31c Mon Sep 17 00:00:00 2001 From: toutdesuite Date: Fri, 28 Feb 2020 17:05:54 +0800 Subject: [PATCH] Update optimizer-hints.md --- reference/performance/optimizer-hints.md | 56 ++++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/reference/performance/optimizer-hints.md b/reference/performance/optimizer-hints.md index c5d51363ddfa6..c4109bc660146 100644 --- a/reference/performance/optimizer-hints.md +++ b/reference/performance/optimizer-hints.md @@ -182,6 +182,34 @@ The `USE_INDEX_MERGE(t1_name, idx1_name [, idx2_name ...])` hint tells the optim 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. + ## 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. @@ -225,31 +253,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. - -### 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.