Skip to content

Commit

Permalink
cache session charset (#2798)
Browse files Browse the repository at this point in the history
* cache session charset

* add cache invalidation
  • Loading branch information
max-hoffman authored Dec 19, 2024
1 parent 701e962 commit e44b780
Showing 1 changed file with 15 additions and 8 deletions.
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

0 comments on commit e44b780

Please sign in to comment.