From 2d586be71ea953af47de22aaff764733ddf75614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 16 Apr 2021 13:53:52 +0200 Subject: [PATCH 1/2] cherry pick #5349 to release-5.0 Signed-off-by: ti-srebot --- explain-overview.md | 6 +++++- sql-statements/sql-statement-explain.md | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/explain-overview.md b/explain-overview.md index 5c2a51e2c4575..4cf2a853e07b4 100644 --- a/explain-overview.md +++ b/explain-overview.md @@ -5,6 +5,10 @@ summary: Learn about the execution plan information returned by the `EXPLAIN` st # `EXPLAIN` Overview +> **Note:** +> +> When you use the MySQL client to connect to TiDB, to read the output result in a clearer way without line wrapping, you can use the `pager less -S` command. Then, after the `EXPLAIN` result is output, you can press the right arrow button on your keyboard to horizontally scroll through the output. + SQL is a declarative language. It describes what the results of a query should look like, **not the methodology** to actually retrieve those results. TiDB considers all the possible ways in which a query could be executed, including using what order to join tables and whether any potential indexes can be used. The process of _considering query execution plans_ is known as SQL optimization. The `EXPLAIN` statement shows the selected execution plan for a given statement. That is, after considering hundreds or thousands of ways in which the query could be executed, TiDB believes that this _plan_ will consume the least resources and execute in the shortest amount of time: @@ -99,4 +103,4 @@ The `operator info` can show useful information such as which conditions were ab * `keep order:false` shows that the semantics of this query did not require TiKV to return the results in order. If the query were to be modified to require an order (such as `SELECT * FROM t WHERE a = 1 ORDER BY id`), then this condition would be `keep order:true`. * `stats:pseudo` shows that the estimates shown in `estRows` might not be accurate. TiDB periodically updates statistics as part of a background operation. A manual update can also be performed by running `ANALYZE TABLE t`. -Different operators output different information after the `EXPLAIN` statement is executed. You can use optimizer hints to control the behavior of the optimizer, and thereby controlling the selection of the physical operators. For example, `/*+ HASH_JOIN(t1, t2) */` means that the optimizer uses the `Hash Join` algorithm. For more details, see [Optimizer Hints](/optimizer-hints.md). \ No newline at end of file +Different operators output different information after the `EXPLAIN` statement is executed. You can use optimizer hints to control the behavior of the optimizer, and thereby controlling the selection of the physical operators. For example, `/*+ HASH_JOIN(t1, t2) */` means that the optimizer uses the `Hash Join` algorithm. For more details, see [Optimizer Hints](/optimizer-hints.md). diff --git a/sql-statements/sql-statement-explain.md b/sql-statements/sql-statement-explain.md index 60eff0a6e3bc5..5b814409d2417 100644 --- a/sql-statements/sql-statement-explain.md +++ b/sql-statements/sql-statement-explain.md @@ -27,6 +27,10 @@ TiDB supports the `EXPLAIN [options] FOR CONNECTION connection_id` statement. Ho ## `EXPLAIN` output format +> **Note:** +> +> If you use the `mysql` client to connect to TiDB you may want to use `pager less -S` to avoid line wrapping in your terminal and instead press the right arrow on your keyboard to horizontally scroll through the explain output. + Currently, `EXPLAIN` in TiDB outputs 5 columns: `id`, `estRows`, `task`, `access object`, `operator info`. Each operator in the execution plan is described by these attributes, with each row in the `EXPLAIN` output describing an operator. The description of each attribute is as follows: | Attribute name | Description | From 154bfaef8405ec8a6a906c29bed041afc50231df Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Fri, 16 Apr 2021 20:00:38 +0800 Subject: [PATCH 2/2] Update sql-statements/sql-statement-explain.md --- sql-statements/sql-statement-explain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-explain.md b/sql-statements/sql-statement-explain.md index 5b814409d2417..128dc6323f115 100644 --- a/sql-statements/sql-statement-explain.md +++ b/sql-statements/sql-statement-explain.md @@ -29,7 +29,7 @@ TiDB supports the `EXPLAIN [options] FOR CONNECTION connection_id` statement. Ho > **Note:** > -> If you use the `mysql` client to connect to TiDB you may want to use `pager less -S` to avoid line wrapping in your terminal and instead press the right arrow on your keyboard to horizontally scroll through the explain output. +> When you use the MySQL client to connect to TiDB, to read the output result in a clearer way without line wrapping, you can use the `pager less -S` command. Then, after the `EXPLAIN` result is output, you can press the right arrow button on your keyboard to horizontally scroll through the output. Currently, `EXPLAIN` in TiDB outputs 5 columns: `id`, `estRows`, `task`, `access object`, `operator info`. Each operator in the execution plan is described by these attributes, with each row in the `EXPLAIN` output describing an operator. The description of each attribute is as follows: