From 824d8f1f89ddb3ef0e50ebfc9f040ab0d716a29f Mon Sep 17 00:00:00 2001 From: Chengpeng Yan <41809508+Reminiscent@users.noreply.github.com> Date: Fri, 20 Nov 2020 20:43:23 +0800 Subject: [PATCH 1/4] cherry pick #18017 to release-4.0 Signed-off-by: ti-srebot --- bindinfo/bind_test.go | 23 ++++ executor/adapter.go | 6 ++ executor/executor.go | 6 ++ executor/set.go | 4 + executor/slow_query.go | 78 ++++++++++++++ executor/slow_query_test.go | 4 +- infoschema/perfschema/const.go | 1 + infoschema/tables.go | 2 + infoschema/tables_test.go | 7 ++ planner/optimize.go | 10 ++ sessionctx/variable/session.go | 24 +++++ sessionctx/variable/session_test.go | 2 + sessionctx/variable/sysvar.go | 120 +++++++++++++++++++++ sessionctx/variable/tidb_vars.go | 4 + sessionctx/variable/varsutil.go | 6 ++ sessionctx/variable/varsutil_test.go | 20 ++++ util/stmtsummary/statement_summary.go | 11 ++ util/stmtsummary/statement_summary_test.go | 2 +- 18 files changed, 328 insertions(+), 2 deletions(-) diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index d55d42e30f70f..4188c25c023a8 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -1427,6 +1427,7 @@ func (s *testSuite) TestbindingSource(c *C) { c.Assert(bind.Source, Equals, bindinfo.Capture) } +<<<<<<< HEAD func (s *testSuite) TestIssue19836(c *C) { tk := testkit.NewTestKit(c, s.store) s.cleanBindingEnv(tk) @@ -1464,4 +1465,26 @@ func (s *testSuite) TestDMLIndexHintBind(c *C) { tk.MustExec("delete from t where b = 1 and c > 1") c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:idx_c") c.Assert(tk.MustUseIndex("delete from t where b = 1 and c > 1", "idx_c(c)"), IsTrue) +======= +func (s *testSuite) TestSPMHitInfo(c *C) { + tk := testkit.NewTestKit(c, s.store) + s.cleanBindingEnv(tk) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("drop table if exists t2") + tk.MustExec("create table t1(id int)") + tk.MustExec("create table t2(id int)") + + c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue) + c.Assert(tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue) + + tk.MustExec("SELECT * from t1,t2 where t1.id = t2.id") + tk.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("0")) + tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") + + c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue) + tk.MustExec("SELECT * from t1,t2 where t1.id = t2.id") + tk.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("1")) + tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id") +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) } diff --git a/executor/adapter.go b/executor/adapter.go index 830690a653666..4eb2e7100b7ee 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -894,6 +894,11 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) { Prepared: a.isPreparedStmt, HasMoreResults: hasMoreResults, PlanFromCache: sessVars.FoundInPlanCache, +<<<<<<< HEAD +======= + PlanFromBinding: sessVars.FoundInBinding, + RewriteInfo: sessVars.RewritePhaseInfo, +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) KVTotal: time.Duration(atomic.LoadInt64(&stmtDetail.WaitKVRespDuration)), PDTotal: time.Duration(atomic.LoadInt64(&stmtDetail.WaitPDRespDuration)), BackoffTotal: time.Duration(atomic.LoadInt64(&stmtDetail.BackoffDuration)), @@ -1057,6 +1062,7 @@ func (a *ExecStmt) SummaryStmt(succ bool) { IsInternal: sessVars.InRestrictedSQL, Succeed: succ, PlanInCache: sessVars.FoundInPlanCache, + PlanInBinding: sessVars.FoundInBinding, ExecRetryCount: a.retryCount, StmtExecDetails: stmtDetail, Prepared: a.isPreparedStmt, diff --git a/executor/executor.go b/executor/executor.go index b072ce1c2fc02..0f6eef79bb637 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1707,6 +1707,12 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { vars.StmtCtx = sc vars.PrevFoundInPlanCache = vars.FoundInPlanCache vars.FoundInPlanCache = false +<<<<<<< HEAD +======= + vars.ClearStmtVars() + vars.PrevFoundInBinding = vars.FoundInBinding + vars.FoundInBinding = false +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) return } diff --git a/executor/set.go b/executor/set.go index 75b6b0db95c60..c1753f3ed1313 100644 --- a/executor/set.go +++ b/executor/set.go @@ -184,6 +184,10 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e sessionVars.StmtCtx.AppendWarning(fmt.Errorf("Set operation for '%s' will not take effect", variable.TiDBFoundInPlanCache)) return nil } + if name == variable.TiDBFoundInBinding { + sessionVars.StmtCtx.AppendWarning(fmt.Errorf("Set operation for '%s' will not take effect", variable.TiDBFoundInBinding)) + return nil + } err = variable.SetSessionSystemVar(sessionVars, name, value) if err != nil { return err diff --git a/executor/slow_query.go b/executor/slow_query.go index d31a1e2ff9d32..73416180633ff 100755 --- a/executor/slow_query.go +++ b/executor/slow_query.go @@ -430,6 +430,7 @@ func (e *slowQueryRetriever) parseLog(ctx sessionctx.Context, log []string, offs } type slowQueryTuple struct { +<<<<<<< HEAD time types.Time txnStartTs uint64 user string @@ -490,6 +491,76 @@ type slowQueryTuple struct { plan string planDigest string backoffDetail string +======= + time types.Time + txnStartTs uint64 + user string + host string + connID uint64 + execRetryCount uint64 + execRetryTime float64 + queryTime float64 + parseTime float64 + compileTime float64 + rewriteTime float64 + preprocSubqueries uint64 + preprocSubQueryTime float64 + optimizeTime float64 + waitTSTime float64 + preWriteTime float64 + waitPrewriteBinlogTime float64 + commitTime float64 + getCommitTSTime float64 + commitBackoffTime float64 + backoffTypes string + resolveLockTime float64 + localLatchWaitTime float64 + writeKeys uint64 + writeSize uint64 + prewriteRegion uint64 + txnRetry uint64 + copTime float64 + processTime float64 + waitTime float64 + backOffTime float64 + lockKeysTime float64 + requestCount uint64 + totalKeys uint64 + processKeys uint64 + db string + indexIDs string + digest string + statsInfo string + avgProcessTime float64 + p90ProcessTime float64 + maxProcessTime float64 + maxProcessAddress string + avgWaitTime float64 + p90WaitTime float64 + maxWaitTime float64 + maxWaitAddress string + memMax int64 + diskMax int64 + prevStmt string + sql string + isInternal bool + succ bool + planFromCache bool + planFromBinding bool + prepared bool + kvTotal float64 + pdTotal float64 + backoffTotal float64 + writeSQLRespTotal float64 + plan string + planDigest string + backoffDetail string + rocksdbDeleteSkippedCount uint64 + rocksdbKeySkippedCount uint64 + rocksdbBlockCacheCount uint64 + rocksdbBlockReadCount uint64 + rocksdbBlockReadByte uint64 +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) } func (st *slowQueryTuple) setFieldValue(tz *time.Location, field, value string, lineNum int, checker *slowLogChecker) (valid bool, err error) { @@ -621,6 +692,8 @@ func (st *slowQueryTuple) setFieldValue(tz *time.Location, field, value string, st.succ, err = strconv.ParseBool(value) case variable.SlowLogPlanFromCache: st.planFromCache, err = strconv.ParseBool(value) + case variable.SlowLogPlanFromBinding: + st.planFromBinding, err = strconv.ParseBool(value) case variable.SlowLogPlan: st.plan = value case variable.SlowLogPlanDigest: @@ -728,6 +801,11 @@ func (st *slowQueryTuple) convertToDatumRow() []types.Datum { } else { record = append(record, types.NewIntDatum(0)) } + if st.planFromBinding { + record = append(record, types.NewIntDatum(1)) + } else { + record = append(record, types.NewIntDatum(0)) + } record = append(record, types.NewStringDatum(parsePlan(st.plan))) record = append(record, types.NewStringDatum(st.planDigest)) record = append(record, types.NewStringDatum(st.prevStmt)) diff --git a/executor/slow_query_test.go b/executor/slow_query_test.go index a4fec998f47cc..344fb4400310f 100644 --- a/executor/slow_query_test.go +++ b/executor/slow_query_test.go @@ -68,6 +68,7 @@ func (s *testExecSuite) TestParseSlowLogPanic(c *C) { # Mem_max: 70724 # Disk_max: 65536 # Plan_from_cache: true +# Plan_from_binding: true # Succ: false # Plan_digest: 60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4 # Prev_stmt: update t set i = 1; @@ -106,6 +107,7 @@ func (s *testExecSuite) TestParseSlowLogFile(c *C) { # Mem_max: 70724 # Disk_max: 65536 # Plan_from_cache: true +# Plan_from_binding: true # Succ: false # Plan_digest: 60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4 # Prev_stmt: update t set i = 1; @@ -133,7 +135,7 @@ select * from t;` `0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0.38,0.021,0,0,0,1,637,0,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,` + `0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,0,` + `Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` + - `0,0,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` + + `0,0,1,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` + `update t set i = 1;,select * from t;` c.Assert(recordString, Equals, expectRecordString) diff --git a/infoschema/perfschema/const.go b/infoschema/perfschema/const.go index 86a5f1766739f..157ce4c7ae7c9 100644 --- a/infoschema/perfschema/const.go +++ b/infoschema/perfschema/const.go @@ -415,6 +415,7 @@ const tableEventsStatementsSummaryByDigest = "CREATE TABLE if not exists perform "LAST_SEEN timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000'," + "PLAN_IN_CACHE bool NOT NULL," + "PLAN_CACHE_HITS bigint unsigned NOT NULL," + + "PLAN_IN_BINDING bool NOT NULL," + "QUANTILE_95 bigint unsigned NOT NULL," + "QUANTILE_99 bigint unsigned NOT NULL," + "QUANTILE_999 bigint unsigned NOT NULL," + diff --git a/infoschema/tables.go b/infoschema/tables.go index 41a4f2b180ba4..4f625fae31749 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -770,6 +770,7 @@ var slowQueryCols = []columnInfo{ {name: variable.SlowLogPrepared, tp: mysql.TypeTiny, size: 1}, {name: variable.SlowLogSucc, tp: mysql.TypeTiny, size: 1}, {name: variable.SlowLogPlanFromCache, tp: mysql.TypeTiny, size: 1}, + {name: variable.SlowLogPlanFromBinding, tp: mysql.TypeTiny, size: 1}, {name: variable.SlowLogPlan, tp: mysql.TypeLongBlob, size: types.UnspecifiedLength}, {name: variable.SlowLogPlanDigest, tp: mysql.TypeVarchar, size: 128}, {name: variable.SlowLogPrevStmt, tp: mysql.TypeLongBlob, size: types.UnspecifiedLength}, @@ -1231,6 +1232,7 @@ var tableStatementsSummaryCols = []columnInfo{ {name: "LAST_SEEN", tp: mysql.TypeTimestamp, size: 26, flag: mysql.NotNullFlag, comment: "The time these statements are seen for the last time"}, {name: "PLAN_IN_CACHE", tp: mysql.TypeTiny, size: 1, flag: mysql.NotNullFlag, comment: "Whether the last statement hit plan cache"}, {name: "PLAN_CACHE_HITS", tp: mysql.TypeLonglong, size: 20, flag: mysql.NotNullFlag, comment: "The number of times these statements hit plan cache"}, + {name: "PLAN_IN_BINDING", tp: mysql.TypeTiny, size: 1, flag: mysql.NotNullFlag, comment: "Whether the last statement is matched with the hints in the binding"}, {name: "QUERY_SAMPLE_TEXT", tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "Sampled original statement"}, {name: "PREV_SAMPLE_TEXT", tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "The previous statement before commit"}, {name: "PLAN_DIGEST", tp: mysql.TypeVarchar, size: 64, comment: "Digest of its execution plan"}, diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 68c9a0060c03f..e9a7342a7181f 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -636,10 +636,17 @@ func (s *testTableSuite) TestSlowQuery(c *C) { tk.MustExec("set time_zone = '+08:00';") re := tk.MustQuery("select * from information_schema.slow_query") re.Check(testutil.RowsWithSep("|", +<<<<<<< HEAD "2019-02-12 19:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) tk.MustExec("set time_zone = '+00:00';") re = tk.MustQuery("select * from information_schema.slow_query") re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) +======= + "2019-02-12 19:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|100|10|10|10|100|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) + tk.MustExec("set time_zone = '+00:00';") + re = tk.MustQuery("select * from information_schema.slow_query") + re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|100|10|10|10|100|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) // Test for long query. f, err := os.OpenFile(slowLogFileName, os.O_CREATE|os.O_WRONLY, 0644) diff --git a/planner/optimize.go b/planner/optimize.go index cc6ac50cfd25d..459bc47d8026d 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -123,6 +123,10 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in sctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("sql_select_limit is set, so plan binding is not activated")) return bestPlan, names, nil } + err = setFoundInBinding(sctx, true) + if err != nil { + return nil, nil, err + } bestPlanHint := plannercore.GenHintsFromPhysicalPlan(bestPlan) if len(bindRecord.Bindings) > 0 { orgBinding := bindRecord.Bindings[0] // the first is the original binding @@ -471,6 +475,12 @@ func handleStmtHints(hints []*ast.TableOptimizerHint) (stmtHints stmtctx.StmtHin return } +func setFoundInBinding(sctx sessionctx.Context, opt bool) error { + vars := sctx.GetSessionVars() + err := vars.SetSystemVar(variable.TiDBFoundInBinding, variable.BoolToOnOff(opt)) + return err +} + func init() { plannercore.OptimizeAstNode = Optimize } diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 05de9ef3b8d56..560d6e3eefe7d 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -637,6 +637,17 @@ type SessionVars struct { // PrevFoundInPlanCache indicates whether the last statement was found in plan cache. PrevFoundInPlanCache bool +<<<<<<< HEAD +======= + // FoundInBinding indicates whether the execution plan is matched with the hints in the binding. + FoundInBinding bool + // PrevFoundInBinding indicates whether the last execution plan is matched with the hints in the binding. + PrevFoundInBinding bool + + // OptimizerUseInvisibleIndexes indicates whether optimizer can use invisible index + OptimizerUseInvisibleIndexes bool + +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) // SelectLimit limits the max counts of select statement's output SelectLimit uint64 @@ -741,6 +752,8 @@ func NewSessionVars() *SessionVars { WindowingUseHighPrecision: true, PrevFoundInPlanCache: DefTiDBFoundInPlanCache, FoundInPlanCache: DefTiDBFoundInPlanCache, + PrevFoundInBinding: DefTiDBFoundInBinding, + FoundInBinding: DefTiDBFoundInBinding, SelectLimit: math.MaxUint64, AllowAutoRandExplicitInsert: DefTiDBAllowAutoRandExplicitInsert, EnableAmendPessimisticTxn: DefTiDBEnableAmendPessimisticTxn, @@ -1351,6 +1364,13 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { config.GetGlobalConfig().CheckMb4ValueInUTF8 = TiDBOptOn(val) case TiDBFoundInPlanCache: s.FoundInPlanCache = TiDBOptOn(val) +<<<<<<< HEAD +======= + case TiDBFoundInBinding: + s.FoundInBinding = TiDBOptOn(val) + case TiDBEnableCollectExecutionInfo: + config.GetGlobalConfig().EnableCollectExecutionInfo = TiDBOptOn(val) +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) case SQLSelectLimit: result, err := strconv.ParseUint(val, 10, 64) if err != nil { @@ -1618,6 +1638,8 @@ const ( SlowLogPrepared = "Prepared" // SlowLogPlanFromCache is used to indicate whether this plan is from plan cache. SlowLogPlanFromCache = "Plan_from_cache" + // SlowLogPlanFromBinding is used to indicate whether this plan is matched with the hints in the binding. + SlowLogPlanFromBinding = "Plan_from_binding" // SlowLogHasMoreResults is used to indicate whether this sql has more following results. SlowLogHasMoreResults = "Has_more_results" // SlowLogSucc is used to indicate whether this sql execute successfully. @@ -1668,6 +1690,7 @@ type SlowQueryLogItems struct { Succ bool Prepared bool PlanFromCache bool + PlanFromBinding bool HasMoreResults bool PrevStmt string Plan string @@ -1832,6 +1855,7 @@ func (s *SessionVars) SlowLogFormat(logItems *SlowQueryLogItems) string { writeSlowLogItem(&buf, SlowLogPrepared, strconv.FormatBool(logItems.Prepared)) writeSlowLogItem(&buf, SlowLogPlanFromCache, strconv.FormatBool(logItems.PlanFromCache)) + writeSlowLogItem(&buf, SlowLogPlanFromBinding, strconv.FormatBool(logItems.PlanFromBinding)) writeSlowLogItem(&buf, SlowLogHasMoreResults, strconv.FormatBool(logItems.HasMoreResults)) writeSlowLogItem(&buf, SlowLogKVTotal, strconv.FormatFloat(logItems.KVTotal.Seconds(), 'f', -1, 64)) writeSlowLogItem(&buf, SlowLogPDTotal, strconv.FormatFloat(logItems.PDTotal.Seconds(), 'f', -1, 64)) diff --git a/sessionctx/variable/session_test.go b/sessionctx/variable/session_test.go index b58ab81a6b4d9..e50e1521fe9c4 100644 --- a/sessionctx/variable/session_test.go +++ b/sessionctx/variable/session_test.go @@ -199,6 +199,7 @@ func (*testSessionSuite) TestSlowLogFormat(c *C) { # Disk_max: 6666 # Prepared: true # Plan_from_cache: true +# Plan_from_binding: true # Has_more_results: true # KV_total: 10 # PD_total: 11 @@ -222,6 +223,7 @@ func (*testSessionSuite) TestSlowLogFormat(c *C) { DiskMax: diskMax, Prepared: true, PlanFromCache: true, + PlanFromBinding: true, HasMoreResults: true, KVTotal: 10 * time.Second, PDTotal: 11 * time.Second, diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 1aa72e1a533bd..c879bb553f631 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -683,6 +683,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableRateLimitAction, Value: boolToOnOff(DefTiDBEnableRateLimitAction)}, /* The following variable is defined as session scope but is actually server scope. */ +<<<<<<< HEAD {ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)}, {ScopeSession, TiDBPProfSQLCPU, strconv.Itoa(DefTiDBPProfSQLCPU)}, {ScopeSession, TiDBDDLSlowOprThreshold, strconv.Itoa(DefTiDBDDLSlowOprThreshold)}, @@ -733,6 +734,125 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, TiDBRedactLog, BoolToIntStr(DefTiDBRedactLog)}, {ScopeGlobal, TiDBEnableTelemetry, BoolToIntStr(DefTiDBEnableTelemetry)}, {ScopeGlobal | ScopeSession, TiDBEnableAmendPessimisticTxn, boolToOnOff(DefTiDBEnableAmendPessimisticTxn)}, +======= + {Scope: ScopeSession, Name: TiDBGeneralLog, Value: BoolToOnOff(DefTiDBGeneralLog), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBPProfSQLCPU, Value: strconv.Itoa(DefTiDBPProfSQLCPU), Type: TypeInt, MinValue: 0, MaxValue: 1}, + {Scope: ScopeSession, Name: TiDBDDLSlowOprThreshold, Value: strconv.Itoa(DefTiDBDDLSlowOprThreshold)}, + {Scope: ScopeSession, Name: TiDBConfig, Value: ""}, + {Scope: ScopeGlobal, Name: TiDBDDLReorgWorkerCount, Value: strconv.Itoa(DefTiDBDDLReorgWorkerCount), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64}, + {Scope: ScopeGlobal, Name: TiDBDDLReorgBatchSize, Value: strconv.Itoa(DefTiDBDDLReorgBatchSize), Type: TypeUnsigned, MinValue: int64(MinDDLReorgBatchSize), MaxValue: uint64(MaxDDLReorgBatchSize), AutoConvertOutOfRange: true}, + {Scope: ScopeGlobal, Name: TiDBDDLErrorCountLimit, Value: strconv.Itoa(DefTiDBDDLErrorCountLimit), Type: TypeUnsigned, MinValue: 0, MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, + {Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW"}, + {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, AutoConvertOutOfRange: true}, + {Scope: ScopeGlobal, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority]}, + {Scope: ScopeSession, Name: TiDBEnableRadixJoin, Value: BoolToOnOff(DefTiDBUseRadixJoin), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: 63}, + {Scope: ScopeSession, Name: TiDBSlowQueryFile, Value: ""}, + {Scope: ScopeGlobal, Name: TiDBScatterRegion, Value: BoolToOnOff(DefTiDBScatterRegion), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBWaitSplitRegionFinish, Value: BoolToOnOff(DefTiDBWaitSplitRegionFinish), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBWaitSplitRegionTimeout, Value: strconv.Itoa(DefWaitSplitRegionTimeout), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxInt64}, + {Scope: ScopeSession, Name: TiDBLowResolutionTSO, Value: BoolOff, Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBExpensiveQueryTimeThreshold, Value: strconv.Itoa(DefTiDBExpensiveQueryTimeThreshold), Type: TypeUnsigned, MinValue: int64(MinExpensiveQueryTimeThreshold), MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, + {Scope: ScopeSession, Name: TiDBMemoryUsageAlarmRatio, Value: strconv.FormatFloat(config.GetGlobalConfig().Performance.MemoryUsageAlarmRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableNoopFuncs, Value: BoolToOnOff(DefTiDBEnableNoopFuncs), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBReplicaRead, Value: "leader", Type: TypeEnum, PossibleValues: []string{"leader", "follower", "leader-and-follower"}}, + {Scope: ScopeSession, Name: TiDBAllowRemoveAutoInc, Value: BoolToOnOff(DefTiDBAllowRemoveAutoInc), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableStmtSummary, Value: BoolToOnOff(config.GetGlobalConfig().StmtSummary.Enable), Type: TypeBool, AllowEmpty: true}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryInternalQuery, Value: BoolToOnOff(config.GetGlobalConfig().StmtSummary.EnableInternalQuery), Type: TypeBool, AllowEmpty: true}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryRefreshInterval, Value: strconv.Itoa(config.GetGlobalConfig().StmtSummary.RefreshInterval), Type: TypeInt, MinValue: 1, MaxValue: uint64(math.MaxInt32), AllowEmpty: true}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryHistorySize, Value: strconv.Itoa(config.GetGlobalConfig().StmtSummary.HistorySize), Type: TypeInt, MinValue: 0, MaxValue: uint64(math.MaxUint8), AllowEmpty: true}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryMaxStmtCount, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().StmtSummary.MaxStmtCount), 10), Type: TypeInt, MinValue: 1, MaxValue: uint64(math.MaxInt16), AllowEmpty: true}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryMaxSQLLength, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().StmtSummary.MaxSQLLength), 10), Type: TypeInt, MinValue: 0, MaxValue: uint64(math.MaxInt32), AllowEmpty: true}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBCapturePlanBaseline, Value: BoolOff, Type: TypeBool, AllowEmptyAll: true}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBUsePlanBaselines, Value: BoolToOnOff(DefTiDBUsePlanBaselines), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBEvolvePlanBaselines, Value: BoolToOnOff(DefTiDBEvolvePlanBaselines), Type: TypeBool}, + {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskMaxTime, Value: strconv.Itoa(DefTiDBEvolvePlanTaskMaxTime), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64}, + {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskStartTime, Value: DefTiDBEvolvePlanTaskStartTime, Type: TypeTime}, + {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskEndTime, Value: DefTiDBEvolvePlanTaskEndTime, Type: TypeTime}, + {Scope: ScopeSession, Name: TiDBIsolationReadEngines, Value: strings.Join(config.GetGlobalConfig().IsolationRead.Engines, ", "), Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { + engines := strings.Split(normalizedValue, ",") + var formatVal string + for i, engine := range engines { + engine = strings.TrimSpace(engine) + if i != 0 { + formatVal += "," + } + switch { + case strings.EqualFold(engine, kv.TiKV.Name()): + formatVal += kv.TiKV.Name() + case strings.EqualFold(engine, kv.TiFlash.Name()): + formatVal += kv.TiFlash.Name() + case strings.EqualFold(engine, kv.TiDB.Name()): + formatVal += kv.TiDB.Name() + default: + return normalizedValue, ErrWrongValueForVar.GenWithStackByArgs(TiDBIsolationReadEngines, normalizedValue) + } + } + return formatVal, nil + }}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBStoreLimit, Value: strconv.FormatInt(atomic.LoadInt64(&config.GetGlobalConfig().TiKVClient.StoreLimit), 10), Type: TypeInt, MinValue: 0, MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, + {Scope: ScopeSession, Name: TiDBMetricSchemaStep, Value: strconv.Itoa(DefTiDBMetricSchemaStep), Type: TypeUnsigned, MinValue: 10, MaxValue: 60 * 60 * 60}, + {Scope: ScopeSession, Name: TiDBMetricSchemaRangeDuration, Value: strconv.Itoa(DefTiDBMetricSchemaRangeDuration), Type: TypeUnsigned, MinValue: 10, MaxValue: 60 * 60 * 60}, + {Scope: ScopeSession, Name: TiDBSlowLogThreshold, Value: strconv.Itoa(logutil.DefaultSlowThreshold), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64}, + {Scope: ScopeSession, Name: TiDBRecordPlanInSlowLog, Value: int32ToBoolStr(logutil.DefaultRecordPlanInSlowLog), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBEnableSlowLog, Value: BoolToOnOff(logutil.DefaultTiDBEnableSlowLog), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBQueryLogMaxLen, Value: strconv.Itoa(logutil.DefaultQueryLogMaxLen), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64}, + {Scope: ScopeSession, Name: TiDBCheckMb4ValueInUTF8, Value: BoolToOnOff(config.GetGlobalConfig().CheckMb4ValueInUTF8), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBFoundInPlanCache, Value: BoolToOnOff(DefTiDBFoundInPlanCache), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBFoundInBinding, Value: BoolToOnOff(DefTiDBFoundInBinding), Type: TypeBool}, + {Scope: ScopeSession, Name: TiDBEnableCollectExecutionInfo, Value: BoolToOnOff(DefTiDBEnableCollectExecutionInfo), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBAllowAutoRandExplicitInsert, Value: BoolToOnOff(DefTiDBAllowAutoRandExplicitInsert), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableClusteredIndex, Value: BoolToOnOff(DefTiDBEnableClusteredIndex), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBPartitionPruneMode, Value: string(StaticOnly), Type: TypeStr, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { + if !PartitionPruneMode(normalizedValue).Valid() { + return normalizedValue, ErrWrongTypeForVar.GenWithStackByArgs(TiDBPartitionPruneMode) + } + return normalizedValue, nil + }}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBSlowLogMasking, Value: BoolToOnOff(DefTiDBRedactLog), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBRedactLog, Value: BoolToOnOff(DefTiDBRedactLog), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBShardAllocateStep, Value: strconv.Itoa(DefTiDBShardAllocateStep), Type: TypeInt, MinValue: 1, MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, + {Scope: ScopeGlobal, Name: TiDBEnableTelemetry, Value: BoolToOnOff(DefTiDBEnableTelemetry), Type: TypeBool}, + {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableAmendPessimisticTxn, Value: BoolToOnOff(DefTiDBEnableAmendPessimisticTxn), Type: TypeBool}, + + // for compatibility purpose, we should leave them alone. + // TODO: Follow the Terminology Updates of MySQL after their changes arrived. + // https://mysqlhighavailability.com/mysql-terminology-updates/ + {Scope: ScopeSession, Name: PseudoSlaveMode, Value: "", Type: TypeInt}, + {Scope: ScopeGlobal, Name: "slave_pending_jobs_size_max", Value: "16777216"}, + {Scope: ScopeGlobal, Name: "slave_transaction_retries", Value: "10"}, + {Scope: ScopeGlobal, Name: "slave_checkpoint_period", Value: "300"}, + {Scope: ScopeGlobal, Name: MasterVerifyChecksum, Value: BoolOff, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_trace_level", Value: ""}, + {Scope: ScopeGlobal, Name: "master_info_repository", Value: "FILE"}, + {Scope: ScopeGlobal, Name: "rpl_stop_slave_timeout", Value: "31536000"}, + {Scope: ScopeGlobal, Name: "slave_net_timeout", Value: "3600"}, + {Scope: ScopeGlobal, Name: "sync_master_info", Value: "10000"}, + {Scope: ScopeGlobal, Name: "init_slave", Value: ""}, + {Scope: ScopeGlobal, Name: SlaveCompressedProtocol, Value: BoolOff, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_slave_trace_level", Value: ""}, + {Scope: ScopeGlobal, Name: LogSlowSlaveStatements, Value: BoolOff, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "slave_checkpoint_group", Value: "512"}, + {Scope: ScopeNone, Name: "slave_load_tmpdir", Value: "/var/tmp/"}, + {Scope: ScopeGlobal, Name: "slave_parallel_type", Value: ""}, + {Scope: ScopeGlobal, Name: "slave_parallel_workers", Value: "0"}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_timeout", Value: "10000", Type: TypeInt}, + {Scope: ScopeNone, Name: "slave_skip_errors", Value: BoolOff}, + {Scope: ScopeGlobal, Name: "sql_slave_skip_counter", Value: "0"}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_slave_enabled", Value: BoolOff, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_enabled", Value: BoolOff, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "slave_preserve_commit_order", Value: BoolOff, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "slave_exec_mode", Value: "STRICT"}, + {Scope: ScopeNone, Name: "log_slave_updates", Value: BoolOff, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_wait_point", Value: "AFTER_SYNC", Type: TypeEnum, PossibleValues: []string{"AFTER_SYNC", "AFTER_COMMIT"}}, + {Scope: ScopeGlobal, Name: "slave_sql_verify_checksum", Value: BoolOn, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "slave_max_allowed_packet", Value: "1073741824"}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_wait_for_slave_count", Value: "1", Type: TypeInt, MinValue: 1, MaxValue: 65535}, + {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_wait_no_slave", Value: BoolOn, Type: TypeBool}, + {Scope: ScopeGlobal, Name: "slave_rows_search_algorithms", Value: "TABLE_SCAN,INDEX_SCAN"}, + {Scope: ScopeGlobal, Name: SlaveAllowBatching, Value: BoolOff, Type: TypeBool}, +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) } // SynonymsSysVariables is synonyms of system variables. diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 98877daca6152..86533843b2319 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -177,6 +177,9 @@ const ( // TiDBFoundInPlanCache indicates whether the last statement was found in plan cache TiDBFoundInPlanCache = "last_plan_from_cache" + // TiDBFoundInBinding indicates whether the last statement was matched with the hints in the binding. + TiDBFoundInBinding = "last_plan_from_binding" + // TiDBAllowAutoRandExplicitInsert indicates whether explicit insertion on auto_random column is allowed. TiDBAllowAutoRandExplicitInsert = "allow_auto_random_explicit_insert" ) @@ -521,6 +524,7 @@ const ( DefTiDBMetricSchemaStep = 60 // 60s DefTiDBMetricSchemaRangeDuration = 60 // 60s DefTiDBFoundInPlanCache = false + DefTiDBFoundInBinding = false DefTiDBEnableCollectExecutionInfo = true DefTiDBAllowAutoRandExplicitInsert = false DefTiDBRedactLog = false diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index acd70bd14ef56..817e1a8e401a6 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -162,7 +162,13 @@ func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) { case TiDBCapturePlanBaseline: return CapturePlanBaseline.GetVal(), true, nil case TiDBFoundInPlanCache: +<<<<<<< HEAD return BoolToIntStr(s.PrevFoundInPlanCache), true, nil +======= + return BoolToOnOff(s.PrevFoundInPlanCache), true, nil + case TiDBFoundInBinding: + return BoolToOnOff(s.PrevFoundInBinding), true, nil +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) case TiDBEnableCollectExecutionInfo: return BoolToIntStr(config.GetGlobalConfig().EnableCollectExecutionInfo), true, nil } diff --git a/sessionctx/variable/varsutil_test.go b/sessionctx/variable/varsutil_test.go index be47632f29636..2c78acc8f75ac 100644 --- a/sessionctx/variable/varsutil_test.go +++ b/sessionctx/variable/varsutil_test.go @@ -87,6 +87,7 @@ func (s *testVarsutilSuite) TestNewSessionVars(c *C) { c.Assert(vars.TiDBOptJoinReorderThreshold, Equals, DefTiDBOptJoinReorderThreshold) c.Assert(vars.EnableFastAnalyze, Equals, DefTiDBUseFastAnalyze) c.Assert(vars.FoundInPlanCache, Equals, DefTiDBFoundInPlanCache) + c.Assert(vars.FoundInBinding, Equals, DefTiDBFoundInBinding) c.Assert(vars.AllowAutoRandExplicitInsert, Equals, DefTiDBAllowAutoRandExplicitInsert) assertFieldsGreaterThanZero(c, reflect.ValueOf(vars.Concurrency)) @@ -453,8 +454,27 @@ func (s *testVarsutilSuite) TestVarsutil(c *C) { c.Assert(err, IsNil) val, err = GetSessionSystemVar(v, TiDBFoundInPlanCache) c.Assert(err, IsNil) +<<<<<<< HEAD c.Assert(val, Equals, "0") c.Assert(v.systems[TiDBFoundInPlanCache], Equals, "1") +======= + c.Assert(val, Equals, "OFF") + c.Assert(v.systems[TiDBFoundInPlanCache], Equals, "ON") + + err = SetSessionSystemVar(v, TiDBFoundInBinding, types.NewStringDatum("1")) + c.Assert(err, IsNil) + val, err = GetSessionSystemVar(v, TiDBFoundInBinding) + c.Assert(err, IsNil) + c.Assert(val, Equals, "OFF") + c.Assert(v.systems[TiDBFoundInBinding], Equals, "ON") + + err = SetSessionSystemVar(v, TiDBEnableChangeColumnType, types.NewStringDatum("ON")) + c.Assert(err, IsNil) + val, err = GetSessionSystemVar(v, TiDBEnableChangeColumnType) + c.Assert(err, IsNil) + c.Assert(val, Equals, "ON") + c.Assert(v.systems[TiDBEnableChangeColumnType], Equals, "ON") +>>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) err = SetSessionSystemVar(v, "UnknownVariable", types.NewStringDatum("on")) c.Assert(err, ErrorMatches, ".*]Unknown system variable 'UnknownVariable'") diff --git a/util/stmtsummary/statement_summary.go b/util/stmtsummary/statement_summary.go index 943d0bdb299fb..81891c93499b6 100644 --- a/util/stmtsummary/statement_summary.go +++ b/util/stmtsummary/statement_summary.go @@ -180,6 +180,7 @@ type stmtSummaryByDigestElement struct { // plan cache planInCache bool planCacheHits int64 + planInBinding bool // pessimistic execution retry information. execRetryCount uint execRetryTime time.Duration @@ -209,6 +210,7 @@ type StmtExecInfo struct { IsInternal bool Succeed bool PlanInCache bool + PlanInBinding bool ExecRetryCount uint ExecRetryTime time.Duration execdetails.StmtExecDetails @@ -598,6 +600,7 @@ func newStmtSummaryByDigestElement(sei *StmtExecInfo, beginTime int64, intervalS authUsers: make(map[string]struct{}), planInCache: false, planCacheHits: 0, + planInBinding: false, prepared: sei.Prepared, } ssElement.add(sei, intervalSeconds) @@ -753,6 +756,13 @@ func (ssElement *stmtSummaryByDigestElement) add(sei *StmtExecInfo, intervalSeco ssElement.planInCache = false } + // SPM + if sei.PlanInBinding { + ssElement.planInBinding = true + } else { + ssElement.planInBinding = false + } + // other ssElement.sumAffectedRows += sei.StmtCtx.AffectedRows() ssElement.sumMem += sei.MemMax @@ -870,6 +880,7 @@ func (ssElement *stmtSummaryByDigestElement) toDatum(ssbd *stmtSummaryByDigest) types.NewTime(types.FromGoTime(ssElement.lastSeen), mysql.TypeTimestamp, 0), ssElement.planInCache, ssElement.planCacheHits, + ssElement.planInBinding, ssElement.sampleSQL, ssElement.prevSQL, ssbd.planDigest, diff --git a/util/stmtsummary/statement_summary_test.go b/util/stmtsummary/statement_summary_test.go index 75afc6231c5df..df7ec05352d62 100644 --- a/util/stmtsummary/statement_summary_test.go +++ b/util/stmtsummary/statement_summary_test.go @@ -615,7 +615,7 @@ func (s *testStmtSummarySuite) TestToDatum(c *C) { stmtExecInfo1.ExecDetail.CommitDetail.TxnRetry, stmtExecInfo1.ExecDetail.CommitDetail.TxnRetry, 0, 0, 1, "txnLock:1", stmtExecInfo1.MemMax, stmtExecInfo1.MemMax, stmtExecInfo1.DiskMax, stmtExecInfo1.DiskMax, 0, 0, 0, 0, 0, stmtExecInfo1.StmtCtx.AffectedRows(), - t, t, 0, 0, stmtExecInfo1.OriginalSQL, stmtExecInfo1.PrevSQL, "plan_digest", ""} + t, t, 0, 0, 0, stmtExecInfo1.OriginalSQL, stmtExecInfo1.PrevSQL, "plan_digest", ""} match(c, datums[0], expectedDatum...) datums = s.ssMap.ToHistoryDatum(nil, true) c.Assert(len(datums), Equals, 1) From fb5e0dca797c4c05014a36ebafc6a2c1db0ad6f4 Mon Sep 17 00:00:00 2001 From: Reminiscent Date: Wed, 2 Dec 2020 15:18:27 +0800 Subject: [PATCH 2/4] solve conflicts --- bindinfo/bind_test.go | 41 --------- executor/adapter.go | 4 - executor/executor.go | 4 - executor/slow_query.go | 72 +--------------- go.mod | 2 +- infoschema/tables_test.go | 12 +-- sessionctx/variable/session.go | 12 --- sessionctx/variable/sysvar.go | 121 +-------------------------- sessionctx/variable/varsutil.go | 6 +- sessionctx/variable/varsutil_test.go | 16 +--- 10 files changed, 8 insertions(+), 282 deletions(-) diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index 4188c25c023a8..ce091b6ae27ad 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -19,7 +19,6 @@ import ( "flag" "fmt" "os" - "strconv" "testing" "time" @@ -1427,45 +1426,6 @@ func (s *testSuite) TestbindingSource(c *C) { c.Assert(bind.Source, Equals, bindinfo.Capture) } -<<<<<<< HEAD -func (s *testSuite) TestIssue19836(c *C) { - tk := testkit.NewTestKit(c, s.store) - s.cleanBindingEnv(tk) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, key (a));") - tk.MustExec("CREATE SESSION BINDING FOR select * from t where a = 1 limit 5, 5 USING select * from t ignore index (a) where a = 1 limit 5, 5;") - tk.MustExec("PREPARE stmt FROM 'select * from t where a = 40 limit ?, ?';") - tk.MustExec("set @a=1;") - tk.MustExec("set @b=2;") - tk.MustExec("EXECUTE stmt USING @a, @b;") - tk.Se.SetSessionManager(&mockSessionManager{ - PS: []*util.ProcessInfo{tk.Se.ShowProcess()}, - }) - explainResult := testkit.Rows( - "Limit_8 2.00 0 root time:0s, loops:0 offset:1, count:2 N/A N/A", - "└─TableReader_14 3.00 0 root time:0s, loops:0 data:Limit_13 N/A N/A", - " └─Limit_13 3.00 0 cop[tikv] time:0ns, loops:0 offset:0, count:3 N/A N/A", - " └─Selection_12 3.00 0 cop[tikv] time:0ns, loops:0 eq(test.t.a, 40) N/A N/A", - " └─TableFullScan_11 3000.00 0 cop[tikv] table:t time:0ns, loops:0 keep order:false, stats:pseudo N/A N/A", - ) - tk.MustQuery("explain for connection " + strconv.FormatUint(tk.Se.ShowProcess().ID, 10)).Check(explainResult) -} - -func (s *testSuite) TestDMLIndexHintBind(c *C) { - tk := testkit.NewTestKit(c, s.store) - s.cleanBindingEnv(tk) - tk.MustExec("use test") - tk.MustExec("create table t(a int, b int, c int, key idx_b(b), key idx_c(c))") - - tk.MustExec("delete from t where b = 1 and c > 1") - c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:idx_b") - c.Assert(tk.MustUseIndex("delete from t where b = 1 and c > 1", "idx_b(b)"), IsTrue) - tk.MustExec("create global binding for delete from t where b = 1 and c > 1 using delete from t use index(idx_c) where b = 1 and c > 1") - tk.MustExec("delete from t where b = 1 and c > 1") - c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:idx_c") - c.Assert(tk.MustUseIndex("delete from t where b = 1 and c > 1", "idx_c(c)"), IsTrue) -======= func (s *testSuite) TestSPMHitInfo(c *C) { tk := testkit.NewTestKit(c, s.store) s.cleanBindingEnv(tk) @@ -1486,5 +1446,4 @@ func (s *testSuite) TestSPMHitInfo(c *C) { tk.MustExec("SELECT * from t1,t2 where t1.id = t2.id") tk.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("1")) tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id") ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) } diff --git a/executor/adapter.go b/executor/adapter.go index 4eb2e7100b7ee..9f2e2be44a755 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -894,11 +894,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) { Prepared: a.isPreparedStmt, HasMoreResults: hasMoreResults, PlanFromCache: sessVars.FoundInPlanCache, -<<<<<<< HEAD -======= PlanFromBinding: sessVars.FoundInBinding, - RewriteInfo: sessVars.RewritePhaseInfo, ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) KVTotal: time.Duration(atomic.LoadInt64(&stmtDetail.WaitKVRespDuration)), PDTotal: time.Duration(atomic.LoadInt64(&stmtDetail.WaitPDRespDuration)), BackoffTotal: time.Duration(atomic.LoadInt64(&stmtDetail.BackoffDuration)), diff --git a/executor/executor.go b/executor/executor.go index 0f6eef79bb637..be406246e9f3a 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1707,12 +1707,8 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { vars.StmtCtx = sc vars.PrevFoundInPlanCache = vars.FoundInPlanCache vars.FoundInPlanCache = false -<<<<<<< HEAD -======= - vars.ClearStmtVars() vars.PrevFoundInBinding = vars.FoundInBinding vars.FoundInBinding = false ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) return } diff --git a/executor/slow_query.go b/executor/slow_query.go index 73416180633ff..f1b9fb7187ba5 100755 --- a/executor/slow_query.go +++ b/executor/slow_query.go @@ -430,7 +430,6 @@ func (e *slowQueryRetriever) parseLog(ctx sessionctx.Context, log []string, offs } type slowQueryTuple struct { -<<<<<<< HEAD time types.Time txnStartTs uint64 user string @@ -483,6 +482,7 @@ type slowQueryTuple struct { isInternal bool succ bool planFromCache bool + planFromBinding bool prepared bool kvTotal float64 pdTotal float64 @@ -491,76 +491,6 @@ type slowQueryTuple struct { plan string planDigest string backoffDetail string -======= - time types.Time - txnStartTs uint64 - user string - host string - connID uint64 - execRetryCount uint64 - execRetryTime float64 - queryTime float64 - parseTime float64 - compileTime float64 - rewriteTime float64 - preprocSubqueries uint64 - preprocSubQueryTime float64 - optimizeTime float64 - waitTSTime float64 - preWriteTime float64 - waitPrewriteBinlogTime float64 - commitTime float64 - getCommitTSTime float64 - commitBackoffTime float64 - backoffTypes string - resolveLockTime float64 - localLatchWaitTime float64 - writeKeys uint64 - writeSize uint64 - prewriteRegion uint64 - txnRetry uint64 - copTime float64 - processTime float64 - waitTime float64 - backOffTime float64 - lockKeysTime float64 - requestCount uint64 - totalKeys uint64 - processKeys uint64 - db string - indexIDs string - digest string - statsInfo string - avgProcessTime float64 - p90ProcessTime float64 - maxProcessTime float64 - maxProcessAddress string - avgWaitTime float64 - p90WaitTime float64 - maxWaitTime float64 - maxWaitAddress string - memMax int64 - diskMax int64 - prevStmt string - sql string - isInternal bool - succ bool - planFromCache bool - planFromBinding bool - prepared bool - kvTotal float64 - pdTotal float64 - backoffTotal float64 - writeSQLRespTotal float64 - plan string - planDigest string - backoffDetail string - rocksdbDeleteSkippedCount uint64 - rocksdbKeySkippedCount uint64 - rocksdbBlockCacheCount uint64 - rocksdbBlockReadCount uint64 - rocksdbBlockReadByte uint64 ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) } func (st *slowQueryTuple) setFieldValue(tz *time.Location, field, value string, lineNum int, checker *slowLogChecker) (valid bool, err error) { diff --git a/go.mod b/go.mod index d77a4e9666f09..61cfe39e1a1b6 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/pingcap/kvproto v0.0.0-20200907074027-32a3a0accf7d github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8 github.com/pingcap/parser v0.0.0-20201130080042-c3ddfec58248 - github.com/pingcap/sysutil v0.0.0-20201130064824-f0c8aa6a6966 + github.com/pingcap/sysutil v0.0.0-20201130064824-f0c8aa6a6966 github.com/pingcap/tidb-tools v4.0.6-0.20200828085514-03575b185007+incompatible github.com/pingcap/tipb v0.0.0-20200618092958-4fad48b4c8c3 github.com/prometheus/client_golang v1.5.1 diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index e9a7342a7181f..3541eaa7c655c 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -636,18 +636,10 @@ func (s *testTableSuite) TestSlowQuery(c *C) { tk.MustExec("set time_zone = '+08:00';") re := tk.MustQuery("select * from information_schema.slow_query") re.Check(testutil.RowsWithSep("|", -<<<<<<< HEAD - "2019-02-12 19:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) + "2019-02-12 19:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) tk.MustExec("set time_zone = '+00:00';") re = tk.MustQuery("select * from information_schema.slow_query") - re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) -======= - "2019-02-12 19:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|100|10|10|10|100|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) - tk.MustExec("set time_zone = '+00:00';") - re = tk.MustQuery("select * from information_schema.slow_query") - re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|100|10|10|10|100|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) - + re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) // Test for long query. f, err := os.OpenFile(slowLogFileName, os.O_CREATE|os.O_WRONLY, 0644) c.Assert(err, IsNil) diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 560d6e3eefe7d..4fce95916af2e 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -637,17 +637,10 @@ type SessionVars struct { // PrevFoundInPlanCache indicates whether the last statement was found in plan cache. PrevFoundInPlanCache bool -<<<<<<< HEAD -======= // FoundInBinding indicates whether the execution plan is matched with the hints in the binding. FoundInBinding bool // PrevFoundInBinding indicates whether the last execution plan is matched with the hints in the binding. PrevFoundInBinding bool - - // OptimizerUseInvisibleIndexes indicates whether optimizer can use invisible index - OptimizerUseInvisibleIndexes bool - ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) // SelectLimit limits the max counts of select statement's output SelectLimit uint64 @@ -1364,13 +1357,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { config.GetGlobalConfig().CheckMb4ValueInUTF8 = TiDBOptOn(val) case TiDBFoundInPlanCache: s.FoundInPlanCache = TiDBOptOn(val) -<<<<<<< HEAD -======= case TiDBFoundInBinding: s.FoundInBinding = TiDBOptOn(val) - case TiDBEnableCollectExecutionInfo: - config.GetGlobalConfig().EnableCollectExecutionInfo = TiDBOptOn(val) ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) case SQLSelectLimit: result, err := strconv.ParseUint(val, 10, 64) if err != nil { diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index c879bb553f631..e4966be07f110 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -683,7 +683,6 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableRateLimitAction, Value: boolToOnOff(DefTiDBEnableRateLimitAction)}, /* The following variable is defined as session scope but is actually server scope. */ -<<<<<<< HEAD {ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)}, {ScopeSession, TiDBPProfSQLCPU, strconv.Itoa(DefTiDBPProfSQLCPU)}, {ScopeSession, TiDBDDLSlowOprThreshold, strconv.Itoa(DefTiDBDDLSlowOprThreshold)}, @@ -728,131 +727,13 @@ var defaultSysVars = []*SysVar{ {ScopeSession, TiDBQueryLogMaxLen, strconv.Itoa(logutil.DefaultQueryLogMaxLen)}, {ScopeSession, TiDBCheckMb4ValueInUTF8, BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUTF8)}, {ScopeSession, TiDBFoundInPlanCache, BoolToIntStr(DefTiDBFoundInPlanCache)}, + {ScopeSession, TiDBFoundInBinding, BoolToIntStr(DefTiDBFoundInBinding)}, {ScopeSession, TiDBEnableCollectExecutionInfo, BoolToIntStr(DefTiDBEnableCollectExecutionInfo)}, {ScopeGlobal | ScopeSession, TiDBAllowAutoRandExplicitInsert, boolToOnOff(DefTiDBAllowAutoRandExplicitInsert)}, {ScopeGlobal | ScopeSession, TiDBSlowLogMasking, BoolToIntStr(DefTiDBRedactLog)}, {ScopeGlobal | ScopeSession, TiDBRedactLog, BoolToIntStr(DefTiDBRedactLog)}, {ScopeGlobal, TiDBEnableTelemetry, BoolToIntStr(DefTiDBEnableTelemetry)}, {ScopeGlobal | ScopeSession, TiDBEnableAmendPessimisticTxn, boolToOnOff(DefTiDBEnableAmendPessimisticTxn)}, -======= - {Scope: ScopeSession, Name: TiDBGeneralLog, Value: BoolToOnOff(DefTiDBGeneralLog), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBPProfSQLCPU, Value: strconv.Itoa(DefTiDBPProfSQLCPU), Type: TypeInt, MinValue: 0, MaxValue: 1}, - {Scope: ScopeSession, Name: TiDBDDLSlowOprThreshold, Value: strconv.Itoa(DefTiDBDDLSlowOprThreshold)}, - {Scope: ScopeSession, Name: TiDBConfig, Value: ""}, - {Scope: ScopeGlobal, Name: TiDBDDLReorgWorkerCount, Value: strconv.Itoa(DefTiDBDDLReorgWorkerCount), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64}, - {Scope: ScopeGlobal, Name: TiDBDDLReorgBatchSize, Value: strconv.Itoa(DefTiDBDDLReorgBatchSize), Type: TypeUnsigned, MinValue: int64(MinDDLReorgBatchSize), MaxValue: uint64(MaxDDLReorgBatchSize), AutoConvertOutOfRange: true}, - {Scope: ScopeGlobal, Name: TiDBDDLErrorCountLimit, Value: strconv.Itoa(DefTiDBDDLErrorCountLimit), Type: TypeUnsigned, MinValue: 0, MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, - {Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW"}, - {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, AutoConvertOutOfRange: true}, - {Scope: ScopeGlobal, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority]}, - {Scope: ScopeSession, Name: TiDBEnableRadixJoin, Value: BoolToOnOff(DefTiDBUseRadixJoin), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: 63}, - {Scope: ScopeSession, Name: TiDBSlowQueryFile, Value: ""}, - {Scope: ScopeGlobal, Name: TiDBScatterRegion, Value: BoolToOnOff(DefTiDBScatterRegion), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBWaitSplitRegionFinish, Value: BoolToOnOff(DefTiDBWaitSplitRegionFinish), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBWaitSplitRegionTimeout, Value: strconv.Itoa(DefWaitSplitRegionTimeout), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxInt64}, - {Scope: ScopeSession, Name: TiDBLowResolutionTSO, Value: BoolOff, Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBExpensiveQueryTimeThreshold, Value: strconv.Itoa(DefTiDBExpensiveQueryTimeThreshold), Type: TypeUnsigned, MinValue: int64(MinExpensiveQueryTimeThreshold), MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, - {Scope: ScopeSession, Name: TiDBMemoryUsageAlarmRatio, Value: strconv.FormatFloat(config.GetGlobalConfig().Performance.MemoryUsageAlarmRatio, 'f', -1, 64), Type: TypeFloat, MinValue: 0.0, MaxValue: 1.0}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableNoopFuncs, Value: BoolToOnOff(DefTiDBEnableNoopFuncs), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBReplicaRead, Value: "leader", Type: TypeEnum, PossibleValues: []string{"leader", "follower", "leader-and-follower"}}, - {Scope: ScopeSession, Name: TiDBAllowRemoveAutoInc, Value: BoolToOnOff(DefTiDBAllowRemoveAutoInc), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableStmtSummary, Value: BoolToOnOff(config.GetGlobalConfig().StmtSummary.Enable), Type: TypeBool, AllowEmpty: true}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryInternalQuery, Value: BoolToOnOff(config.GetGlobalConfig().StmtSummary.EnableInternalQuery), Type: TypeBool, AllowEmpty: true}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryRefreshInterval, Value: strconv.Itoa(config.GetGlobalConfig().StmtSummary.RefreshInterval), Type: TypeInt, MinValue: 1, MaxValue: uint64(math.MaxInt32), AllowEmpty: true}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryHistorySize, Value: strconv.Itoa(config.GetGlobalConfig().StmtSummary.HistorySize), Type: TypeInt, MinValue: 0, MaxValue: uint64(math.MaxUint8), AllowEmpty: true}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryMaxStmtCount, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().StmtSummary.MaxStmtCount), 10), Type: TypeInt, MinValue: 1, MaxValue: uint64(math.MaxInt16), AllowEmpty: true}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBStmtSummaryMaxSQLLength, Value: strconv.FormatUint(uint64(config.GetGlobalConfig().StmtSummary.MaxSQLLength), 10), Type: TypeInt, MinValue: 0, MaxValue: uint64(math.MaxInt32), AllowEmpty: true}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBCapturePlanBaseline, Value: BoolOff, Type: TypeBool, AllowEmptyAll: true}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBUsePlanBaselines, Value: BoolToOnOff(DefTiDBUsePlanBaselines), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBEvolvePlanBaselines, Value: BoolToOnOff(DefTiDBEvolvePlanBaselines), Type: TypeBool}, - {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskMaxTime, Value: strconv.Itoa(DefTiDBEvolvePlanTaskMaxTime), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64}, - {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskStartTime, Value: DefTiDBEvolvePlanTaskStartTime, Type: TypeTime}, - {Scope: ScopeGlobal, Name: TiDBEvolvePlanTaskEndTime, Value: DefTiDBEvolvePlanTaskEndTime, Type: TypeTime}, - {Scope: ScopeSession, Name: TiDBIsolationReadEngines, Value: strings.Join(config.GetGlobalConfig().IsolationRead.Engines, ", "), Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { - engines := strings.Split(normalizedValue, ",") - var formatVal string - for i, engine := range engines { - engine = strings.TrimSpace(engine) - if i != 0 { - formatVal += "," - } - switch { - case strings.EqualFold(engine, kv.TiKV.Name()): - formatVal += kv.TiKV.Name() - case strings.EqualFold(engine, kv.TiFlash.Name()): - formatVal += kv.TiFlash.Name() - case strings.EqualFold(engine, kv.TiDB.Name()): - formatVal += kv.TiDB.Name() - default: - return normalizedValue, ErrWrongValueForVar.GenWithStackByArgs(TiDBIsolationReadEngines, normalizedValue) - } - } - return formatVal, nil - }}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBStoreLimit, Value: strconv.FormatInt(atomic.LoadInt64(&config.GetGlobalConfig().TiKVClient.StoreLimit), 10), Type: TypeInt, MinValue: 0, MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, - {Scope: ScopeSession, Name: TiDBMetricSchemaStep, Value: strconv.Itoa(DefTiDBMetricSchemaStep), Type: TypeUnsigned, MinValue: 10, MaxValue: 60 * 60 * 60}, - {Scope: ScopeSession, Name: TiDBMetricSchemaRangeDuration, Value: strconv.Itoa(DefTiDBMetricSchemaRangeDuration), Type: TypeUnsigned, MinValue: 10, MaxValue: 60 * 60 * 60}, - {Scope: ScopeSession, Name: TiDBSlowLogThreshold, Value: strconv.Itoa(logutil.DefaultSlowThreshold), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64}, - {Scope: ScopeSession, Name: TiDBRecordPlanInSlowLog, Value: int32ToBoolStr(logutil.DefaultRecordPlanInSlowLog), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBEnableSlowLog, Value: BoolToOnOff(logutil.DefaultTiDBEnableSlowLog), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBQueryLogMaxLen, Value: strconv.Itoa(logutil.DefaultQueryLogMaxLen), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64}, - {Scope: ScopeSession, Name: TiDBCheckMb4ValueInUTF8, Value: BoolToOnOff(config.GetGlobalConfig().CheckMb4ValueInUTF8), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBFoundInPlanCache, Value: BoolToOnOff(DefTiDBFoundInPlanCache), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBFoundInBinding, Value: BoolToOnOff(DefTiDBFoundInBinding), Type: TypeBool}, - {Scope: ScopeSession, Name: TiDBEnableCollectExecutionInfo, Value: BoolToOnOff(DefTiDBEnableCollectExecutionInfo), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBAllowAutoRandExplicitInsert, Value: BoolToOnOff(DefTiDBAllowAutoRandExplicitInsert), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableClusteredIndex, Value: BoolToOnOff(DefTiDBEnableClusteredIndex), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBPartitionPruneMode, Value: string(StaticOnly), Type: TypeStr, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { - if !PartitionPruneMode(normalizedValue).Valid() { - return normalizedValue, ErrWrongTypeForVar.GenWithStackByArgs(TiDBPartitionPruneMode) - } - return normalizedValue, nil - }}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBSlowLogMasking, Value: BoolToOnOff(DefTiDBRedactLog), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBRedactLog, Value: BoolToOnOff(DefTiDBRedactLog), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBShardAllocateStep, Value: strconv.Itoa(DefTiDBShardAllocateStep), Type: TypeInt, MinValue: 1, MaxValue: uint64(math.MaxInt64), AutoConvertOutOfRange: true}, - {Scope: ScopeGlobal, Name: TiDBEnableTelemetry, Value: BoolToOnOff(DefTiDBEnableTelemetry), Type: TypeBool}, - {Scope: ScopeGlobal | ScopeSession, Name: TiDBEnableAmendPessimisticTxn, Value: BoolToOnOff(DefTiDBEnableAmendPessimisticTxn), Type: TypeBool}, - - // for compatibility purpose, we should leave them alone. - // TODO: Follow the Terminology Updates of MySQL after their changes arrived. - // https://mysqlhighavailability.com/mysql-terminology-updates/ - {Scope: ScopeSession, Name: PseudoSlaveMode, Value: "", Type: TypeInt}, - {Scope: ScopeGlobal, Name: "slave_pending_jobs_size_max", Value: "16777216"}, - {Scope: ScopeGlobal, Name: "slave_transaction_retries", Value: "10"}, - {Scope: ScopeGlobal, Name: "slave_checkpoint_period", Value: "300"}, - {Scope: ScopeGlobal, Name: MasterVerifyChecksum, Value: BoolOff, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_trace_level", Value: ""}, - {Scope: ScopeGlobal, Name: "master_info_repository", Value: "FILE"}, - {Scope: ScopeGlobal, Name: "rpl_stop_slave_timeout", Value: "31536000"}, - {Scope: ScopeGlobal, Name: "slave_net_timeout", Value: "3600"}, - {Scope: ScopeGlobal, Name: "sync_master_info", Value: "10000"}, - {Scope: ScopeGlobal, Name: "init_slave", Value: ""}, - {Scope: ScopeGlobal, Name: SlaveCompressedProtocol, Value: BoolOff, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_slave_trace_level", Value: ""}, - {Scope: ScopeGlobal, Name: LogSlowSlaveStatements, Value: BoolOff, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "slave_checkpoint_group", Value: "512"}, - {Scope: ScopeNone, Name: "slave_load_tmpdir", Value: "/var/tmp/"}, - {Scope: ScopeGlobal, Name: "slave_parallel_type", Value: ""}, - {Scope: ScopeGlobal, Name: "slave_parallel_workers", Value: "0"}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_timeout", Value: "10000", Type: TypeInt}, - {Scope: ScopeNone, Name: "slave_skip_errors", Value: BoolOff}, - {Scope: ScopeGlobal, Name: "sql_slave_skip_counter", Value: "0"}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_slave_enabled", Value: BoolOff, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_enabled", Value: BoolOff, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "slave_preserve_commit_order", Value: BoolOff, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "slave_exec_mode", Value: "STRICT"}, - {Scope: ScopeNone, Name: "log_slave_updates", Value: BoolOff, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_wait_point", Value: "AFTER_SYNC", Type: TypeEnum, PossibleValues: []string{"AFTER_SYNC", "AFTER_COMMIT"}}, - {Scope: ScopeGlobal, Name: "slave_sql_verify_checksum", Value: BoolOn, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "slave_max_allowed_packet", Value: "1073741824"}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_wait_for_slave_count", Value: "1", Type: TypeInt, MinValue: 1, MaxValue: 65535}, - {Scope: ScopeGlobal, Name: "rpl_semi_sync_master_wait_no_slave", Value: BoolOn, Type: TypeBool}, - {Scope: ScopeGlobal, Name: "slave_rows_search_algorithms", Value: "TABLE_SCAN,INDEX_SCAN"}, - {Scope: ScopeGlobal, Name: SlaveAllowBatching, Value: BoolOff, Type: TypeBool}, ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) } // SynonymsSysVariables is synonyms of system variables. diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 817e1a8e401a6..09b61c93d1ac2 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -162,13 +162,9 @@ func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) { case TiDBCapturePlanBaseline: return CapturePlanBaseline.GetVal(), true, nil case TiDBFoundInPlanCache: -<<<<<<< HEAD return BoolToIntStr(s.PrevFoundInPlanCache), true, nil -======= - return BoolToOnOff(s.PrevFoundInPlanCache), true, nil case TiDBFoundInBinding: - return BoolToOnOff(s.PrevFoundInBinding), true, nil ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) + return BoolToIntStr(s.PrevFoundInBinding), true, nil case TiDBEnableCollectExecutionInfo: return BoolToIntStr(config.GetGlobalConfig().EnableCollectExecutionInfo), true, nil } diff --git a/sessionctx/variable/varsutil_test.go b/sessionctx/variable/varsutil_test.go index 2c78acc8f75ac..536d490a57847 100644 --- a/sessionctx/variable/varsutil_test.go +++ b/sessionctx/variable/varsutil_test.go @@ -454,27 +454,15 @@ func (s *testVarsutilSuite) TestVarsutil(c *C) { c.Assert(err, IsNil) val, err = GetSessionSystemVar(v, TiDBFoundInPlanCache) c.Assert(err, IsNil) -<<<<<<< HEAD c.Assert(val, Equals, "0") c.Assert(v.systems[TiDBFoundInPlanCache], Equals, "1") -======= - c.Assert(val, Equals, "OFF") - c.Assert(v.systems[TiDBFoundInPlanCache], Equals, "ON") err = SetSessionSystemVar(v, TiDBFoundInBinding, types.NewStringDatum("1")) c.Assert(err, IsNil) val, err = GetSessionSystemVar(v, TiDBFoundInBinding) c.Assert(err, IsNil) - c.Assert(val, Equals, "OFF") - c.Assert(v.systems[TiDBFoundInBinding], Equals, "ON") - - err = SetSessionSystemVar(v, TiDBEnableChangeColumnType, types.NewStringDatum("ON")) - c.Assert(err, IsNil) - val, err = GetSessionSystemVar(v, TiDBEnableChangeColumnType) - c.Assert(err, IsNil) - c.Assert(val, Equals, "ON") - c.Assert(v.systems[TiDBEnableChangeColumnType], Equals, "ON") ->>>>>>> 2c66371d8... planner, sessionctx : Add 'last_plan_from_binding' to help know whether sql's plan is matched with the hints in the binding (#18017) + c.Assert(val, Equals, "0") + c.Assert(v.systems[TiDBFoundInBinding], Equals, "1") err = SetSessionSystemVar(v, "UnknownVariable", types.NewStringDatum("on")) c.Assert(err, ErrorMatches, ".*]Unknown system variable 'UnknownVariable'") From e1aa57d6329425faf82f4d5b0bc32c332cd4c2d4 Mon Sep 17 00:00:00 2001 From: Reminiscent Date: Wed, 2 Dec 2020 15:28:25 +0800 Subject: [PATCH 3/4] solve conflicts --- bindinfo/bind_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ planner/optimize.go | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index ce091b6ae27ad..c5a704ae30923 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -19,6 +19,7 @@ import ( "flag" "fmt" "os" + "strconv" "testing" "time" @@ -1426,6 +1427,45 @@ func (s *testSuite) TestbindingSource(c *C) { c.Assert(bind.Source, Equals, bindinfo.Capture) } +func (s *testSuite) TestIssue19836(c *C) { + tk := testkit.NewTestKit(c, s.store) + s.cleanBindingEnv(tk) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, key (a));") + tk.MustExec("CREATE SESSION BINDING FOR select * from t where a = 1 limit 5, 5 USING select * from t ignore index (a) where a = 1 limit 5, 5;") + tk.MustExec("PREPARE stmt FROM 'select * from t where a = 40 limit ?, ?';") + tk.MustExec("set @a=1;") + tk.MustExec("set @b=2;") + tk.MustExec("EXECUTE stmt USING @a, @b;") + tk.Se.SetSessionManager(&mockSessionManager{ + PS: []*util.ProcessInfo{tk.Se.ShowProcess()}, + }) + explainResult := testkit.Rows( + "Limit_8 2.00 0 root time:0s, loops:0 offset:1, count:2 N/A N/A", + "└─TableReader_14 3.00 0 root time:0s, loops:0 data:Limit_13 N/A N/A", + " └─Limit_13 3.00 0 cop[tikv] time:0ns, loops:0 offset:0, count:3 N/A N/A", + " └─Selection_12 3.00 0 cop[tikv] time:0ns, loops:0 eq(test.t.a, 40) N/A N/A", + " └─TableFullScan_11 3000.00 0 cop[tikv] table:t time:0ns, loops:0 keep order:false, stats:pseudo N/A N/A", + ) + tk.MustQuery("explain for connection " + strconv.FormatUint(tk.Se.ShowProcess().ID, 10)).Check(explainResult) +} + +func (s *testSuite) TestDMLIndexHintBind(c *C) { + tk := testkit.NewTestKit(c, s.store) + s.cleanBindingEnv(tk) + tk.MustExec("use test") + tk.MustExec("create table t(a int, b int, c int, key idx_b(b), key idx_c(c))") + + tk.MustExec("delete from t where b = 1 and c > 1") + c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:idx_b") + c.Assert(tk.MustUseIndex("delete from t where b = 1 and c > 1", "idx_b(b)"), IsTrue) + tk.MustExec("create global binding for delete from t where b = 1 and c > 1 using delete from t use index(idx_c) where b = 1 and c > 1") + tk.MustExec("delete from t where b = 1 and c > 1") + c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:idx_c") + c.Assert(tk.MustUseIndex("delete from t where b = 1 and c > 1", "idx_c(c)"), IsTrue) +} + func (s *testSuite) TestSPMHitInfo(c *C) { tk := testkit.NewTestKit(c, s.store) s.cleanBindingEnv(tk) diff --git a/planner/optimize.go b/planner/optimize.go index 459bc47d8026d..87cbe51e9676e 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -477,7 +477,7 @@ func handleStmtHints(hints []*ast.TableOptimizerHint) (stmtHints stmtctx.StmtHin func setFoundInBinding(sctx sessionctx.Context, opt bool) error { vars := sctx.GetSessionVars() - err := vars.SetSystemVar(variable.TiDBFoundInBinding, variable.BoolToOnOff(opt)) + err := vars.SetSystemVar(variable.TiDBFoundInBinding, variable.BoolToIntStr(opt)) return err } From d07debf129d9b21be579b33dfc86fd7f72af294a Mon Sep 17 00:00:00 2001 From: Reminiscent Date: Fri, 12 Mar 2021 11:06:15 +0800 Subject: [PATCH 4/4] fix conflicts --- bindinfo/bind_test.go | 22 ++++++++++++++++++++++ infoschema/tables_test.go | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index cbc0a08852034..5daecc922a765 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -1541,6 +1541,28 @@ func (s *testSuite) TestCapturePlanBaselineIgnoreTiFlash(c *C) { c.Assert(rows[0][1], Equals, "SELECT /*+ use_index(@`sel_1` `test`.`t` )*/ * FROM `test`.`t`") } +func (s *testSuite) TestSPMHitInfo(c *C) { + tk := testkit.NewTestKit(c, s.store) + s.cleanBindingEnv(tk) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("drop table if exists t2") + tk.MustExec("create table t1(id int)") + tk.MustExec("create table t2(id int)") + + c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue) + c.Assert(tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue) + + tk.MustExec("SELECT * from t1,t2 where t1.id = t2.id") + tk.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("0")) + tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id") + + c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue) + tk.MustExec("SELECT * from t1,t2 where t1.id = t2.id") + tk.MustQuery(`select @@last_plan_from_binding;`).Check(testkit.Rows("1")) + tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id") +} + func (s *testSuite) TestNotEvolvePlanForReadStorageHint(c *C) { tk := testkit.NewTestKit(c, s.store) s.cleanBindingEnv(tk) diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 6759efa55f8c1..5e425730a9231 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -638,10 +638,10 @@ func (s *testTableSuite) TestSlowQuery(c *C) { tk.MustExec("set time_zone = '+08:00';") re := tk.MustQuery("select * from information_schema.slow_query") re.Check(testutil.RowsWithSep("|", - "2019-02-12 19:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) + "2019-02-12 19:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) tk.MustExec("set time_zone = '+00:00';") re = tk.MustQuery("select * from information_schema.slow_query") - re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) + re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|localhost|6|57|0.12|4.895492|0.4|0.2|0.000000003|2|0.000000002|0.00000001|0.000000003|0.19|0.21|0.01|0|0.18|[txnLock]|0.03|0|15|480|1|8|0.3824278|0.161|0.101|0.092|1.71|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|65536|0|0|0|0||0|1|1|0|abcd|60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4|update t set i = 2;|select * from t_slim;")) // Test for long query. f, err := os.OpenFile(slowLogFileName, os.O_CREATE|os.O_WRONLY, 0644)