diff options
author | Alexander Barkov <bar@mariadb.com> | 2022-12-14 18:46:27 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2023-03-21 10:07:57 +0400 |
commit | 8d51c6d234b1730d4ff3b2c1fe7828eeca81998b (patch) | |
tree | 4a0d7ff0038e218b3f9de741c18fa7c8409fdf3c /sql/mysqld.cc | |
parent | ceb0e7f944b5c252d999ac06012ac0e05925c0b2 (diff) | |
download | mariadb-git-bb-10.11-bar-collations.tar.gz |
MDEV-30164 System variable for default collationsbb-10.11-bar-collations
This patch adds a way to override default collations
(or "character set collations") for desired character sets.
The SQL standard says:
> Each collation known in an SQL-environment is applicable to one
> or more character sets, and for each character set, one or more
> collations are applicable to it, one of which is associated with
> it as its character set collation.
In MariaDB, character set collations has been hard-coded so far,
e.g. utf8mb4_general_ci has been a hard-coded character set collation
for utf8mb4.
This patch allows to override (globally per server, or per session)
character set collations, so for example, uca1400_ai_ci can be set as a
character set collation for Unicode character sets
(instead of compiled xxx_general_ci).
The array of overridden character set collations is stored in a new
(session and global) system variable @@character_set_collations and
can be set as a comma separated list of charset=collation pairs, e.g.:
SET @@character_set_collations='utf8mb3=uca1400_ai_ci,utf8mb4=uca1400_ai_ci';
The variable is empty by default, which mean use the hard-coded
character set collations (e.g. utf8mb4_general_ci for utf8mb4).
The variable can also be set globally by passing to the server startup command
line, and/or in my.cnf.
Diffstat (limited to 'sql/mysqld.cc')
-rw-r--r-- | sql/mysqld.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 23f34dd0d84..f62f0dc1515 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -342,6 +342,7 @@ char *enforced_storage_engine=NULL; char *gtid_pos_auto_engines; plugin_ref *opt_gtid_pos_auto_plugins; static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME; +static const char *character_set_collations_str= ""; Thread_cache thread_cache; static bool binlog_format_used= false; LEX_STRING opt_init_connect, opt_init_slave; @@ -4271,6 +4272,18 @@ static int init_common_variables() */ myf utf8_flag= global_system_variables.old_behavior & OLD_MODE_UTF8_IS_UTF8MB3 ? MY_UTF8_IS_UTF8MB3 : 0; + + if (character_set_collations_str[0]) + { + Lex_cstring_strlen str(character_set_collations_str); + if (global_system_variables.character_set_collations. + from_text(str, utf8_flag)) + { + sql_print_error(ER_DEFAULT(ER_WRONG_VALUE_FOR_VAR), + "character_set_collations", character_set_collations_str); + } + } + for (;;) { char *next_character_set_name= strchr(default_character_set_name, ','); @@ -4289,7 +4302,13 @@ static int init_common_variables() return 1; // Eof of the list } else + { + Charset_collation_map_st::Used used; + default_charset_info= global_system_variables.character_set_collations. + get_collation_for_charset(&used, + default_charset_info); break; + } } if (default_collation_name) @@ -6469,6 +6488,9 @@ struct my_option my_long_options[]= {"collation-server", 0, "Set the default collation.", &default_collation_name, &default_collation_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + {"character-set-collations", 0, "Set default collations for character sets.", + &character_set_collations_str, &character_set_collations_str, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, {"console", OPT_CONSOLE, "Write error output on screen; don't remove the console window on windows.", &opt_console, &opt_console, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, |