How to Adjust the Display of Execution Plans in the Command Line?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 如何调整命令行中执行计划的显示?

| username: 春风十里

[TiDB Usage Environment] Test/PoC
[TiDB Version] 7.5
[Encountered Issue: Issue Phenomenon and Impact]
When viewing the execution plan in the TiDB command line, due to the large amount of content, the display format is serialized and looks a bit messy, as shown in the screenshot below:

How to adjust the execution plan to display in one line in the command line?
For example, reading the execution plan in MySQL Workbench is more convenient:

| username: forever | Original post link

  1. When zoomed out, if it’s small enough, it will fit on one line.
  2. Add \G at the end.
| username: Kongdom | Original post link

\G can display the result vertically.

| username: 江湖故人 | Original post link

You can output to a file with \o out.txt, and then in vim, turn off automatic line wrapping with :set nowrap.

| username: zhanggame1 | Original post link

Copy it out and take a look.

| username: 江湖故人 | Original post link

If you’re using the MySQL client, you can try pager less -S.
Functionality of the pager command
alias mysql=“mysql --pager=‘less -S -n -i -F -X’”

mycli can also be used.
can mycli wrap very long text into multiple lines? · Issue #463 · dbcli/mycli · GitHub

| username: 春风十里 | Original post link

Thank you for the reply.

  1. I have tried it, and it does work sometimes, but not when the plan is too large.
  2. Although \G can change the format, it loses the indentation of the execution plan, making it less readable.
| username: 春风十里 | Original post link

Thanks for the reply, I’ll try it later.

| username: 春风十里 | Original post link

Copy it out. I tried Sublime and txt files, but they are all serialized and not good-looking.

| username: wangccsy | Original post link

Got it. Thanks.

| username: Jayjlchen | Original post link

Generally, you access it through a bastion host, which has Notepad++. When you copy it to Notepad++, it is well-organized. Moreover, analyzing the execution plan is much more convenient with these tools.

| username: 春风十里 | Original post link

This basically meets the format display requirements, but the only regret is that when copying, you can only paste the content on the screen and cannot paste all the content at once. Only Notepad++ displays the format the same as the screenshot.

| username: 春风十里 | Original post link

I don’t know how to use this, I couldn’t get it to work.

| username: dba远航 | Original post link

It works normally after shrinking.

| username: 随缘天空 | Original post link

Use the command pager less -S

| username: Kongdom | Original post link

:+1: Official detailed thumbs up~

| username: 江湖故人 | Original post link

To disable automatic line wrapping after opening vim: :set nowrap

| username: 随缘天空 | Original post link

The official documentation is still very detailed.

| username: 小龙虾爱大龙虾 | Original post link

Is pager less -S still not working? Then it should be an issue with your client, such as your PuTTY or Xshell settings being too narrow. Check the settings and take a look.

| username: 春风十里 | Original post link

Are you using a Mac system? Is it because of different terminals?
I use Windows and Xshell, and it seems there is no \o command.