Improve charset selection

The charset sent in the handshake is now done with the following
priorities:

* First Master server
* Last Slave server
* First Running server or Down server whose charset is known

The change is that server in the Down state to which we've successfully
connected to can also be used as the charset source. This, in addition
with an "empty" default charset, helps avoid the use of the default latin1
charset unless absolutely necessary.
This commit is contained in:
Markus Mäkelä
2020-03-11 23:46:35 +02:00
parent caf3b4cf75
commit 291d2e987f
3 changed files with 17 additions and 8 deletions

View File

@ -406,7 +406,8 @@ const char* dbg_decode_response(GWBUF* pPacket)
void mxs_update_server_charset(MYSQL* mysql, SERVER* server)
{
const char* CHARSET_QUERY =
"SELECT co.id FROM information_schema.collations AS co "
"SELECT co.id, @@global.character_set_server "
"FROM information_schema.collations AS co "
"JOIN information_schema.character_sets AS cs "
"ON (co.collation_name = cs.default_collate_name) "
"WHERE cs.character_set_name=@@global.character_set_server;";
@ -419,7 +420,13 @@ void mxs_update_server_charset(MYSQL* mysql, SERVER* server)
{
if (row[0])
{
server->charset = atoi(row[0]);
auto charset = atoi(row[0]);
if (server->charset != charset)
{
MXS_NOTICE("Server '%s' charset: %s", server->name(), row[1]);
server->charset = charset;
}
}
}