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

expensivequery: fix the issue that max_exec_time hint doesn't work if it exceeds the expensive-threshold (#17359) #17536

Merged
merged 6 commits into from
Jun 17, 2020
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
12 changes: 12 additions & 0 deletions server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/util/arena"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
)

Expand Down Expand Up @@ -426,6 +427,17 @@ func (ts *ConnTestSuite) TestConnExecutionTimeout(c *C) {
err = cc.handleQuery(context.Background(), "select * FROM testTable2 WHERE SLEEP(1);")
c.Assert(err, IsNil)

_, err = se.Execute(context.Background(), "set @@max_execution_time = 1500;")
c.Assert(err, IsNil)

_, err = se.Execute(context.Background(), "set @@tidb_expensive_query_time_threshold = 1;")
c.Assert(err, IsNil)

records, err := se.Execute(context.Background(), "select SLEEP(2);")
c.Assert(err, IsNil)
tk := testkit.NewTestKit(c, ts.store)
tk.ResultSetToResult(records[0], Commentf("%v", records[0])).Check(testkit.Rows("1"))

_, err = se.Execute(context.Background(), "set @@max_execution_time = 0;")
c.Assert(err, IsNil)

Expand Down
7 changes: 4 additions & 3 deletions util/expensivequery/expensivequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ func (eqh *Handle) Run() {
case <-ticker.C:
processInfo := sm.ShowProcessList()
for _, info := range processInfo {
if len(info.Info) == 0 || info.ExceedExpensiveTimeThresh {
if len(info.Info) == 0 {
continue
}
costTime := time.Since(info.Time)
if costTime >= time.Second*time.Duration(threshold) && log.GetLevel() <= zapcore.WarnLevel {
if !info.ExceedExpensiveTimeThresh && costTime >= time.Second*time.Duration(threshold) && log.GetLevel() <= zapcore.WarnLevel {
logExpensiveQuery(costTime, info)
info.ExceedExpensiveTimeThresh = true
}

} else if info.MaxExecutionTime > 0 && costTime > time.Duration(info.MaxExecutionTime)*time.Millisecond {
if info.MaxExecutionTime > 0 && costTime > time.Duration(info.MaxExecutionTime)*time.Millisecond {
sm.Kill(info.ID, true)
}
}
Expand Down