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

comment-syntax: add TiDB-specific comment syntax #3477

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Changes from all commits
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
8 changes: 6 additions & 2 deletions comment-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ TiDB 也跟 MySQL 保持一致,支持一种 C 风格注释的变体:
/*!50110 Specific code */
```

在这种格式中,TiDB 会执行注释中的语句,这个语法是为了让这些 SQL 在其他的数据库中被忽略,而在 TiDB 中被执行
和 MySQL 一样,TiDB 会执行注释中的语句

例如:`SELECT /*! STRAIGHT_JOIN */ col1 FROM table1,table2 WHERE ...`

Expand All @@ -125,7 +125,11 @@ TiDB 也跟 MySQL 保持一致,支持一种 C 风格注释的变体:

## TiDB 可执行的注释语法

TiDB 也有独立的注释语法,称为 TiDB 可执行注释语法,格式为 `/*T![feature_id] XXX */`。只有在当前版本中实现了 `feature_id` 对应的功能特性的 TiDB,才会试图解析该注释里的 SQL 片段。例如 v3.1.1 中引入了 `AUTO_RANDOM` 特性,该版本能够将 `/*T![auto_rand] auto_random */` 解析为 `auto_random`;而 v3.0.0 中没有实现 `AUTO_RANDOM` 特性,则上述 SQL 语句片段会被忽略。
TiDB 也有独立的注释语法,称为 TiDB 可执行注释语法。主要分为两种:

* `/*T! Specific code */`:该语法只能被 TiDB 解析执行,而在其他数据库中会被忽略。

* `/*T![feature_id] Specific code */`:该语法用于保证 TiDB 不同版本之间的兼容性。只有在当前版本中实现了 `feature_id` 对应的功能特性的 TiDB,才会试图解析该注释里的 SQL 片段。例如 v3.1.1 中引入了 `AUTO_RANDOM` 特性,该版本能够将 `/*T![auto_rand] auto_random */` 解析为 `auto_random`;而 v3.0.0 中没有实现 `AUTO_RANDOM` 特性,则上述 SQL 语句片段会被忽略。

## 优化器注释语法

Expand Down