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: choose TableScan when use an empty index hint #12037

Merged
merged 15 commits into from
Sep 6, 2019

Conversation

francis0407
Copy link
Member

What problem does this PR solve?

fix #12033.

schema:

mysql> create table t(a int, b int primary key, index idx_a(a));

before this pr:

mysql> explain select a from t use index();
+-------------------+----------+------+---------------------------------------------------------------------+
| id                | count    | task | operator info                                                       |
+-------------------+----------+------+---------------------------------------------------------------------+
| IndexReader_7     | 10000.00 | root | index:IndexScan_6                                                   |
| └─IndexScan_6     | 10000.00 | cop  | table:t, index:a, range:[NULL,+inf], keep order:false, stats:pseudo |
+-------------------+----------+------+---------------------------------------------------------------------+

after this pr:

mysql> explain select a from t use index();
+-------------------+----------+------+------------------------------------------------------------+
| id                | count    | task | operator info                                              |
+-------------------+----------+------+------------------------------------------------------------+
| TableReader_5     | 10000.00 | root | data:TableScan_4                                           |
| └─TableScan_4     | 10000.00 | cop  | table:t, range:[-inf,+inf], keep order:false, stats:pseudo |
+-------------------+----------+------+------------------------------------------------------------+

What is changed and how it works?

Check List

Tests

  • Unit test

@francis0407 francis0407 added type/bugfix This PR fixes a bug. sig/planner SIG: Planner labels Sep 5, 2019
@codecov
Copy link

codecov bot commented Sep 5, 2019

Codecov Report

Merging #12037 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #12037   +/-   ##
===========================================
  Coverage   81.8853%   81.8853%           
===========================================
  Files           447        447           
  Lines         97159      97159           
===========================================
  Hits          79559      79559           
  Misses        12071      12071           
  Partials       5529       5529

// For example: `select a from t use index()`.
if path := getTablePath(publicPaths); path != nil {
if hint.HintType == ast.HintIgnore {
ignored = append(ignored, path)
Copy link
Member

Choose a reason for hiding this comment

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

This ignore case doesn't make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. I'll remove this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is another issue. I tried ignore index() in MySQL, it returns a syntax Error.

mysql> explain select b from tt ignore index();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

But TiDB allows such syntax.

@@ -558,6 +558,19 @@ func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInf
}

hasScanHint = true
if hint.IndexNames == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also consider the comment style hint like index(t)?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

// For example: `select a from t use index()`.
if path := getTablePath(publicPaths); path != nil {
hasUseOrForce = true
path.forced = true
Copy link
Member

Choose a reason for hiding this comment

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

You need check whether is ignore or force.
Or you'll set table path as forced although no index is ignored by IGNORE INDEX()

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@francis0407
Copy link
Member Author

/rebuild

@francis0407
Copy link
Member Author

/run-all-tests

@francis0407
Copy link
Member Author

/rebuild

@francis0407
Copy link
Member Author

/run-all-tests

1 similar comment
@francis0407
Copy link
Member Author

/run-all-tests

@francis0407
Copy link
Member Author

/rebuild

@@ -558,6 +558,15 @@ func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInf
}

hasScanHint = true
if hint.IndexNames == nil && hint.HintType != ast.HintIgnore {
Copy link
Member

Choose a reason for hiding this comment

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

How about adding a comment? From MySQL document:

It is syntactically valid to omit index_list for USE INDEX, which means “use no indexes.” Omitting index_list for FORCE INDEX or IGNORE INDEX is a syntax error.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@francis0407 francis0407 added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 6, 2019
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 status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 6, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 6, 2019

/run-all-tests

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

planner: should use TableScan when use index() has no arguments
6 participants