#At file:///home/gluh/MySQL/mysql-5.1-bug-33717/ based on revid:kgeorge@stripped
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.
modified:
mysql-test/r/csv.result
mysql-test/r/default.result
mysql-test/r/type_ranges.result
mysql-test/t/csv.test
sql/item.cc
sql/sql_insert.cc
storage/csv/ha_tina.cc
=== modified file 'mysql-test/r/csv.result'
--- a/mysql-test/r/csv.result 2009-01-23 12:22:05 +0000
+++ b/mysql-test/r/csv.result 2009-02-27 10:42:53 +0000
@@ -5394,17 +5394,28 @@ select * from t1;
ERROR HY000: File 'MYSQLD_DATADIR/test/t1.CSV' not found (Errcode: 2)
unlock tables;
drop table t1;
-create table t1(a enum ('a') not null) engine=csv;
-insert into t1 values (2);
+CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV;
+INSERT INTO t1 VALUES();
Warnings:
-Warning 1265 Data truncated for column 'a' at row 1
-select * from t1 limit 1;
-ERROR HY000: Table 't1' is marked as crashed and should be repaired
-repair table t1;
-Table Op Msg_type Msg_text
-test.t1 repair Warning Data truncated for column 'a' at row 1
-test.t1 repair status OK
-select * from t1 limit 1;
-a
-drop table t1;
+Warning 1364 Field 'e' doesn't have a default value
+INSERT INTO t1 VALUES(default);
+Warnings:
+Warning 1364 Field 'e' doesn't have a default value
+INSERT INTO t1 VALUES(0);
+Warnings:
+Warning 1265 Data truncated for column 'e' at row 1
+INSERT INTO t1 VALUES(3);
+Warnings:
+Warning 1265 Data truncated for column 'e' at row 1
+INSERT INTO t1 VALUES(-1);
+Warnings:
+Warning 1265 Data truncated for column 'e' at row 1
+SELECT * FROM t1;
+e
+foo
+foo
+
+
+
+DROP TABLE t1;
End of 5.1 tests
=== modified file 'mysql-test/r/default.result'
--- a/mysql-test/r/default.result 2008-09-03 08:06:03 +0000
+++ b/mysql-test/r/default.result 2009-02-27 10:42:53 +0000
@@ -169,6 +169,7 @@ insert into bug20691 values (2, 3, 5, '0
insert into bug20691 (x) values (2);
Warnings:
Warning 1364 Field 'a' doesn't have a default value
+Warning 1364 Field 'b' doesn't have a default value
Warning 1364 Field 'c' doesn't have a default value
Warning 1364 Field 'd' doesn't have a default value
Warning 1364 Field 'e' doesn't have a default value
@@ -193,7 +194,7 @@ a b c d e f g h i x
two large 00:00:05 0007-01-01 11 13 17 0019-01-01 00:00:00 23 1
small 00:00:00 0000-00-00 0 0000-00-00 00:00:00 0 2
two large 00:00:05 0007-01-01 11 13 17 0019-01-01 00:00:00 23 3
- 00:00:00 0000-00-00 0 0000-00-00 00:00:00 0 4
+ small 00:00:00 0000-00-00 0 0000-00-00 00:00:00 0 4
drop table bug20691;
create table t1 (id int not null);
insert into t1 values(default);
=== modified file 'mysql-test/r/type_ranges.result'
--- a/mysql-test/r/type_ranges.result 2007-11-13 13:24:48 +0000
+++ b/mysql-test/r/type_ranges.result 2009-02-27 10:42:53 +0000
@@ -125,6 +125,8 @@ Warning 1264 Out of range value for colu
Warning 1264 Out of range value for column 'umedium' at row 1
Warning 1265 Data truncated for column 'options' at row 1
insert into t1 (tiny) values (1);
+Warnings:
+Warning 1364 Field 'options' doesn't have a default value
select auto,string,tiny,short,medium,long_int,longlong,real_float,real_double,utiny,ushort,umedium,ulong,ulonglong,mod(floor(time_stamp/1000000),1000000)-mod(curdate(),1000000),date_field,time_field,date_time,blob_col,tinyblob_col,mediumblob_col,longblob_col from t1;
auto string tiny short medium long_int longlong real_float real_double utiny ushort umedium ulong ulonglong mod(floor(time_stamp/1000000),1000000)-mod(curdate(),1000000) date_field time_field date_time blob_col tinyblob_col mediumblob_col longblob_col
10 1 1 1 1 1 1 1.0 1.0000 1 00001 1 1 1 0 0000-00-00 00:00:00 0000-00-00 00:00:00 1 1 1 1
=== modified file 'mysql-test/t/csv.test'
--- a/mysql-test/t/csv.test 2009-01-23 12:22:05 +0000
+++ b/mysql-test/t/csv.test 2009-02-27 10:42:53 +0000
@@ -1806,16 +1806,15 @@ drop table t1;
--disconnect con1
#
-# Bug#41441 repair csv table crashes debug server
+# Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for MyISAM
#
-# Note: The test should be removed after Bug#33717 is fixed
-
-create table t1(a enum ('a') not null) engine=csv;
-insert into t1 values (2);
---error ER_CRASHED_ON_USAGE
-select * from t1 limit 1;
-repair table t1;
-select * from t1 limit 1;
-drop table t1;
+CREATE TABLE t1 (e enum('foo','bar') NOT NULL) ENGINE = CSV;
+INSERT INTO t1 VALUES();
+INSERT INTO t1 VALUES(default);
+INSERT INTO t1 VALUES(0);
+INSERT INTO t1 VALUES(3);
+INSERT INTO t1 VALUES(-1);
+SELECT * FROM t1;
+DROP TABLE t1;
--echo End of 5.1 tests
=== modified file 'sql/item.cc'
--- a/sql/item.cc 2009-02-20 09:50:50 +0000
+++ b/sql/item.cc 2009-02-27 10:42:53 +0000
@@ -6214,6 +6214,7 @@ void Item_default_value::print(String *s
int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
{
+ int err= 0;
if (!arg)
{
if (field_arg->flags & NO_DEFAULT_VALUE_FLAG)
@@ -6243,10 +6244,10 @@ int Item_default_value::save_in_field(Fi
ER(ER_NO_DEFAULT_FOR_FIELD),
field_arg->field_name);
}
- return 1;
+ err= 1;
}
field_arg->set_default();
- return 0;
+ return err;
}
return Item_field::save_in_field(field_arg, no_conversions);
}
=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc 2009-02-19 21:09:35 +0000
+++ b/sql/sql_insert.cc 2009-02-27 10:42:53 +0000
@@ -1602,8 +1602,7 @@ int check_that_all_fields_are_given_valu
for (Field **field=entry->field ; *field ; field++)
{
if (!bitmap_is_set(write_set, (*field)->field_index) &&
- ((*field)->flags & NO_DEFAULT_VALUE_FLAG) &&
- ((*field)->real_type() != MYSQL_TYPE_ENUM))
+ ((*field)->flags & NO_DEFAULT_VALUE_FLAG))
{
bool view= FALSE;
if (table_list)
=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc 2008-12-29 12:50:51 +0000
+++ b/storage/csv/ha_tina.cc 2009-02-27 10:42:53 +0000
@@ -679,9 +679,13 @@ int ha_tina::find_current_row(uchar *buf
if (read_all || bitmap_is_set(table->read_set, (*field)->field_index))
{
+ bool is_enum= ((*field)->real_type() == MYSQL_TYPE_ENUM);
if ((*field)->store(buffer.ptr(), buffer.length(), buffer.charset(),
- CHECK_FIELD_WARN))
- goto err;
+ is_enum ? CHECK_FIELD_IGNORE : CHECK_FIELD_WARN))
+ {
+ if (!is_enum)
+ goto err;
+ }
if ((*field)->flags & BLOB_FLAG)
{
Field_blob *blob= *(Field_blob**) field;
Attachment: [text/bzr-bundle] bzr/sergey.glukhov@sun.com-20090227104253-dzndik6ehcup40nc.bundle