Skip to content

doc: explain - #34774

Merged
guanshengliang merged 6 commits into
3.0from
enh/3.0/explain-doc
Mar 20, 2026
Merged

guanshengliang merged 6 commits into
3.0from
enh/3.0/explain-doc

Conversation

@Tony2h

@Tony2h Tony2h commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Description

Issue(s)

  • Close/close/Fix/fix/Resolve/resolve: Issue Link

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copilot AI review requested due to automatic review settings March 13, 2026 09:27
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces new, detailed documentation for the EXPLAIN SQL command, which is a critical tool for understanding and optimizing query performance. The documentation explains how to use EXPLAIN and EXPLAIN ANALYZE to inspect query execution plans, analyze runtime metrics, and diagnose performance bottlenecks. It aims to empower users with the knowledge to effectively tune their SQL queries and troubleshoot slow performance, with content provided in both English and Chinese.

Highlights

  • New EXPLAIN Documentation: Introduced comprehensive documentation for the EXPLAIN and EXPLAIN ANALYZE SQL commands, providing detailed insights into query execution plans and runtime metrics for performance tuning and diagnosis.
  • Detailed Query Analysis Tools: The new documentation covers syntax, parameters (ANALYZE, VERBOSE), result format, common operators, and an extensive quick reference for various metrics (execution cost, I/O cost, network exchange, etc.), along with diagnostic suggestions and examples.
  • Multilingual Support: The documentation is available in both English and Chinese, ensuring accessibility for a broader user base.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • docs/en/14-reference/03-taos-sql/28-explain.md
    • Added comprehensive documentation for the EXPLAIN SQL command.
  • docs/zh/14-reference/03-taos-sql/28-explain.md
    • Added the Chinese localized version of the EXPLAIN SQL command documentation.
Activity
  • The pull request description includes a standard checklist, but no specific activity or review comments were provided in the context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds new SQL manual documentation pages for EXPLAIN in both English and Chinese, describing how to interpret execution plans and runtime metrics for query tuning and troubleshooting.

Changes:

  • Introduces EXPLAIN / EXPLAIN ANALYZE syntax and parameter explanations (ANALYZE, VERBOSE).
  • Documents common plan operators and key metrics (including Exec cost and scan I/O cost fields).
  • Provides multiple end-to-end examples and diagnostic suggestions for typical performance scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/zh/14-reference/03-taos-sql/28-explain.md New Chinese documentation for EXPLAIN, including metrics reference, examples, and diagnostic guidance.
docs/en/14-reference/03-taos-sql/28-explain.md New English documentation for EXPLAIN, mirroring the structure and guidance in the Chinese version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*************************** 80.row ***************************
QUERY_PLAN: Planning Time: 0.484 ms
*************************** 81.row ***************************
QUERY_PLAN: Execution Time: 8.138 m

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

*************************** 80.row ***************************
QUERY_PLAN: Planning Time: 0.484 ms
*************************** 81.row ***************************
QUERY_PLAN: Execution Time: 8.138 m

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds comprehensive documentation for the EXPLAIN command in both English and Chinese. The documentation is well-structured and provides a great level of detail. My review includes a few suggestions to fix minor typos and inconsistencies in the examples and text to further improve clarity and correctness.

```sql
taos> EXPLAIN ANALYZE VERBOSE true SELECT _wstart, _wend, count(*), avg(current) FROM meters INTERVAL(10s) \G;
*************************** 1.row ***************************
QUERY_PLAN: -> Merge Aligned Interval on Column (cost=0.626..0.626 rows=10 functions=4 width=32 input_order=asc output_order=asc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There appears to be a typo in the example output. There are two spaces after Column, which should probably be one.

Suggested change
QUERY_PLAN: -> Merge Aligned Interval on Column (cost=0.626..0.626 rows=10 functions=4 width=32 input_order=asc output_order=asc)
QUERY_PLAN: -> Merge Aligned Interval on Column (cost=0.626..0.626 rows=10 functions=4 width=32 input_order=asc output_order=asc)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

不是

*************************** 9.row ***************************
QUERY_PLAN: Output: Ignore Group Id: false
*************************** 10.row ***************************
QUERY_PLAN: Merge Key: _group_id asc, asc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The Merge Key in this example output is confusing: _group_id asc, asc. It seems a column name is missing after the comma. For clarity, please specify the second sort key. Given this is a time-window query, ts would be a likely candidate for the second key.

Suggested change
QUERY_PLAN: Merge Key: _group_id asc, asc
QUERY_PLAN: Merge Key: _group_id asc, ts asc

*************************** 80.row ***************************
QUERY_PLAN: Planning Time: 0.484 ms
*************************** 81.row ***************************
QUERY_PLAN: Execution Time: 8.138 m

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The unit for Execution Time appears to be a typo. It's given as m, which could mean minutes. However, other examples in this document use ms (milliseconds), and the corresponding Planning Time is in ms. It's likely this should also be ms, as 8 minutes seems inconsistent with the context.

Suggested change
QUERY_PLAN: Execution Time: 8.138 m
QUERY_PLAN: Execution Time: 8.138 ms

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

duplicated

| `mode=ts_order` | 按时间序组织扫描 | 常见于普通时间序扫描 |
| `offset=` | 当前算子承接到的 `OFFSET` | 用于判断偏移是否参与了当前层裁剪 |
| `order=[asc\|x desc\|y]` | 扫描时顺序读取与逆序读取的计数 | 用于判断扫描是否主要按升序还是降序进行 |
| `origin_vgroup_num=` | 原始 vgroup 数量 | 用于观察虚拟稳定表查询的并行规模 |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The term "虚拟稳定表" is used here. However, in other parts of this document (e.g., lines 118, 134), "超级表" is used for "supertable". The English version of the documentation also uses "supertable". For consistency, please consider changing "虚拟稳定表" to "虚拟超级表".

Suggested change
| `origin_vgroup_num=` | 原始 vgroup 数量 | 用于观察虚拟稳定表查询的并行规模 |
| `origin_vgroup_num=` | 原始 vgroup 数量 | 用于观察虚拟超级表查询的并行规模 |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

```sql
taos> EXPLAIN ANALYZE VERBOSE true SELECT _wstart, _wend, count(*), avg(current) FROM meters INTERVAL(10s) \G;
*************************** 1.row ***************************
QUERY_PLAN: -> Merge Aligned Interval on Column (cost=0.626..0.626 rows=10 functions=4 width=32 input_order=asc output_order=asc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There appears to be a typo in the example output. There are two spaces after Column, which should probably be one.

Suggested change
QUERY_PLAN: -> Merge Aligned Interval on Column (cost=0.626..0.626 rows=10 functions=4 width=32 input_order=asc output_order=asc)
QUERY_PLAN: -> Merge Aligned Interval on Column (cost=0.626..0.626 rows=10 functions=4 width=32 input_order=asc output_order=asc)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

duplicated

*************************** 9.row ***************************
QUERY_PLAN: Output: Ignore Group Id: false
*************************** 10.row ***************************
QUERY_PLAN: Merge Key: _group_id asc, asc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The Merge Key in this example output is confusing: _group_id asc, asc. It seems a column name is missing after the comma. For clarity, please specify the second sort key. Given this is a time-window query, ts would be a likely candidate for the second key.

Suggested change
QUERY_PLAN: Merge Key: _group_id asc, asc
QUERY_PLAN: Merge Key: _group_id asc, ts asc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

duplicated

*************************** 80.row ***************************
QUERY_PLAN: Planning Time: 0.484 ms
*************************** 81.row ***************************
QUERY_PLAN: Execution Time: 8.138 m

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The unit for Execution Time appears to be a typo. It's given as m, which could mean minutes. However, other examples in this document use ms (milliseconds), and the corresponding Planning Time is in ms. It's likely this should also be ms, as 8 minutes seems inconsistent with the context.

Suggested change
QUERY_PLAN: Execution Time: 8.138 m
QUERY_PLAN: Execution Time: 8.138 ms

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

duplicated

- [数据查询](./20-select.md)
- [特色查询](./24-distinguished.md)
- [关联查询](./25-join.md)
- [标签索引](./26-tagindex.md)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The link to "标签索引" points to ./26-tagindex.md. The corresponding link in the English version is ./26-tag-index.md (with a hyphen). Please verify if 26-tagindex.md is the correct filename, as the missing hyphen might result in a broken link.

Suggested change
- [标签索引](./26-tagindex.md)
- [标签索引](./26-tag-index.md)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not a problem

@Tony2h
Tony2h force-pushed the enh/3.0/explain-doc branch from 77717fe to df1c59e Compare March 18, 2026 08:19
Copilot AI review requested due to automatic review settings March 18, 2026 08:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds new SQL manual pages documenting EXPLAIN / EXPLAIN ANALYZE output (plan tree structure, common operators, and key metrics) to help users interpret execution plans for tuning and troubleshooting.

Changes:

  • Add a Chinese reference page for EXPLAIN with metric/operator explanations and diagnostic guidance.
  • Add an English reference page for EXPLAIN with parallel content and examples.
  • Provide multiple sample outputs covering plain plans, verbose plans, and analyzed runtime metrics.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
docs/zh/14-reference/03-taos-sql/28-explain.md New Chinese documentation for EXPLAIN, including syntax, metric quick reference, examples, and diagnostic suggestions.
docs/en/14-reference/03-taos-sql/28-explain.md New English documentation for EXPLAIN, mirroring the Chinese content with examples and guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +62 to +69
`EXPLAIN` returns a single column named `QUERY_PLAN`. Each row is either a node in the plan tree or a row with detailed statistic information.

The execution plan is displayed as a tree:

- The topmost node is where the final result is produced
- Deeper indentation means closer to the underlying scan
- The operator name appears after `->`
- When `VERBOSE true` is enabled, rows with detailed statistic information are appended below each operator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

*************************** 80.row ***************************
QUERY_PLAN: Planning Time: 0.484 ms
*************************** 81.row ***************************
QUERY_PLAN: Execution Time: 8.138 m

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

*************************** 80.row ***************************
QUERY_PLAN: Planning Time: 0.484 ms
*************************** 81.row ***************************
QUERY_PLAN: Execution Time: 8.138 m

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +62 to +69
`EXPLAIN` returns a single column named `QUERY_PLAN`. Each row is either a node in the plan tree or a row with detailed statistic information.

The execution plan is displayed as a tree:

- The topmost node is where the final result is produced
- Deeper indentation means closer to the underlying scan
- The operator name appears after `->`
- When `VERBOSE true` is enabled, rows with detailed statistic information are appended below each operator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

duplicated


## 返回结果说明

`EXPLAIN` 的返回结果只有一列,列名为 `QUERY_PLAN`。每一行是计划树中的一个节点或一个详细统计信息。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

## 语法

```sql
EXPLAIN [ANALYZE] [VERBOSE {true | false}] query_or_subquery;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

query_or_subquery 简单描述一下范围,比如流计算、Insert into select、show支不支持之类的

| `Tag Scan on ...` | 标签扫描 | 判断是否只基于标签或元数据就能缩小扫描范围 |
| `Virtual Table Scan on ...` | 虚拟表扫描 | 判断虚拟表查询是否已经在逻辑层裁剪数据 |

## 指标速查

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

子查询的格式和计划没有说明,加一章节说明一下吧,举个示例

@guanshengliang
guanshengliang merged commit cc51cb8 into 3.0 Mar 20, 2026
4 checks passed
@guanshengliang
guanshengliang deleted the enh/3.0/explain-doc branch March 20, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants