MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Ramil Kalimullin Date:April 25 2010 11:06am
Subject:bzr commit into mysql-5.1-bugteam branch (ramil:3357) Bug#50946
View as plain text  
#At file:///home/ram/mysql/b50946-5.1-bugteam/ based on revid:staale.smedseng@stripped

 3357 Ramil Kalimullin	2010-04-25
      Fix for bug#50946: fast index creation still seems to copy the table 
      
      Problem: ALTER TABLE ADD INDEX may lead to table copying if there's
      numeric field(s) with non-default display width modificator specified.
      
      Fix: compare numeric field's storage lenghts when we decide whether 
      they can be considered 'equal' for table alteration purposes.
     @ mysql-test/r/error_simulation.result
        Fix for bug#50946: fast index creation still seems to copy the table
          - test result.
     @ mysql-test/t/error_simulation.test
        Fix for bug#50946: fast index creation still seems to copy the table
          - test case.
     @ sql/field.cc
        Fix for bug#50946: fast index creation still seems to copy the table
          - check numeric field's pack lengths instead of it's display lenghts
        comparing fields equality for table alteration purposes.
     @ sql/sql_table.cc
        Fix for bug#50946: fast index creation still seems to copy the table
          - check compare_tables() result for testing purposes.

    modified:
      mysql-test/r/error_simulation.result
      mysql-test/t/error_simulation.test
      sql/field.cc
      sql/sql_table.cc
=== modified file 'mysql-test/r/error_simulation.result'
--- a/mysql-test/r/error_simulation.result	2008-04-03 08:27:56 +0000
+++ b/mysql-test/r/error_simulation.result	2010-04-25 11:06:40 +0000
@@ -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
+#

=== modified file 'mysql-test/t/error_simulation.test'
--- a/mysql-test/t/error_simulation.test	2008-04-03 08:27:56 +0000
+++ b/mysql-test/t/error_simulation.test	2010-04-25 11:06:40 +0000
@@ -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 #

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2010-03-17 18:15:41 +0000
+++ b/sql/field.cc	2010-04-25 11:06:40 +0000
@@ -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()));
 }
 
 

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-04-12 10:12:20 +0000
+++ b/sql/sql_table.cc	2010-04-25 11:06:40 +0000
@@ -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;
   }


Attachment: [text/bzr-bundle] bzr/ramil@mysql.com-20100425110640-iy0jbnovtsshm0tl.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (ramil:3357) Bug#50946Ramil Kalimullin25 Apr