From 716f4cae4686fd3cadfc6da7cd831a3bc9584368 Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Fri, 5 Aug 2022 14:24:06 +0800 Subject: [PATCH 1/2] planner: update the doc for merge hint (#9683) --- basic-features.md | 2 +- .../dev-guide-use-common-table-expression.md | 4 ++++ optimizer-hints.md | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/basic-features.md b/basic-features.md index ef0fbcc0adcc4..4583c860cf667 100644 --- a/basic-features.md +++ b/basic-features.md @@ -92,7 +92,7 @@ This document lists the features supported in each TiDB version. Note that suppo | [Auto increment](/auto-increment.md) | Y | Y | Y | Y | Y | Y | Y | Y | | [Auto random](/auto-random.md) | Y | Y | Y | Y | Y | Y | Y | Y | | [DDL algorithm assertions](/sql-statements/sql-statement-alter-table.md) | Y | Y | Y | Y | Y | Y | Y | Y | -| [Multi-schema change: add columns](/system-variables.md#tidb_enable_change_multi_schema) | Experimental | Experimental | Experimental | Experimental | Experimental | Experimental | Experimental | Experimental | +| Multi-schema change: add columns | Experimental | Experimental | Experimental | Experimental | Experimental | Experimental | Experimental | Experimental | | [Change column type](/sql-statements/sql-statement-modify-column.md) | Y | Y | Y | Y | Y | Y | N | N | | [Temporary tables](/temporary-tables.md) | Y | Y | Y | Y | N | N | N | N | diff --git a/develop/dev-guide-use-common-table-expression.md b/develop/dev-guide-use-common-table-expression.md index da7304ef13b35..dd28f9eb4ea7c 100644 --- a/develop/dev-guide-use-common-table-expression.md +++ b/develop/dev-guide-use-common-table-expression.md @@ -172,6 +172,10 @@ First, check out the books written by the author (ID is `2299112019`) in the CTE Note that the query in `books_authored_by_rm` executes only once, and then TiDB creates a temporary space to cache its result. When the queries in `books_with_average_ratings` and `books_with_orders` refer to `books_authored_by_rm`, TiDB gets its result directly from this temporary space. +> **Tip:** +> +> If the efficiency of the default CTE queries is not good, you can use the [`MERGE()`](/optimizer-hints.md#merge) hint to expand the CTE subquery to the outer query to improve the efficiency. + ### Recursive CTE Recursive CTE can be defined using the following syntax: diff --git a/optimizer-hints.md b/optimizer-hints.md index 2f0ffcb5523bc..6b42daa777d07 100644 --- a/optimizer-hints.md +++ b/optimizer-hints.md @@ -294,6 +294,27 @@ SHOW WARNINGS; +---------+------+-------------------------------------------------------------------------------------------------------------------+ ``` +### MERGE() + +Using the `MERGE()` hint in queries with common table expressions (CTE) can disable the materialization of the subqueries and expand the subquery inlines into CTE. This hint is only applicable to non-recursive CTE. In some scenarios, using `MERGE()` brings higher execution efficiency than the default behavior of allocating a temporary space. For example, pushing down query conditions or in nesting CTE queries: + +```sql +-- Uses the hint to push down the predicate of the outer query. +WITH CTE AS (SELECT /*+ MERGE() */ * FROM tc WHERE tc.a < 60) SELECT * FROM CTE WHERE CTE.a < 18; + +-- Uses the hint in a nested CTE query to expand a CTE inline into the outer query. +WITH CTE1 AS (SELECT * FROM t1), CTE2 AS (WITH CTE3 AS (SELECT /*+ MERGE() */ * FROM t2), CTE4 AS (SELECT * FROM t3) SELECT * FROM CTE3, CTE4) SELECT * FROM CTE1, CTE2; +``` + +> **Note:** +> +> `MERGE()` is only applicable to simple CTE queries. It is not applicable in the following situations: +> +> - [Recursive CTE](/develop/dev-guide-use-common-table-expression.md#recursive-cte) +> - Subqueries with inlines that cannot be expanded, such as aggregate operators, window functions, and `DISTINCT`. +> +> When the number of CTE references is too high, the query performance might be lower than the default materialization behavior. + ## Hints that take effect in the whole query This category of hints can only follow behind the **first** `SELECT`, `UPDATE` or `DELETE` keyword, which is equivalent to modifying the value of the specified system variable when this query is executed. The priority of the hint is higher than that of existing system variables. From a565595aba1b6cf51632337ca779b23092ed5804 Mon Sep 17 00:00:00 2001 From: Aolin Date: Fri, 5 Aug 2022 14:26:06 +0800 Subject: [PATCH 2/2] config: add description of report-min-resolved-ts-interval (#9776) --- tikv-configuration-file.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tikv-configuration-file.md b/tikv-configuration-file.md index d9841619f730a..9e9eead5b5224 100644 --- a/tikv-configuration-file.md +++ b/tikv-configuration-file.md @@ -853,6 +853,12 @@ Configuration items related to Raftstore. + Default value: `1MB` + Minimum value: `0` +### `report-min-resolved-ts-interval` New in v6.2.0 + ++ If you set this configuration value greater than `0`, TiKV checks the minimum ResolvedTS regularly for all Regions on the current node and reports the information to PD. ++ Default value: `0s` ++ Minimum value: `0s` + ## Coprocessor Configuration items related to Coprocessor.