Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-4215

Incorrect enum values returned when using union after "create as select"

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 10.0.1, 5.5.29, 5.1.67, 5.2.14, 5.3.12
    • Fix Version/s: 10.0, 5.5
    • Component/s: None
    • Labels:

      Description

      Consider the following terminal session demonstrating the bug:

      MariaDB [(none)]> create database d1;
      Query OK, 1 row affected (0.00 sec)
      
      MariaDB [(none)]> use d1;
      Database changed
      MariaDB [d1]> create table t1 (e enum('one', 'two'));
      Query OK, 0 rows affected (0.75 sec)
      
      MariaDB [d1]> insert into t1 values ('one');
      Query OK, 1 row affected (0.40 sec)
      
      MariaDB [d1]> create table t2 (e enum('one', 'two')) as select * from t1;
      Query OK, 1 row affected (0.78 sec)
      Records: 1  Duplicates: 0  Warnings: 0
      
      MariaDB [d1]> select * from t2;
      +------+
      | e    |
      +------+
      | one  |
      +------+
      1 row in set (0.01 sec)
      
      MariaDB [d1]> select * from t2 union all select * from t2;
      +------+
      | e    |
      +------+
      | o    |
      | o    |
      +------+
      2 rows in set (0.00 sec)
      
      MariaDB [d1]> alter table t2 engine MyISAM;
      Query OK, 1 row affected (0.91 sec)                
      Records: 1  Duplicates: 0  Warnings: 0
      
      MariaDB [d1]> select * from t2 union all select * from t2;
      +------+
      | e    |
      +------+
      | one  |
      | one  |
      +------+
      2 rows in set (0.00 sec)
      
      MariaDB [d1]> 
      

      This bug exists in MySQL 5.1 too. It seems that the following one-liner fixes the problem but I'm not sure if it can break something else.

      --- a/sql/sql_table.cc
      +++ b/sql/sql_table.cc
      @@ -3144,7 +3144,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
                sql_field->charset=           (dup_field->charset ?
                                               dup_field->charset :
                                               create_info->default_table_charset);
      -         sql_field->length=            dup_field->char_length;
      +         sql_field->length=            dup_field->length;
                 sql_field->pack_length=      dup_field->pack_length;
                 sql_field->key_length=       dup_field->key_length;
                sql_field->decimals=          dup_field->decimals;
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              pivanof Pavel Ivanov added a comment -

              It looks like http://bugs.mysql.com/bug.php?id=14139 is relevant and the actual fix should look differently.

              Show
              pivanof Pavel Ivanov added a comment - It looks like http://bugs.mysql.com/bug.php?id=14139 is relevant and the actual fix should look differently.
              Hide
              elenst Elena Stepanova added a comment -

              (The priority has been decreased because it's an upstream bug, reproducible on all of MySQL 5.1-5.6).

              Hi Pavel,

              Since you mentioned that it was reproducible on MySQL – have you already filed it for MySQL, or are you planning to?
              If you have, could you please provide the bug number?
              If you haven't and aren't planning to, we can do it on your behalf.

              Show
              elenst Elena Stepanova added a comment - (The priority has been decreased because it's an upstream bug, reproducible on all of MySQL 5.1-5.6). Hi Pavel, Since you mentioned that it was reproducible on MySQL – have you already filed it for MySQL, or are you planning to? If you have, could you please provide the bug number? If you haven't and aren't planning to, we can do it on your behalf.
              Hide
              pivanof Pavel Ivanov added a comment -

              I haven't filed and am not planning to. Feel free to file yourself.

              Show
              pivanof Pavel Ivanov added a comment - I haven't filed and am not planning to. Feel free to file yourself.
              Hide
              elenst Elena Stepanova added a comment -
              Show
              elenst Elena Stepanova added a comment - Filed as http://bugs.mysql.com/bug.php?id=68577

                People

                • Assignee:
                  Unassigned
                  Reporter:
                  pivanof Pavel Ivanov
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated: