Skip to content

Commit

Permalink
MDEV-28767 Collation "binary" is not accepted for databases, tables, …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
abarkov committed Nov 2, 2024
1 parent cca85eb commit e60fd6c
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
48 changes: 48 additions & 0 deletions mysql-test/main/ctype_binary.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
47 changes: 47 additions & 0 deletions mysql-test/main/ctype_binary.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
19 changes: 19 additions & 0 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e60fd6c

Please sign in to comment.