dolt icon indicating copy to clipboard operation
dolt copied to clipboard

enum values should be case insensitive

Open zachmu opened this issue 3 years ago • 2 comments

They're case sensitive now. Compare mysql:

mysql> create table enums (a int primary key, b enum ('one', 'two', 'three'));
Query OK, 0 rows affected (0.06 sec)

mysql> insert into enums values (1, 'one');
Query OK, 1 row affected (0.01 sec)

mysql> insert into enums values (2, 'TWO');
Query OK, 1 row affected (0.01 sec)

mysql> select * from enums;
+---+------+
| a | b    |
+---+------+
| 1 | one  |
| 2 | two  |
+---+------+
2 rows in set (0.00 sec)

In Dolt this causes an error:

enums> create table enums (a int primary key, b enum ('one', 'two', 'three'));
enums> insert into enums values (1, 'one');
Query OK, 1 row affected
enums> insert into enums values (2, 'TWO');
value TWO is not valid for this Enum

zachmu avatar Aug 08 '22 16:08 zachmu

Is this actually a bug? This seems like a collation issue, Dolt defaults to a case-sensitive collation and I think MySQL defaults to a case-insensitive one.

Hydrocharged avatar Aug 08 '22 22:08 Hydrocharged

I think there are a couple issues here...

There definitely is a collation connection here, like Daylon mentions. MySQL 8's default collation (utf8mb4_0900_ai_ci ) is case-insensitive, which matches Dolt's current behavior, but since Dolt defaults to the utf8mb4_0900_bin, Dolt really should be treating enum values in a case-sensitive matter.

There's also an issue with Dolt not preserving the originally specified case for enum values in show create table and information_schema.columns.columntype. Regardless of the collation setting, MySQL preserves the original case in those places, so we should do the same.

I'll keep digging in, but wanted to share what I've tested and found out so far.

fulghum avatar Aug 10 '22 20:08 fulghum

https://github.com/dolthub/go-mysql-server/pull/1179 addresses the second issue in my previous comment – preserving the case when displaying table metadata.

There are still some behavioral differences between GMS and MySQL around handling case for enum values based on the collation in use though, so leaving this issue open to track those.

fulghum avatar Aug 11 '22 22:08 fulghum

@fulghum Would you mind detailing any of the remaining issues with ENUM values? At least regarding all of the issues mentioned here, it seems that they have all been fixed.

Hydrocharged avatar Aug 17 '22 16:08 Hydrocharged

Thanks for pinging this one to close it out @Hydrocharged. I had a todo in my tests with a couple more cases to test after collation changes. I just added them in https://github.com/dolthub/go-mysql-server/pull/1196 and they are all working beautifully now that your collation work has landed, so I'll go ahead and close this issue out, too. 👏

fulghum avatar Aug 17 '22 16:08 fulghum