[MDEV-9333] Inconsistency when copying from INT to ENUM Created: 2015-12-28  Updated: 2019-11-18

Status: Open
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 5.5, 10.0, 10.1, 10.2
Fix Version/s: 10.2

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None

Epic Link: Data type cleanups

 Description   

In this script:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT, b ENUM('2','3'));
INSERT INTO t1 VALUES(2,'2');
UPDATE t1 SET b=a;
SELECT b FROM t1;

copying is done using val_int() method of the field "a", which returns 2 and then further converts to ENUM value[2], which is '3'. So the script returns:

+------+
| b    |
+------+
| 3    |
+------+

The same behavior is demonstrated in this script:

DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (2);
CREATE TABLE t2 (b ENUM('2','3'));
INSERT INTO t2 SELECT * FROM t1;
SELECT *FROM t2;

+------+
| b    |
+------+
| 3    |
+------+

Now if I use ALTER:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES(2);
ALTER TABLE t1 CHANGE a b ENUM('2','3');
SELECT * FROM t1;

it goes through val_str() of the field "a" which returns string '2', so the result is:

+------+
| b    |
+------+
| 2    |
+------+

All three cases should return the same result.



 Comments   
Comment by Brian Evans [ 2016-05-20 ]

I see a regression in the treatment of enums and ints in general here.

create table mariadb_bug ( i int primary key, bug enum('0','1') NOT NULL DEFAULT '0' );
insert into mariadb_bug values (1, 0),(2, 0),(3, 1);
select * from mariadb_bug;

MySQL 5.1.50:
+---+-----+
| i | bug |
+---+-----+
| 1 | 0   |
| 2 | 0   |
| 3 | 1   |
+---+-----+
 
MariaDB 10.0.23:
+---+-----+
| i | bug |
+---+-----+
| 1 |     |
| 2 |     |
| 3 | 0   |
+---+-----+
 
MariaDB 10.1.14:
+---+-----+
| i | bug |
+---+-----+
| 1 |     |
| 2 |     |
| 3 | 0   |
+---+-----+

Comment by Brian Evans [ 2016-05-20 ]

Interestingly enough:

MySQL 5.5.48:

+---+-----+
| i | bug |
+---+-----+
| 1 |     |
| 2 |     |
| 3 | 0   |
+---+-----+

Generated at Thu Feb 08 07:33:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.