-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #12037 +/- ##
===========================================
Coverage 81.8853% 81.8853%
===========================================
Files 447 447
Lines 97159 97159
===========================================
Hits 79559 79559
Misses 12071 12071
Partials 5529 5529 |
planner/core/planbuilder.go
Outdated
// For example: `select a from t use index()`. | ||
if path := getTablePath(publicPaths); path != nil { | ||
if hint.HintType == ast.HintIgnore { | ||
ignored = append(ignored, path) |
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.
This ignore case doesn't make sense?
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.
Sure. I'll remove this.
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.
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.
planner/core/planbuilder.go
Outdated
@@ -558,6 +558,19 @@ func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInf | |||
} | |||
|
|||
hasScanHint = true | |||
if hint.IndexNames == nil { |
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.
Could you also consider the comment style hint like index(t)
?
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.
fixed
// For example: `select a from t use index()`. | ||
if path := getTablePath(publicPaths); path != nil { | ||
hasUseOrForce = true | ||
path.forced = true |
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.
You need check whether is ignore or force.
Or you'll set table path as forced although no index is ignored by IGNORE INDEX()
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.
fixed
/rebuild |
/run-all-tests |
/rebuild |
/run-all-tests |
1 similar comment
/run-all-tests |
/rebuild |
@@ -558,6 +558,15 @@ func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInf | |||
} | |||
|
|||
hasScanHint = true | |||
if hint.IndexNames == nil && hint.HintType != ast.HintIgnore { |
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.
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.
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.
addressed
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.
LGTM
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.
LGTM.
/run-all-tests |
What problem does this PR solve?
fix #12033.
schema:
before this pr:
after this pr:
What is changed and how it works?
Check List
Tests