Skip to content

Commit 8696741

Browse files
committed
cherry-pick pingcap#50915
1 parent 2e6006c commit 8696741

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

executor/adapter.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func (a *ExecStmt) PointGet(ctx context.Context) (*recordSet, error) {
341341
if raw, ok := sctx.(processinfoSetter); ok {
342342
pi = raw
343343
sql := a.OriginText()
344-
maxExecutionTime := getMaxExecutionTime(sctx)
344+
maxExecutionTime := sctx.GetSessionVars().GetMaxExecutionTime()
345345
// Update processinfo, ShowProcess() will use it.
346346
pi.SetProcessInfo(sql, time.Now(), cmd, maxExecutionTime)
347347
if sctx.GetSessionVars().StmtCtx.StmtType == "" {
@@ -545,7 +545,7 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
545545
sql = ss.SecureText()
546546
}
547547
}
548-
maxExecutionTime := getMaxExecutionTime(sctx)
548+
maxExecutionTime := sctx.GetSessionVars().GetMaxExecutionTime()
549549
// Update processinfo, ShowProcess() will use it.
550550
if a.Ctx.GetSessionVars().StmtCtx.StmtType == "" {
551551
a.Ctx.GetSessionVars().StmtCtx.StmtType = ast.GetStmtLabel(a.StmtNode)
@@ -804,14 +804,6 @@ func isNoResultPlan(p plannercore.Plan) bool {
804804
return false
805805
}
806806

807-
// getMaxExecutionTime get the max execution timeout value.
808-
func getMaxExecutionTime(sctx sessionctx.Context) uint64 {
809-
if sctx.GetSessionVars().StmtCtx.HasMaxExecutionTime {
810-
return sctx.GetSessionVars().StmtCtx.MaxExecutionTime
811-
}
812-
return sctx.GetSessionVars().MaxExecutionTime
813-
}
814-
815807
type chunkRowRecordSet struct {
816808
rows []chunk.Row
817809
idx int

expression/builtin_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ func (b *builtinTiDBDecodeSQLDigestsSig) evalString(row chunk.Row) (string, bool
922922

923923
// Querying may take some time and it takes a context.Context as argument, which is not available here.
924924
// We simply create a context with a timeout here.
925-
timeout := time.Duration(b.ctx.GetSessionVars().MaxExecutionTime) * time.Millisecond
925+
timeout := time.Duration(b.ctx.GetSessionVars().GetMaxExecutionTime()) * time.Millisecond
926926
if timeout == 0 || timeout > 20*time.Second {
927927
timeout = 20 * time.Second
928928
}

planner/core/plan_stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func RequestLoadStats(ctx sessionctx.Context, neededHistItems []model.TableItemI
8484
if hintMaxExecutionTime <= 0 {
8585
hintMaxExecutionTime = maxDuration
8686
}
87-
sessMaxExecutionTime := int64(ctx.GetSessionVars().MaxExecutionTime)
87+
sessMaxExecutionTime := int64(ctx.GetSessionVars().GetMaxExecutionTime())
8888
if sessMaxExecutionTime <= 0 {
8989
sessMaxExecutionTime = maxDuration
9090
}

session/sessiontest/session_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3195,7 +3195,7 @@ func TestGlobalVarAccessor(t *testing.T) {
31953195
tk1.MustExec("set @@global.max_execution_time = 100")
31963196
tk2 := testkit.NewTestKit(t, store)
31973197
tk2.MustExec("use test")
3198-
require.Equal(t, uint64(100), tk2.Session().GetSessionVars().MaxExecutionTime)
3198+
require.Equal(t, uint64(100), tk2.Session().GetSessionVars().GetMaxExecutionTime())
31993199
tk1.MustExec("set @@global.max_execution_time = 0")
32003200

32013201
result := tk.MustQuery("show global variables where variable_name='sql_select_limit';")

sessionctx/variable/session.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,13 @@ func (s *SessionVars) AllocNewPlanID() int {
17161716
return int(s.PlanID.Add(1))
17171717
}
17181718

1719+
func (s *SessionVars) GetMaxExecutionTime() uint64 {
1720+
if s.StmtCtx.HasMaxExecutionTime {
1721+
return s.StmtCtx.MaxExecutionTime
1722+
}
1723+
return s.MaxExecutionTime
1724+
}
1725+
17191726
const (
17201727
// PlacementModeStrict indicates all placement operations should be checked strictly in ddl
17211728
PlacementModeStrict string = "STRICT"

0 commit comments

Comments
 (0)