List:Commits« Previous MessageNext Message »
From:Martin Skold Date:February 27 2008 3:29pm
Subject:bk commit into 5.1 tree (mskold:1.2650) BUG#31233
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of mskold.  When mskold does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-27 16:29:43+01:00, mskold@stripped +5 -0
  bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: post review fixes

  mysql-test/suite/ndb/r/ndb_alter_table3.result@stripped, 2008-02-27 16:28:41+01:00, mskold@stripped +47 -0
    bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: post review fixes

  mysql-test/suite/ndb/t/ndb_alter_table3.test@stripped, 2008-02-27 16:28:41+01:00, mskold@stripped +28 -0
    bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: post review fixes

  sql/ha_ndbcluster.cc@stripped, 2008-02-27 16:28:41+01:00, mskold@stripped +8 -19
    bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: post review fixes

  sql/mysql_priv.h@stripped, 2008-02-27 16:28:41+01:00, mskold@stripped +1 -1
    bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: post review fixes

  sql/sql_table.cc@stripped, 2008-02-27 16:28:41+01:00, mskold@stripped +23 -4
    bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: post review fixes

diff -Nrup a/mysql-test/suite/ndb/r/ndb_alter_table3.result b/mysql-test/suite/ndb/r/ndb_alter_table3.result
--- a/mysql-test/suite/ndb/r/ndb_alter_table3.result	2007-06-27 14:27:28 +02:00
+++ b/mysql-test/suite/ndb/r/ndb_alter_table3.result	2008-02-27 16:28:41 +01:00
@@ -33,3 +33,50 @@ a
 drop table t4;
 show tables;
 Tables_in_test
+create table t1(a int not null) engine=ndb;
+$PK Bigunsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+PRIMARY KEY($PK) - UniqueHashIndex
+insert into t1 values (1),(2),(3);
+alter table t1 add primary key (a);
+a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+PRIMARY KEY(a) - UniqueHashIndex
+PRIMARY(a) - OrderedIndex
+update t1 set a = 17 where a = 1;
+select * from t1 order by a;
+a
+2
+3
+17
+alter table t1 drop primary key;
+$PK Bigunsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+PRIMARY KEY($PK) - UniqueHashIndex
+update t1 set a = 1 where a = 17;
+select * from t1 order by a;
+a
+1
+2
+3
+drop table t1;
+create table t1(a int not null) engine=ndb;
+$PK Bigunsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+PRIMARY KEY($PK) - UniqueHashIndex
+insert into t1 values (1),(2),(3);
+create unique index pk on t1(a);
+a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+PRIMARY KEY(a) - UniqueHashIndex
+update t1 set a = 17 where a = 1;
+select * from t1 order by a;
+a
+2
+3
+17
+alter table t1 drop index pk;
+$PK Bigunsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+PRIMARY KEY($PK) - UniqueHashIndex
+update t1 set a = 1 where a = 17;
+select * from t1 order by a;
+a
+1
+2
+3
+drop table t1;
diff -Nrup a/mysql-test/suite/ndb/t/ndb_alter_table3.test b/mysql-test/suite/ndb/t/ndb_alter_table3.test
--- a/mysql-test/suite/ndb/t/ndb_alter_table3.test	2007-07-04 22:06:22 +02:00
+++ b/mysql-test/suite/ndb/t/ndb_alter_table3.test	2008-02-27 16:28:41 +01:00
@@ -46,3 +46,31 @@ select * from t4;
 drop table t4;
 show tables;
 connection server1;
+
+# Check add/drop primary key (not supported on-line)
+create table t1(a int not null) engine=ndb;
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep PRIMARY
+insert into t1 values (1),(2),(3);
+alter table t1 add primary key (a);
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep PRIMARY
+update t1 set a = 17 where a = 1;
+select * from t1 order by a;
+alter table t1 drop primary key;
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep PRIMARY
+update t1 set a = 1 where a = 17;
+select * from t1 order by a;
+drop table t1;
+
+# bug#31233 mysql_alter_table() fails to drop UNIQUE KEY
+create table t1(a int not null) engine=ndb;
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep PRIMARY
+insert into t1 values (1),(2),(3);
+create unique index pk on t1(a);
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep PRIMARY
+update t1 set a = 17 where a = 1;
+select * from t1 order by a;
+alter table t1 drop index pk;
+--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | grep PRIMARY
+update t1 set a = 1 where a = 17;
+select * from t1 order by a;
+drop table t1;
diff -Nrup a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
--- a/sql/ha_ndbcluster.cc	2007-12-15 14:59:38 +01:00
+++ b/sql/ha_ndbcluster.cc	2008-02-27 16:28:41 +01:00
@@ -9939,35 +9939,24 @@ bool ha_ndbcluster::check_if_incompatibl
 
   if (table_changes != IS_EQUAL_YES)
     DBUG_RETURN(COMPATIBLE_DATA_NO);
