WL#13068: Deprecate BINARY keyword for specifying _bin collations
Affects: Server-8.0
—
Status: Complete
In MySQL you can use the BINARY keyword to sepcifiy that you want the *_bin collation of a character set (https://dev.mysql.com/doc/refman/8.0/en/binary-varbinary.html). This is not a standard SQL feature, just syntactic sugar that adds to the confusion between the BINARY "character set" and *_bin collations. Example: mysql> create table foo (v varchar(10) binary); Query OK, 0 rows affected (0.06 sec) mysql> show create table foo; +-------+-----.... | Table | Create Table | +-------+-----.... | foo | CREATE TABLE `foo` ( `v` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +-------+-----.... 1 row in set (0.01 sec) You can also write v varchar(10) character set utf8 binary --> utf8_bin v varchar(10) character set latin1 binary --> latin1_bin etc. I suggest this use of the BINARY keyword is deprecated.
F1: any use of the BINARY keyword in a query when (and only when) the goal is to specify a _bin collation of a character set, should trigger a warning like this: 'BINARY as attribute of a type' is deprecated and will be removed in a future release. Please use a CHARACTER SET clause with _bin collation instead Examples: # CREATE TABLE for column create table t1 (v varchar(10) binary); create table t1 (v varchar(10) character set latin1 binary); create table t1 (v varchar(10) binary ascii); create table t1 (v varchar(10) unicode binary); alter table t1 modify v varchar(10) binary character set latin1; select cast('a' as char(2) binary); select convert('a', char(2) binary); All above statements should send a warning. But the ones below shouldn't, as they do select a "binary" *charset*, not just a "_bin" collation of another charset create table t1 (v binary(10)); create table t1 (v varchar(10)) character set binary; alter table t1 character set binary; create database mysqltest2 default character set = binary; set names binary; select convert("123" using binary); select char(123 using binary); create table t1 (v varchar(10) byte);
A few calls to push_warning() will be inserted in the right parser rules in sql_yacc.yy
Copyright (c) 2000, 2024, Oracle Corporation and/or its affiliates. All rights reserved.