Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable: remove StrictSQLMode in variable.SessionVars #50624

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7890,7 +7890,7 @@ func validateCommentLength(vars *variable.SessionVars, name string, comment *str
}
if len(*comment) > maxLen {
err := errTooLongComment.GenWithStackByArgs(name, maxLen)
if vars.StrictSQLMode {
if vars.SQLMode.HasStrictMode() {
// may be treated like an error.
return "", err
}
Expand Down
22 changes: 18 additions & 4 deletions pkg/ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (
"github.com/pingcap/tidb/pkg/util/dbterror"
"github.com/pingcap/tidb/pkg/util/logutil"
decoder "github.com/pingcap/tidb/pkg/util/rowDecoder"
"github.com/pingcap/tidb/pkg/util/stringutil"
"github.com/prometheus/client_golang/prometheus"
"github.com/tikv/client-go/v2/oracle"
"github.com/tikv/client-go/v2/tikv"
Expand All @@ -77,8 +78,17 @@ const (

var (
telemetryAddIndexIngestUsage = metrics.TelemetryAddIndexIngestCnt
// SuppressErrorTooLongKeyKey is used by SchemaTracker to suppress err too long key error
SuppressErrorTooLongKeyKey stringutil.StringerStr = "suppressErrorTooLongKeyKey"
)

func suppressErrorTooLongKeyKey(sctx sessionctx.Context) bool {
if suppress, ok := sctx.Value(SuppressErrorTooLongKeyKey).(bool); ok && suppress {
return true
}
return false
}

func buildIndexColumns(ctx sessionctx.Context, columns []*model.ColumnInfo, indexPartSpecifications []*ast.IndexPartSpecification) ([]*model.IndexColumn, bool, error) {
// Build offsets.
idxParts := make([]*model.IndexColumn, 0, len(indexPartSpecifications))
Expand Down Expand Up @@ -113,7 +123,8 @@ func buildIndexColumns(ctx sessionctx.Context, columns []*model.ColumnInfo, inde
if sumLength > maxIndexLength {
// The multiple column index and the unique index in which the length sum exceeds the maximum size
// will return an error instead produce a warning.
if ctx == nil || ctx.GetSessionVars().StrictSQLMode || mysql.HasUniKeyFlag(col.GetFlag()) || len(indexPartSpecifications) > 1 {
suppress := suppressErrorTooLongKeyKey(ctx)
if ctx == nil || (ctx.GetSessionVars().SQLMode.HasStrictMode() && !suppress) || mysql.HasUniKeyFlag(col.GetFlag()) || len(indexPartSpecifications) > 1 {
return nil, false, dbterror.ErrTooLongKey.GenWithStackByArgs(sumLength, maxIndexLength)
}
// truncate index length and produce warning message in non-restrict sql mode.
Expand Down Expand Up @@ -222,9 +233,12 @@ func checkIndexColumn(ctx sessionctx.Context, col *model.ColumnInfo, indexColumn
}
// Specified length must be shorter than the max length for prefix.
maxIndexLength := config.GetGlobalConfig().MaxIndexLength
if indexColumnLen > maxIndexLength && (ctx == nil || ctx.GetSessionVars().StrictSQLMode) {
// return error in strict sql mode
return dbterror.ErrTooLongKey.GenWithStackByArgs(indexColumnLen, maxIndexLength)
if indexColumnLen > maxIndexLength {
suppress := suppressErrorTooLongKeyKey(ctx)
if ctx == nil || (ctx.GetSessionVars().SQLMode.HasStrictMode() && !suppress) {
// return error in strict sql mode
return dbterror.ErrTooLongKey.GenWithStackByArgs(indexColumnLen, maxIndexLength)
}
}
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/ddl/schematracker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,13 @@ func (d *Checker) CreateTable(ctx sessionctx.Context, stmt *ast.CreateTableStmt)
// some unit test will also check warnings, we reset the warnings after SchemaTracker use session context again.
count := ctx.GetSessionVars().StmtCtx.WarningCount()
// backup old session variables because CreateTable will change them.
strictSQLMode := ctx.GetSessionVars().StrictSQLMode
enableClusteredIndex := ctx.GetSessionVars().EnableClusteredIndex

err = d.tracker.CreateTable(ctx, stmt)
if err != nil {
panic(err)
}

ctx.GetSessionVars().StrictSQLMode = strictSQLMode
ctx.GetSessionVars().EnableClusteredIndex = enableClusteredIndex
ctx.GetSessionVars().StmtCtx.TruncateWarnings(int(count))

Expand Down
5 changes: 2 additions & 3 deletions pkg/ddl/schematracker/dm_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,12 @@ func (d SchemaTracker) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStm
return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ident.Schema)
}
// suppress ErrTooLongKey
strictSQLModeBackup := ctx.GetSessionVars().StrictSQLMode
ctx.GetSessionVars().StrictSQLMode = false
ctx.SetValue(ddl.SuppressErrorTooLongKeyKey, true)
// support drop PK
enableClusteredIndexBackup := ctx.GetSessionVars().EnableClusteredIndex
ctx.GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOff
defer func() {
ctx.GetSessionVars().StrictSQLMode = strictSQLModeBackup
ctx.ClearValue(ddl.SuppressErrorTooLongKeyKey)
ctx.GetSessionVars().EnableClusteredIndex = enableClusteredIndexBackup
}()

Expand Down
33 changes: 18 additions & 15 deletions pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) {
// pushing them down to TiKV as flags.

sc.InRestrictedSQL = vars.InRestrictedSQL
strictSQLMode := vars.SQLMode.HasStrictMode()

errLevels := sc.ErrLevels()
errLevels[errctx.ErrGroupDividedByZero] = errctx.LevelWarn
Expand All @@ -2126,26 +2127,26 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) {
errLevels[errctx.ErrGroupAutoIncReadFailed] = errctx.LevelWarn
errLevels[errctx.ErrGroupNoMatchedPartition] = errctx.LevelWarn
}
errLevels[errctx.ErrGroupBadNull] = errctx.ResolveErrLevel(false, !vars.StrictSQLMode || stmt.IgnoreErr)
errLevels[errctx.ErrGroupBadNull] = errctx.ResolveErrLevel(false, !strictSQLMode || stmt.IgnoreErr)
errLevels[errctx.ErrGroupDividedByZero] = errctx.ResolveErrLevel(
!vars.SQLMode.HasErrorForDivisionByZeroMode(),
!vars.StrictSQLMode || stmt.IgnoreErr,
!strictSQLMode || stmt.IgnoreErr,
)
sc.Priority = stmt.Priority
sc.SetTypeFlags(sc.TypeFlags().
WithTruncateAsWarning(!vars.StrictSQLMode || stmt.IgnoreErr).
WithTruncateAsWarning(!strictSQLMode || stmt.IgnoreErr).
WithIgnoreInvalidDateErr(vars.SQLMode.HasAllowInvalidDatesMode()).
WithIgnoreZeroInDate(!vars.SQLMode.HasNoZeroInDateMode() ||
!vars.SQLMode.HasNoZeroDateMode() || !vars.StrictSQLMode || stmt.IgnoreErr ||
!vars.SQLMode.HasNoZeroDateMode() || !strictSQLMode || stmt.IgnoreErr ||
vars.SQLMode.HasAllowInvalidDatesMode()))
case *ast.CreateTableStmt, *ast.AlterTableStmt:
sc.InCreateOrAlterStmt = true
sc.SetTypeFlags(sc.TypeFlags().
WithTruncateAsWarning(!vars.StrictSQLMode).
WithTruncateAsWarning(!strictSQLMode).
WithIgnoreInvalidDateErr(vars.SQLMode.HasAllowInvalidDatesMode()).
WithIgnoreZeroInDate(!vars.SQLMode.HasNoZeroInDateMode() || !vars.StrictSQLMode ||
WithIgnoreZeroInDate(!vars.SQLMode.HasNoZeroInDateMode() || !strictSQLMode ||
vars.SQLMode.HasAllowInvalidDatesMode()).
WithIgnoreZeroDateErr(!vars.SQLMode.HasNoZeroDateMode() || !vars.StrictSQLMode))
WithIgnoreZeroDateErr(!vars.SQLMode.HasNoZeroDateMode() || !strictSQLMode))

case *ast.LoadDataStmt:
sc.InLoadDataStmt = true
Expand Down Expand Up @@ -2257,41 +2258,43 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) {

// ResetUpdateStmtCtx resets statement context for UpdateStmt.
func ResetUpdateStmtCtx(sc *stmtctx.StatementContext, stmt *ast.UpdateStmt, vars *variable.SessionVars) {
strictSQLMode := vars.SQLMode.HasStrictMode()
sc.InUpdateStmt = true
errLevels := sc.ErrLevels()
errLevels[errctx.ErrGroupDupKey] = errctx.ResolveErrLevel(false, stmt.IgnoreErr)
errLevels[errctx.ErrGroupBadNull] = errctx.ResolveErrLevel(false, !vars.StrictSQLMode || stmt.IgnoreErr)
errLevels[errctx.ErrGroupBadNull] = errctx.ResolveErrLevel(false, !strictSQLMode || stmt.IgnoreErr)
errLevels[errctx.ErrGroupDividedByZero] = errctx.ResolveErrLevel(
!vars.SQLMode.HasErrorForDivisionByZeroMode(),
!vars.StrictSQLMode || stmt.IgnoreErr,
!strictSQLMode || stmt.IgnoreErr,
)
errLevels[errctx.ErrGroupNoMatchedPartition] = errctx.ResolveErrLevel(false, stmt.IgnoreErr)
sc.SetErrLevels(errLevels)
sc.Priority = stmt.Priority
sc.SetTypeFlags(sc.TypeFlags().
WithTruncateAsWarning(!vars.StrictSQLMode || stmt.IgnoreErr).
WithTruncateAsWarning(!strictSQLMode || stmt.IgnoreErr).
WithIgnoreInvalidDateErr(vars.SQLMode.HasAllowInvalidDatesMode()).
WithIgnoreZeroInDate(!vars.SQLMode.HasNoZeroInDateMode() || !vars.SQLMode.HasNoZeroDateMode() ||
!vars.StrictSQLMode || stmt.IgnoreErr || vars.SQLMode.HasAllowInvalidDatesMode()))
!strictSQLMode || stmt.IgnoreErr || vars.SQLMode.HasAllowInvalidDatesMode()))
}

// ResetDeleteStmtCtx resets statement context for DeleteStmt.
func ResetDeleteStmtCtx(sc *stmtctx.StatementContext, stmt *ast.DeleteStmt, vars *variable.SessionVars) {
strictSQLMode := vars.SQLMode.HasStrictMode()
sc.InDeleteStmt = true
errLevels := sc.ErrLevels()
errLevels[errctx.ErrGroupDupKey] = errctx.ResolveErrLevel(false, stmt.IgnoreErr)
errLevels[errctx.ErrGroupBadNull] = errctx.ResolveErrLevel(false, !vars.StrictSQLMode || stmt.IgnoreErr)
errLevels[errctx.ErrGroupBadNull] = errctx.ResolveErrLevel(false, !strictSQLMode || stmt.IgnoreErr)
errLevels[errctx.ErrGroupDividedByZero] = errctx.ResolveErrLevel(
!vars.SQLMode.HasErrorForDivisionByZeroMode(),
!vars.StrictSQLMode || stmt.IgnoreErr,
!strictSQLMode || stmt.IgnoreErr,
)
sc.SetErrLevels(errLevels)
sc.Priority = stmt.Priority
sc.SetTypeFlags(sc.TypeFlags().
WithTruncateAsWarning(!vars.StrictSQLMode || stmt.IgnoreErr).
WithTruncateAsWarning(!strictSQLMode || stmt.IgnoreErr).
WithIgnoreInvalidDateErr(vars.SQLMode.HasAllowInvalidDatesMode()).
WithIgnoreZeroInDate(!vars.SQLMode.HasNoZeroInDateMode() || !vars.SQLMode.HasNoZeroDateMode() ||
!vars.StrictSQLMode || stmt.IgnoreErr || vars.SQLMode.HasAllowInvalidDatesMode()))
!strictSQLMode || stmt.IgnoreErr || vars.SQLMode.HasAllowInvalidDatesMode()))
}

func setOptionForTopSQL(sc *stmtctx.StatementContext, snapshot kv.Snapshot) {
Expand Down
1 change: 0 additions & 1 deletion pkg/executor/executor_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ func TestErrLevelsForResetStmtContext(t *testing.T) {
for _, stmt := range c.stmt {
msg := fmt.Sprintf("%d: %s, stmt: %T", i, c.name, stmt)
ctx.GetSessionVars().SQLMode = c.sqlMode
ctx.GetSessionVars().StrictSQLMode = ctx.GetSessionVars().SQLMode.HasStrictMode()
require.NoError(t, ResetContextOfStmt(ctx, stmt), msg)
ec := ctx.GetSessionVars().StmtCtx.ErrCtx()
require.Equal(t, c.levels, ec.LevelMap(), msg)
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ func (e *InsertValues) fillColValue(
if !hasValue && mysql.HasNoDefaultValueFlag(column.ToInfo().GetFlag()) {
vars := e.Ctx().GetSessionVars()
sc := vars.StmtCtx
if vars.StrictSQLMode {
if vars.SQLMode.HasStrictMode() {
return datum, table.ErrNoDefaultValue.FastGenByArgs(column.ToInfo().Name)
}
sc.AppendWarning(table.ErrNoDefaultValue.FastGenByArgs(column.ToInfo().Name))
Expand Down
6 changes: 1 addition & 5 deletions pkg/executor/mem_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,11 +1158,7 @@ func getColIDAndPkColIDs(ctx sessionctx.Context, tbl table.Table, columns []*mod
pkColIDs = []int64{-1}
}
defVal := func(i int) ([]byte, error) {
sessVars := ctx.GetSessionVars()
originStrict := sessVars.StrictSQLMode
sessVars.StrictSQLMode = false
d, err := table.GetColOriginDefaultValue(ctx, columns[i])
sessVars.StrictSQLMode = originStrict
d, err := table.GetColOriginDefaultValueWithoutStrictSQLMode(ctx, columns[i])
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func TestSetVar(t *testing.T) {
require.False(t, vars.IsAutocommit())

tk.MustExec("set @@sql_mode = 'strict_trans_tables'")
require.True(t, vars.StrictSQLMode)
require.True(t, vars.SQLMode.HasStrictMode())
tk.MustExec("set @@sql_mode = ''")
require.False(t, vars.StrictSQLMode)
require.False(t, vars.SQLMode.HasStrictMode())

tk.MustExec("set names utf8")
charset, collation := vars.GetCharsetInfo()
Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ func (b *builtinCharSig) evalString(ctx EvalContext, row chunk.Row) (string, boo
if err != nil {
tc := typeCtx(ctx)
tc.AppendWarning(err)
if strictMode(ctx) {
if sqlMode(ctx).HasStrictMode() {
return "", true, nil
}
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/expression/builtin_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1424,9 +1424,11 @@ func TestChar(t *testing.T) {
run(i, v.result, v.warnings, v.str, v.iNum, v.fNum, v.charset)
}
// char() returns null only when the sql_mode is strict.
ctx.GetSessionVars().StrictSQLMode = true
require.True(t, ctx.GetSessionVars().SQLMode.HasStrictMode())
run(-1, nil, 1, 123456, "utf8")
ctx.GetSessionVars().StrictSQLMode = false

ctx.GetSessionVars().SQLMode = ctx.GetSessionVars().SQLMode &^ (mysql.ModeStrictTransTables | mysql.ModeStrictAllTables)
require.False(t, ctx.GetSessionVars().SQLMode.HasStrictMode())
run(-2, string([]byte{1}), 1, 123456, "utf8")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,7 @@ func (b *builtinCharSig) vecEvalString(ctx EvalContext, input *chunk.Chunk, resu
}
encBuf := &bytes.Buffer{}
enc := charset.FindEncoding(b.tp.GetCharset())
hasStrictMode := strictMode(ctx)
hasStrictMode := sqlMode(ctx).HasStrictMode()
for i := 0; i < n; i++ {
bigints = bigints[0:0]
for j := 0; j < l-1; j++ {
Expand Down
1 change: 1 addition & 0 deletions pkg/expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func TestDate(t *testing.T) {
}

// test nil
ctx.GetSessionVars().SQLMode = mysql.DelSQLMode(ctx.GetSessionVars().SQLMode, mysql.ModeNoZeroDate)
tblNil := []struct {
Input interface{}
Year interface{}
Expand Down
6 changes: 2 additions & 4 deletions pkg/expression/builtin_time_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/mock"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -579,8 +578,7 @@ func BenchmarkVectorizedBuiltinTimeFunc(b *testing.B) {
}

func TestVecMonth(t *testing.T) {
ctx := mock.NewContext()
ctx.GetSessionVars().SQLMode |= mysql.ModeNoZeroDate
ctx := createContext(t)
typeFlags := ctx.GetSessionVars().StmtCtx.TypeFlags()
ctx.GetSessionVars().StmtCtx.SetTypeFlags(typeFlags.WithTruncateAsWarning(true))
input := chunk.New([]*types.FieldType{types.NewFieldType(mysql.TypeDatetime)}, 3, 3)
Expand All @@ -590,7 +588,7 @@ func TestVecMonth(t *testing.T) {
input.AppendTime(0, types.ZeroDate)

f, _, _, result := genVecBuiltinFuncBenchCase(ctx, ast.Month, vecExprBenchCase{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDatetime}})
require.True(t, ctx.GetSessionVars().StrictSQLMode)
require.True(t, ctx.GetSessionVars().SQLMode.HasStrictMode())
require.NoError(t, f.vecEvalInt(ctx, input, result))
require.Equal(t, 0, len(ctx.GetSessionVars().StmtCtx.GetWarnings()))

Expand Down
4 changes: 0 additions & 4 deletions pkg/expression/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ func sqlMode(ctx EvalContext) mysql.SQLMode {
return ctx.GetSessionVars().SQLMode
}

func strictMode(ctx EvalContext) bool {
return ctx.GetSessionVars().StrictSQLMode
}

func typeCtx(ctx EvalContext) types.Context {
return ctx.GetSessionVars().StmtCtx.TypeCtx()
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,11 +1413,6 @@ func TestTimeBuiltin(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
originSQLMode := tk.Session().GetSessionVars().StrictSQLMode
tk.Session().GetSessionVars().StrictSQLMode = true
defer func() {
tk.Session().GetSessionVars().StrictSQLMode = originSQLMode
}()
tk.MustExec("use test")

// for makeDate
Expand Down
5 changes: 5 additions & 0 deletions pkg/expression/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/testkit/testmain"
"github.com/pingcap/tidb/pkg/testkit/testsetup"
"github.com/pingcap/tidb/pkg/util/mock"
Expand Down Expand Up @@ -58,6 +59,10 @@ func TestMain(m *testing.M) {

func createContext(t *testing.T) *mock.Context {
ctx := mock.NewContext()
sqlMode, err := mysql.GetSQLMode(mysql.DefaultSQLMode)
require.NoError(t, err)
require.True(t, sqlMode.HasStrictMode())
ctx.GetSessionVars().SQLMode = sqlMode
ctx.GetSessionVars().StmtCtx.SetTimeZone(time.Local)
sc := ctx.GetSessionVars().StmtCtx
sc.SetTypeFlags(sc.TypeFlags().WithTruncateAsWarning(true))
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func Optimize(ctx context.Context, sctx sessionctx.Context, node ast.Node, is in
}
}

if sctx.GetSessionVars().StrictSQLMode && !IsReadOnly(node, sessVars) {
if sctx.GetSessionVars().SQLMode.HasStrictMode() && !IsReadOnly(node, sessVars) {
sessVars.StmtCtx.TiFlashEngineRemovedDueToStrictSQLMode = true
_, hasTiFlashAccess := sessVars.IsolationReadEngines[kv.TiFlash]
if hasTiFlashAccess {
Expand Down
2 changes: 1 addition & 1 deletion pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ func (s *session) String() string {
"user": sessVars.User,
"currDBName": sessVars.CurrentDB,
"status": sessVars.Status,
"strictMode": sessVars.StrictSQLMode,
"strictMode": sessVars.SQLMode.HasStrictMode(),
}
if s.txn.Valid() {
// if txn is committed or rolled back, txn is nil.
Expand Down
4 changes: 0 additions & 4 deletions pkg/sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,6 @@ type SessionVars struct {
// the slow log to make it be compatible with MySQL, https://github.com/pingcap/tidb/issues/17846.
CurrentDBChanged bool

// StrictSQLMode indicates if the session is in strict mode.
StrictSQLMode bool

// CommonGlobalLoaded indicates if common global variable has been loaded for this session.
CommonGlobalLoaded bool

Expand Down Expand Up @@ -1944,7 +1941,6 @@ func NewSessionVars(hctx HookContext) *SessionVars {
TxnCtx: &TransactionContext{},
RetryInfo: &RetryInfo{},
ActiveRoles: make([]*auth.RoleIdentity, 0, 10),
StrictSQLMode: true,
AutoIncrementIncrement: DefAutoIncrementIncrement,
AutoIncrementOffset: DefAutoIncrementOffset,
Status: mysql.ServerStatusAutocommit,
Expand Down
1 change: 0 additions & 1 deletion pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,6 @@ var defaultSysVars = []*SysVar{
if err != nil {
return errors.Trace(err)
}
s.StrictSQLMode = sqlMode.HasStrictMode()
s.SQLMode = sqlMode
s.SetStatusFlag(mysql.ServerStatusNoBackslashEscaped, sqlMode.HasNoBackslashEscapesMode())
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestSQLModeVar(t *testing.T) {
require.Equal(t, "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION", val)

require.Nil(t, sv.SetSessionFromHook(vars, val)) // sets to strict from above
require.True(t, vars.StrictSQLMode)
require.True(t, vars.SQLMode.HasStrictMode())

sqlMode, err := mysql.GetSQLMode(val)
require.NoError(t, err)
Expand All @@ -79,7 +79,7 @@ func TestSQLModeVar(t *testing.T) {
require.Equal(t, "ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION", val)

require.Nil(t, sv.SetSessionFromHook(vars, val)) // sets to non-strict from above
require.False(t, vars.StrictSQLMode)
require.False(t, vars.SQLMode.HasStrictMode())
sqlMode, err = mysql.GetSQLMode(val)
require.NoError(t, err)
require.Equal(t, sqlMode, vars.SQLMode)
Expand Down
Loading