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

cherry-pick sys variables #15330

Merged
merged 4 commits into from
Apr 4, 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
10 changes: 10 additions & 0 deletions pkg/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ var (
defaultLoggerLabelKey = "role"
defaultLoggerLabelVal = "logging_cn"

// default sql_mode
dafaultSqlMode = "ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"

// default lower_case_table_names
defaultLowerCaseTableNames = "1"
)
Expand Down Expand Up @@ -287,6 +290,9 @@ type FrontendParameters struct {

// disable select into
DisableSelectInto bool `toml:"disable-select-into"`

// default sql_mode default value
SqlMode string `toml:"sql-mode"`
}

func (fp *FrontendParameters) SetDefaultValues() {
Expand Down Expand Up @@ -402,6 +408,10 @@ func (fp *FrontendParameters) SetDefaultValues() {
if fp.CleanKillQueueInterval == 0 {
fp.CleanKillQueueInterval = defaultCleanKillQueueInterval
}

if fp.SqlMode == "" {
fp.SqlMode = dafaultSqlMode
}
}

func (fp *FrontendParameters) SetMaxMessageSize(size uint64) {
Expand Down
44 changes: 44 additions & 0 deletions pkg/frontend/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,19 @@ func (ses *Session) InitGlobalSystemVariables() error {
pu := ses.GetParameterUnit()
mp := ses.GetMemPool()

updateSqls := ses.getUpdateVariableSqlsByToml()
for _, sql := range updateSqls {
_, err = executeSQLInBackgroundSession(
sysTenantCtx,
ses,
mp,
pu,
sql)
if err != nil {
return err
}
}

rsset, err = executeSQLInBackgroundSession(
sysTenantCtx,
ses,
Expand Down Expand Up @@ -1899,6 +1912,19 @@ func (ses *Session) InitGlobalSystemVariables() error {
pu := ses.GetParameterUnit()
mp := ses.GetMemPool()

updateSqls := ses.getUpdateVariableSqlsByToml()
for _, sql := range updateSqls {
_, err = executeSQLInBackgroundSession(
tenantCtx,
ses,
mp,
pu,
sql)
if err != nil {
return err
}
}

rsset, err = executeSQLInBackgroundSession(
tenantCtx,
ses,
Expand Down Expand Up @@ -1940,6 +1966,24 @@ func (ses *Session) InitGlobalSystemVariables() error {
return err
}

func (ses *Session) getUpdateVariableSqlsByToml() []string {
updateSqls := make([]string, 0)
tenantInfo := ses.GetTenantInfo()
// sql_mode
if getVariableValue(ses.pu.SV.SqlMode) != gSysVarsDefs["sql_mode"].Default {
sqlForUpdate := getSqlForUpdateSystemVariableValue(ses.pu.SV.SqlMode, uint64(tenantInfo.GetTenantID()), "sql_mode")
updateSqls = append(updateSqls, sqlForUpdate)
}

// lower_case_table_names
if getVariableValue(ses.pu.SV.LowerCaseTableNames) != gSysVarsDefs["lower_case_table_names"].Default {
sqlForUpdate := getSqlForUpdateSystemVariableValue(getVariableValue(ses.pu.SV.LowerCaseTableNames), uint64(tenantInfo.GetTenantID()), "lower_case_table_names")
updateSqls = append(updateSqls, sqlForUpdate)
}

return updateSqls
}

func (ses *Session) GetPrivilege() *privilege {
ses.mu.Lock()
defer ses.mu.Unlock()
Expand Down
Loading