#At file:///home/satya/WORK/mysql-6.0-bugteam-33696/
2900 Satya B 2008-11-05
Fix for Bug#33696 - CSV storage engine allows nullable columns via ALTER TABLE statements
Problem:
After the fast online-alter table changes, CSV engine allows nullable columns via alter table and also the existing non-null columns can be modified to null columns.
All columns in CSV Engine should be NON-NULL always.
How it was solved:
Found that we evaluate the changes that will be made to altered table. During this evaluation, we check for the behaviour of the new fields in temporary altered table with the fields in the original table and maintain as table_changes. This is passed to storage engines along with the new information. Storage engines can add further checks and return the compatibility state.CSV Engine has this information but ignores it and returns always true. Changed the behaviour to return compatible or not based on the information passed from the server.
In sql_table.cc: mysql_alter_table(...), create_altered_table(...) creates the altered table and table->file->check_if_supported_alter(..) checks if a table can be altered on-line
Note:
The csv_alter_table exists in the repository and was disabled due to this bug.
added:
mysql-test/r/csv_alter_table.result
modified:
mysql-test/t/disabled.def
storage/csv/ha_tina.cc
per-file messages:
mysql-test/r/csv_alter_table.result
Result file for csv_alter_table.test(the test file exists in the main branch)
mysql-test/t/disabled.def
Enabling the disabled test csv_alter_table.test
storage/csv/ha_tina.cc
Fixed check_if_incompatible_data to return correct compatibility state based on the information provided from server.
=== added file 'mysql-test/r/csv_alter_table.result'
--- a/mysql-test/r/csv_alter_table.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/csv_alter_table.result 2008-11-05 12:03:55 +0000
@@ -0,0 +1,40 @@
+# ===== csv_alter_table.1 =====
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a int NOT NULL) ENGINE = CSV;
+ALTER TABLE t1 ADD COLUMN b CHAR(5) NOT NULL;
+DESC t1;
+Field Type Null Key Default Extra
+a int(11) NO NULL
+b char(5) NO NULL
+ALTER TABLE t1 DROP COLUMN b;
+DESC t1;
+Field Type Null Key Default Extra
+a int(11) NO NULL
+ALTER TABLE t1 MODIFY a BIGINT NOT NULL;
+DESC t1;
+Field Type Null Key Default Extra
+a bigint(20) NO NULL
+ALTER TABLE t1 CHANGE a a INT NOT NULL;
+DESC t1;
+Field Type Null Key Default Extra
+a int(11) NO NULL
+DROP TABLE t1;
+# ===== csv_alter_table.2 =====
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a int NOT NULL) ENGINE = CSV;
+ALTER TABLE t1 ADD COLUMN b CHAR(5);
+ERROR 42000: The storage engine for the table doesn't support nullable columns
+DESC t1;
+Field Type Null Key Default Extra
+a int(11) NO NULL
+ALTER TABLE t1 MODIFY a BIGINT;
+ERROR 42000: The storage engine for the table doesn't support nullable columns
+DESC t1;
+Field Type Null Key Default Extra
+a int(11) NO NULL
+ALTER TABLE t1 CHANGE a a INT;
+ERROR 42000: The storage engine for the table doesn't support nullable columns
+DESC t1;
+Field Type Null Key Default Extra
+a int(11) NO NULL
+DROP TABLE t1;
=== modified file 'mysql-test/t/disabled.def'
--- a/mysql-test/t/disabled.def 2008-10-15 19:12:49 +0000
+++ b/mysql-test/t/disabled.def 2008-11-05 12:03:55 +0000
@@ -17,7 +17,6 @@ lowercase_table3 : Bug#32667 low
rpl_log_pos : Bug#8693 Test 'rpl_log_pos' fails sometimes
ctype_create : Bug#32965 main.ctype_create fails
backup_no_engine : Bug#36021 2008-04-13 rsomla server crashes when openning table with unknown storage engine
-csv_alter_table : Bug#33696 2008-01-21 pcrews no .result file - bug allows NULL columns in CSV tables
query_cache_wlock_invalidate_func: Bug#35390 causes not deterministic results.
cast : Bug#35594 2008-03-27 main.cast fails on Windows2003-64
maria-preload : Bug#35107 crashes
=== modified file 'storage/csv/ha_tina.cc'
--- a/storage/csv/ha_tina.cc 2008-08-23 00:18:35 +0000
+++ b/storage/csv/ha_tina.cc 2008-11-05 12:03:55 +0000
@@ -1595,10 +1595,21 @@ int ha_tina::check(THD* thd, HA_CHECK_OP
}
+/**
+ Return the compatiblity of alter table changes, created for new
+ fast on-line alter table operation.
+ @param info Information about new altered table properties
+ @param table_changes Information if the table layout is changed
+ @retval COMPATIBLE_DATA_NO Altered table changes made are incompatible
+ @retval COMPATIBLE_DATA_YES Altered table changes made are compatible
+*/
bool ha_tina::check_if_incompatible_data(HA_CREATE_INFO *info,
uint table_changes)
{
- return COMPATIBLE_DATA_YES;
+ if (table_changes == IS_EQUAL_NO)
+ return COMPATIBLE_DATA_NO;
+ else
+ return COMPATIBLE_DATA_YES;
}
struct st_mysql_storage_engine csv_storage_engine=