Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explain: add hint about disabling line wrapping with less #5349

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion explain-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ aliases: ['/docs/dev/query-execution-plan/','/docs/dev/reference/performance/und

# `EXPLAIN` Overview

> **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.
Copy link
Contributor

@TomShawn TomShawn Apr 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • pager less -S and "the right arrow on your keyboard" are used together?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how this works:

mysql> pager less -S
mysql> EXPLAIN ANALYZE SELECT.....

The output is shown in less and instead of wrapping lines it chops off the part that doesn't fit on the screen. Then by pressing the right arrow key on the keyboard you can 'scroll' to the right. Here \G in MySQL doesn't help.

Example w/o this:
image

Example with less -S:
image

Here you can see that less indicates there is more output on the right with >. The output can be viewed by pressing the right arrow key on the keyboard.

This improves the output of the tree-like explain output that is in the id column of the explain output.

dveeden marked this conversation as resolved.
Show resolved Hide resolved

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:
Expand Down Expand Up @@ -100,4 +104,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).
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).
4 changes: 4 additions & 0 deletions sql-statements/sql-statement-explain.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 |
Expand Down