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/sql_class.h | |
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/sql_class.h')
-rw-r--r-- | sql/sql_class.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h index 54a213d8553..57eb31a3542 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -887,6 +887,8 @@ typedef struct system_variables vers_asof_timestamp_t vers_asof_timestamp; ulong vers_alter_history; my_bool binlog_alter_two_phase; + + Charset_collation_map_st character_set_collations; } SV; /** @@ -2925,7 +2927,9 @@ public: typedef uint used_t; enum { RAND_USED=1, TIME_ZONE_USED=2, QUERY_START_SEC_PART_USED=4, - THREAD_SPECIFIC_USED=8 }; + THREAD_SPECIFIC_USED=8, + CHARACTER_SET_COLLATIONS_USED= 16 + }; used_t used; @@ -5620,6 +5624,29 @@ public: }; +class Character_set_collations_used: public Charset_collation_map_st::Used +{ + THD *m_thd; +public: + Character_set_collations_used(THD *thd) + :m_thd(thd) + { } + ~Character_set_collations_used() + { + /* + Mark THD that the collation map was used, + no matter if a compiled or a mapped collation was + found during charset->collation resolution. + Even if the map was empty, we still need to print + SET @@session.character_set_collations=''; + in mariadb-binlog output. + */ + if (m_used) + m_thd->used|= THD::CHARACTER_SET_COLLATIONS_USED; + } +}; + + /* Start a new independent transaction for the THD. The old one is stored in this object and restored when calling |