-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
optimizer hints: add notes for how to specify the table name in hints #8292
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
optimizer-hints.md
Outdated
|
||
在使用诸如 [MERGE_JOIN](#MERGE_JOIN(t1_name-[,-tl_name-...])) 的 Hint 时,我们会需要在 Hint 中提供表名。为了让语法解析时对表名的处理逻辑与 MySQL 的处理逻辑相同。在使用 Hint 中使用表名时,需要注意如下的限制: | ||
|
||
如果这个表有别名,那么只有的使用它的别名可以生效。如果这个表不在当前通过 `USE DATABASE` 命令所指定的数据库中,那么我们需要使用 `数据库名.别名` 的方式指定这个表。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果这个表有别名,那么只有的使用它的别名可以生效...
的 多余?
optimizer-hints.md
Outdated
```sql | ||
USE test; | ||
DROP TABLE IF EXISTS test_hint; | ||
CREATE TABLE test_hint(a int); | ||
SELECT /*+ HASH_JOIN(t1) */ * FROM test_hint t1, test_hint t2; | ||
SELECT /*+ HASH_JOIN(test.t1) */ * FROM test_hint t1, test_hint t2; | ||
SELECT /*+ HASH_JOIN(test_hint) */ * FROM test_hint t1, test_hint t2; | ||
DROP DATABASE IF EXISTS test_hint_db; | ||
CREATE DATABASE test_hint_db; | ||
CREATE TABLE test_hint_db.test_hint(a int); | ||
SELECT /*+ HASH_JOIN(t1) */ * FROM test_hint_db.test_hint t1, test_hint t2; | ||
SELECT /*+ HASH_JOIN(test_hint_db.t1) */ * FROM test_hint_db.test_hint t1, test_hint t2; | ||
SELECT /*+ HASH_JOIN(test_hint_db.test_hint) */ * FROM test_hint_db.test_hint t1, test_hint t2; | ||
``` | ||
|
||
在上述的例子中只有如下几个 SQL 是可以被使用 Hint 的,其他 Hint 都会提示找不到 Hint 所指定的表名。 | ||
|
||
```sql | ||
USE test; | ||
DROP TABLE IF EXISTS test_hint; | ||
CREATE TABLE test_hint(a int); | ||
SELECT /*+ HASH_JOIN(t1) */ * FROM test_hint t1, test_hint t2; | ||
SELECT /*+ HASH_JOIN(test.t1) */ * FROM test_hint t1, test_hint t2; | ||
SELECT /*+ HASH_JOIN(test_hint_db.t1) */ * FROM test_hint_db.test_hint t1, test_hint t2; | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
先放错误的示例可能会误导读者,建议先举例 use db + 直接使用别名,无 db + db.别名的2种情况,然后再说不正确的样例。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about English version?
I'll translate the approved Chinese version into English. First, let's have this PR approved. |
Add comments
Let's do a review and merge into branch, thx. @TomShawn |
@winoros Please take a look at the comments above and address them. Thanks~ |
Removed the needs-cherry-pick-release-6.3 label because the v6.3 docs have been archived at https://docs-archive.pingcap.com/zh/tidb/v6.3 and will no longer receive new updates. |
Removed the needs-cherry-pick-release-6.4 label because the v6.4 docs have been archived at https://docs-archive.pingcap.com/zh/tidb/v6.4 and will no longer receive new updates. |
Co-authored-by: xixirangrang <[email protected]>
Co-authored-by: xixirangrang <[email protected]>
@@ -61,6 +61,37 @@ SELECT /*+ HASH_JOIN(@sel_1 t1@sel_1, t3) */ * FROM (SELECT t1.a, t1.b FROM t t1 | |||
> | |||
> Hint 声明的位置必须在指定生效的查询块之中或之前,不能是在之后的查询块中,否则无法生效。 | |||
|
|||
## Hint 中的表名 | |||
|
|||
在使用诸如 [MERGE_JOIN](#MERGE_JOIN(t1_name-[,-tl_name-...])) 的 Hint 时,需要在 Hint 中提供表名。为了确保语法解析时对表名的处理逻辑与 MySQL 的处理逻辑相同,在使用 Hint 中使用表名时,需要注意,如果表有别名,必须使用它的别名才可以生效。如果这个表不在当前通过 `USE DATABASE` 命令所指定的数据库中,那么需要使用 `table_name.alias` 的方式指定这个表。参考以下示例。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在使用诸如 [MERGE_JOIN](#MERGE_JOIN(t1_name-[,-tl_name-...])) 的 Hint 时,需要在 Hint 中提供表名。为了确保语法解析时对表名的处理逻辑与 MySQL 的处理逻辑相同,在使用 Hint 中使用表名时,需要注意,如果表有别名,必须使用它的别名才可以生效。如果这个表不在当前通过 `USE DATABASE` 命令所指定的数据库中,那么需要使用 `table_name.alias` 的方式指定这个表。参考以下示例。 | |
在使用诸如 [MERGE_JOIN](#merge_joint1_name--tl_name-) 的 Hint 时,需要在 Hint 中提供表名。为了确保语法解析时对表名的处理逻辑与 MySQL 的处理逻辑相同,在使用 Hint 中使用表名时,需要注意,如果表有别名,必须使用它的别名才可以生效。如果这个表不在当前通过 `USE DATABASE` 命令所指定的数据库中,那么需要使用 `table_name.alias` 的方式指定这个表。参考以下示例。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那么需要使用
table_name.alias
的方式指定这个表
这里是 db_name.alias
吧?下面示例用的是 db_name(L80)
SELECT /*+ HASH_JOIN(test_hint_db.test_hint) */ * FROM test_hint_db.test_hint t1, test_hint t2; /* hint 不生效,因为未使用别名 */ | ||
``` | ||
|
||
上述例子中,只有下面几个 SQL 是可以被使用 Hint 的,其他 Hint 都会提示找不到 Hint 所指定的表名。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上述例子中,只有下面几个 SQL 是可以被使用 Hint 的,其他 Hint 都会提示找不到 Hint 所指定的表名。 | |
上述例子中,只有下面几个 SQL 的 Hint 生效,其他语句的 Hint 都会提示找不到 Hint 所指定的表名。 |
Removed the needs-cherry-pick-release-6.6 label because the v6.6 docs have been archived at https://docs-archive.pingcap.com/zh/tidb/v6.6 and will no longer receive new updates. |
@winoros: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Removed the |
closed after confirming with owner |
First-time contributors' checklist
What is changed, added or deleted? (Required)
It's a little against intuition when we are specifying a table in the optimizer hints. So we add some notes to tell the user how to use it.
Which TiDB version(s) do your changes apply to? (Required)
Tips for choosing the affected version(s):
By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.
For details, see tips for choosing the affected versions (in Chinese).
What is the related PR or file link(s)?
Do your changes match any of the following descriptions?