Bug #33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for MyISAM
Submitted: 7 Jan 2008 3:52 Modified: 10 Sep 14:06
Reporter: Patrick Crews
Status: Patch approved
Category:Server: DML Severity:S3 (Non-critical)
Version:5.0+ OS:Any
Assigned to: Sergey Gluhov Target Version:5.1+
Tags: disabled
Triage: Triaged: D3 (Medium) / R3 (Medium) / E3 (Medium)

[7 Jan 2008 3:52] Patrick Crews
Description:
INSERT INTO <table> (default) fails for enum data types in CSV tables.  Will result in a
crashed table.

INSERT INTO ... () works properly -- populates the field with the first value of the enum
declaration.

Also tested against MyISAM, and will not crash the table, but will not populate the field
with default

How to repeat:
Use the following SQL:

CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV;
INSERT INTO t1 VALUES();
SELECT * from t1;
INSERT INTO t1 VALUES(default);
SELECT * from t1;

# This will not crash the table, but INSERT(default) will result in blank data
CREATE TABLE t2(e2 enum('foo','bar') NOT NULL);
INSERT INTO t2 VALUES();
SELECT * from t2;
INSET INTO t2 values(default);
SELECT * from t2;

Suggested fix:
Ensure that INSERT INTO <table> VALUES(default) works the same as INSERT INTO <table>
VALUES() as specified in the documentation.
[7 Jan 2008 10:28] Miguel Solorzano
Thank you for the bug report.

mysql> CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV;
Query OK, 0 rows affected (0.14 sec)

mysql> INSERT INTO t1 VALUES();
Query OK, 1 row affected (0.05 sec)

mysql> SELECT * from t1;
+-----+
| e   |
+-----+
| foo |
+-----+
1 row in set (0.00 sec)

mysql> INSERT INTO t1 VALUES(default);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> SELECT * from t1;
ERROR 1194 (HY000): Table 't1' is marked as crashed and should be repaired
mysql> CREATE TABLE t2(e2 enum('foo','bar') NOT NULL);
Query OK, 0 rows affected (0.08 sec)
[13 Nov 2008 11:18] Gleb Shchepa
5.0 is affected too with exception: CSV doesn't crash, but it inserts wrong default result
like MyISAM.
[12 Dec 2008 17:23] Shane Bester
I opened bug #41441 as a sister to this (crash on windows debug server)
[26 Dec 2008 17:47] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/62353

2746 Sergey Glukhov	2008-12-26
      Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for
MyISAM
      Table corruption happens during table reading in ha_tina::find_current_row() func.
      Field::store() method returns error(true) if stored value is 0, but 0 is legal
value.
      The fix is to return false if the value is 0.
      Additional fix:
      INSERT...(default) and INSERT...() have the same behaviour now.
[6 Feb 11:04] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/65451

2741 Sergey Glukhov	2009-02-06
      Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for
MyISAM
      Table corruption happens during table reading in ha_tina::find_current_row() func.
      Field::store() method returns error(true) if stored value is 0, but 0 is legal
value.
      The fix is to return false if the value is 0.
      Additional fix:
        INSERT...(default) and INSERT...() have the same behaviour now.
[27 Feb 11:43] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/67828

2828 Sergey Glukhov	2009-02-27
      Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for
MyISAM
      Table corruption happens during table reading in ha_tina::find_current_row() func.
      Field::store() method returns error(true) if stored value is 0.
      The fix:
      added special case for enum type which correctly processes 0 value.
      Additional fix:
      INSERT...(default) and INSERT...() have the same behaviour now.
     @ mysql-test/r/csv.result
        test result
     @ mysql-test/r/default.result
        result fix
     @ mysql-test/r/type_ranges.result
        result fix
     @ mysql-test/t/csv.test
        result fix
     @ sql/item.cc
        set default value
     @ sql/sql_insert.cc
        removed check for ENUM field. The reason is that
        ENUM field behavoir should be the same as other
        fileds have.
     @ storage/csv/ha_tina.cc
        Table corruption happens during table reading in ha_tina::find_current_row()
func.
        Field::store() method returns error(true) if stored value is 0.
        The fix:
        added special case for enum type which correctly processes 0 value.
[31 Mar 11:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/70869

2840 Sergey Glukhov	2009-03-31
      Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for
MyISAM
      Table corruption happens during table reading in ha_tina::find_current_row() func.
      Field::store() method returns error(true) if stored value is 0.
      The fix:
      added special case for enum type which correctly processes 0 value.
      Additional fix:
      INSERT...(default) and INSERT...() have the same behaviour now.
     @ mysql-test/r/csv.result
        test result
     @ mysql-test/r/default.result
        result fix
     @ mysql-test/t/csv.test
        test case
     @ sql/item.cc
        Changes:
        --do not print warning for 'enum' type if there is no default value
        --set default value
     @ storage/csv/ha_tina.cc
        Table corruption happens during table reading in ha_tina::find_current_row()
func.
        Field::store() method returns error(true) if stored value is 0.
        The fix:
        added special case for enum type which correctly processes 0 value.
[19 May 11:17] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/74467

2840 Sergey Glukhov	2009-05-19
      Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for
MyISAM(for 5.0 & 5.1)
      Table corruption happens during table reading in ha_tina::find_current_row() func.
      Field::store() method returns error(true) if stored value is 0.
      The fix:
      added special case for enum type which correctly processes 0 value.
      Additional fix:
      INSERT...(default) and INSERT...() have the same behaviour now for enum type.
     @ mysql-test/r/csv.result
        test result
     @ mysql-test/r/default.result
        result fix
     @ mysql-test/t/csv.test
        test case
     @ sql/item.cc
        Changes:
        --do not print warning for 'enum' type if there is no default value
        --set default value
     @ storage/csv/ha_tina.cc
        Table corruption happens during table reading in ha_tina::find_current_row()
func.
        Field::store() method returns error(true) if stored value is 0.
        The fix:
        added special case for enum type which correctly processes 0 value.