diff --git a/mysql-test/r/error_simulation.result b/mysql-test/r/error_simulation.result index 6153dad2534..27e51a33112 100644 --- a/mysql-test/r/error_simulation.result +++ b/mysql-test/r/error_simulation.result @@ -18,3 +18,26 @@ SELECT MAX(a) FROM t1 GROUP BY a,b; ERROR 23000: Can't write; duplicate key in table 'tmp_table' set tmp_table_size=default; DROP TABLE t1; +# +# Bug #50946: fast index creation still seems to copy the table +# +CREATE TABLE t1 (a INT(100) NOT NULL); +INSERT INTO t1 VALUES (1), (0), (2); +SET SESSION debug='+d,alter_table_only_index_change'; +ALTER TABLE t1 ADD INDEX a(a); +SET SESSION debug=DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(100) NOT NULL, + KEY `a` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t1; +a +0 +1 +2 +DROP TABLE t1; +# +# End of 5.1 tests +# diff --git a/mysql-test/t/error_simulation.test b/mysql-test/t/error_simulation.test index f730c95208e..7cd16a6bc5a 100644 --- a/mysql-test/t/error_simulation.test +++ b/mysql-test/t/error_simulation.test @@ -33,3 +33,19 @@ set tmp_table_size=default; DROP TABLE t1; +--echo # +--echo # Bug #50946: fast index creation still seems to copy the table +--echo # +CREATE TABLE t1 (a INT(100) NOT NULL); +INSERT INTO t1 VALUES (1), (0), (2); +SET SESSION debug='+d,alter_table_only_index_change'; +ALTER TABLE t1 ADD INDEX a(a); +SET SESSION debug=DEFAULT; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # End of 5.1 tests +--echo # diff --git a/sql/field.cc b/sql/field.cc index b6323d7b839..b203a42a918 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -8878,14 +8878,20 @@ bool Field_num::eq_def(Field *field) } +/** + Check whether two numeric fields can be considered 'equal' for table + alteration purposes. Fields are equal if they are of the same type + and retain the same pack length. +*/ + uint Field_num::is_equal(Create_field *new_field) { return ((new_field->sql_type == real_type()) && - ((new_field->flags & UNSIGNED_FLAG) == (uint) (flags & - UNSIGNED_FLAG)) && + ((new_field->flags & UNSIGNED_FLAG) == + (uint) (flags & UNSIGNED_FLAG)) && ((new_field->flags & AUTO_INCREMENT_FLAG) == (uint) (flags & AUTO_INCREMENT_FLAG)) && - (new_field->length <= max_display_length())); + (new_field->pack_length == pack_length())); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index ad72cab664e..1101be67d5e 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6922,6 +6922,13 @@ view_err: &candidate_key_count)) goto err; + DBUG_EXECUTE_IF("alter_table_only_metadata_change", { + if (need_copy_table_res != ALTER_TABLE_METADATA_ONLY) + goto err; }); + DBUG_EXECUTE_IF("alter_table_only_index_change", { + if (need_copy_table_res != ALTER_TABLE_INDEX_CHANGED) + goto err; }); + if (need_copy_table == ALTER_TABLE_METADATA_ONLY) need_copy_table= need_copy_table_res; }