-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: support create binding from history #39436
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
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. |
… binding_create
@@ -1098,7 +1098,7 @@ | |||
"Projection_3 10000.00 root Column#2, Column#3, Column#4, Column#5, Column#6, Column#7, Column#8, Column#9", | |||
"└─MemTableScan_4 10000.00 root table:PROCESSLIST " | |||
], | |||
"Result": [" test Sleep 0 autocommit select USER, HOST, DB, COMMAND, TIME, STATE, INFO, DIGEST from information_schema.processlist 7284ef6cf62f14bccb9fa24aff861b419e9cf59b2c098d3069c7c10bc35d0c14"] | |||
"Result": [" test Sleep 0 autocommit select USER, HOST, DB, COMMAND, TIME, STATE, INFO, DIGEST from information_schema.processlist 786234ab0b57f68ad9452021ba5299ab0c1e879a37c8810ceeaf4a1074fe9daa"] |
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.
Why is it changed?
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 it's because we add new key words DIGEST
and the parser changed
planner/core/common_plans.go
Outdated
@@ -265,6 +265,7 @@ type SQLBindPlan struct { | |||
Charset string | |||
Collation string | |||
NewStatus string | |||
Source string |
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.
Please add some comments for this new field.
planner/core/preprocess.go
Outdated
EraseLastSemicolon(node.OriginNode) | ||
EraseLastSemicolon(node.HintedNode) | ||
p.checkBindGrammar(node.OriginNode, node.HintedNode, p.sctx.GetSessionVars().CurrentDB) | ||
if node.PlanDigest == "" { |
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.
Please add some comments like 'if planDigest is not empty, then ...';
planner/core/planbuilder.go
Outdated
logutil.BgLogger().Debug("[sql-bind] parse origin SQL failed in create binding from history", | ||
zap.String("SQL", bindableStmt.Query), zap.Error(err)) |
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.
Should we return this error directly here?
planner/core/planbuilder.go
Outdated
logutil.BgLogger().Debug("[sql-bind] parse origin SQL failed in create binding from history", | ||
zap.String("SQL", bindableStmt.Query), zap.Error(err)) | ||
} | ||
bindSQL := bindinfo.GenerateBindSQL(context.TODO(), originNode, bindableStmt.PlanHint, true, bindableStmt.Schema) |
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.
The captured argument should be false
.
@@ -1388,3 +1388,50 @@ func TestDropBindBySQLDigest(t *testing.T) { | |||
tk.MustGetErrMsg(fmt.Sprintf("drop binding for sql digest '%s'", "1"), "can't find any binding for `1`") | |||
tk.MustGetErrMsg(fmt.Sprintf("drop binding for sql digest '%s'", ""), "sql digest is empty") | |||
} | |||
|
|||
func TestCreateBindingFromHistory(t *testing.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.
If the binding already exists, what will happen after create binding from history?
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.
will be covered, only the newest exists
planner/core/planbuilder.go
Outdated
@@ -1039,7 +1040,48 @@ func checkHintedSQL(sql, charset, collation, db string) error { | |||
return nil | |||
} | |||
|
|||
func (b *PlanBuilder) buildCreateBindPlanFromPlanDigest(v *ast.CreateBindingStmt) (Plan, error) { | |||
if v.PlanDigest == "" { | |||
return nil, errors.New("sql digest is empty") |
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.
plan digest is empty
?
Co-authored-by: Chengpeng Yan <41809508+Reminiscent@users.noreply.github.com>
/merge |
This pull request has been accepted and is ready to merge. Commit hash: bbfb53d
|
This reverts commit bac93cf.
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 3c3bf82
|
TiDB MergeCI notify🔴 Bad News! [2] CI still failing after this pr merged.
|
What problem does this PR solve?
Issue Number: ref #39199
Problem Summary:
What is changed and how it works?
Support create binding from history using plan digest
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.