List:Commits« Previous MessageNext Message »
From:ahristov Date:December 1 2006 3:21pm
Subject:bk commit into 5.0 tree (andrey:1.2358)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of andrey. When andrey 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, 2006-12-01 16:20:55+01:00, andrey@stripped +2 -0
  Merge ahristov@stripped:/home/bk/mysql-5.0-maint
  into  example.com:/work/bug24395-v2/my50
  MERGE: 1.2327.1.7

  myisam/mi_open.c@stripped, 2006-12-01 16:20:48+01:00, andrey@stripped +0 -0
    Auto merged
    MERGE: 1.95.1.2

  sql/sql_table.cc@stripped, 2006-12-01 16:20:48+01:00, andrey@stripped +0 -0
    Auto merged
    MERGE: 1.326.1.1

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	andrey
# Host:	example.com
# Root:	/work/bug24395-v2/my50/RESYNC

--- 1.98/myisam/mi_open.c	2006-12-01 16:21:04 +01:00
+++ 1.99/myisam/mi_open.c	2006-12-01 16:21:04 +01:00
@@ -1264,13 +1264,30 @@ int mi_enable_indexes(MI_INFO *info)
   RETURN
     0  indexes are not disabled
     1  all indexes are disabled
-   [2  non-unique indexes are disabled - NOT YET IMPLEMENTED]
+    2  non-unique indexes are disabled
 */
 
 int mi_indexes_are_disabled(MI_INFO *info)
 {
   MYISAM_SHARE *share= info->s;
 
-  return (! mi_is_any_key_active(share->state.key_map) && share->base.keys);
+  /*
+    No keys or all are enabled. keys is the number of keys. Left shifted
+    gives us only one bit set. When decreased by one, gives us all all bits
+    up to this one set and it gets unset.
+  */
+  if (!share->base.keys ||
+      (mi_is_all_keys_active(share->state.key_map, share->base.keys)))
+    return 0;
+
+  /* All are disabled */
+  if (mi_is_any_key_active(share->state.key_map))
+    return 1;
+
+  /*
+    We have keys. Some enabled, some disabled.
+    Don't check for any non-unique disabled but return directly 2
+  */
+  return 2;
 }
 

--- 1.327/sql/sql_table.cc	2006-12-01 16:21:04 +01:00
+++ 1.328/sql/sql_table.cc	2006-12-01 16:21:05 +01:00
@@ -37,7 +37,9 @@ static char *make_unique_key_name(const 
 static int copy_data_between_tables(TABLE *from,TABLE *to,
                                     List<create_field> &create, bool ignore,
 				    uint order_num, ORDER *order,
-				    ha_rows *copied,ha_rows *deleted);
+				    ha_rows *copied,ha_rows *deleted,
+                                    enum enum_enable_or_disable keys_onoff);
+
 static bool prepare_blob_field(THD *thd, create_field *sql_field);
 static bool check_engine(THD *thd, const char *table_name,
                          enum db_type *new_engine);                             
@@ -2934,6 +2936,54 @@ err:
 
 
 /*
+  Manages enabling/disabling of indexes for ALTER TABLE
+
+  SYNOPSIS
+    alter_table_manage_keys()
+      table                  Target table
+      indexes_were_disabled  Whether the indexes of the from table
+                             were disabled
+      keys_onoff             ENABLE | DISABLE | LEAVE_AS_IS
+
+  RETURN VALUES
+    FALSE  OK
+    TRUE   Error
+*/
+
+static
+bool alter_table_manage_keys(TABLE *table, int indexes_were_disabled,
+                             enum enum_enable_or_disable keys_onoff)
+{
+  int error= 0;
+  DBUG_ENTER("alter_table_manage_keys");
+  DBUG_PRINT("enter", ("table=%p were_disabled=%d on_off=%d",
+             table, indexes_were_disabled, keys_onoff));
+
+  switch (keys_onoff) {
+  case ENABLE:
+    error= table->file->enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
+    break;
+  case LEAVE_AS_IS:
+    if (!indexes_were_disabled)
+      break;
+    /* fall-through: disabled indexes */
+  case DISABLE:
+    error= table->file->disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
+  }
+
+  if (error == HA_ERR_WRONG_COMMAND)
+  {
+    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+                        ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA), table->s->table_name);
+    error= 0;
+  } else if (error)
+    table->file->print_error(error, MYF(0));
+
+  DBUG_RETURN(error);
+}
+
+
+/*
   Alter table
 */
 
@@ -3586,8 +3636,20 @@ view_err:
     new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
     new_table->next_number_field=new_table->found_next_number_field;
     error=copy_data_between_tables(table, new_table, create_list, ignore,
-				   order_num, order, &copied, &deleted);
+				   order_num, order, &copied, &deleted,
+                                   alter_info->keys_onoff);
   }
+  else if (!new_table)
+  {
+    VOID(pthread_mutex_lock(&LOCK_open));
+    wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
+    table->file->external_lock(thd, F_WRLCK);
+    alter_table_manage_keys(table, table->file->indexes_are_disabled(),
+                            alter_info->keys_onoff);
+    table->file->external_lock(thd, F_UNLCK);
+    VOID(pthread_mutex_unlock(&LOCK_open));
+  }
+
   thd->last_insert_id=next_insert_id;		// Needed for correct log
   thd->count_cuted_fields= CHECK_FIELD_IGNORE;
 
@@ -3815,7 +3877,8 @@ copy_data_between_tables(TABLE *from,TAB
                          bool ignore,
 			 uint order_num, ORDER *order,
 			 ha_rows *copied,
-			 ha_rows *deleted)
+			 ha_rows *deleted,
+                         enum enum_enable_or_disable keys_onoff)
 {
   int error;
   Copy_field *copy,*copy_end;
@@ -3847,6 +3910,9 @@ copy_data_between_tables(TABLE *from,TAB
 
   if (to->file->external_lock(thd, F_WRLCK))
     DBUG_RETURN(-1);
+
+  /* We need external lock before we can disable/enable keys */
+  alter_table_manage_keys(to, from->file->indexes_are_disabled(), keys_onoff);
 
   /* We can abort alter table for any table type */
   thd->no_trans_update= 0;
Thread
bk commit into 5.0 tree (andrey:1.2358)ahristov1 Dec