mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +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:
@@ -0,0 +1,77 @@
|
||||
-- source include/have_utf8.inc
|
||||
-- source include/have_utf8mb4.inc
|
||||
-- source include/have_ucs2.inc
|
||||
-- source include/have_binlog_format_statement.inc
|
||||
-- source include/have_log_bin.inc
|
||||
|
||||
--disable_query_log
|
||||
CALL mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
|
||||
--enable_query_log
|
||||
|
||||
RESET MASTER;
|
||||
SET timestamp=1000000000;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-30164 System variable for default collations
|
||||
--echo #
|
||||
|
||||
SET character_set_collations='utf8mb3=utf8mb3_bin,ucs2=ucs2_bin';
|
||||
|
||||
CREATE TABLE t1 (a VARCHAR(20));
|
||||
DROP TABLE t1;
|
||||
|
||||
CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET utf8mb4);
|
||||
DROP TABLE t1;
|
||||
|
||||
CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin);
|
||||
DROP TABLE t1;
|
||||
|
||||
CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET utf8mb3);
|
||||
|
||||
INSERT INTO t1 VALUES ('a00');
|
||||
INSERT INTO t1 VALUES (_utf8mb3'a01-utf8mb3');
|
||||
INSERT INTO t1 VALUES (_utf8mb4'a01-utf8mb4');
|
||||
|
||||
PREPARE stmt FROM 'INSERT INTO t1 VALUES (?)';
|
||||
EXECUTE stmt USING _utf8mb3'a02-utf8mb3';
|
||||
EXECUTE stmt USING _utf8mb4'a02-utf8mb4';
|
||||
|
||||
EXECUTE stmt USING CONVERT('a03-utf8mb3' USING utf8mb3);
|
||||
EXECUTE stmt USING CONVERT('a03-utf8mb4' USING utf8mb4);
|
||||
|
||||
EXECUTE stmt USING IF(0,CONVERT('a04-utf8mb3' USING utf8mb3),CONVERT('a03-utf8mb4' USING utf8mb4));
|
||||
EXECUTE stmt USING IF(1,CONVERT('a04-utf8mb3' USING utf8mb3),CONVERT('a03-utf8mb4' USING utf8mb4));
|
||||
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
PREPARE stmt FROM 'CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET utf8mb4)';
|
||||
EXECUTE stmt;
|
||||
DROP TABLE t1;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
PREPARE stmt FROM 'CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET utf8mb3)';
|
||||
EXECUTE stmt;
|
||||
DROP TABLE t1;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
|
||||
EXECUTE IMMEDIATE 'CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET utf8mb4)';
|
||||
DROP TABLE t1;
|
||||
|
||||
EXECUTE IMMEDIATE 'CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET utf8mb3)';
|
||||
DROP TABLE t1;
|
||||
|
||||
|
||||
### Starting master-bin.000002
|
||||
FLUSH LOGS;
|
||||
|
||||
--disable_query_log
|
||||
SELECT "--- ---- ---" as "";
|
||||
--enable_query_log
|
||||
|
||||
let $MYSQLD_DATADIR= `select @@datadir`;
|
||||
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
|
||||
--replace_regex /SQL_LOAD_MB-[0-9a-f]+-[0-9a-f]+/SQL_LOAD_MB-#-#/ /@@session.sql_mode=\d+/@@session.sql_mode=#/ /collation_server=\d+/collation_server=#/
|
||||
--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLD_DATADIR/master-bin.000001
|
Reference in New Issue
Block a user