[MDEV-20902] Table with two UCS2 ENUM or SET fields is created wrongly Created: 2019-10-27  Updated: 2020-06-23

Status: Open
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: upstream-fixed

Issue Links:
Relates
relates to MDEV-22111 ERROR 1064 & 1033 and SIGSEGV on CREA... Closed

 Description   

CREATE TABLE t1 (
    f1 ENUM ('a','b') CHARACTER SET ucs2,
    f2 ENUM ('a','b') CHARACTER SET ucs2
);
SHOW CREATE TABLE t1;

The table is created seemingly without a problem, but the definition is wrong (note question marks):

10.3 803d0521

MariaDB [test]> CREATE TABLE t1 (
    ->     f1 ENUM ('a','b') CHARACTER SET ucs2,
    ->     f2 ENUM ('a','b') CHARACTER SET ucs2
    -> );
Query OK, 0 rows affected (0.311 sec)
 
MariaDB [test]> SHOW CREATE TABLE t1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                          |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `f1` enum('?','?') CHARACTER SET ucs2 DEFAULT NULL,
  `f2` enum('?','?') CHARACTER SET ucs2 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.002 sec)

And indeed, an attempt to insert a value causes a problem:

MariaDB [test]> INSERT INTO t1 VALUES ('a','a');
ERROR 1265 (01000): Data truncated for column 'f1' at row 1

Same with SETs.
When there is only one such field, it works all right (note that f2 is now utf8):

MariaDB [test]> CREATE TABLE t1 (
    ->     f1 ENUM ('a','b') CHARACTER SET ucs2,
    ->     f2 ENUM ('a','b') CHARACTER SET utf8
    -> );
Query OK, 0 rows affected (0.215 sec)
 
MariaDB [test]> SHOW CREATE TABLE t1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                          |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `f1` enum('a','b') CHARACTER SET ucs2 DEFAULT NULL,
  `f2` enum('a','b') CHARACTER SET utf8 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.002 sec)

Reproducible on all MariaDB 5.5-10.5 and MySQL 5.6/5.7. Not reproducible on MySQL 8.0.



 Comments   
Comment by Elena Stepanova [ 2020-02-04 ]

Remarkably, a table with three such columns is fine again:

CREATE TABLE t1 (
f1 ENUM ('a','b') CHARACTER SET ucs2,
f2 ENUM ('a','b') CHARACTER SET ucs2,
f3 ENUM ('a','b') CHARACTER SET ucs2
);
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `f1` enum('','') CHARACTER SET ucs2 DEFAULT NULL,
  `f2` enum('','') CHARACTER SET ucs2 DEFAULT NULL,
  `f3` enum('','') CHARACTER SET ucs2 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Generated at Thu Feb 08 09:03:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.