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

cache session charset #2798

Merged
merged 2 commits into from
Dec 19, 2024
Merged
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
23 changes: 15 additions & 8 deletions sql/base_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type BaseSession struct {
lastQueryInfo map[string]*atomic.Value
tx Transaction
ignoreAutocommit bool
charset CharacterSetID

// When the MySQL database updates any tables related to privileges, it increments its counter. We then update our
// privilege set if our counter doesn't equal the database's counter.
Expand Down Expand Up @@ -177,6 +178,9 @@ func (s *BaseSession) setSessVar(ctx *Context, sysVar SystemVariable, value inte
}
sysVarName := strings.ToLower(sysVar.GetName())
s.systemVars[sysVarName] = svv
if sysVarName == characterSetResultsSysVarName {
s.charset = CharacterSet_Unspecified
}
return nil
}

Expand Down Expand Up @@ -263,15 +267,18 @@ func (s *BaseSession) GetCharacterSet() CharacterSetID {

// GetCharacterSetResults returns the result character set for this session (defined by the system variable `character_set_results`).
func (s *BaseSession) GetCharacterSetResults() CharacterSetID {
sysVar, _ := s.systemVars[characterSetResultsSysVarName]
if sysVar.Val == nil {
return CharacterSet_Unspecified
}
charSet, err := ParseCharacterSet(sysVar.Val.(string))
if err != nil {
panic(err) // shouldn't happen
if s.charset == CharacterSet_Unspecified {
sysVar, _ := s.systemVars[characterSetResultsSysVarName]
if sysVar.Val == nil {
return CharacterSet_Unspecified
}
var err error
s.charset, err = ParseCharacterSet(sysVar.Val.(string))
if err != nil {
panic(err) // shouldn't happen
}
}
return charSet
return s.charset
}

// GetCollation returns the collation for this session (defined by the system variable `collation_connection`).
Expand Down
Loading