Skip to content

Commit

Permalink
variable: unifiy MaxExecuteTime usage and fix some problem (#50915) (#…
Browse files Browse the repository at this point in the history
…52618)

close #50872, close #50914
  • Loading branch information
ti-chi-bot authored Nov 11, 2024
1 parent 051f12c commit c6f28f0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
12 changes: 2 additions & 10 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (a *ExecStmt) PointGet(ctx context.Context) (*recordSet, error) {
if raw, ok := sctx.(processinfoSetter); ok {
pi = raw
sql := a.OriginText()
maxExecutionTime := getMaxExecutionTime(sctx)
maxExecutionTime := sctx.GetSessionVars().GetMaxExecutionTime()
// Update processinfo, ShowProcess() will use it.
pi.SetProcessInfo(sql, time.Now(), cmd, maxExecutionTime)
if sctx.GetSessionVars().StmtCtx.StmtType == "" {
Expand Down Expand Up @@ -545,7 +545,7 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) {
sql = ss.SecureText()
}
}
maxExecutionTime := getMaxExecutionTime(sctx)
maxExecutionTime := sctx.GetSessionVars().GetMaxExecutionTime()
// Update processinfo, ShowProcess() will use it.
if a.Ctx.GetSessionVars().StmtCtx.StmtType == "" {
a.Ctx.GetSessionVars().StmtCtx.StmtType = ast.GetStmtLabel(a.StmtNode)
Expand Down Expand Up @@ -804,14 +804,6 @@ func isNoResultPlan(p plannercore.Plan) bool {
return false
}

// getMaxExecutionTime get the max execution timeout value.
func getMaxExecutionTime(sctx sessionctx.Context) uint64 {
if sctx.GetSessionVars().StmtCtx.HasMaxExecutionTime {
return sctx.GetSessionVars().StmtCtx.MaxExecutionTime
}
return sctx.GetSessionVars().MaxExecutionTime
}

type chunkRowRecordSet struct {
rows []chunk.Row
idx int
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ func (b *builtinTiDBDecodeSQLDigestsSig) evalString(row chunk.Row) (string, bool

// Querying may take some time and it takes a context.Context as argument, which is not available here.
// We simply create a context with a timeout here.
timeout := time.Duration(b.ctx.GetSessionVars().MaxExecutionTime) * time.Millisecond
timeout := time.Duration(b.ctx.GetSessionVars().GetMaxExecutionTime()) * time.Millisecond
if timeout == 0 || timeout > 20*time.Second {
timeout = 20 * time.Second
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/plan_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func RequestLoadStats(ctx sessionctx.Context, neededHistItems []model.TableItemI
if hintMaxExecutionTime <= 0 {
hintMaxExecutionTime = maxDuration
}
sessMaxExecutionTime := int64(ctx.GetSessionVars().MaxExecutionTime)
sessMaxExecutionTime := int64(ctx.GetSessionVars().GetMaxExecutionTime())
if sessMaxExecutionTime <= 0 {
sessMaxExecutionTime = maxDuration
}
Expand Down
2 changes: 1 addition & 1 deletion session/sessiontest/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3195,7 +3195,7 @@ func TestGlobalVarAccessor(t *testing.T) {
tk1.MustExec("set @@global.max_execution_time = 100")
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")
require.Equal(t, uint64(100), tk2.Session().GetSessionVars().MaxExecutionTime)
require.Equal(t, uint64(100), tk2.Session().GetSessionVars().GetMaxExecutionTime())
tk1.MustExec("set @@global.max_execution_time = 0")

result := tk.MustQuery("show global variables where variable_name='sql_select_limit';")
Expand Down
8 changes: 8 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,14 @@ func (s *SessionVars) AllocNewPlanID() int {
return int(s.PlanID.Add(1))
}

// GetMaxExecutionTime returns the max execution time of the current session. If it's hinted, return the hinted value.
func (s *SessionVars) GetMaxExecutionTime() uint64 {
if s.StmtCtx.HasMaxExecutionTime {
return s.StmtCtx.MaxExecutionTime
}
return s.MaxExecutionTime
}

const (
// PlacementModeStrict indicates all placement operations should be checked strictly in ddl
PlacementModeStrict string = "STRICT"
Expand Down

0 comments on commit c6f28f0

Please sign in to comment.