-  
-  /**
-   * Changing from/to primary key
-   *
-   * This is _not_ correct, but check_if_incompatible_data-interface
-   *   doesnt give more info, so I guess that we can't do any
-   *   online add index if not using primary key
-   *
-   *   This as mysql will handle a unique not null index as primary 
-   *     even wo/ user specifiying it... :-(
-   *   
-   */
-  if ((table_share->primary_key == MAX_KEY && pk) ||
-      (table_share->primary_key != MAX_KEY && !pk) ||
-      (table_share->primary_key == MAX_KEY && !pk && ai))
-  {
-    DBUG_RETURN(COMPATIBLE_DATA_NO);
-  }
-  
+
   /* Check that auto_increment value was not changed */
   if ((create_info->used_fields & HA_CREATE_USED_AUTO) &&
       create_info->auto_increment_value != 0)
+  {
+    DBUG_PRINT("info", ("auto_increment value changed"));
     DBUG_RETURN(COMPATIBLE_DATA_NO);
+  }
   
   /* Check that row format didn't change */
   if ((create_info->used_fields & HA_CREATE_USED_AUTO) &&
       get_row_type() != create_info->row_type)
+  {
+    DBUG_PRINT("info", ("row format changed"));
     DBUG_RETURN(COMPATIBLE_DATA_NO);
+  }
 
+  DBUG_PRINT("info", ("new table seems compatible"));
   DBUG_RETURN(COMPATIBLE_DATA_YES);
 }
 
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h	2008-02-08 17:10:38 +01:00
+++ b/sql/mysql_priv.h	2008-02-27 16:28:41 +01:00
@@ -2146,7 +2146,7 @@ uint build_table_shadow_filename(char *b
 #define FN_TO_IS_TMP    (1 << 1)
 #define FN_IS_TMP       (FN_FROM_IS_TMP | FN_TO_IS_TMP)
 #define NO_FRM_RENAME   (1 << 2)
-#define FN_FRM_ONLY     (1 << 3)
+#define FRM_ONLY     (1 << 3)
 
 /* from hostname.cc */
 struct in_addr;
diff -Nrup a/sql/sql_table.cc b/sql/sql_table.cc
--- a/sql/sql_table.cc	2008-02-08 17:10:38 +01:00
+++ b/sql/sql_table.cc	2008-02-27 16:28:41 +01:00
@@ -1831,7 +1831,7 @@ bool quick_rm_table(handlerton *base,con
   if (my_delete(path,MYF(0)))
     error= 1; /* purecov: inspected */
   path[path_length - reg_ext_length]= '\0'; // Remove reg_ext
-  if (!(flags & FN_FRM_ONLY))
+  if (!(flags & FRM_ONLY))
     error|= ha_delete_table(current_thd, base, path, db, table_name, 0);
   DBUG_RETURN(error);
 }
@@ -6311,6 +6311,7 @@ view_err:
     KEY   *key;
     uint  *idx_p;
     uint  *idx_end_p;
+    bool is_candidate_key= true;
 
     if (table->s->db_type()->alter_table_flags)
       alter_flags= table->s->db_type()->alter_table_flags(alter_info->flags);
@@ -6328,8 +6329,9 @@ view_err:
            Unique key. Check for "PRIMARY"
            or if dropping last unique key.
         */
-        if ((uint) (key - table->key_info) !=  table->s->primary_key)
+        if ((uint) (key - table->key_info) ==  table->s->primary_key)
         {
+          DBUG_PRINT("info", ("Dropping primary key"));
           /* Primary key. */
           needed_online_flags|=  HA_ONLINE_DROP_PK_INDEX;
           needed_fast_flags|= HA_ONLINE_DROP_PK_INDEX_NO_WRITES;
@@ -6363,11 +6365,26 @@ view_err:
         /*
            Unique key. Check for "PRIMARY"
            or if adding first unique key
+           defined on non-nullable fields
         */
+        KEY_PART_INFO *part_end= key->key_part + key->key_parts;    
+        bool is_candidate_key= true;
+
+        /*
+          Check that all fields in key are declared
+          NOT NULL
+         */
+        for (KEY_PART_INFO *key_part= key->key_part;
+             key_part < part_end;
+             key_part++)
+          is_candidate_key=
+            (is_candidate_key && 
+             (! table->field[key_part->fieldnr]->maybe_null()));
         if ((! my_strcasecmp(system_charset_info,
                              key->name, primary_key_name)) ||
-            (no_pk && candidate_key_count == 0))
+            (no_pk && candidate_key_count == 0 && is_candidate_key))
         {
+          DBUG_PRINT("info", ("Adding primary key"));
           /* Primary key. */
           needed_online_flags|=  HA_ONLINE_ADD_PK_INDEX;
           needed_fast_flags|= HA_ONLINE_ADD_PK_INDEX_NO_WRITES;
@@ -6401,6 +6418,8 @@ view_err:
       pk_changed= 2;
     }
 
+    DBUG_PRINT("info", ("needed_online_flags: 0x%lx, needed_fast_flags: 0x%lx",
+                        needed_online_flags, needed_fast_flags));
     /*
       Online or fast add/drop index is possible only if
       the primary key is not added and dropped in the same statement.
@@ -6901,7 +6920,7 @@ err1:
   else
     VOID(quick_rm_table(new_db_type, new_db, tmp_name,
                         create_info->frm_only
-                        ? FN_IS_TMP | FN_FRM_ONLY
+                        ? FN_IS_TMP | FRM_ONLY
                         : FN_IS_TMP));
 
 err:
Thread
bk commit into 5.1 tree (mskold:1.2650) BUG#31233Martin Skold27 Feb