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: show binding information in explain format = 'verbose' #26930

Merged
merged 3 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2036,10 +2036,9 @@ func (s *testSuite) TestExplainShowBindSQL(c *C) {
"select * from `test` . `t` SELECT * FROM `test`.`t` USE INDEX (`a`)",
))

tk.MustExec("explain select * from t")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Using the bindSQL: SELECT * FROM `test`.`t` USE INDEX (`a`)"))
tk.MustExec("explain analyze select * from t")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Using the bindSQL: SELECT * FROM `test`.`t` USE INDEX (`a`)"))
tk.MustExec("explain format = 'verbose' select * from t")
tk.MustQuery("show warnings").Check(testkit.Rows("Note 1105 Using the bindSQL: SELECT * FROM `test`.`t` USE INDEX (`a`)"))
// explain analyze do not support verbose yet.
}

func (s *testSuite) TestDMLIndexHintBind(c *C) {
Expand Down
1 change: 1 addition & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) {
if explainStmt, ok := s.(*ast.ExplainStmt); ok {
sc.InExplainStmt = true
sc.IgnoreExplainIDSuffix = (strings.ToLower(explainStmt.Format) == types.ExplainFormatBrief)
sc.InVerboseExplain = strings.ToLower(explainStmt.Format) == types.ExplainFormatVerbose
s = explainStmt.Stmt
}
if _, ok := s.(*ast.ExplainForStmt); ok {
Expand Down
4 changes: 2 additions & 2 deletions planner/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in
if err := setFoundInBinding(sctx, true); err != nil {
logutil.BgLogger().Warn("set tidb_found_in_binding failed", zap.Error(err))
}
if _, ok := stmtNode.(*ast.ExplainStmt); ok {
sessVars.StmtCtx.AppendWarning(errors.Errorf("Using the bindSQL: %v", chosenBinding.BindSQL))
if sessVars.StmtCtx.InVerboseExplain {
sessVars.StmtCtx.AppendNote(errors.Errorf("Using the bindSQL: %v", chosenBinding.BindSQL))
}
}
// Restore the hint to avoid changing the stmt node.
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ type StatementContext struct {
DiskTracker disk.Tracker
LogOnExceed [2]memory.LogOnExceed
}

// InVerboseExplain indicates the statement is "explain format='verbose' ...".
InVerboseExplain bool
}

// StmtHints are SessionVars related sql hints.
Expand Down