diff --git a/executor/adapter.go b/executor/adapter.go index 3f0d261b0530f..9466ba4f80144 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -509,10 +509,14 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) { } 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 !a.IsReadOnly(a.Ctx.GetSessionVars()) { + maxExecutionTime = 0 + } + pi.SetProcessInfo(sql, time.Now(), cmd, maxExecutionTime) } failpoint.Inject("mockDelayInnerSessionExecute", func() { diff --git a/server/conn_test.go b/server/conn_test.go index 1cd98a9c4c76e..0f9acc6f183d6 100644 --- a/server/conn_test.go +++ b/server/conn_test.go @@ -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) {