From e44b780a5716d8bde402ef46761e9d1aa0d9e083 Mon Sep 17 00:00:00 2001 From: Maximilian Hoffman Date: Thu, 19 Dec 2024 09:49:26 -0800 Subject: [PATCH] cache session charset (#2798) * cache session charset * add cache invalidation --- sql/base_session.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sql/base_session.go b/sql/base_session.go index e08e642325..d5998dc6fe 100644 --- a/sql/base_session.go +++ b/sql/base_session.go @@ -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. @@ -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 } @@ -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`).