From 5dce51b2b5ac4ef50656e4d0baafc6c83c89f497 Mon Sep 17 00:00:00 2001 From: yuxianjiang Date: Thu, 23 Dec 2021 11:35:45 +0800 Subject: [PATCH] [feature] Return more infomation when set names Problem ======= After execute 'set names' statement with collation, session track do not return the newly specified collation. From code below we know that character_set_connection and collation_connection use the same CHARSET_INFO variables. --- static Sys_var_struct Sys_character_set_connection( "character_set_connection", "The character set used for " "literals that do not have a character set introducer and for " "number-to-string conversion", SESSION_VAR(collation_connection), NO_CMD_LINE, offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info), NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_not_null), ON_UPDATE(fix_thd_charset)); static Sys_var_struct Sys_collation_connection( "collation_connection", "The collation of the connection " "character set", SESSION_VAR(collation_connection), NO_CMD_LINE, offsetof(CHARSET_INFO, name), DEFAULT(&default_charset_info), NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_collation_not_null), ON_UPDATE(fix_thd_charset)); --- But as we show variables like collation_connection and character_set_connection, they have different value returned. So when execute set names with collation, although we know charset changed, but the detailed collation info is missing. Solution ======== Add collation_connection session track when set names. --- sql/set_var.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/set_var.cc b/sql/set_var.cc index 35fb210..5c7fcf7 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1174,6 +1174,9 @@ int set_var_collation_client::update(THD *thd) LEX_CSTRING cs_connection= {"character_set_connection", sizeof("character_set_connection") - 1}; thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)->mark_as_changed(thd, &cs_connection); + LEX_CSTRING cs_collation= {"collation_connection", + sizeof("collation_connection") - 1}; + thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)->mark_as_changed(thd, &cs_collation); } if (thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER)->is_enabled()) thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER)->mark_as_changed(thd, NULL); -- 1.8.3.1