diff --git a/executor/adapter.go b/executor/adapter.go index 5f01aa51e0378..5e12cce1ccc69 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -1538,7 +1538,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) { if a.retryCount > 0 { slowItems.ExecRetryTime = costTime - sessVars.DurationParse - sessVars.DurationCompile - time.Since(a.retryStartTime) } - if _, ok := a.StmtNode.(*ast.CommitStmt); ok { + if _, ok := a.StmtNode.(*ast.CommitStmt); ok && sessVars.PrevStmt != nil { slowItems.PrevStmt = sessVars.PrevStmt.String() } slowLog := sessVars.SlowLogFormat(slowItems) diff --git a/ttl/ttlworker/session.go b/ttl/ttlworker/session.go index 1514c1746f348..6326fff5f11d7 100644 --- a/ttl/ttlworker/session.go +++ b/ttl/ttlworker/session.go @@ -60,7 +60,8 @@ func getSession(pool sessionPool) (session.Session, error) { pool.Put(resource) }) - if _, err = se.ExecuteSQL(context.Background(), "commit"); err != nil { + // Force rollback the session to guarantee the session is not in any explicit transaction + if _, err = se.ExecuteSQL(context.Background(), "ROLLBACK"); err != nil { se.Close() return nil, err }