MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Ramil Kalimullin Date:March 19 2010 11:15am
Subject:bzr commit into mysql-5.1-bugteam branch (ramil:3404) Bug#50946
View as plain text  
#At file:///home/ram/mysql/b50946-5.1-bugteam/ based on revid:svoj@stripped

 3404 Ramil Kalimullin	2010-03-19
      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/alter_table.result
        Fix for bug#50946: fast index creation still seems to copy the table
          - test result.
     @ mysql-test/t/alter_table.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/alter_table.result
      mysql-test/t/alter_table.test
      sql/field.cc
      sql/sql_table.cc
=== modified file 'mysql-test/r/alter_table.result'
--- a/mysql-test/r/alter_table.result	2009-12-18 12:00:30 +0000
+++ b/mysql-test/r/alter_table.result	2010-03-19 11:15:31 +0000
@@ -1345,4 +1345,24 @@ DROP TABLE t1;
 CREATE TABLE t1 (a TEXT, id INT, b INT);
 ALTER TABLE t1 DROP COLUMN a, ADD COLUMN c TEXT FIRST;
 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_allow_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/alter_table.test'
--- a/mysql-test/t/alter_table.test	2009-12-18 12:00:30 +0000
+++ b/mysql-test/t/alter_table.test	2010-03-19 11:15:31 +0000
@@ -1072,5 +1072,17 @@ ALTER TABLE t1 DROP COLUMN a, ADD COLUMN
 
 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_allow_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 End of 5.1 tests

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2010-03-14 16:01:45 +0000
+++ b/sql/field.cc	2010-03-19 11:15:31 +0000
@@ -8874,14 +8874,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-02-28 17:29:19 +0000
+++ b/sql/sql_table.cc	2010-03-19 11:15:31 +0000
@@ -6878,6 +6878,13 @@ view_err:
                        &candidate_key_count))
       goto err;
    
+    DBUG_EXECUTE_IF("alter_table_allow_only_metadata_change", {
+      if (need_copy_table_res != ALTER_TABLE_METADATA_ONLY)
+        goto err; });
+    DBUG_EXECUTE_IF("alter_table_allow_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-20100319111531-6bcb2hnpvg80b59j.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (ramil:3404) Bug#50946Ramil Kalimullin19 Mar