From e60fd6c204571ace0e6d48524efaca8758a7f3a2 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Sat, 2 Nov 2024 11:52:03 +0400 Subject: [PATCH] MDEV-28767 Collation "binary" is not accepted for databases, tables, columns MariaDB in a COLLATE clause supported 'binary' only as an identifier: COLLATE `binary` Fixing the parser to understand 'binary' as a keyword: COLLATE binary This is for MySQL compatibility. --- mysql-test/main/ctype_binary.result | 48 +++++++++++++++++++++++++++++ mysql-test/main/ctype_binary.test | 47 ++++++++++++++++++++++++++++ sql/sql_yacc.yy | 19 ++++++++++++ 3 files changed, 114 insertions(+) diff --git a/mysql-test/main/ctype_binary.result b/mysql-test/main/ctype_binary.result index d91faf4c3d6d0..75eb5ccd4f0d3 100644 --- a/mysql-test/main/ctype_binary.result +++ b/mysql-test/main/ctype_binary.result @@ -3454,3 +3454,51 @@ DROP TABLE t1; # # End of 10.5 tests # +# +# Start of 10.11 tests +# +# +# MDEV-28767 Collation "binary" is not accepted for databases, tables, columns +# +CREATE TABLE t1 (a CHAR(1) COLLATE binary); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` binary(1) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a enum('a') CHARACTER SET binary COLLATE binary DEFAULT NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` enum('a') CHARACTER SET binary DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a enum('a') COLLATE binary DEFAULT NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` enum('a') CHARACTER SET binary DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a CHAR(1) CHARACTER SET latin1 COLLATE binary); +ERROR 42000: COLLATION 'binary' is not valid for CHARACTER SET 'latin1' +CREATE TABLE t1 (a CHAR(10)) COLLATE binary; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` binary(10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=binary +DROP TABLE t1; +CREATE TABLE t1 (a CHAR(10)) CHARACTER SET latin1 COLLATE binary; +ERROR 42000: COLLATION 'binary' is not valid for CHARACTER SET 'latin1' +CREATE DATABASE db1 COLLATE binary; +SHOW CREATE DATABASE db1; +Database Create Database +db1 CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET binary */ +DROP DATABASE db1; +CREATE DATABASE db1 CHARACTER SET latin1 COLLATE binary; +ERROR 42000: COLLATION 'binary' is not valid for CHARACTER SET 'latin1' +# +# End of 10.11 tests +# diff --git a/mysql-test/main/ctype_binary.test b/mysql-test/main/ctype_binary.test index 756c96fcf60ef..9537f09e9b13b 100644 --- a/mysql-test/main/ctype_binary.test +++ b/mysql-test/main/ctype_binary.test @@ -294,3 +294,50 @@ DROP TABLE t1; --echo # --echo # End of 10.5 tests --echo # + +--echo # +--echo # Start of 10.11 tests +--echo # + +--echo # +--echo # MDEV-28767 Collation "binary" is not accepted for databases, tables, columns +--echo # + +# Column level + +CREATE TABLE t1 (a CHAR(1) COLLATE binary); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a enum('a') CHARACTER SET binary COLLATE binary DEFAULT NULL); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a enum('a') COLLATE binary DEFAULT NULL); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--error ER_COLLATION_CHARSET_MISMATCH +CREATE TABLE t1 (a CHAR(1) CHARACTER SET latin1 COLLATE binary); + + +# Table level +CREATE TABLE t1 (a CHAR(10)) COLLATE binary; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--error ER_COLLATION_CHARSET_MISMATCH +CREATE TABLE t1 (a CHAR(10)) CHARACTER SET latin1 COLLATE binary; + + +# Database level +CREATE DATABASE db1 COLLATE binary; +SHOW CREATE DATABASE db1; +DROP DATABASE db1; + +--error ER_COLLATION_CHARSET_MISMATCH +CREATE DATABASE db1 CHARACTER SET latin1 COLLATE binary; + +--echo # +--echo # End of 10.11 tests +--echo # diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 93ff0ca1ca63b..6284d445f77b8 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -6594,6 +6594,11 @@ collation_name: collation_name_or_default: collation_name { $$=$1; } | DEFAULT { $$.set_collate_default(); } + | BINARY // MySQL compatibility + { + const Lex_exact_collation bin(&my_charset_bin); + $$= Lex_extended_collation(bin); + } ; opt_default: @@ -6654,6 +6659,20 @@ binary: { $$.set_collate_default(); } + | charset_or_alias COLLATE_SYM BINARY // MySQL compatibility + { + const Lex_exact_collation bin(&my_charset_bin); + Lex_extended_collation tmp(bin); + if (tmp.merge_exact_charset(Lex_exact_charset($1))) + MYSQL_YYABORT; + $$= Lex_exact_charset_extended_collation_attrs(tmp); + } + | COLLATE_SYM BINARY // MySQL compatibility + { + const Lex_exact_collation bin(&my_charset_bin); + const Lex_extended_collation tmp(bin); + $$= Lex_exact_charset_extended_collation_attrs(tmp); + } ; opt_bin_mod: