List:Commits« Previous MessageNext Message »
From:Martin Skold Date:March 12 2008 1:43pm
Subject:bk commit into 5.1 tree (mskold:1.2531) 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-03-12 14:43:09+01:00, mskold@stripped +1 -0
  bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: Post-review fixes

  sql/sql_table.cc@stripped, 2008-03-12 14:43:02+01:00, mskold@stripped +45 -22
    bug#31233 mysql_alter_table() fails to drop UNIQUE KEY: Post-review fixes

diff -Nrup a/sql/sql_table.cc b/sql/sql_table.cc
--- a/sql/sql_table.cc	2008-02-28 12:19:12 +01:00
+++ b/sql/sql_table.cc	2008-03-12 14:43:02 +01:00
@@ -5231,6 +5231,22 @@ compare_tables(TABLE *table,
     KEY_PART_INFO *table_part_end= table_key->key_part + table_key->key_parts;
     KEY_PART_INFO *new_part;
 
+   /*
+      Check if key is a candidate key, i.e. a unique index with no index
+      fields nullable, then key is either already primary key or could
+      be promoted to primary key if the original primary key is dropped.
+      Count all candidate keys.
+    */
+    not_nullable= true;
+    for (table_part= table_key->key_part;
+         table_part < table_part_end;
+         table_part++)
+    {
+      not_nullable= not_nullable && (! table_part->field->maybe_null());
+    }
+    if ((table_key->flags & HA_NOSAME) && not_nullable)
+      (*candidate_key_count)++;
+
     /* Search a new key with the same name. */
     for (new_key= *key_info_buffer; new_key < new_key_end; new_key++)
     {
@@ -5252,8 +5268,6 @@ compare_tables(TABLE *table,
         (table_key->key_parts != new_key->key_parts))
       goto index_changed;
 
-    
-    not_nullable= true;
     /*
       Check that the key parts remain compatible between the old and
       new tables.
@@ -5262,8 +5276,6 @@ compare_tables(TABLE *table,
          table_part < table_part_end;
          table_part++, new_part++)
     {
-      not_nullable= not_nullable && (! table_part->field->maybe_null());
-
       /*
 	Key definition has changed if we are using a different field or
 	if the used key part length is different. We know that the fields
@@ -5273,15 +5285,6 @@ compare_tables(TABLE *table,
           (table_part->fieldnr - 1 != new_part->fieldnr))
 	goto index_changed;
     }
-
-    /*
-      Count all candidate keys,
-      i.e all non-nullable unique indexes
-     */
-    if ((table_key->flags & HA_NOSAME) && not_nullable)
-      (*candidate_key_count)++;
-
-
     continue;
 
   index_changed:
@@ -6311,7 +6314,6 @@ 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);
@@ -6336,12 +6338,29 @@ view_err:
           needed_online_flags|=  HA_ONLINE_DROP_PK_INDEX;
           needed_fast_flags|= HA_ONLINE_DROP_PK_INDEX_NO_WRITES;
           pk_changed++;
+          candidate_key_count--;
         }
         else
         {
+          KEY_PART_INFO *part_end= key->key_part + key->key_parts;    
+          bool is_candidate_key= true;
+
           /* Non-primary unique key. */
           needed_online_flags|=  HA_ONLINE_DROP_UNIQUE_INDEX;
           needed_fast_flags|= HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES;
+
+          /*
+            Check if all fields in key are declared
+            NOT NULL and adjust candidate_key_count
+          */
+          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 (is_candidate_key)
+            candidate_key_count--;
         }
       }
       else
@@ -6362,16 +6381,13 @@ view_err:
       DBUG_PRINT("info", ("index added: '%s'", key->name));
       if (key->flags & HA_NOSAME)
       {
-        /*
-           Unique key. Check for "PRIMARY"
-           or if adding first unique key
-           defined on non-nullable fields
-        */
+        /* Unique key */
+
         KEY_PART_INFO *part_end= key->key_part + key->key_parts;    
         bool is_candidate_key= true;
 
         /*
-          Check that all fields in key are declared
+          Check if all fields in key are declared
           NOT NULL
          */
         for (KEY_PART_INFO *key_part= key->key_part;
@@ -6380,8 +6396,15 @@ view_err:
           is_candidate_key=
             (is_candidate_key && 
              (! table->field[key_part->fieldnr]->maybe_null()));
-        if ((! my_strcasecmp(system_charset_info,
-                             key->name, primary_key_name)) ||
+
+        /*
+           Check for "PRIMARY"
+           or if adding first unique key
+           defined on non-nullable fields
+        */
+
+        if ((!my_strcasecmp(system_charset_info,
+                            key->name, primary_key_name)) ||
             (no_pk && candidate_key_count == 0 && is_candidate_key))
         {
           DBUG_PRINT("info", ("Adding primary key"));
Thread
bk commit into 5.1 tree (mskold:1.2531) BUG#31233Martin Skold12 Mar