From c0d84b7ef7fe639f8ac95a47e31b151784e7300a Mon Sep 17 00:00:00 2001 From: Max Hoffman Date: Wed, 18 Dec 2024 15:20:57 -0800 Subject: [PATCH 1/2] cache session charset --- sql/base_session.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sql/base_session.go b/sql/base_session.go index e08e642325..b6ef2b648f 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. @@ -263,15 +264,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`). From fb510d95a7421e53579f3c797b75df9f44eb6f06 Mon Sep 17 00:00:00 2001 From: Max Hoffman Date: Thu, 19 Dec 2024 09:36:14 -0800 Subject: [PATCH 2/2] add cache invalidation --- sql/base_session.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/base_session.go b/sql/base_session.go index b6ef2b648f..d5998dc6fe 100644 --- a/sql/base_session.go +++ b/sql/base_session.go @@ -178,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 }