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

@@ -0,0 +1,83 @@
include/master-slave.inc
[connection master]
#
# MDEV-30164 System variable for default collations
#
connection master;
SET @@character_set_collations='utf8mb3=uca1400_ai_ci,'
'utf8mb4=uca1400_ai_ci,'
'ucs2=uca1400_ai_ci,'
'utf16=uca1400_ai_ci,'
'utf32=uca1400_ai_ci';
connection master;
CREATE TABLE t1 AS SELECT CHAR(0x61 USING utf8mb4);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`CHAR(0x61 USING utf8mb4)` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
connection slave;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`CHAR(0x61 USING utf8mb4)` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
connection master;
DROP TABLE t1;
connection slave;
connection master;
CREATE TABLE t1 AS SELECT CONVERT('a' USING utf8mb4);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`CONVERT('a' USING utf8mb4)` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
connection slave;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`CONVERT('a' USING utf8mb4)` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
connection master;
DROP TABLE t1;
connection slave;
connection master;
CREATE TABLE t1 (
c0 TEXT CHARACTER SET utf8mb3,
c1 TEXT CHARACTER SET utf8mb4,
c2 TEXT CHARACTER SET utf16,
c3 TEXT CHARACTER SET utf32,
c4 TEXT CHARACTER SET ucs2
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c0` text CHARACTER SET utf8mb3 COLLATE utf8mb3_uca1400_ai_ci DEFAULT NULL,
`c1` text CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci DEFAULT NULL,
`c2` text CHARACTER SET utf16 COLLATE utf16_uca1400_ai_ci DEFAULT NULL,
`c3` text CHARACTER SET utf32 COLLATE utf32_uca1400_ai_ci DEFAULT NULL,
`c4` text CHARACTER SET ucs2 COLLATE ucs2_uca1400_ai_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
connection slave;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c0` text CHARACTER SET utf8mb3 COLLATE utf8mb3_uca1400_ai_ci DEFAULT NULL,
`c1` text CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci DEFAULT NULL,
`c2` text CHARACTER SET utf16 COLLATE utf16_uca1400_ai_ci DEFAULT NULL,
`c3` text CHARACTER SET utf32 COLLATE utf32_uca1400_ai_ci DEFAULT NULL,
`c4` text CHARACTER SET ucs2 COLLATE ucs2_uca1400_ai_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
connection master;
DROP TABLE t1;
connection slave;
connection master;
CREATE DATABASE db1 CHARACTER SET utf8mb4;
connection slave;
SHOW CREATE DATABASE db1;
Database Create Database
db1 CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci */
connection master;
DROP DATABASE db1;
connection slave;
include/rpl_end.inc

View File

@@ -52,7 +52,7 @@ SET TIMESTAMP=1293832861.123456/*!*/;
SET @@session.time_zone='+03:00'/*!*/;
insert t1 (b,c) values (now(6), now(6))
/*!*/;
SET TIMESTAMP=1293832861.123456/*!*/;
SET TIMESTAMP=1293832861/*!*/;
COMMIT
/*!*/;
START TRANSACTION
@@ -68,7 +68,7 @@ START TRANSACTION
SET TIMESTAMP=1643756522.654321/*!*/;
insert t1 (b,c) values (now(), now())
/*!*/;
SET TIMESTAMP=1643756522.654321/*!*/;
SET TIMESTAMP=1643756522/*!*/;
COMMIT
/*!*/;
START TRANSACTION
@@ -76,7 +76,7 @@ START TRANSACTION
SET TIMESTAMP=1643756522.654321/*!*/;
insert t1 (b,c) values (0,0)
/*!*/;
SET TIMESTAMP=1643756522.654321/*!*/;
SET TIMESTAMP=1643756522/*!*/;
COMMIT
/*!*/;
START TRANSACTION
@@ -84,7 +84,7 @@ START TRANSACTION
SET TIMESTAMP=1643756522.654321/*!*/;
insert t1 (a,b,c) values (0,0,now(6))
/*!*/;
SET TIMESTAMP=1643756522.654321/*!*/;
SET TIMESTAMP=1643756522/*!*/;
COMMIT
/*!*/;
SET TIMESTAMP=1643756522/*!*/;

View File

@@ -0,0 +1,60 @@
--source include/have_binlog_format_row.inc
--source include/master-slave.inc
--echo #
--echo # MDEV-30164 System variable for default collations
--echo #
--connection master
SET @@character_set_collations='utf8mb3=uca1400_ai_ci,'
'utf8mb4=uca1400_ai_ci,'
'ucs2=uca1400_ai_ci,'
'utf16=uca1400_ai_ci,'
'utf32=uca1400_ai_ci';
--connection master
CREATE TABLE t1 AS SELECT CHAR(0x61 USING utf8mb4);
SHOW CREATE TABLE t1;
--sync_slave_with_master
SHOW CREATE TABLE t1;
--connection master
DROP TABLE t1;
--sync_slave_with_master
--connection master
CREATE TABLE t1 AS SELECT CONVERT('a' USING utf8mb4);
SHOW CREATE TABLE t1;
--sync_slave_with_master
SHOW CREATE TABLE t1;
--connection master
DROP TABLE t1;
--sync_slave_with_master
--connection master
CREATE TABLE t1 (
c0 TEXT CHARACTER SET utf8mb3,
c1 TEXT CHARACTER SET utf8mb4,
c2 TEXT CHARACTER SET utf16,
c3 TEXT CHARACTER SET utf32,
c4 TEXT CHARACTER SET ucs2
);
SHOW CREATE TABLE t1;
--sync_slave_with_master
SHOW CREATE TABLE t1;
--connection master
DROP TABLE t1;
--sync_slave_with_master
--connection master
CREATE DATABASE db1 CHARACTER SET utf8mb4;
--sync_slave_with_master
SHOW CREATE DATABASE db1;
--connection master
DROP DATABASE db1;
--sync_slave_with_master
--source include/rpl_end.inc