diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index a1e53c7f696ac..1e2281ee20438 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -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) { diff --git a/executor/executor.go b/executor/executor.go index 8a408911915cd..12cab3e4a8866 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -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 { diff --git a/planner/optimize.go b/planner/optimize.go index 39d1e78ef8857..64e3e8fd7ced6 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -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. diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index 048e24827ee34..23d4040e5c3be 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -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.