Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong ENUM value is updated to and seems it's mixed up with ENUM index #56832

Closed
lance6716 opened this issue Oct 25, 2024 · 2 comments · Fixed by #57550
Closed

Wrong ENUM value is updated to and seems it's mixed up with ENUM index #56832

lance6716 opened this issue Oct 25, 2024 · 2 comments · Fixed by #57550
Assignees
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@lance6716
Copy link
Contributor

lance6716 commented Oct 25, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> create table t (id int primary key, c enum('0', '1', '2'));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (0,'0'), (1,'1'), (2,'2');
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> update t set c = 2 where id = 0;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from t;
+----+------+
| id | c    |
+----+------+
|  0 | 1    |
|  1 | 1    |
|  2 | 2    |
+----+------+
3 rows in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.27    |
+-----------+
1 row in set (0.00 sec)

2. What did you expect to see? (Required)

as above

3. What did you see instead (Required)

mysql> create table t (id int primary key, c enum('0', '1', '2'));
Query OK, 0 rows affected (0.04 sec)

mysql> insert into t values (0,'0'), (1,'1'), (2,'2');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> update t set c = 2 where id = 0;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from t;
+----+------+
| id | c    |
+----+------+
|  0 | 2    |
|  1 | 1    |
|  2 | 2    |
+----+------+
3 rows in set (0.01 sec)

mysql> select version();
+-----------------------------------------+
| version()                               |
+-----------------------------------------+
| 8.0.11-TiDB-v8.4.0-alpha-25-gb02581a7a4 |
+-----------------------------------------+
1 row in set (0.01 sec)

in the last SELECT, the first row is different from MySQL

4. What is your TiDB version? (Required)

Release Version: v8.4.0-alpha-25-gb02581a7a4
Edition: Community
Git Commit Hash: b02581a7a47e98b49901c025767d175ee63fbf23
Git Branch: HEAD
UTC Build Time: 2024-08-23 03:07:52
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
@lance6716
Copy link
Contributor Author

lance6716 commented Oct 25, 2024

maybe caused by

tidb/pkg/types/enum.go

Lines 51 to 58 in 5faeca4

func ParseEnum(elems []string, name string, collation string) (Enum, error) {
if enumName, err := ParseEnumName(elems, name, collation); err == nil {
return enumName, nil
}
// name doesn't exist, maybe an integer?
if num, err := strconv.ParseUint(name, 0, 64); err == nil {
return ParseEnumValue(elems, num)
}
we check enum value first. I think we should check enum index first, or decide the priority based on datum type.

@pt-cc
Copy link

pt-cc commented Oct 29, 2024

When will there be a new version? I am migrating from Mariadb to tidb and I am stuck on enum and cannot synchronize data.

@ti-chi-bot ti-chi-bot added the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 1, 2024
@jebter jebter added affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. labels Nov 8, 2024
@xhebox xhebox self-assigned this Nov 8, 2024
@xhebox xhebox removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 labels Nov 20, 2024
@ti-chi-bot ti-chi-bot bot closed this as completed in 1c059a1 Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants