summaryrefslogtreecommitdiff
path: root/sql/sql_parse.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2022-12-14 18:46:27 +0400
committerAlexander Barkov <bar@mariadb.com>2023-03-21 10:07:57 +0400
commit8d51c6d234b1730d4ff3b2c1fe7828eeca81998b (patch)
tree4a0d7ff0038e218b3f9de741c18fa7c8409fdf3c /sql/sql_parse.cc
parentceb0e7f944b5c252d999ac06012ac0e05925c0b2 (diff)
downloadmariadb-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_parse.cc')
-rw-r--r--sql/sql_parse.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index b5d93e6fd99..0e35beed8f7 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -6049,6 +6049,27 @@ finish:
}
thd->reset_kill_query();
}
+
+ /*
+ If a non-default collation (in @@character_set_collations)
+ was used during the statement, the mysqlbinlog output for
+ the current statement will contain a sequence like this:
+
+ SET character_set_collations='utf8mb3=utf8mb3_bin';
+ INSERT INTO t1 VALUES (_utf8mb3'test');
+ COMMIT;
+
+ The statment (INSERT in this example) is already in binlog at this point, and the
+ and the "SET character_set_collations" is written inside a
+ Q_CHARACTER_SET_COLLATIONS chunk in its log entry header.
+ The flag CHARACTER_SET_COLLATIONS_USED is not needed any more.
+
+ Let's suppress the flag to avoid a Q_CHARACTER_SET_COLLATIONS chunk
+ inside the COMMIT log entry header - it would be useless and would
+ only waste space in the binary log.
+ */
+ thd->used&= ~THD::CHARACTER_SET_COLLATIONS_USED;
+
if (unlikely(thd->is_error()) ||
(thd->variables.option_bits & OPTION_MASTER_SQL_ERROR))
{