[MDEV-15960] Wrong data type on CREATE..SELECT char_or_enum_or_text_spvar Created: 2018-04-21 Updated: 2018-04-22 Resolved: 2018-04-22 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data types, Stored routines |
| Affects Version/s: | 10.1, 10.2, 10.3 |
| Fix Version/s: | 10.3.7 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
Notice, the column data type in the table does not match the variable data type. |
| Comments |
| Comment by Alexander Barkov [ 2018-04-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem happens in adjust_max_effective_column_length(). It's supposed to adjust the maximum length for the integer data types according to their capacity (instead of the user-specified length), e.g. convert int(3) to int(11). However, the code also erroneously adjusts the length for the blob data types, because their max_display_length() returns something bigger than max_length, which was previously set to char_length() by Type_std_attributes::set(). So later Type_handler::blob_type_handler() converts a wrong (too large) length to a wrong (longer) BLOB variant. Another option would be to fix Item_splocal::create_field_for_create_select() from:
to:
This will make sure preserve the data type of the variable. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2018-04-22 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
The same problem: I start mysql --column-type-info test an run this script:
Notice, the variable reports itself STRING (that is CHAR). Ok. Now I use a ENUM column in a UNION with a CHAR column:
Notice, the ENUM column worked as CHAR and the result column t2.a is also of the type CHAR. This is also OK. Now I use a ENUM variable in a UNION with a CHAR column
Notice, the ENUM variable worked as CHAR and the result column t2.a is also of the type CHAR. This is also OK. But if I now create a table from an ENUM variable alone, without a UNION, it works as VARCHAR:
This is wrong. It should create at least a column of the char(1) data type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2018-04-22 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
The same problem is repeatable with a CHAR variable:
The expected column data type should be char(1). |