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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.0.1, 5.5.29, 5.1.67, 5.2.14, 5.3.12, 10.3.4, 10.5.9
    • None
    • None

    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;

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              pivanof Pavel Ivanov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.