Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fzzf678 committed Dec 1, 2022
1 parent 307dce2 commit b26251d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
9 changes: 9 additions & 0 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,14 +1428,23 @@ func TestCreateBindingFromHistory(t *testing.T) {
tk.MustExec(bindSQL)
planDigest := tk.MustQuery(fmt.Sprintf("select plan_digest from information_schema.statements_summary where query_sample_text = '%s'", bindSQL)).Rows()
tk.MustExec(fmt.Sprintf("create session binding from history using plan digest '%s'", planDigest[0][0]))
showRes := tk.MustQuery("show bindings").Rows()
require.Equal(t, len(showRes), 1)
require.Equal(t, planDigest[0][0], showRes[0][10])
for _, sql := range testCase.sqls {
tk.MustExec(fmt.Sprintf(sql, ""))
tk.MustQuery("select @@last_plan_from_binding").Check(testkit.Rows("1"))
}
}
showRes := tk.MustQuery("show bindings").Rows()
require.Equal(t, len(showRes), 1)
tk.MustExec(fmt.Sprintf("drop binding for sql digest '%s'", showRes[0][9]))
}

// exception cases
tk.MustGetErrMsg(fmt.Sprintf("create binding from history using plan digest '%s'", "1"), "can't find any plans for '1'")
tk.MustGetErrMsg(fmt.Sprintf("create binding from history using plan digest '%s'", ""), "plan digest is empty")
tk.MustExec("create binding for select * from t1, t2 where t1.id = t2.id using select /*+ merge_join(t1, t2) */ * from t1, t2 where t1.id = t2.id")
showRes := tk.MustQuery("show bindings").Rows()
require.Equal(t, showRes[0][10], "") // plan digest should be nil by create for
}
13 changes: 7 additions & 6 deletions executor/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ func (e *SQLBindExec) createSQLBind() error {
}()

bindInfo := bindinfo.Binding{
BindSQL: e.bindSQL,
Charset: e.charset,
Collation: e.collation,
Status: bindinfo.Enabled,
Source: e.source,
SQLDigest: e.sqlDigest,
BindSQL: e.bindSQL,
Charset: e.charset,
Collation: e.collation,
Status: bindinfo.Enabled,
Source: e.source,
SQLDigest: e.sqlDigest,
PlanDigest: e.planDigest,
}
record := &bindinfo.BindRecord{
OriginalSQL: e.normdOrigSQL,
Expand Down
1 change: 1 addition & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4817,6 +4817,7 @@ func (b *executorBuilder) buildSQLBindExec(v *plannercore.SQLBindPlan) Executor
newStatus: v.NewStatus,
source: v.Source,
sqlDigest: v.SQLDigest,
planDigest: v.PlanDigest,
}
return e
}
Expand Down
3 changes: 2 additions & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,9 @@ func (b *PlanBuilder) buildCreateBindPlanFromPlanDigest(v *ast.CreateBindingStmt
Db: utilparser.GetDefaultDB(originNode, bindableStmt.Schema),
Charset: bindableStmt.Charset,
Collation: bindableStmt.Collation,
SQLDigest: sqlDigestWithDB.String(),
Source: bindinfo.History,
SQLDigest: sqlDigestWithDB.String(),
PlanDigest: v.PlanDigest,
}
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SuperPriv, "", "", "", nil)
return p, nil
Expand Down

0 comments on commit b26251d

Please sign in to comment.