1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-30164 System variable for default 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.
This commit is contained in:
Alexander Barkov
2022-12-14 18:46:27 +04:00
parent 584c2351de
commit 75f25e4ca7
59 changed files with 2228 additions and 111 deletions

View File

@@ -6257,7 +6257,9 @@ int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond)
const char *comment;
restore_record(table, s->default_values);
table->field[0]->store(&tmp_cs->cs_name, scs);
table->field[1]->store(&tmp_cs->coll_name, scs);
CHARSET_INFO *def_cl= thd->variables.character_set_collations.
get_collation_for_charset(thd, tmp_cs);
table->field[1]->store(&def_cl->coll_name, scs);
comment= tmp_cs->comment ? tmp_cs->comment : "";
table->field[2]->store(comment, strlen(comment), scs);
table->field[3]->store((longlong) tmp_cs->mbmaxlen, TRUE);
@@ -6360,6 +6362,8 @@ int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond)
(tmp_cs->state & MY_CS_HIDDEN) ||
!(tmp_cs->state & MY_CS_PRIMARY))
continue;
CHARSET_INFO *def_cl= thd->variables.character_set_collations.
get_collation_for_charset(thd, tmp_cs);
for (cl= all_charsets;
cl < all_charsets + array_elements(all_charsets) ;
cl ++)
@@ -6400,7 +6404,7 @@ int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond)
table->field[2]->store((longlong) tmp_cl->number, TRUE);
table->field[3]->set_notnull(); // IS_DEFAULT
table->field[3]->store(
Show::Yes_or_empty::value(tmp_cl->default_flag()), scs);
Show::Yes_or_empty::value(def_cl == tmp_cl), scs);
}
table->field[4]->store(
Show::Yes_or_empty::value(tmp_cl->compiled_flag()), scs);
@@ -6428,6 +6432,8 @@ int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond)
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
!(tmp_cs->state & MY_CS_PRIMARY))
continue;
CHARSET_INFO *def_cl= thd->variables.character_set_collations.
get_collation_for_charset(thd, tmp_cs);
for (cl= all_charsets;
cl < all_charsets + array_elements(all_charsets) ;
cl ++)
@@ -6447,7 +6453,7 @@ int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond)
table->field[2]->store(full_collation_name, scs);
table->field[3]->store(tmp_cl->number);
table->field[4]->store(
Show::Yes_or_empty::value(tmp_cl->default_flag()), scs);
Show::Yes_or_empty::value(def_cl == tmp_cl), scs);
if (schema_table_store_record(thd, table))
return 1;
}