Skip to content

Commit

Permalink
add a tidb_pessimistic_lock session variable to control transaction b…
Browse files Browse the repository at this point in the history
…ehavior (pingcap#7)
  • Loading branch information
tiancaiamao authored Apr 17, 2019
1 parent bd5294e commit e0e0993
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (e *SimpleExec) executeBegin(ctx context.Context, s *ast.BeginStmt) error {
if err != nil {
return err
}
if s.Pessimistic || config.GetGlobalConfig().TxnPessimistic {
if s.Pessimistic || config.GetGlobalConfig().TxnPessimistic || e.ctx.GetSessionVars().PessimisticLock {
txn.SetOption(kv.Pessimistic, true)
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ type SessionVars struct {

// SlowQueryFile indicates which slow query log file for SLOW_QUERY table to parse.
SlowQueryFile string

PessimisticLock bool
}

// ConnectionInfo present connection used by audit.
Expand Down Expand Up @@ -725,6 +727,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error {
config.GetGlobalConfig().CheckMb4ValueInUTF8 = TiDBOptOn(val)
case TiDBSlowQueryFile:
s.SlowQueryFile = val
case TiDBPessimisticLock:
s.PessimisticLock = TiDBOptOn(val)
}
s.systems[name] = val
return nil
Expand Down
1 change: 1 addition & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ var defaultSysVars = []*SysVar{
{ScopeGlobal | ScopeSession, TiDBRetryLimit, strconv.Itoa(DefTiDBRetryLimit)},
{ScopeGlobal | ScopeSession, TiDBDisableTxnAutoRetry, BoolToIntStr(DefTiDBDisableTxnAutoRetry)},
{ScopeGlobal | ScopeSession, TiDBConstraintCheckInPlace, BoolToIntStr(DefTiDBConstraintCheckInPlace)},
{ScopeSession, TiDBPessimisticLock, strconv.Itoa(DefTiDBPessimisticLock)},
{ScopeSession, TiDBOptimizerSelectivityLevel, strconv.Itoa(DefTiDBOptimizerSelectivityLevel)},
{ScopeGlobal | ScopeSession, TiDBEnableWindowFunction, BoolToIntStr(DefEnableWindowFunction)},
/* The following variable is defined as session scope but is actually server scope. */
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ const (
// tidb_optimizer_selectivity_level is used to control the selectivity estimation level.
TiDBOptimizerSelectivityLevel = "tidb_optimizer_selectivity_level"

// tidb_pessimistic_lock is used to control the transactin behavior.
TiDBPessimisticLock = "tidb_pessimistic_lock"

// tidb_enable_table_partition is used to control table partition feature.
// The valid value include auto/on/off:
// auto: enable table partition when that feature is implemented.
Expand Down Expand Up @@ -282,6 +285,7 @@ const (
DefTiDBHashJoinConcurrency = 5
DefTiDBProjectionConcurrency = 4
DefTiDBOptimizerSelectivityLevel = 0
DefTiDBPessimisticLock = 0
DefTiDBDDLReorgWorkerCount = 16
DefTiDBDDLReorgBatchSize = 1024
DefTiDBDDLErrorCountLimit = 512
Expand Down

0 comments on commit e0e0993

Please sign in to comment.