Skip to content

Commit

Permalink
skip log slow query for DDL statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin2037 committed Oct 27, 2022
1 parent 753e3da commit 8f72d79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,17 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
sql = ss.SecureText()
}
}

maxExecutionTime := getMaxExecutionTime(sctx)
// Update processinfo, ShowProcess() will use it.
pi.SetProcessInfo(sql, time.Now(), cmd, maxExecutionTime)
if a.Ctx.GetSessionVars().StmtCtx.StmtType == "" {
a.Ctx.GetSessionVars().StmtCtx.StmtType = ast.GetStmtLabel(a.StmtNode)
}
// Since maxExecutionTime is used only for query statement, here we limit it affect scope.
if !isQueryStmt(a.Ctx.GetSessionVars().StmtCtx.StmtType) {
maxExecutionTime = 0
}
pi.SetProcessInfo(sql, time.Now(), cmd, maxExecutionTime)
}

failpoint.Inject("mockDelayInnerSessionExecute", func() {
Expand Down Expand Up @@ -556,6 +561,14 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
}, nil
}

// check statement type with nodeType string from stmtNode.
func isQueryStmt(nodeType string) bool {
if nodeType == "Select" || nodeType == "Execute" {
return true
}
return false
}

func (a *ExecStmt) handleStmtForeignKeyTrigger(ctx context.Context, e Executor) error {
stmtCtx := a.Ctx.GetSessionVars().StmtCtx
if stmtCtx.ForeignKeyTriggerCtx.HasFKCascades {
Expand Down
5 changes: 5 additions & 0 deletions server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,11 @@ func TestConnExecutionTimeout(t *testing.T) {

err = cc.handleQuery(context.Background(), "select /*+ MAX_EXECUTION_TIME(100)*/ * FROM testTable2 WHERE SLEEP(1);")
require.NoError(t, err)

tk.MustExec("set @@max_execution_time = 500;")

err = cc.handleQuery(context.Background(), "alter table testTable2 add index idx(age);")
require.NoError(t, err)
}

func TestShutDown(t *testing.T) {
Expand Down

0 comments on commit 8f72d79

Please sign in to comment.