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

planner: add warning when the table name of indexHint cannot be found (#15517) #15762

Merged
merged 7 commits into from
Apr 15, 2020

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented Mar 27, 2020

cherry-pick #15517 to release-3.1


What problem does this PR solve?

Problem Summary:

Throw a warning when the index hint is not applicable(i.e. cannot find the table).

What is changed and how it works?

What's Changed:
Before this PR:

mysql> explain select /*+ use_index(p, a) */ * from t;
+-----------------------+----------+-----------+-----------------------------------------+
| id                    | estRows  | task      | operator info                           |
+-----------------------+----------+-----------+-----------------------------------------+
| TableReader_5         | 10000.00 | root      | data:TableFullScan_4                    |
| └─TableFullScan_4     | 10000.00 | cop[tikv] | table:t, keep order:false, stats:pseudo |
+-----------------------+----------+-----------+-----------------------------------------+
2 rows in set (0.00 sec)

After this PR:

mysql> explain select /*+ use_index(p, a) */ * from t;
+-----------------------+----------+-----------+-----------------------------------------+
| id                    | estRows  | task      | operator info                           |
+-----------------------+----------+-----------+-----------------------------------------+
| TableReader_5         | 10000.00 | root      | data:TableFullScan_4                    |
| └─TableFullScan_4     | 10000.00 | cop[tikv] | table:t, keep order:false, stats:pseudo |
+-----------------------+----------+-----------+-----------------------------------------+
2 rows in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1815 | IndexHint for table p is not applicable. |
+---------+------+------------------------------------------+
1 row in set (0.00 sec)

How it Works:

Check if there are unused tableHints after building the select statement.

Check List

Tests

  • Unit test

Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor Author

sre-bot commented Mar 27, 2020

/run-all-tests

@francis0407
Copy link
Member

/run-unit-test

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

@francis0407 Please resolve conflicts.

…lease-3.1-dd141728a329

# Conflicts:
#	planner/core/testdata/integration_suite_in.json
#	planner/core/testdata/integration_suite_out.json
@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 5, 2020

@zz-jason, @eurekaka, @XuHuaiyu, @lzmhhh123, PTAL.

1 similar comment
@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 7, 2020

@zz-jason, @eurekaka, @XuHuaiyu, @lzmhhh123, PTAL.

@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 10, 2020

@sre-bot, please update your pull request.

@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 10, 2020

@zz-jason, @eurekaka, @XuHuaiyu, @lzmhhh123, PTAL.

@francis0407
Copy link
Member

PTAL @zz-jason @lzmhhh123

Comment on lines 31 to 53
{
"name": "TestReadFromStorageHint",
"cases": [
"desc select avg(a) from t",
"desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t",
"desc select /*+ read_from_storage(tiflash[t]) */ sum(a) from t",
"desc select /*+ read_from_storage(tiflash[t]) */ sum(a+1) from t",
"desc select /*+ read_from_storage(tiflash[t]) */ sum(isnull(a)) from t",
"desc select * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)",
"desc select /*+ read_from_storage(tiflash[tt]) */ * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)",
"desc select * from ttt order by ttt.a desc",
"desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a desc",
"desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a"
]
},
{
"name": "TestReadFromStorageHintAndIsolationRead",
"cases": [
"desc select /*+ read_from_storage(tikv[t], tiflash[t]) */ avg(a) from t",
"desc select /*+ read_from_storage(tikv[t]) */ avg(a) from t",
"desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t"
]
},
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests have been involved in integration_serial_suite_in.json. Is it correct to re-present here?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's a mistake. I have removed them in the latest commit. PTAL

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

LGTM

@lzmhhh123 lzmhhh123 added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 15, 2020
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason removed the status/LGT1 Indicates that a PR has LGTM 1. label Apr 15, 2020
@zz-jason zz-jason added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/PTAL labels Apr 15, 2020
@zz-jason
Copy link
Member

/run-all-tests

1 similar comment
@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 15, 2020

/run-all-tests

@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 15, 2020

@sre-bot merge failed.

@zz-jason
Copy link
Member

/run-integration-common-test

@zz-jason zz-jason merged commit 9f1d049 into pingcap:release-3.1 Apr 15, 2020
@zz-jason
Copy link
Member

/run-integration-common-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug. type/3.1-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants