From ad7b9569220a9c1b0af1db52ac79ae16b28adc41 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 15 May 2006 19:41:04 +0300 Subject: [PATCH] Fix, or a workaround for Bug#19386 "Multiple alter causes crashed table" The problem is that in a MyISAM table the following column after a varchar field gets corrupted, if varchar field is extended. This should be made to work without a copy in the future, but I'm not sure if this code is ready yet. This fix will force copy in this case. It will not do any harm to have it here, only makes alter table a bit slower in this case. If this should work for MyISAM, then the bug is somewhere else in that code. Until it works, I propose this as a temporary fix or a workaround. Test case for the bug has been added. mysql-test/r/alter_table.result: Added test case for Bug#19386: Multiple alter causes crashed table. mysql-test/t/alter_table.test: Added test case for Bug#19386: Multiple alter causes crashed table. sql/ha_myisam.cc: For MyISAM type, if varchar column is extended, it should return not compatible for now. In other words, it forces a copy of the table during alter table. --- mysql-test/r/alter_table.result | 10 ++++++++++ mysql-test/t/alter_table.test | 13 +++++++++++++ sql/ha_myisam.cc | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index 1ad9cd6d1e9..f4332ea9888 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -647,3 +647,13 @@ SELECT LENGTH(s) FROM t1; LENGTH(s) 10 DROP TABLE t1; +CREATE TABLE t1 (v VARCHAR(3), b INT); +INSERT INTO t1 VALUES ('abc', 5); +SELECT * FROM t1; +v b +abc 5 +ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4); +SELECT * FROM t1; +v b +abc 5 +DROP TABLE t1; diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 7cddb8bafa9..efe58579785 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -469,3 +469,16 @@ ALTER TABLE t1 MODIFY s BINARY(10); SELECT HEX(s) FROM t1; SELECT LENGTH(s) FROM t1; DROP TABLE t1; + +# +# Bug#19386: Multiple alter causes crashed table +# The trailing column would get corrupted data, or server could not even read +# it. +# + +CREATE TABLE t1 (v VARCHAR(3), b INT); +INSERT INTO t1 VALUES ('abc', 5); +SELECT * FROM t1; +ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4); +SELECT * FROM t1; +DROP TABLE t1; diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 786d45a4966..40081c975c8 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -1786,7 +1786,8 @@ bool ha_myisam::check_if_incompatible_data(HA_CREATE_INFO *info, if (info->auto_increment_value != auto_increment_value || info->data_file_name != data_file_name || info->index_file_name != index_file_name || - table_changes == IS_EQUAL_NO) + table_changes == IS_EQUAL_NO || + table_changes & IS_EQUAL_PACK_LENGTH) // Not implemented yet return COMPATIBLE_DATA_NO; if ((options & (HA_OPTION_PACK_RECORD | HA_OPTION_CHECKSUM |