List:Commits« Previous MessageNext Message »
From:konstantin Date:August 14 2007 2:14pm
Subject:bk commit into 5.1 tree (kostja:1.2547)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of kostja. When kostja 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, 2007-08-14 18:14:05+04:00, kostja@bodhi.(none) +18 -0
  Manual resolve of the merge of ONLINE ALTER TABLE patch with the
  latest tree - a preview. Passes the compiler test. Two known bugs will 
  prevent this code from passing the test suite. 

  sql/field.cc@stripped, 2007-08-14 18:14:00+04:00, kostja@bodhi.(none) +13 -17
    Manual merge.

  sql/field.h@stripped, 2007-08-14 18:14:00+04:00, kostja@bodhi.(none) +2 -2
    Manual merge.

  sql/ha_ndbcluster.cc@stripped, 2007-08-14 18:14:00+04:00, kostja@bodhi.(none) +3 -3
    Manual merge.

  sql/ha_ndbcluster_binlog.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +2 -2
    Manual merge.

  sql/log.cc@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +1 -1
    Manual merge.

  sql/log.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +3 -3
    Manual merge.

  sql/log_event.cc@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +10 -9
    Manual merge.

  sql/log_event.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +2 -3
    Manual merge.

  sql/mysql_priv.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +1 -1
    Manual merge.

  sql/rpl_rli.cc@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +25 -25
    Manual merge.

  sql/rpl_rli.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +7 -6
    Manual merge.

  sql/rpl_utility.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +4 -4
    Manual merge.

  sql/slave.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +3 -3
    Manual merge.

  sql/sql_class.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +1 -2
    Manual merge.

  sql/sql_lex.cc@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +1 -1
    Manual merge.

  sql/sql_lex.h@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +4 -10
    Manual merge.

  sql/sql_table.cc@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +141 -2299
    Manual merge.

  sql/table.cc@stripped, 2007-08-14 18:14:01+04:00, kostja@bodhi.(none) +1 -1
    Manual merge.

diff -Nrup a/sql/field.cc b/sql/field.cc
--- a/sql/field.cc	2007-08-10 19:18:09 +04:00
+++ b/sql/field.cc	2007-08-14 18:14:00 +04:00
@@ -1372,7 +1372,8 @@ bool Field::send_binary(Protocol *protoc
 
    @return  New pointer into memory based on from + length of the data
 */
-const char *Field::unpack(char* to, const char *from, uint param_data)
+const uchar *
+Field::unpack(uchar *to, const uchar *from, uint param_data)
 {
   uint length=pack_length();
   int from_type= 0;
@@ -2697,9 +2698,8 @@ uint Field_new_decimal::is_equal(Create_
 
    @return  New pointer into memory based on from + length of the data
 */
-const char *Field_new_decimal::unpack(char* to, 
-                                      const char *from, 
-                                      uint param_data)
+const uchar *
+Field_new_decimal::unpack(uchar* to, const uchar *from, uint param_data)
 {
   uint from_precision= (param_data & 0xff00) >> 8U;
   uint from_decimal= param_data & 0x00ff;
@@ -2723,7 +2723,7 @@ const char *Field_new_decimal::unpack(ch
       just the first step the resizing operation. The second step does the
       resizing using the precision and decimals from the slave.
     */
-    bin2decimal((char *)from, &dec, from_precision, from_decimal);
+    bin2decimal((uchar *)from, &dec, from_precision, from_decimal);
     decimal2bin(&dec, to, precision, decimals());
   }
   else
@@ -6395,8 +6395,7 @@ uchar *Field_string::pack(uchar *to, con
 
    @return  New pointer into memory based on from + length of the data
 */
-const uchar *Field_string::unpack(char *to,
-                                  const uchar *from,
+const uchar *Field_string::unpack(uchar *to, const uchar *from,
                                   uint param_data)
 {
   uint from_len= param_data & 0x00ff;                 // length.
@@ -6406,7 +6405,7 @@ const uchar *Field_string::unpack(char *
   DBUG_ASSERT(f_length <= 255);
   length= (uint) *from++;
   bitmap_set_bit(table->write_set,field_index);
-  store(from, length, system_charset_info);
+  store((char*) from, length, system_charset_info);
   return from+length;
 }
 
@@ -6918,9 +6917,8 @@ uchar *Field_varstring::pack_key_from_ke
 
    @return  New pointer into memory based on from + length of the data
 */
-const char *Field_varstring::unpack(char *to, 
-                                    const char *from,
-                                    uint param_data)
+const uchar *
+Field_varstring::unpack(uchar *to, const uchar *from, uint param_data)
 {
   uint length;
   uint l_bytes= (param_data && (param_data < field_length)) ? 
@@ -7655,9 +7653,8 @@ uchar *Field_blob::pack(uchar *to, const
 
    @return  New pointer into memory based on from + length of the data
 */
-const uchar *Field_blob::unpack(char *to,
-                                const uchar *from,
-                                uint param_data)
+const uchar *
+Field_blob::unpack(uchar *to, const uchar *from, uint param_data)
 {
   return unpack(to, from);
 }
@@ -8722,9 +8719,8 @@ uchar *Field_bit::pack(uchar *to, const 
 
    @return  New pointer into memory based on from + length of the data
 */
-const char *Field_bit::unpack(char *to,
-                              const char *from,
-                              uint param_data)
+const uchar *
+Field_bit::unpack(uchar *to, const uchar *from, uint param_data)
 {
   uint const from_len= (param_data >> 8U) & 0x00ff;
   uint const from_bit_len= param_data & 0x00ff;
diff -Nrup a/sql/field.h b/sql/field.h
--- a/sql/field.h	2007-08-10 19:18:09 +04:00
+++ b/sql/field.h	2007-08-14 18:14:00 +04:00
@@ -1319,7 +1319,7 @@ public:
     }
   }
   Field_blob(uint32 packlength_arg)
-    :Field_longstr((char*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
+    :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
     packlength(packlength_arg) {}
   enum_field_types type() const { return MYSQL_TYPE_BLOB;}
   enum ha_base_keytype key_type() const
@@ -1378,7 +1378,7 @@ public:
      @retval The length in the row plus the size of the data.
   */
   uint32 get_packed_size(const uchar *ptr)
-    { return packlength + get_length((const char *)ptr); }
+    { return packlength + get_length((const uchar*)ptr); }
 
   inline uint32 get_length(uint row_offset=0)
   { return get_length(ptr+row_offset); }
diff -Nrup a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
--- a/sql/ha_ndbcluster.cc	2007-08-10 19:18:09 +04:00
+++ b/sql/ha_ndbcluster.cc	2007-08-14 18:14:00 +04:00
@@ -11043,7 +11043,7 @@ int ha_ndbcluster::alter_table_phase1(TH
 
 int ha_ndbcluster::alter_frm(const char *file, NDB_ALTER_DATA *alter_data)
 {
-  const void *data= NULL, *pack_data= NULL;
+  uchar *data= NULL, *pack_data= NULL;
   uint length, pack_length;
   int error= 0;
 
@@ -11061,8 +11061,8 @@ int ha_ndbcluster::alter_frm(const char 
       packfrm(data, length, &pack_data, &pack_length))
   {
     DBUG_PRINT("info", ("Missing frm for %s", m_tabname));
-    my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
-    my_free((char*)pack_data, MYF(MY_ALLOW_ZERO_PTR));
+    my_free(data, MYF(MY_ALLOW_ZERO_PTR));
+    my_free(pack_data, MYF(MY_ALLOW_ZERO_PTR));
     error= 1;
   }
   else
diff -Nrup a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h
--- a/sql/ha_ndbcluster_binlog.h	2007-08-10 18:19:10 +04:00
+++ b/sql/ha_ndbcluster_binlog.h	2007-08-14 18:14:01 +04:00
@@ -48,8 +48,8 @@ public:
   ~Ndb_event_data()
   {
     share= 0;
-    my_free((gptr) ndb_value[0], MYF(MY_WME));
-    my_free((gptr) ndb_value[1], MYF(MY_WME));
+    my_free(ndb_value[0], MYF(MY_WME));
+    my_free(ndb_value[1], MYF(MY_WME));
   }
   NDB_SHARE *share;
   NdbValue *ndb_value[2];
diff -Nrup a/sql/log.cc b/sql/log.cc
--- a/sql/log.cc	2007-06-15 21:36:14 +04:00
+++ b/sql/log.cc	2007-08-14 18:14:01 +04:00
@@ -2883,7 +2883,7 @@ err:
 
 #ifdef HAVE_REPLICATION
 
-int MYSQL_BIN_LOG::purge_first_log(struct st_relay_log_info* rli, bool included) 
+int MYSQL_BIN_LOG::purge_first_log(RELAY_LOG_INFO *rli, bool included)
 {
   int error;
   DBUG_ENTER("purge_first_log");
diff -Nrup a/sql/log.h b/sql/log.h
--- a/sql/log.h	2007-06-17 08:56:31 +04:00
+++ b/sql/log.h	2007-08-14 18:14:01 +04:00
@@ -16,7 +16,7 @@
 #ifndef LOG_H
 #define LOG_H
 
-struct st_relay_log_info;
+struct RELAY_LOG_INFO;
 
 class Format_description_log_event;
 
@@ -121,7 +121,7 @@ extern TC_LOG_DUMMY tc_log_dummy;
 #define LOG_CLOSE_TO_BE_OPENED	2
 #define LOG_CLOSE_STOP_EVENT	4
 
-struct st_relay_log_info;
+struct RELAY_LOG_INFO;
 
 typedef struct st_log_info
 {
@@ -361,7 +361,7 @@ public:
                  bool need_mutex, bool need_update_threads,
                  ulonglong *decrease_log_space);
   int purge_logs_before_date(time_t purge_time);
-  int purge_first_log(struct st_relay_log_info* rli, bool included);
+  int purge_first_log(RELAY_LOG_INFO *rli, bool included);
   bool reset_logs(THD* thd);
   void close(uint exiting);
 
diff -Nrup a/sql/log_event.cc b/sql/log_event.cc
--- a/sql/log_event.cc	2007-08-10 19:18:09 +04:00
+++ b/sql/log_event.cc	2007-08-14 18:14:01 +04:00
@@ -6604,7 +6604,8 @@ Table_map_log_event::Table_map_log_event
   */
   uint num_null_bytes= (m_table->s->fields + 7) / 8;
   m_data_size+= num_null_bytes;
-  m_meta_memory= my_multi_malloc(MYF(MY_WME),
+  m_meta_memory= (uchar*)
+                 my_multi_malloc(MYF(MY_WME),
                                  &m_null_bits, num_null_bytes,
                                  &m_field_metadata, m_field_metadata_size,
                                  NULL);
@@ -6714,7 +6715,8 @@ Table_map_log_event::Table_map_log_event
     {
       m_field_metadata_size= net_field_length(&ptr_after_colcnt);
       uint num_null_bytes= (m_colcnt + 7) / 8;
-      m_meta_memory= my_multi_malloc(MYF(MY_WME),
+      m_meta_memory= (uchar*)
+                     my_multi_malloc(MYF(MY_WME),
                                      &m_null_bits, num_null_bytes,
                                      &m_field_metadata, m_field_metadata_size,
                                      NULL);
@@ -6942,13 +6944,12 @@ bool Table_map_log_event::write_data_bod
   return (my_b_safe_write(file, dbuf,      sizeof(dbuf)) ||
           my_b_safe_write(file, (const uchar*)m_dbnam,   m_dblen+1) ||
           my_b_safe_write(file, tbuf,      sizeof(tbuf)) ||
-          my_b_safe_write(file, (const byte*)m_tblnam,  m_tbllen+1) ||
-          my_b_safe_write(file, reinterpret_cast<byte*>(cbuf),
-                          cbuf_end - (char*) cbuf) ||
-          my_b_safe_write(file, reinterpret_cast<byte*>(m_coltype), m_colcnt) ||
-          my_b_safe_write(file, reinterpret_cast<byte*>(mbuf), (size_t) (mbuf_end - mbuf)) ||
-          my_b_safe_write(file, reinterpret_cast<byte*>(m_field_metadata), m_field_metadata_size),
-          my_b_safe_write(file, reinterpret_cast<byte*>(m_null_bits), (m_colcnt + 7) / 8));
+          my_b_safe_write(file, (uchar*) m_tblnam,  m_tbllen+1) ||
+          my_b_safe_write(file, cbuf, cbuf_end - cbuf) ||
+          my_b_safe_write(file, m_coltype, m_colcnt) ||
+          my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
+          my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
+          my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
  }
 #endif
 
diff -Nrup a/sql/log_event.h b/sql/log_event.h
--- a/sql/log_event.h	2007-08-10 19:18:10 +04:00
+++ b/sql/log_event.h	2007-08-14 18:14:01 +04:00
@@ -521,8 +521,7 @@ class THD;
 
 class Format_description_log_event;
 
-struct st_relay_log_info;
-typedef st_relay_log_info RELAY_LOG_INFO;
+struct RELAY_LOG_INFO;
 
 #ifdef MYSQL_CLIENT
 /*
@@ -2094,7 +2093,7 @@ private:
   */
   ulong         m_field_metadata_size;
   uchar        *m_null_bits;
-  gptr          m_meta_memory;
+  uchar        *m_meta_memory;
 };
 
 
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h	2007-08-10 19:18:10 +04:00
+++ b/sql/mysql_priv.h	2007-08-14 18:14:01 +04:00
@@ -238,7 +238,7 @@ enum open_table_mode
 { OTM_OPEN= 0,
   OTM_CREATE= 1,
   OTM_ALTER= 2
-}
+};
 
 /***************************************************************************
   Configuration parameters
diff -Nrup a/sql/rpl_rli.cc b/sql/rpl_rli.cc
--- a/sql/rpl_rli.cc	2007-06-09 10:29:43 +04:00
+++ b/sql/rpl_rli.cc	2007-08-14 18:14:01 +04:00
@@ -29,7 +29,7 @@ int init_strvar_from_file(char *var, int
 			  const char *default_val);
 
 
-st_relay_log_info::st_relay_log_info()
+RELAY_LOG_INFO::RELAY_LOG_INFO()
   :Slave_reporting_capability("SQL"),
    no_storage(FALSE), replicate_same_server_id(::replicate_same_server_id),
    info_fd(-1), cur_log_fd(-1), save_temporary_tables(0),
@@ -41,7 +41,7 @@ st_relay_log_info::st_relay_log_info()
    tables_to_lock(0), tables_to_lock_count(0),
    last_event_start_time(0), m_flags(0)
 {
-  DBUG_ENTER("st_relay_log_info::st_relay_log_info");
+  DBUG_ENTER("RELAY_LOG_INFO::RELAY_LOG_INFO");
 
   group_relay_log_name[0]= event_relay_log_name[0]=
     group_master_log_name[0]= 0;
@@ -61,9 +61,9 @@ st_relay_log_info::st_relay_log_info()
 }
 
 
-st_relay_log_info::~st_relay_log_info()
+RELAY_LOG_INFO::~RELAY_LOG_INFO()
 {
-  DBUG_ENTER("st_relay_log_info::~st_relay_log_info");
+  DBUG_ENTER("RELAY_LOG_INFO::~RELAY_LOG_INFO");
 
   pthread_mutex_destroy(&run_lock);
   pthread_mutex_destroy(&data_lock);
@@ -346,7 +346,7 @@ static int count_relay_log_space(RELAY_L
       rli - RELAY_LOG_INFO structure where UNTIL condition should be reset
  */
 
-void st_relay_log_info::clear_until_condition()
+void RELAY_LOG_INFO::clear_until_condition()
 {
   DBUG_ENTER("clear_until_condition");
 
@@ -599,16 +599,16 @@ err:
                 before reaching the desired log/position
  */
 
-int st_relay_log_info::wait_for_pos(THD* thd, String* log_name,
-                                    longlong log_pos,
-                                    longlong timeout)
+int RELAY_LOG_INFO::wait_for_pos(THD* thd, String* log_name,
+                                 longlong log_pos,
+                                 longlong timeout)
 {
   int event_count = 0;
   ulong init_abort_pos_wait;
   int error=0;
   struct timespec abstime; // for timeout checking
   const char *msg;
-  DBUG_ENTER("st_relay_log_info::wait_for_pos");
+  DBUG_ENTER("RELAY_LOG_INFO::wait_for_pos");
 
   if (!inited)
     DBUG_RETURN(-1);
@@ -779,10 +779,10 @@ improper_arguments: %d  timed_out: %d",
 }
 
 
-void st_relay_log_info::inc_group_relay_log_pos(ulonglong log_pos,
+void RELAY_LOG_INFO::inc_group_relay_log_pos(ulonglong log_pos,
                                                 bool skip_lock)
 {
-  DBUG_ENTER("st_relay_log_info::inc_group_relay_log_pos");
+  DBUG_ENTER("RELAY_LOG_INFO::inc_group_relay_log_pos");
 
   if (!skip_lock)
     pthread_mutex_lock(&data_lock);
@@ -836,10 +836,10 @@ void st_relay_log_info::inc_group_relay_
 }
 
 
-void st_relay_log_info::close_temporary_tables()
+void RELAY_LOG_INFO::close_temporary_tables()
 {
   TABLE *table,*next;
-  DBUG_ENTER("st_relay_log_info::close_temporary_tables");
+  DBUG_ENTER("RELAY_LOG_INFO::close_temporary_tables");
 
   for (table=save_temporary_tables ; table ; table=next)
   {
@@ -950,12 +950,12 @@ err:
 /*
      Check if condition stated in UNTIL clause of START SLAVE is reached.
    SYNOPSYS
-     st_relay_log_info::is_until_satisfied()
+     RELAY_LOG_INFO::is_until_satisfied()
    DESCRIPTION
      Checks if UNTIL condition is reached. Uses caching result of last
      comparison of current log file name and target log file name. So cached
      value should be invalidated if current log file name changes
-     (see st_relay_log_info::notify_... functions).
+     (see RELAY_LOG_INFO::notify_... functions).
 
      This caching is needed to avoid of expensive string comparisons and
      strtol() conversions needed for log names comparison. We don't need to
@@ -975,11 +975,11 @@ err:
      false - condition not met
 */
 
-bool st_relay_log_info::is_until_satisfied()
+bool RELAY_LOG_INFO::is_until_satisfied()
 {
   const char *log_name;
   ulonglong log_pos;
-  DBUG_ENTER("st_relay_log_info::is_until_satisfied");
+  DBUG_ENTER("RELAY_LOG_INFO::is_until_satisfied");
 
   DBUG_ASSERT(until_condition != UNTIL_NONE);
 
@@ -1055,9 +1055,9 @@ bool st_relay_log_info::is_until_satisfi
 }
 
 
-void st_relay_log_info::cached_charset_invalidate()
+void RELAY_LOG_INFO::cached_charset_invalidate()
 {
-  DBUG_ENTER("st_relay_log_info::cached_charset_invalidate");
+  DBUG_ENTER("RELAY_LOG_INFO::cached_charset_invalidate");
 
   /* Full of zeroes means uninitialized. */
   bzero(cached_charset, sizeof(cached_charset));
@@ -1065,9 +1065,9 @@ void st_relay_log_info::cached_charset_i
 }
 
 
-bool st_relay_log_info::cached_charset_compare(char *charset) const
+bool RELAY_LOG_INFO::cached_charset_compare(char *charset) const
 {
-  DBUG_ENTER("st_relay_log_info::cached_charset_compare");
+  DBUG_ENTER("RELAY_LOG_INFO::cached_charset_compare");
 
   if (bcmp((uchar*) cached_charset, (uchar*) charset,
            sizeof(cached_charset)))
@@ -1079,7 +1079,7 @@ bool st_relay_log_info::cached_charset_c
 }
 
 
-void st_relay_log_info::stmt_done(my_off_t event_master_log_pos,
+void RELAY_LOG_INFO::stmt_done(my_off_t event_master_log_pos,
                                   time_t event_creation_time)
 {
   clear_flag(IN_STMT);
@@ -1126,9 +1126,9 @@ void st_relay_log_info::stmt_done(my_off
 }
 
 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
-void st_relay_log_info::cleanup_context(THD *thd, bool error)
+void RELAY_LOG_INFO::cleanup_context(THD *thd, bool error)
 {
-  DBUG_ENTER("st_relay_log_info::cleanup_context");
+  DBUG_ENTER("RELAY_LOG_INFO::cleanup_context");
 
   DBUG_ASSERT(sql_thd == thd);
   /*
@@ -1156,7 +1156,7 @@ void st_relay_log_info::cleanup_context(
   DBUG_VOID_RETURN;
 }
 
-void st_relay_log_info::clear_tables_to_lock()
+void RELAY_LOG_INFO::clear_tables_to_lock()
 {
   while (tables_to_lock)
   {
diff -Nrup a/sql/rpl_rli.h b/sql/rpl_rli.h
--- a/sql/rpl_rli.h	2007-08-10 19:18:10 +04:00
+++ b/sql/rpl_rli.h	2007-08-14 18:14:01 +04:00
@@ -17,6 +17,7 @@
 #define RPL_RLI_H
 
 #include "rpl_tblmap.h"
+#include "rpl_utility.h"
 #include "rpl_reporting.h"
 
 struct RPL_TABLE_LIST;
@@ -26,14 +27,14 @@ struct RPL_TABLE_LIST;
 
   Replication SQL Thread
 
-  st_relay_log_info contains:
+  RELAY_LOG_INFO contains:
     - the current relay log
     - the current relay log offset
     - master log name
     - master log sequence corresponding to the last update
     - misc information specific to the SQL thread
 
-  st_relay_log_info is initialized from the slave.info file if such exists.
+  RELAY_LOG_INFO is initialized from the slave.info file if such exists.
   Otherwise, data members are intialized with defaults. The initialization is
   done with init_relay_log_info() call.
 
@@ -48,7 +49,7 @@ struct RPL_TABLE_LIST;
 
 *****************************************************************************/
 
-typedef struct st_relay_log_info : public Slave_reporting_capability
+struct RELAY_LOG_INFO: public Slave_reporting_capability
 {
   /**
      Flags for the state of the replication.
@@ -254,8 +255,8 @@ typedef struct st_relay_log_info : publi
   char ign_master_log_name_end[FN_REFLEN];
   ulonglong ign_master_log_pos_end;
 
-  st_relay_log_info();
-  ~st_relay_log_info();
+  RELAY_LOG_INFO();
+  ~RELAY_LOG_INFO();
 
   /*
     Invalidate cached until_log_name and group_relay_log_name comparison 
@@ -390,7 +391,7 @@ typedef struct st_relay_log_info : publi
 
 private:
   uint32 m_flags;
-} RELAY_LOG_INFO;
+};
 
 
 // Defined in rpl_rli.cc
diff -Nrup a/sql/rpl_utility.h b/sql/rpl_utility.h
--- a/sql/rpl_utility.h	2007-08-10 19:18:10 +04:00
+++ b/sql/rpl_utility.h	2007-08-14 18:14:01 +04:00
@@ -23,8 +23,7 @@
 #include "mysql_priv.h"
 #include "my_bitmap.h"
 
-struct st_relay_log_info;
-typedef st_relay_log_info RELAY_LOG_INFO;
+struct RELAY_LOG_INFO;
 
 /**
   A table definition from the master.
@@ -64,7 +63,8 @@ public:
     : m_size(size), m_type(0),
       m_field_metadata(0), m_null_bits(0), m_memory(NULL)
   {
-    m_memory= my_multi_malloc(MYF(MY_WME),
+    m_memory= (uchar*)
+              my_multi_malloc(MYF(MY_WME),
                               &m_type, size,
                               &m_field_metadata, size * sizeof(short),
                               &m_null_bits, (m_size + 7) / 8,
@@ -239,7 +239,7 @@ private:
   field_type *m_type;                     // Array of type descriptors
   short int *m_field_metadata;
   uchar *m_null_bits;
-  gptr m_memory;
+  uchar *m_memory;
 };
 
 /**
diff -Nrup a/sql/slave.h b/sql/slave.h
--- a/sql/slave.h	2007-06-09 10:29:44 +04:00
+++ b/sql/slave.h	2007-08-14 18:14:01 +04:00
@@ -28,9 +28,9 @@
 #define MAX_SLAVE_ERROR    2000
 
 
-// Forward declarations
-struct st_relay_log_info;
-typedef st_relay_log_info RELAY_LOG_INFO;
+/************************** Forward declarations ****************************/
+
+struct RELAY_LOG_INFO;
 
 class MASTER_INFO;
 
diff -Nrup a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h	2007-07-02 02:03:22 +04:00
+++ b/sql/sql_class.h	2007-08-14 18:14:01 +04:00
@@ -23,8 +23,7 @@
 #include "log.h"
 #include "rpl_tblmap.h"
 
-struct st_relay_log_info;
-typedef st_relay_log_info RELAY_LOG_INFO;
+struct RELAY_LOG_INFO;
 
 class Query_log_event;
 class Load_log_event;
diff -Nrup a/sql/sql_lex.cc b/sql/sql_lex.cc
--- a/sql/sql_lex.cc	2007-06-29 17:59:17 +04:00
+++ b/sql/sql_lex.cc	2007-08-14 18:14:01 +04:00
@@ -1406,7 +1406,7 @@ Alter_info::Alter_info(const Alter_info 
   tablespace_op(rhs.tablespace_op),
   partition_names(rhs.partition_names, mem_root),
   no_parts(rhs.no_parts),
-  change_level(rhs.change_level),
+  force_offline_alter(force_offline_alter),
   datetime_field(rhs.datetime_field),
   error_if_not_empty(rhs.error_if_not_empty)
 {
diff -Nrup a/sql/sql_lex.h b/sql/sql_lex.h
--- a/sql/sql_lex.h	2007-08-10 18:19:12 +04:00
+++ b/sql/sql_lex.h	2007-08-14 18:14:01 +04:00
@@ -836,13 +836,6 @@ inline bool st_select_lex_unit::is_union
 #define ALTER_REMOVE_PARTITIONING (1L << 30)
 #define ALTER_FOREIGN_KEY         (1L << 31)
 
-enum enum_alter_table_change_level
-{
-  ALTER_TABLE_METADATA_ONLY= 0,
-  ALTER_TABLE_DATA_CHANGED= 1,
-  ALTER_TABLE_INDEX_CHANGED= 2
-};
-
 /**
   @brief Parsing data for CREATE or ALTER TABLE.
 
@@ -862,7 +855,8 @@ public:
   enum tablespace_op_type       tablespace_op;
   List<char>                    partition_names;
   uint                          no_parts;
-  enum_alter_table_change_level change_level;
+  /** TRUE if we want to override ONLINE ALTER TABLE capability */
+  bool                          force_offline_alter;
   Create_field                 *datetime_field;
   bool                          error_if_not_empty;  
     
@@ -872,7 +866,7 @@ public:
     keys_onoff(LEAVE_AS_IS),
     tablespace_op(NO_TABLESPACE_OP),
     no_parts(0),
-    change_level(ALTER_TABLE_METADATA_ONLY),
+    force_offline_alter(FALSE),
     datetime_field(NULL),
     error_if_not_empty(FALSE)
   {}
@@ -888,7 +882,7 @@ public:
     tablespace_op= NO_TABLESPACE_OP;
     no_parts= 0;
     partition_names.empty();
-    change_level= ALTER_TABLE_METADATA_ONLY;
+    force_offline_alter= FALSE;
     datetime_field= 0;
     error_if_not_empty= FALSE;
   }
diff -Nrup a/sql/sql_table.cc b/sql/sql_table.cc
--- a/sql/sql_table.cc	2007-08-10 19:18:10 +04:00
+++ b/sql/sql_table.cc	2007-08-14 18:14:01 +04:00
@@ -229,214 +229,6 @@ uint build_tmptable_filename(THD* thd, c
 }
 
 /*
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  Return values for compare_tables().
-  If you make compare_tables() non-static, move them to a header file.
-*/
-#define ALTER_TABLE_DATA_CHANGED  1
-#define ALTER_TABLE_INDEX_CHANGED 2
-
-
-/*
-  SYNOPSIS
-    mysql_copy_create_list()
-    orig_create_list          Original list of created fields
-    inout::new_create_list    Copy of original list
-
-  RETURN VALUES
-    FALSE                     Success
-    TRUE                      Memory allocation error
-
-  DESCRIPTION
-    mysql_prepare_table destroys the create_list and in some cases we need
-    this lists for more purposes. Thus we copy it specifically for use
-    by mysql_prepare_table
-*/
-
-static int mysql_copy_create_list(List<create_field> *orig_create_list,
-                                  List<create_field> *new_create_list)
-{
-  List_iterator<create_field> prep_field_it(*orig_create_list);
-  create_field *prep_field;
-  DBUG_ENTER("mysql_copy_create_list");
-
-  while ((prep_field= prep_field_it++))
-  {
-    create_field *field= new create_field(*prep_field);
-    if (!field || new_create_list->push_back(field))
-    {
-      mem_alloc_error(2);
-      DBUG_RETURN(TRUE);
-    }
-  }
-  DBUG_RETURN(FALSE);
-}
-
-
-/*
-  SYNOPSIS
-    mysql_copy_key_list()
-    orig_key                  Original list of keys
-    inout::new_key            Copy of original list
-
-  RETURN VALUES
-    FALSE                     Success
-    TRUE                      Memory allocation error
-
-  DESCRIPTION
-    mysql_prepare_table destroys the key list and in some cases we need
-    this lists for more purposes. Thus we copy it specifically for use
-    by mysql_prepare_table
-*/
-
-static int mysql_copy_key_list(List<Key> *orig_key,
-                               List<Key> *new_key)
-{
-  List_iterator<Key> prep_key_it(*orig_key);
-  Key *prep_key;
-  DBUG_ENTER("mysql_copy_key_list");
-
-  while ((prep_key= prep_key_it++))
-  {
-    List<key_part_spec> prep_columns;
-    List_iterator<key_part_spec> prep_col_it(prep_key->columns);
-    key_part_spec *prep_col;
-    Key *temp_key;
-
-    while ((prep_col= prep_col_it++))
-    {
-      key_part_spec *prep_key_part;
-
-      if (!(prep_key_part= new key_part_spec(*prep_col)))
-      {
-        mem_alloc_error(sizeof(key_part_spec));
-        DBUG_RETURN(TRUE);
-      }
-      if (prep_columns.push_back(prep_key_part))
-      {
-        mem_alloc_error(2);
-        DBUG_RETURN(TRUE);
-      }
-    }
-    if (!(temp_key= new Key(prep_key->type, prep_key->name,
-                            &prep_key->key_create_info,
-                            prep_key->generated,
-                            prep_columns)))
-    {
-      mem_alloc_error(sizeof(Key));
-      DBUG_RETURN(TRUE);
-    }
-    if (new_key->push_back(temp_key))
-    {
-      mem_alloc_error(2);
-      DBUG_RETURN(TRUE);
-    }
-  }
-  DBUG_RETURN(FALSE);
-}
-
-/*
-<<<<<<< local sql/sql_table.cc 1.438
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-  SYNOPSIS
-    mysql_copy_create_list()
-    orig_create_list          Original list of created fields
-    inout::new_create_list    Copy of original list
-
-  RETURN VALUES
-    FALSE                     Success
-    TRUE                      Memory allocation error
-
-  DESCRIPTION
-    mysql_prepare_table destroys the create_list and in some cases we need
-    this lists for more purposes. Thus we copy it specifically for use
-    by mysql_prepare_table
-*/
-
-static int mysql_copy_create_list(List<create_field> *orig_create_list,
-                                  List<create_field> *new_create_list)
-{
-  List_iterator<create_field> prep_field_it(*orig_create_list);
-  create_field *prep_field;
-  DBUG_ENTER("mysql_copy_create_list");
-
-  while ((prep_field= prep_field_it++))
-  {
-    create_field *field= new create_field(*prep_field);
-    if (!field || new_create_list->push_back(field))
-    {
-      mem_alloc_error(2);
-      DBUG_RETURN(TRUE);
-    }
-  }
-  DBUG_RETURN(FALSE);
-}
-
-
-/*
-  SYNOPSIS
-    mysql_copy_key_list()
-    orig_key                  Original list of keys
-    inout::new_key            Copy of original list
-
-  RETURN VALUES
-    FALSE                     Success
-    TRUE                      Memory allocation error
-
-  DESCRIPTION
-    mysql_prepare_table destroys the key list and in some cases we need
-    this lists for more purposes. Thus we copy it specifically for use
-    by mysql_prepare_table
-*/
-
-static int mysql_copy_key_list(List<Key> *orig_key,
-                               List<Key> *new_key)
-{
-  List_iterator<Key> prep_key_it(*orig_key);
-  Key *prep_key;
-  DBUG_ENTER("mysql_copy_key_list");
-
-  while ((prep_key= prep_key_it++))
-  {
-    List<key_part_spec> prep_columns;
-    List_iterator<key_part_spec> prep_col_it(prep_key->columns);
-    key_part_spec *prep_col;
-    Key *temp_key;
-
-    while ((prep_col= prep_col_it++))
-    {
-      key_part_spec *prep_key_part;
-
-      if (!(prep_key_part= new key_part_spec(*prep_col)))
-      {
-        mem_alloc_error(sizeof(key_part_spec));
-        DBUG_RETURN(TRUE);
-      }
-      if (prep_columns.push_back(prep_key_part))
-      {
-        mem_alloc_error(2);
-        DBUG_RETURN(TRUE);
-      }
-    }
-    if (!(temp_key= new Key(prep_key->type, prep_key->name,
-                            &prep_key->key_create_info,
-                            prep_key->generated,
-                            prep_columns)))
-    {
-      mem_alloc_error(sizeof(Key));
-      DBUG_RETURN(TRUE);
-    }
-    if (new_key->push_back(temp_key))
-    {
-      mem_alloc_error(2);
-      DBUG_RETURN(TRUE);
-    }
-  }
-  DBUG_RETURN(FALSE);
-}
-
-/*
->>>>>>>
 --------------------------------------------------------------------------
 
    MODULE: DDL log
@@ -5094,7 +4886,7 @@ err:
 /*
   Copy all changes detected by parser to the HA_ALTER_FLAGS
 */
-void setup_alter_table_flags(ALTER_INFO* alter_info,
+void setup_alter_table_flags(Alter_info *alter_info,
                              HA_ALTER_FLAGS *alter_flags)
 {
   uint flags= alter_info->flags;
@@ -5136,111 +4928,51 @@ void setup_alter_table_flags(ALTER_INFO*
     *alter_flags|= HA_ALTER_FOREIGN_KEY;
 }
 
-/*
-  SYNOPSIS
-    compare_tables()
-      thd                       Thread
-      table                     The original table.
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-      create_list               The fields for the new table.
-      key_info_buffer           An array of KEY structs for the new indexes.
-      key_count                 The number of elements in the array.
-<<<<<<< local sql/sql_table.cc 1.438
-      alter_info                Alter options, fields and keys for the new
-                                table.
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-      create_list               The fields for the new table.
->>>>>>>
-      create_info               Create options for the new table.
-      order_num                 Number of order list elements.
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-      index_drop_buffer   OUT   An array of offsets into table->key_info.
-      index_drop_count    OUT   The number of elements in the array.
-      index_add_buffer    OUT   An array of offsets into key_info_buffer.
-      index_add_count     OUT   The number of elements in the array.
-<<<<<<< local sql/sql_table.cc 1.438
-      need_copy_table     OUT   Result of the comparison. Undefined if error.
-                                Otherwise is one of:
-                                ALTER_TABLE_METADATA_ONLY  No copy needed
-                                ALTER_TABLE_DATA_CHANGED   Data changes,
-                                                           copy needed
-                                ALTER_TABLE_INDEX_CHANGED  Index changes,
-                                                           copy might be needed
-      key_info_buffer     OUT   An array of KEY structs for new indexes
-      index_drop_buffer   OUT   An array of offsets into table->key_info.
-      index_drop_count    OUT   The number of elements in the array.
-      index_add_buffer    OUT   An array of offsets into key_info_buffer.
-      index_add_count     OUT   The number of elements in the array.
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-      varchar                   Table contains varchar (to be removed?)
-      alter_table_flags   OUT   Flags that indicate what will be changed
-      alter_table_info    OUT   Data structures needed for on-line alter
-      table_changes       OUT   Information about particular change
->>>>>>>
 
-  DESCRIPTION
-    'table' (first argument) contains information of the original
-    table, which includes all corresponding parts that the new
-    table has in arguments create_list, key_list and create_info.
-
-    By comparing the changes between the original and new table
-    we can determine how much it has changed after ALTER TABLE
-    and whether we need to make a copy of the table, or just change
-    the .frm file.
+/**
+   @param       thd                Thread
+   @param       table              The original table.
+   @param       alter_info         Alter options, fields and keys for the new
+                                   table.
+   @param       create_info        Create options for the new table.
+   @param       order_num          Number of order list elements.
+   @param[out]  alter_table_flags  Flags that indicate what will be changed
+   @param[out]  ha_alter_info      Data structures needed for on-line alter
+   @param[out]  table_changes      Information about particular change
+
+   First argument 'table' contains information of the original
+   table, which includes all corresponding parts that the new
+   table has in arguments create_list, key_list and create_info.
+
+   By comparing the changes between the original and new table
+   we can determine how much it has changed after ALTER TABLE
+   and whether we need to make a copy of the table, or just change
+   the .frm file.
 
    Mark any changes detected in the alter_table_flags.
 
-    If there are no data changes, but index changes, 'index_drop_buffer'
-    and/or 'index_add_buffer' are populated with offsets into
-    table->key_info or key_info_buffer respectively for the indexes
-    that need to be dropped and/or (re-)created.
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-
-  RETURN VALUES
-    0                           No copy needed
-    ALTER_TABLE_DATA_CHANGED    Data changes, copy needed
-    ALTER_TABLE_INDEX_CHANGED   Index changes, copy might be needed
-<<<<<<< local sql/sql_table.cc 1.438
+   If there are no data changes, but index changes, 'index_drop_buffer'
+   and/or 'index_add_buffer' are populated with offsets into
+   table->key_info or key_info_buffer respectively for the indexes
+   that need to be dropped and/or (re-)created.
 
-  RETURN VALUES
-    TRUE   error
-    FALSE  success
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
->>>>>>>
+   @retval TRUE  error
+   @retval FALSE success
 */
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-static uint compare_tables(TABLE *table, List<create_field> *create_list,
-                           KEY *key_info_buffer, uint key_count,
-                           HA_CREATE_INFO *create_info,
-                           ALTER_INFO *alter_info, uint order_num,
-                           uint *index_drop_buffer, uint *index_drop_count,
-                           uint *index_add_buffer, uint *index_add_count,
-                           bool varchar)
-<<<<<<< local sql/sql_table.cc 1.438
 static
 bool
-compare_tables(TABLE *table,
+compare_tables(THD *thd,
+               TABLE *table,
                Alter_info *alter_info,
                HA_CREATE_INFO *create_info,
                uint order_num,
-               enum_alter_table_change_level *need_copy_table,
-               KEY **key_info_buffer,
-               uint **index_drop_buffer, uint *index_drop_count,
-               uint **index_add_buffer, uint *index_add_count)
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-static void compare_tables(THD *thd, TABLE *table,
-                           List<create_field> *create_list,
-                           HA_CREATE_INFO *create_info,
-                           ALTER_INFO *alter_info, uint order_num,
-                           bool varchar, HA_ALTER_FLAGS *alter_flags,
-                           HA_ALTER_INFO *alter_table_info,
-                           uint *table_changes)
->>>>>>>
+               HA_ALTER_FLAGS *alter_flags,
+               HA_ALTER_INFO *ha_alter_info,
+               uint *table_changes)
 {
   Field **f_ptr, *field;
-  uint tmp= 0;
-  uint key_count;
+  uint table_changes_local= 0;
   List_iterator_fast<Create_field> new_field_it(alter_info->create_list);
   Create_field *new_field;
   KEY_PART_INFO *key_part;
@@ -5276,15 +5008,17 @@ static void compare_tables(THD *thd, TAB
                                    &tmp_alter_info,
                                    (table->s->tmp_table != NO_TMP_TABLE),
                                    &db_options,
-                                   table->file, key_info_buffer,
-                                   &key_count, 0))
-      DBUG_RETURN(1);
+                                   table->file,
+                                   &ha_alter_info->key_info_buffer,
+                                   &ha_alter_info->key_count,
+                                   /* select_field_count */ 0))
+      DBUG_RETURN(TRUE);
     /* Allocate result buffers. */
-    if (! (*index_drop_buffer=
+    if (! (ha_alter_info->index_drop_buffer=
            (uint*) thd->alloc(sizeof(uint) * table->s->keys)) ||
-        ! (*index_add_buffer=
+        ! (ha_alter_info->index_add_buffer=
            (uint*) thd->alloc(sizeof(uint) * tmp_alter_info.key_list.elements)))
-      DBUG_RETURN(1);
+      DBUG_RETURN(TRUE);
   }
   /*
     First we setup alter_table_flags based on what was detected
@@ -5337,21 +5071,12 @@ static void compare_tables(THD *thd, TAB
       !table->s->mysql_version ||
       (table->s->frm_version < FRM_VER_TRUE_VARCHAR && varchar))
   {
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    DBUG_RETURN(ALTER_TABLE_DATA_CHANGED);
-
-<<<<<<< local sql/sql_table.cc 1.438
-    *need_copy_table= ALTER_TABLE_DATA_CHANGED;
-    DBUG_RETURN(0);
-  }
-
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
     /*
-       Check what has changed and set alter_flags
-     */
-    if (table->s->fields < create_list->elements)
+      Check what has changed and set alter_flags
+    */
+    if (table->s->fields < alter_info->create_list.elements)
       *alter_flags|= HA_ADD_COLUMN;
-    else if (table->s->fields > create_list->elements)
+    else if (table->s->fields > alter_info->create_list.elements)
       *alter_flags|= HA_DROP_COLUMN;
     if (create_info->db_type != table->s->db_type() ||
         create_info->used_fields & HA_CREATE_USED_ENGINE)
@@ -5369,7 +5094,6 @@ static void compare_tables(THD *thd, TAB
         (table->s->frm_version < FRM_VER_TRUE_VARCHAR && varchar))
       *alter_flags|=  HA_ALTER_COLUMN_TYPE;
   }
->>>>>>>
   /*
     Go through fields and check if the original ones are compatible
     with new table.
@@ -5382,23 +5106,6 @@ static void compare_tables(THD *thd, TAB
     if (!new_field->charset)
       new_field->charset= create_info->default_table_charset;
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    /* Check that NULL behavior is same for old and new fields */
-    if ((new_field->flags & NOT_NULL_FLAG) !=
-	(uint) (field->flags & NOT_NULL_FLAG))
-      DBUG_RETURN(ALTER_TABLE_DATA_CHANGED);
-
-<<<<<<< local sql/sql_table.cc 1.438
-    /* Check that NULL behavior is same for old and new fields */
-    if ((new_field->flags & NOT_NULL_FLAG) !=
-	(uint) (field->flags & NOT_NULL_FLAG))
-    {
-      *need_copy_table= ALTER_TABLE_DATA_CHANGED;
-      DBUG_RETURN(0);
-    }
-
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
->>>>>>>
     /* Don't pack rows in old tables if the user has requested this. */
     if (create_info->row_type == ROW_TYPE_DYNAMIC ||
         (new_field->flags & BLOB_FLAG) ||
@@ -5406,41 +5113,11 @@ static void compare_tables(THD *thd, TAB
         create_info->row_type != ROW_TYPE_FIXED)
       create_info->table_options|= HA_OPTION_PACK_RECORD;
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    /* Check if field was renamed */
-    field->flags&= ~FIELD_IS_RENAMED;
-    if (my_strcasecmp(system_charset_info,
-		      field->field_name,
-		      new_field->field_name))
-      field->flags|= FIELD_IS_RENAMED;      
-
-    /* Evaluate changes bitmap and send to check_if_incompatible_data() */
-    if (!(tmp= field->is_equal(new_field)))
-      DBUG_RETURN(ALTER_TABLE_DATA_CHANGED);
-    // Clear indexed marker
-<<<<<<< local sql/sql_table.cc 1.438
-    /* Check if field was renamed */
-    field->flags&= ~FIELD_IS_RENAMED;
-    if (my_strcasecmp(system_charset_info,
-		      field->field_name,
-		      new_field->field_name))
-      field->flags|= FIELD_IS_RENAMED;      
-
-    /* Evaluate changes bitmap and send to check_if_incompatible_data() */
-    if (!(tmp= field->is_equal(new_field)))
-    {
-      *need_copy_table= ALTER_TABLE_DATA_CHANGED;
-      DBUG_RETURN(0);
-    }
-    // Clear indexed marker
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-    /*
-      Check how fields have been modified
-    */
+    /* Check how fields have been modified */
     if (alter_info->flags & ALTER_CHANGE_COLUMN)
     {
       /* Evaluate changes bitmap and send to check_if_incompatible_data() */
-      if (!(tmp= field->is_equal(new_field)))
+      if (!(table_changes_local= field->is_equal(new_field)))
         *alter_flags|= HA_ALTER_COLUMN_TYPE;
 
       /* Check if field was renamed */
@@ -5453,8 +5130,8 @@ static void compare_tables(THD *thd, TAB
         *alter_flags|= HA_ALTER_COLUMN_NAME;
       }
 
-      *table_changes|= tmp;
-      if (tmp == IS_EQUAL_PACK_LENGTH)
+      *table_changes|= table_changes_local;
+      if (table_changes_local == IS_EQUAL_PACK_LENGTH)
         *alter_flags|= HA_ALTER_COLUMN_TYPE;
 
       /* Check that NULL behavior is same for old and new fields */
@@ -5464,41 +5141,26 @@ static void compare_tables(THD *thd, TAB
     }
 
     /* Clear indexed marker */
->>>>>>>
     field->flags&= ~FIELD_IN_ADD_INDEX;
   }
 
   /*
-    Go through any extra fields found
-  */
-  for (; new_field; new_field= new_field_it++)
-  {
-// ?
-  }
-
-  /*
     Go through keys and check if the original ones are compatible
     with new table.
   */
   KEY *table_key;
   KEY *table_key_end= table->key_info + table->s->keys;
   KEY *new_key;
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  KEY *new_key_end= key_info_buffer + key_count;
-<<<<<<< local sql/sql_table.cc 1.438
-  KEY *new_key_end= *key_info_buffer + key_count;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
   KEY *new_key_end=
-       alter_table_info->key_info_buffer + alter_table_info->key_count;
->>>>>>>
+       ha_alter_info->key_info_buffer + ha_alter_info->key_count;
 
   DBUG_PRINT("info", ("index count old: %d  new: %d",
-                      table->s->keys, alter_table_info->key_count));
+                      table->s->keys, ha_alter_info->key_count));
   /*
     Step through all keys of the old table and search matching new keys.
   */
-  alter_table_info->index_drop_count= 0;
-  alter_table_info->index_add_count= 0;
+  ha_alter_info->index_drop_count= 0;
+  ha_alter_info->index_add_count= 0;
   for (table_key= table->key_info; table_key < table_key_end; table_key++)
   {
     KEY_PART_INFO *table_part;
@@ -5506,15 +5168,9 @@ static void compare_tables(THD *thd, TAB
     KEY_PART_INFO *new_part;
 
     /* Search a new key with the same name. */
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    for (new_key= key_info_buffer; new_key < new_key_end; new_key++)
-<<<<<<< local sql/sql_table.cc 1.438
-    for (new_key= *key_info_buffer; new_key < new_key_end; new_key++)
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-    for (new_key= alter_table_info->key_info_buffer;
+    for (new_key= ha_alter_info->key_info_buffer;
          new_key < new_key_end;
          new_key++)
->>>>>>>
     {
       if (! strcmp(table_key->name, new_key->name))
         break;
@@ -5522,13 +5178,8 @@ static void compare_tables(THD *thd, TAB
     if (new_key >= new_key_end)
     {
       /* Key not found. Add the offset of the key to the drop buffer. */
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-      index_drop_buffer[(*index_drop_count)++]= table_key - table->key_info;
-<<<<<<< local sql/sql_table.cc 1.438
-      (*index_drop_buffer)[(*index_drop_count)++]= table_key - table->key_info;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-      alter_table_info->index_drop_buffer
-           [alter_table_info->index_drop_count++]=
+      ha_alter_info->index_drop_buffer
+           [ha_alter_info->index_drop_count++]=
            table_key - table->key_info;
       if (table_key->flags & HA_NOSAME)
       {
@@ -5541,7 +5192,6 @@ static void compare_tables(THD *thd, TAB
       }
       else
         *alter_flags|= HA_DROP_INDEX;
->>>>>>>
       DBUG_PRINT("info", ("index dropped: '%s'", table_key->name));
       continue;
     }
@@ -5600,25 +5250,17 @@ static void compare_tables(THD *thd, TAB
 
   index_changed:
     /* Key modified. Add the offset of the key to both buffers. */
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    index_drop_buffer[(*index_drop_count)++]= table_key - table->key_info;
-    index_add_buffer[(*index_add_count)++]= new_key - key_info_buffer;
-<<<<<<< local sql/sql_table.cc 1.438
-    (*index_drop_buffer)[(*index_drop_count)++]= table_key - table->key_info;
-    (*index_add_buffer)[(*index_add_count)++]= new_key - *key_info_buffer;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-    alter_table_info->index_drop_buffer
-         [alter_table_info->index_drop_count++]=
+    ha_alter_info->index_drop_buffer
+         [ha_alter_info->index_drop_count++]=
          table_key - table->key_info;
-    alter_table_info->index_add_buffer
-         [alter_table_info->index_add_count++]=
-         new_key - alter_table_info->key_info_buffer;
->>>>>>>
+    ha_alter_info->index_add_buffer
+         [ha_alter_info->index_add_count++]=
+         new_key - ha_alter_info->key_info_buffer;
     key_part= new_key->key_part;
     end= key_part + new_key->key_parts;
     for(; key_part != end; key_part++)
     {
-      // Mark field to be part of new key 
+      /* Mark field to be part of new key */
       if ((field= table->field[key_part->fieldnr]))
         field->flags|= FIELD_IN_ADD_INDEX;
     }
@@ -5629,15 +5271,9 @@ static void compare_tables(THD *thd, TAB
   /*
     Step through all keys of the new table and find matching old keys.
   */
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  for (new_key= key_info_buffer; new_key < new_key_end; new_key++)
-<<<<<<< local sql/sql_table.cc 1.438
-  for (new_key= *key_info_buffer; new_key < new_key_end; new_key++)
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-  for (new_key= alter_table_info->key_info_buffer;
+  for (new_key= ha_alter_info->key_info_buffer;
        new_key < new_key_end;
        new_key++)
->>>>>>>
   {
     /* Search an old key with the same name. */
     for (table_key= table->key_info; table_key < table_key_end; table_key++)
@@ -5648,20 +5284,14 @@ static void compare_tables(THD *thd, TAB
     if (table_key >= table_key_end)
     {
       /* Key not found. Add the offset of the key to the add buffer. */
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-      index_add_buffer[(*index_add_count)++]= new_key - key_info_buffer;
-<<<<<<< local sql/sql_table.cc 1.438
-      (*index_add_buffer)[(*index_add_count)++]= new_key - *key_info_buffer;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-      alter_table_info->index_add_buffer
-           [alter_table_info->index_add_count++]=
-           new_key - alter_table_info->key_info_buffer;
->>>>>>>
+      ha_alter_info->index_add_buffer
+           [ha_alter_info->index_add_count++]=
+           new_key - ha_alter_info->key_info_buffer;
       key_part= new_key->key_part;
       end= key_part + new_key->key_parts;
       for(; key_part != end; key_part++)
       {
-        // Mark field to be part of new key 
+        /* Mark field to be part of new key */
         if ((field= table->field[key_part->fieldnr]))
           field->flags|= FIELD_IN_ADD_INDEX;
       }
@@ -5679,33 +5309,6 @@ static void compare_tables(THD *thd, TAB
       DBUG_PRINT("info", ("index added: '%s'", new_key->name));
     }
   }
-
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  /* Check if changes are compatible with current handler without a copy */
-  if (table->file->check_if_incompatible_data(create_info, changes))
-    DBUG_RETURN(ALTER_TABLE_DATA_CHANGED);
-
-  if (*index_drop_count || *index_add_count)
-    DBUG_RETURN(ALTER_TABLE_INDEX_CHANGED);
-
-  DBUG_RETURN(0); // Tables are compatible
-<<<<<<< local sql/sql_table.cc 1.438
-  /* Check if changes are compatible with current handler without a copy */
-  if (table->file->check_if_incompatible_data(create_info, changes))
-  {
-    *need_copy_table= ALTER_TABLE_DATA_CHANGED;
-    DBUG_RETURN(0);
-  }
-
-  if (*index_drop_count || *index_add_count)
-  {
-    *need_copy_table= ALTER_TABLE_INDEX_CHANGED;
-    DBUG_RETURN(0);
-  }
-
-  *need_copy_table= ALTER_TABLE_METADATA_ONLY; // Tables are compatible
-  DBUG_RETURN(0);
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
 #ifndef DBUG_OFF
   {
     char dbug_string[HA_MAX_ALTER_FLAGS+1];
@@ -5714,8 +5317,7 @@ static void compare_tables(THD *thd, TAB
   }
 #endif
 
-  DBUG_VOID_RETURN;
->>>>>>>
+  DBUG_RETURN(FALSE);
 }
 
 
@@ -5771,8 +5373,7 @@ int create_temporary_table(THD *thd,
                            char *new_db,
                            char *tmp_name,
                            HA_CREATE_INFO *create_info,
-                           List<create_field> &create_list,
-                           List<Key> &key_list,
+                           Alter_info *alter_info,
                            bool db_changed)
 {
   int error;
@@ -5849,22 +5450,21 @@ int create_temporary_table(THD *thd,
   */
   tmp_disable_binlog(thd);
   error= mysql_create_table(thd, new_db, tmp_name,
-                            create_info,create_list,key_list,1,0,0);
+                            create_info, alter_info, 1, 0);
   reenable_binlog(thd);
 
-DBUG_RETURN(error);
+  DBUG_RETURN(error);
 }
 
 TABLE *create_altered_table(THD *thd,
                             TABLE *table,
                             char *new_db,
                             HA_CREATE_INFO *create_info,
-                            List<create_field> &fields,
-                            List<Key> &keys,
+                            Alter_info *alter_info,
                             bool db_change)
 {
   int error;
-  HA_CREATE_INFO *altered_create_info;
+  HA_CREATE_INFO altered_create_info(*create_info);
   TABLE *altered_table;
   char tmp_name[80];
   char path[FN_REFLEN];
@@ -5872,13 +5472,14 @@ TABLE *create_altered_table(THD *thd,
 
   my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx",
               tmp_file_prefix, current_pid, thd->thread_id);
-  if (!(altered_create_info= copy_create_info(create_info)))
-    goto err;
-  altered_create_info->options&= ~HA_LEX_CREATE_TMP_TABLE;
-  altered_create_info->frm_only= 1;
+  /* Safety fix for InnoDB */
+  if (lower_case_table_names)
+    my_casedn_str(files_charset_info, tmp_name);
+  altered_create_info.options&= ~HA_LEX_CREATE_TMP_TABLE;
+  altered_create_info.frm_only= 1;
   error= create_temporary_table(thd, table, new_db, tmp_name,
-                                altered_create_info,
-                                fields, keys, db_change);
+                                &altered_create_info,
+                                alter_info, db_change);
 
   build_table_filename(path, sizeof(path), new_db, tmp_name, "",
                        FN_IS_TMP);
@@ -5886,7 +5487,6 @@ TABLE *create_altered_table(THD *thd,
                                       OTM_ALTER);
   DBUG_RETURN(altered_table);
 
- err:
   DBUG_RETURN(NULL);
 }
 
@@ -5905,8 +5505,7 @@ int mysql_fast_or_online_alter_table(THD
                                      TABLE *altered_table,
                                      HA_CREATE_INFO *create_info,
                                      HA_ALTER_INFO *alter_info,
-                                     HA_ALTER_FLAGS *alter_table_flags,
-                                     bool lock)
+                                     HA_ALTER_FLAGS *alter_table_flags)
 {
   int error= 0;
   DBUG_ENTER(" mysql_fast_or_online_alter_table");
@@ -6178,7 +5777,17 @@ mysql_prepare_alter_table(THD *thd, TABL
         goto err;
       }
       find_it.after(def);			// Put element after this
-      alter_info->change_level= ALTER_TABLE_DATA_CHANGED;
+      /*
+        XXX: hack for Bug#28427.
+        If column order has changed, force OFFLINE ALTER TABLE
+        without querying engine capabilities.  If we ever have an
+        engine that supports online ALTER TABLE CHANGE COLUMN
+        <name> AFTER <name1> (Falcon?), this fix will effectively
+        disable the capability.
+        TODO: detect the situation in compare_tables, behave based
+        on engine capabilities.
+      */
+      alter_info->force_offline_alter= TRUE;
     }
   }
   if (alter_info->alter_list.elements)
@@ -6419,68 +6028,20 @@ bool mysql_alter_table(THD *thd,char *ne
   handlerton *old_db_type, *new_db_type, *save_old_db_type;
   legacy_db_type table_type;
   frm_type_enum frm_type;
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  uint need_copy_table= 0;
-  bool no_table_reopen= FALSE, varchar= FALSE;
-<<<<<<< local sql/sql_table.cc 1.438
-  enum_alter_table_change_level need_copy_table= ALTER_TABLE_METADATA_ONLY;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
   HA_ALTER_FLAGS alter_table_flags;
-  uint table_changes= IS_EQUAL_YES, need_copy_table= 0;
-  bool no_table_reopen= FALSE, varchar= FALSE;
->>>>>>>
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   uint fast_alter_partition= 0;
   bool partition_changed= FALSE;
 #endif
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  List<create_field> prepared_create_list;
-  List<Key>          prepared_key_list;
-  bool need_lock_for_indexes= TRUE;
-  uint db_options= 0;
-  uint key_count;
-  KEY  *key_info_buffer;
-  uint index_drop_count;
-  uint *index_drop_buffer;
-  uint index_add_count;
-  uint *index_add_buffer;
-<<<<<<< local sql/sql_table.cc 1.438
-  bool need_lock_for_indexes= TRUE;
-  KEY  *key_info_buffer;
-  uint index_drop_count;
-  uint *index_drop_buffer;
-  uint index_add_count;
-  uint *index_add_buffer;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-  List<create_field> prepared_create_list, prepared_create_list2;
-  List<Key>          prepared_key_list, prepared_key_list2;;
-  bool need_lock= TRUE;
-  uint db_options= 0;
->>>>>>>
-  bool committed= 0;
-  HA_ALTER_INFO alter_table_info;
+  HA_ALTER_INFO ha_alter_info;
   DBUG_ENTER("mysql_alter_table");
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  LINT_INIT(index_add_count);
-  LINT_INIT(index_drop_count);
-  LINT_INIT(index_add_buffer);
-  LINT_INIT(index_drop_buffer);
-
-<<<<<<< local sql/sql_table.cc 1.438
-  LINT_INIT(index_add_count);
-  LINT_INIT(index_drop_count);
-  LINT_INIT(index_add_buffer);
-  LINT_INIT(index_drop_buffer);
-
   /*
     Check if we attempt to alter mysql.slow_log or
     mysql.general_log table and return an error if
     it is the case.
     TODO: this design is obsolete and will be removed.
   */
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
->>>>>>>
   if (table_list && table_list->db && table_list->table_name)
   {
     int table_kind= 0;
@@ -6685,22 +6246,6 @@ view_err:
       create_info->db_type= old_db_type;
   }
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-  if (prep_alter_part_table(thd, table, alter_info, create_info, old_db_type,
-                            &partition_changed, &fast_alter_partition))
-    goto err;
-#endif
-<<<<<<< local sql/sql_table.cc 1.438
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-  if (prep_alter_part_table(thd, table, alter_info, create_info, old_db_type,
-                            &partition_changed, &fast_alter_partition))
-  {
-    goto err;
-  }
-#endif
->>>>>>>
   if (check_engine(thd, new_name, create_info))
     goto err;
   new_db_type= create_info->db_type;
@@ -6725,7 +6270,7 @@ view_err:
     my_error(ER_ILLEGAL_HA, MYF(0), table_name);
     goto err;
   }
-  
+
   thd->proc_info="setup";
   if (!(alter_info->flags & ~(ALTER_RENAME | ALTER_KEYS_ONOFF)) &&
       !table->s->tmp_table) // no need to touch frm
@@ -6842,316 +6387,14 @@ view_err:
     DBUG_RETURN(error);
   }
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  /* We have to do full alter table */
-
-  /* Let new create options override the old ones */
-  if (!(used_fields & HA_CREATE_USED_MIN_ROWS))
-    create_info->min_rows= table->s->min_rows;
-  if (!(used_fields & HA_CREATE_USED_MAX_ROWS))
-    create_info->max_rows= table->s->max_rows;
-  if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
-    create_info->avg_row_length= table->s->avg_row_length;
-  if (!(used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
-    create_info->default_table_charset= table->s->table_charset;
-  if (!(used_fields & HA_CREATE_USED_AUTO) && table->found_next_number_field)
-  {
-    /* Table has an autoincrement, copy value to new table */
-    table->file->info(HA_STATUS_AUTO);
-    create_info->auto_increment_value= table->file->stats.auto_increment_value;
-  }
-  if (!(used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE))
-    create_info->key_block_size= table->s->key_block_size;
-
-  restore_record(table, s->default_values);     // Empty record for DEFAULT
-  create_field *def;
-
-  /*
-    First collect all fields from table which isn't in drop_list
-  */
-
-  Field **f_ptr,*field;
-  for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++)
-  {
-    if (field->type() == MYSQL_TYPE_STRING)
-      varchar= TRUE;
-    /* Check if field should be dropped */
-    Alter_drop *drop;
-    drop_it.rewind();
-    while ((drop=drop_it++))
-    {
-      if (drop->type == Alter_drop::COLUMN &&
-	  !my_strcasecmp(system_charset_info,field->field_name, drop->name))
-      {
-	/* Reset auto_increment value if it was dropped */
-	if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
-	    !(used_fields & HA_CREATE_USED_AUTO))
-	{
-	  create_info->auto_increment_value=0;
-	  create_info->used_fields|=HA_CREATE_USED_AUTO;
-	}
-	break;
-      }
-    }
-    if (drop)
-    {
-      drop_it.remove();
-      continue;
-    }
-    /* Check if field is changed */
-    def_it.rewind();
-    while ((def=def_it++))
-    {
-      if (def->change &&
-	  !my_strcasecmp(system_charset_info,field->field_name, def->change))
-	break;
-    }
-    if (def)
-    {						// Field is changed
-      def->field=field;
-      if (!def->after)
-      {
-	create_list.push_back(def);
-	def_it.remove();
-      }
-    }
-    else
-    {
-      /*
-        This field was not dropped and not changed, add it to the list
-        for the new table.
-      */
-      create_list.push_back(def=new create_field(field,field));
-      alter_it.rewind();			// Change default if ALTER
-      Alter_column *alter;
-      while ((alter=alter_it++))
-      {
-	if (!my_strcasecmp(system_charset_info,field->field_name, alter->name))
-	  break;
-      }
-      if (alter)
-      {
-	if (def->sql_type == MYSQL_TYPE_BLOB)
-	{
-	  my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
-          goto err;
-	}
-	if ((def->def=alter->def))              // Use new default
-          def->flags&= ~NO_DEFAULT_VALUE_FLAG;
-        else
-          def->flags|= NO_DEFAULT_VALUE_FLAG;
-	alter_it.remove();
-      }
-    }
-  }
-  def_it.rewind();
-  while ((def=def_it++))			// Add new columns
-  {
-    if (def->change && ! def->field)
-    {
-      my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table_name);
-      goto err;
-    }
-    if (!def->after)
-      create_list.push_back(def);
-    else if (def->after == first_keyword)
-      create_list.push_front(def);
-    else
-    {
-      create_field *find;
-      find_it.rewind();
-      while ((find=find_it++))			// Add new columns
-      {
-	if (!my_strcasecmp(system_charset_info,def->after, find->field_name))
-	  break;
-      }
-      if (!find)
-      {
-	my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table_name);
-        goto err;
-      }
-      find_it.after(def);			// Put element after this
-    }
-  }
-  if (alter_info->alter_list.elements)
-  {
-    my_error(ER_BAD_FIELD_ERROR, MYF(0),
-             alter_info->alter_list.head()->name, table_name);
-    goto err;
-  }
-  if (!create_list.elements)
-  {
-    my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS),
-               MYF(0));
-    goto err;
-  }
-
-  /*
-    Collect all keys which isn't in drop list. Add only those
-    for which some fields exists.
-  */
-
-  for (uint i=0 ; i < table->s->keys ; i++,key_info++)
-  {
-    char *key_name= key_info->name;
-    Alter_drop *drop;
-    drop_it.rewind();
-    while ((drop=drop_it++))
-    {
-      if (drop->type == Alter_drop::KEY &&
-	  !my_strcasecmp(system_charset_info,key_name, drop->name))
-	break;
-    }
-    if (drop)
-    {
-      drop_it.remove();
-      continue;
-    }
-
-    KEY_PART_INFO *key_part= key_info->key_part;
-    key_parts.empty();
-    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
-    {
-      if (!key_part->field)
-	continue;				// Wrong field (from UNIREG)
-      const char *key_part_name=key_part->field->field_name;
-      create_field *cfield;
-      field_it.rewind();
-      while ((cfield=field_it++))
-      {
-	if (cfield->change)
-	{
-	  if (!my_strcasecmp(system_charset_info, key_part_name,
-			     cfield->change))
-	    break;
-	}
-	else if (!my_strcasecmp(system_charset_info,
-				key_part_name, cfield->field_name))
-	  break;
-      }
-      if (!cfield)
-	continue;				// Field is removed
-      uint key_part_length=key_part->length;
-      if (cfield->field)			// Not new field
-      {
-        /*
-          If the field can't have only a part used in a key according to its
-          new type, or should not be used partially according to its
-          previous type, or the field length is less than the key part
-          length, unset the key part length.
-
-          We also unset the key part length if it is the same as the
-          old field's length, so the whole new field will be used.
-
-          BLOBs may have cfield->length == 0, which is why we test it before
-          checking whether cfield->length < key_part_length (in chars).
-         */
-        if (!Field::type_can_have_key_part(cfield->field->type()) ||
-            !Field::type_can_have_key_part(cfield->sql_type) ||
-            /* spatial keys can't have sub-key length */
-            (key_info->flags & HA_SPATIAL) ||
-            (cfield->field->field_length == key_part_length &&
-             !f_is_blob(key_part->key_type)) ||
-	    (cfield->length && (cfield->length < key_part_length /
-                                key_part->field->charset()->mbmaxlen)))
-	  key_part_length= 0;			// Use whole field
-      }
-      key_part_length /= key_part->field->charset()->mbmaxlen;
-      key_parts.push_back(new key_part_spec(cfield->field_name,
-					    key_part_length));
-    }
-    if (key_parts.elements)
-    {
-      KEY_CREATE_INFO key_create_info;
-      bzero((char*) &key_create_info, sizeof(key_create_info));
-
-      key_create_info.algorithm= key_info->algorithm;
-      if (key_info->flags & HA_USES_BLOCK_SIZE)
-        key_create_info.block_size= key_info->block_size;
-      if (key_info->flags & HA_USES_PARSER)
-        key_create_info.parser_name= *key_info->parser_name;
-
-      key_list.push_back(new Key(key_info->flags & HA_SPATIAL ? Key::SPATIAL :
-				 (key_info->flags & HA_NOSAME ?
-				 (!my_strcasecmp(system_charset_info,
-						 key_name, primary_key_name) ?
-				  Key::PRIMARY	: Key::UNIQUE) :
-				  (key_info->flags & HA_FULLTEXT ?
-				   Key::FULLTEXT : Key::MULTIPLE)),
-				 key_name,
-                                 &key_create_info,
-                                 test(key_info->flags & HA_GENERATED_KEY),
-				 key_parts));
-    }
-  }
-  {
-    Key *key;
-    while ((key=key_it++))			// Add new keys
-    {
-      if (key->type != Key::FOREIGN_KEY)
-	key_list.push_back(key);
-      if (key->name &&
-	  !my_strcasecmp(system_charset_info,key->name,primary_key_name))
-      {
-	my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name);
-        goto err;
-      }
-    }
-  }
-
-  if (alter_info->drop_list.elements)
-  {
-    my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0),
-             alter_info->drop_list.head()->name);
-    goto err;
-  }
-  if (alter_info->alter_list.elements)
-  {
-    my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0),
-             alter_info->alter_list.head()->name);
-    goto err;
-  }
-
-  db_create_options= table->s->db_create_options & ~(HA_OPTION_PACK_RECORD);
-  my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx", tmp_file_prefix,
-	      current_pid, thd->thread_id);
-  /* Safety fix for innodb */
-  if (lower_case_table_names)
-    my_casedn_str(files_charset_info, tmp_name);
-  if (new_db_type != old_db_type && !table->file->can_switch_engines()) {
-    my_error(ER_ROW_IS_REFERENCED, MYF(0));
-    goto err;
-  }
-  create_info->db_type=new_db_type;
-  if (!create_info->comment.str)
-  {
-    create_info->comment.str= table->s->comment.str;
-    create_info->comment.length= table->s->comment.length;
-  }
-
-  table->file->update_create_info(create_info);
-  if ((create_info->table_options &
-       (HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS)) ||
-      (used_fields & HA_CREATE_USED_PACK_KEYS))
-    db_create_options&= ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
-  if (create_info->table_options &
-      (HA_OPTION_CHECKSUM | HA_OPTION_NO_CHECKSUM))
-    db_create_options&= ~(HA_OPTION_CHECKSUM | HA_OPTION_NO_CHECKSUM);
-  if (create_info->table_options &
-      (HA_OPTION_DELAY_KEY_WRITE | HA_OPTION_NO_DELAY_KEY_WRITE))
-    db_create_options&= ~(HA_OPTION_DELAY_KEY_WRITE |
-			  HA_OPTION_NO_DELAY_KEY_WRITE);
-  create_info->table_options|= db_create_options;
-
-  if (table->s->tmp_table)
-    create_info->options|=HA_LEX_CREATE_TMP_TABLE;
-<<<<<<< local sql/sql_table.cc 1.438
   /* We have to do full alter table. */
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   if (prep_alter_part_table(thd, table, alter_info, create_info, old_db_type,
                             &partition_changed, &fast_alter_partition))
+  {
     goto err;
+  }
 #endif
   /*
     If the old table had partitions and we are doing ALTER TABLE ...
@@ -7168,656 +6411,46 @@ view_err:
 
   if (mysql_prepare_alter_table(thd, table, create_info, alter_info))
     goto err;
-  
-  need_copy_table= alter_info->change_level;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-  /* We have to do full alter table */
-
-  /* Let new create options override the old ones */
-  if (!(used_fields & HA_CREATE_USED_MIN_ROWS))
-    create_info->min_rows= table->s->min_rows;
-  if (!(used_fields & HA_CREATE_USED_MAX_ROWS))
-    create_info->max_rows= table->s->max_rows;
-  if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
-    create_info->avg_row_length= table->s->avg_row_length;
-  if (!(used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
-    create_info->default_table_charset= table->s->table_charset;
-  if (!(used_fields & HA_CREATE_USED_AUTO) && table->found_next_number_field)
-  {
-    /* Table has an autoincrement, copy value to new table */
-    table->file->info(HA_STATUS_AUTO);
-    create_info->auto_increment_value= table->file->stats.auto_increment_value;
-  }
-  if (!(used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE))
-    create_info->key_block_size= table->s->key_block_size;
-
-  restore_record(table, s->default_values);     // Empty record for DEFAULT
-  create_field *def;
-
-  /*
-    First collect all fields from table which isn't in drop_list
-  */
-
-  Field **f_ptr,*field;
-  for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++)
-  {
-    if (field->type() == MYSQL_TYPE_STRING)
-      varchar= TRUE;
-    /* Check if field should be dropped */
-    Alter_drop *drop;
-    drop_it.rewind();
-    while ((drop=drop_it++))
-    {
-      if (drop->type == Alter_drop::COLUMN &&
-	  !my_strcasecmp(system_charset_info,field->field_name, drop->name))
-      {
-	/* Reset auto_increment value if it was dropped */
-	if (MTYP_TYPENR(field->unireg_check) == Field::NEXT_NUMBER &&
-	    !(used_fields & HA_CREATE_USED_AUTO))
-	{
-	  create_info->auto_increment_value=0;
-	  create_info->used_fields|=HA_CREATE_USED_AUTO;
-	}
-	break;
-      }
-    }
-    if (drop)
-    {
-      drop_it.remove();
-      continue;
-    }
-    /* Check if field is changed */
-    def_it.rewind();
-    while ((def=def_it++))
-    {
-      if (def->change &&
-	  !my_strcasecmp(system_charset_info,field->field_name, def->change))
-	break;
-    }
-    if (def)
-    {						// Field is changed
-      def->field=field;
-      if (!def->after)
-      {
-	create_list.push_back(def);
-	def_it.remove();
-      }
-    }
-    else
-    {
-      /*
-        This field was not dropped and not changed, add it to the list
-        for the new table.
-      */
-      create_list.push_back(def=new create_field(field,field));
-      alter_it.rewind();			// Change default if ALTER
-      Alter_column *alter;
-      while ((alter=alter_it++))
-      {
-	if (!my_strcasecmp(system_charset_info,field->field_name, alter->name))
-	  break;
-      }
-      if (alter)
-      {
-	if (def->sql_type == MYSQL_TYPE_BLOB)
-	{
-	  my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
-	  goto err;
-	}
-	if ((def->def=alter->def))              // Use new default
-          def->flags&= ~NO_DEFAULT_VALUE_FLAG;
-        else
-          def->flags|= NO_DEFAULT_VALUE_FLAG;
-	alter_it.remove();
-      }
-    }
-  }
-  def_it.rewind();
-
-  while ((def=def_it++))			// Add new columns
-  {
-    if (def->change && ! def->field)
-    {
-      my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table_name);
-      goto err;
-    }
-    if (!def->after)
-      create_list.push_back(def);
-    else if (def->after == first_keyword)
-      create_list.push_front(def);
-    else
-    {
-      create_field *find;
-      find_it.rewind();
-      while ((find=find_it++))			// Add new columns
-      {
-	if (!my_strcasecmp(system_charset_info,def->after, find->field_name))
-	  break;
-      }
-      if (!find)
-      {
-	my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table_name);
-	goto err;
-      }
-      find_it.after(def);			// Put element after this
-    }
-  }
-  if (alter_info->alter_list.elements)
-  {
-    my_error(ER_BAD_FIELD_ERROR, MYF(0),
-             alter_info->alter_list.head()->name, table_name);
-    goto err;
-  }
-  if (!create_list.elements)
-  {
-    my_message(ER_CANT_REMOVE_ALL_FIELDS, ER(ER_CANT_REMOVE_ALL_FIELDS),
-               MYF(0));
-    goto err;
-  }
-
-  /*
-    Collect all keys which isn't in drop list. Add only those
-    for which some fields exists.
-  */
-
-  for (uint i=0 ; i < table->s->keys ; i++,key_info++)
-  {
-    char *key_name= key_info->name;
-    Alter_drop *drop;
-    drop_it.rewind();
-    while ((drop=drop_it++))
-    {
-      if (drop->type == Alter_drop::KEY &&
-	  !my_strcasecmp(system_charset_info,key_name, drop->name))
-	break;
-    }
-    if (drop)
-    {
-      drop_it.remove();
-      continue;
-    }
-
-    KEY_PART_INFO *key_part= key_info->key_part;
-    key_parts.empty();
-    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
-    {
-      if (!key_part->field)
-	continue;				// Wrong field (from UNIREG)
-      const char *key_part_name=key_part->field->field_name;
-      create_field *cfield;
-      field_it.rewind();
-      while ((cfield=field_it++))
-      {
-	if (cfield->change)
-	{
-	  if (!my_strcasecmp(system_charset_info, key_part_name,
-			     cfield->change))
-	    break;
-	}
-	else if (!my_strcasecmp(system_charset_info,
-				key_part_name, cfield->field_name))
-	  break;
-      }
-      if (!cfield)
-	continue;				// Field is removed
-      uint key_part_length=key_part->length;
-      if (cfield->field)			// Not new field
-      {
-        /*
-          If the field can't have only a part used in a key according to its
-          new type, or should not be used partially according to its
-          previous type, or the field length is less than the key part
-          length, unset the key part length.
-
-          We also unset the key part length if it is the same as the
-          old field's length, so the whole new field will be used.
-
-          BLOBs may have cfield->length == 0, which is why we test it before
-          checking whether cfield->length < key_part_length (in chars).
-         */
-        if (!Field::type_can_have_key_part(cfield->field->type()) ||
-            !Field::type_can_have_key_part(cfield->sql_type) ||
-            /* spatial keys can't have sub-key length */
-            (key_info->flags & HA_SPATIAL) ||
-            (cfield->field->field_length == key_part_length &&
-             !f_is_blob(key_part->key_type)) ||
-	    (cfield->length && (cfield->length < key_part_length /
-                                key_part->field->charset()->mbmaxlen)))
-	  key_part_length= 0;			// Use whole field
-      }
-      key_part_length /= key_part->field->charset()->mbmaxlen;
-      key_parts.push_back(new key_part_spec(cfield->field_name,
-					    key_part_length));
-    }
-    if (key_parts.elements)
-    {
-      KEY_CREATE_INFO key_create_info;
-      bzero((char*) &key_create_info, sizeof(key_create_info));
-
-      key_create_info.algorithm= key_info->algorithm;
-      if (key_info->flags & HA_USES_BLOCK_SIZE)
-        key_create_info.block_size= key_info->block_size;
-      if (key_info->flags & HA_USES_PARSER)
-        key_create_info.parser_name= *key_info->parser_name;
-
-      key_list.push_back(new Key(key_info->flags & HA_SPATIAL ? Key::SPATIAL :
-				 (key_info->flags & HA_NOSAME ?
-				 (!my_strcasecmp(system_charset_info,
-						 key_name, primary_key_name) ?
-				  Key::PRIMARY	: Key::UNIQUE) :
-				  (key_info->flags & HA_FULLTEXT ?
-				   Key::FULLTEXT : Key::MULTIPLE)),
-				 key_name,
-                                 &key_create_info,
-                                 test(key_info->flags & HA_GENERATED_KEY),
-				 key_parts));
-    }
-  }
-  {
-    Key *key;
-    while ((key=key_it++))			// Add new keys
-    {
-      if (key->type != Key::FOREIGN_KEY)
-	key_list.push_back(key);
-      if (key->name &&
-	  !my_strcasecmp(system_charset_info,key->name,primary_key_name))
-      {
-	my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name);
-	DBUG_RETURN(TRUE);
-      }
-    }
-  }
-
-  if (alter_info->drop_list.elements)
-  {
-    my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0),
-             alter_info->drop_list.head()->name);
-    goto err;
-  }
-  if (alter_info->alter_list.elements)
-  {
-    my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0),
-             alter_info->alter_list.head()->name);
-    goto err;
-  }
-
-  db_create_options= table->s->db_create_options & ~(HA_OPTION_PACK_RECORD);
-  my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx", tmp_file_prefix,
-	      current_pid, thd->thread_id);
-  /* Safety fix for innodb */
-  if (lower_case_table_names)
-    my_casedn_str(files_charset_info, tmp_name);
-  if (new_db_type != old_db_type && !table->file->can_switch_engines()) {
-    my_error(ER_ROW_IS_REFERENCED, MYF(0));
-    goto err;
-  }
-  create_info->db_type=new_db_type;
-  if (!create_info->comment.str)
-  {
-    create_info->comment.str= table->s->comment.str;
-    create_info->comment.length= table->s->comment.length;
-  }
-
-  table->file->update_create_info(create_info);
-  if ((create_info->table_options &
-       (HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS)) ||
-      (used_fields & HA_CREATE_USED_PACK_KEYS))
-    db_create_options&= ~(HA_OPTION_PACK_KEYS | HA_OPTION_NO_PACK_KEYS);
-  if (create_info->table_options &
-      (HA_OPTION_CHECKSUM | HA_OPTION_NO_CHECKSUM))
-    db_create_options&= ~(HA_OPTION_CHECKSUM | HA_OPTION_NO_CHECKSUM);
-  if (create_info->table_options &
-      (HA_OPTION_DELAY_KEY_WRITE | HA_OPTION_NO_DELAY_KEY_WRITE))
-    db_create_options&= ~(HA_OPTION_DELAY_KEY_WRITE |
-			  HA_OPTION_NO_DELAY_KEY_WRITE);
-  create_info->table_options|= db_create_options;
-
-  if (table->s->tmp_table)
-    create_info->options|=HA_LEX_CREATE_TMP_TABLE;
->>>>>>>
 
   set_table_default_charset(thd, create_info, db);
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  {
-    /*
-      For some purposes we need prepared table structures and translated
-      key descriptions with proper default key name assignment.
-
-      Unfortunately, mysql_prepare_table() modifies the field and key
-      lists. mysql_create_table() needs the unmodified lists. Hence, we
-      need to copy the lists and all their elements. The lists contain
-      pointers to the elements only.
-
-      We cannot copy conditionally because the partition code always
-      needs prepared lists and compare_tables() needs them and is almost
-      always called.
-    */
-
-    /* Copy fields. */
-    List_iterator<create_field> prep_field_it(create_list);
-    create_field *prep_field;
-    while ((prep_field= prep_field_it++))
-      prepared_create_list.push_back(new create_field(*prep_field));
-
-    /* Copy keys and key parts. */
-    List_iterator<Key> prep_key_it(key_list);
-    Key *prep_key;
-    while ((prep_key= prep_key_it++))
-    {
-      List<key_part_spec> prep_columns;
-      List_iterator<key_part_spec> prep_col_it(prep_key->columns);
-      key_part_spec *prep_col;
-
-      while ((prep_col= prep_col_it++))
-        prep_columns.push_back(new key_part_spec(*prep_col));
-      prepared_key_list.push_back(new Key(prep_key->type, prep_key->name,
-                                          &prep_key->key_create_info,
-                                          prep_key->generated, prep_columns));
-    }
-
-    /* Create the prepared information. */
-    if (mysql_prepare_table(thd, create_info, &prepared_create_list,
-                            &prepared_key_list,
-                            (table->s->tmp_table != NO_TMP_TABLE), &db_options,
-                            table->file, &key_info_buffer, &key_count, 0))
-      goto err;
-  }
-
-<<<<<<< local sql/sql_table.cc 1.438
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-  {
-    /*
-      For some purposes we need prepared table structures and translated
-      key descriptions with proper default key name assignment.
-
-      Unfortunately, mysql_prepare_table() modifies the field and key
-      lists. mysql_create_table() needs the unmodified lists. Hence, we
-      need to copy the lists and all their elements. The lists contain
-      pointers to the elements only.
-
-      We cannot copy conditionally because the partition code always
-      needs prepared lists and compare_tables() needs them and is almost
-      always called.
-    */
-
-    /* Copy fields. */
-    List_iterator<create_field> prep_field_it(create_list);
-    create_field *prep_field;
-    while ((prep_field= prep_field_it++))
-    {
-      prepared_create_list.push_back(new create_field(*prep_field));
-      prepared_create_list2.push_back(new create_field(*prep_field));
-    }
-    /* Copy keys and key parts. */
-    List_iterator<Key> prep_key_it(key_list);
-    Key *prep_key;
-    while ((prep_key= prep_key_it++))
-    {
-      List<key_part_spec> prep_columns, prep_columns2;
-      List_iterator<key_part_spec> prep_col_it(prep_key->columns);
-      key_part_spec *prep_col;
-
-      while ((prep_col= prep_col_it++))
-      {
-        prep_columns.push_back(new key_part_spec(*prep_col));
-        prep_columns2.push_back(new key_part_spec(*prep_col));
-      }
-      prepared_key_list.push_back(new Key(prep_key->type, prep_key->name,
-                                          &prep_key->key_create_info,
-                                          prep_key->generated, prep_columns));
-      prepared_key_list2.push_back(new Key(prep_key->type, prep_key->name,
-                                           &prep_key->key_create_info,
-                                           prep_key->generated, prep_columns2));
-    }
-
-    /* Create the prepared information. */
-    if (mysql_prepare_table(thd, create_info, &prepared_create_list,
-                            &prepared_key_list,
-                            (table->s->tmp_table != NO_TMP_TABLE), &db_options,
-                            table->file,
-                            &alter_table_info.key_info_buffer,
-                            &alter_table_info.key_count, 0))
-      goto err;
-  }
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   if (fast_alter_partition)
   {
     DBUG_RETURN(fast_alter_partition_table(thd, table, alter_info,
                                            create_info, table_list,
-                                           &create_list, &key_list,
                                            db, table_name,
                                            fast_alter_partition));
   }
 #endif
 
->>>>>>>
   if (thd->variables.old_alter_table
       || (table->s->db_type() != create_info->db_type)
 #ifdef WITH_PARTITION_STORAGE_ENGINE
       || partition_changed
 #endif
      )
-    need_copy_table= ALTER_TABLE_DATA_CHANGED;
-  else
+    alter_info->force_offline_alter= TRUE;
+
+  if (alter_info->force_offline_alter == FALSE)
   {
-    enum_alter_table_change_level need_copy_table_res;
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    /* Try to optimize ALTER TABLE. Allocate result buffers. */
-    if (! (index_drop_buffer=
-           (uint*) thd->alloc(sizeof(uint) * table->s->keys)) ||
-        ! (index_add_buffer=
-           (uint*) thd->alloc(sizeof(uint) * prepared_key_list.elements)))
-      goto err;
-<<<<<<< local sql/sql_table.cc 1.438
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-    /* Try to optimize ALTER TABLE. Allocate result buffers. */
-    if (! (alter_table_info.index_drop_buffer=
-           (uint*) thd->alloc(sizeof(uint) * table->s->keys)) ||
-        ! (alter_table_info.index_add_buffer=
-           (uint*) thd->alloc(sizeof(uint) * prepared_key_list.elements)))
-      goto err;
->>>>>>>
+    uint table_changes= IS_EQUAL_YES;
+    bool need_copy_table= TRUE;
+    Alter_info tmp_alter_info(*alter_info, thd->mem_root);
     /* Check how much the tables differ. */
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    need_copy_table= compare_tables(table, &prepared_create_list,
-                                    key_info_buffer, key_count,
-                                    create_info, alter_info, order_num,
-                                    index_drop_buffer, &index_drop_count,
-                                    index_add_buffer, &index_add_count,
-                                    varchar);
-  }
-
-  /*
-    If there are index changes only, try to do them online. "Index
-    changes only" means also that the handler for the table does not
-    change. The table is open and locked. The handler can be accessed.
-  */
-  if (need_copy_table == ALTER_TABLE_INDEX_CHANGED)
-  {
-    int   pk_changed= 0;
-    ulong alter_flags= 0;
-    ulong needed_online_flags= 0;
-    ulong needed_fast_flags= 0;
-    KEY   *key;
-    uint  *idx_p;
-    uint  *idx_end_p;
-
-    if (table->s->db_type()->alter_table_flags)
-      alter_flags= table->s->db_type()->alter_table_flags(alter_info->flags);
-    DBUG_PRINT("info", ("alter_flags: %lu", alter_flags));
-    /* Check dropped indexes. */
-    for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
-         idx_p < idx_end_p;
-         idx_p++)
-    {
-      key= table->key_info + *idx_p;
-      DBUG_PRINT("info", ("index dropped: '%s'", key->name));
-      if (key->flags & HA_NOSAME)
-      {
-        /* Unique key. Check for "PRIMARY". */
-        if (! my_strcasecmp(system_charset_info,
-                            key->name, primary_key_name))
-        {
-          /* Primary key. */
-          needed_online_flags|=  HA_ONLINE_DROP_PK_INDEX;
-          needed_fast_flags|= HA_ONLINE_DROP_PK_INDEX_NO_WRITES;
-          pk_changed++;
-        }
-        else
-        {
-          /* Non-primary unique key. */
-          needed_online_flags|=  HA_ONLINE_DROP_UNIQUE_INDEX;
-          needed_fast_flags|= HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES;
-        }
-      }
-      else
-      {
-        /* Non-unique key. */
-        needed_online_flags|=  HA_ONLINE_DROP_INDEX;
-        needed_fast_flags|= HA_ONLINE_DROP_INDEX_NO_WRITES;
-      }
-    }
-
-    /* Check added indexes. */
-    for (idx_p= index_add_buffer, idx_end_p= idx_p + index_add_count;
-         idx_p < idx_end_p;
-         idx_p++)
-    {
-      key= key_info_buffer + *idx_p;
-      DBUG_PRINT("info", ("index added: '%s'", key->name));
-      if (key->flags & HA_NOSAME)
-      {
-        /* Unique key. Check for "PRIMARY". */
-        if (! my_strcasecmp(system_charset_info,
-                            key->name, primary_key_name))
-        {
-          /* Primary key. */
-          needed_online_flags|=  HA_ONLINE_ADD_PK_INDEX;
-          needed_fast_flags|= HA_ONLINE_ADD_PK_INDEX_NO_WRITES;
-          pk_changed++;
-        }
-        else
-        {
-          /* Non-primary unique key. */
-          needed_online_flags|=  HA_ONLINE_ADD_UNIQUE_INDEX;
-          needed_fast_flags|= HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES;
-        }
-      }
-      else
-      {
-        /* Non-unique key. */
-        needed_online_flags|=  HA_ONLINE_ADD_INDEX;
-        needed_fast_flags|= HA_ONLINE_ADD_INDEX_NO_WRITES;
-      }
-    }
-<<<<<<< local sql/sql_table.cc 1.438
-    if (compare_tables(table, alter_info,
+    if (compare_tables(thd, table, alter_info,
                        create_info, order_num,
-                       &need_copy_table_res,
-                       &key_info_buffer,
-                       &index_drop_buffer, &index_drop_count,
-                       &index_add_buffer, &index_add_count))
-      goto err;
-   
-    if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
-      need_copy_table= need_copy_table_res;
-  }
-
-  /*
-    If there are index changes only, try to do them online. "Index
-    changes only" means also that the handler for the table does not
-    change. The table is open and locked. The handler can be accessed.
-  */
-  if (need_copy_table == ALTER_TABLE_INDEX_CHANGED)
-  {
-    int   pk_changed= 0;
-    ulong alter_flags= 0;
-    ulong needed_online_flags= 0;
-    ulong needed_fast_flags= 0;
-    KEY   *key;
-    uint  *idx_p;
-    uint  *idx_end_p;
-
-    if (table->s->db_type()->alter_table_flags)
-      alter_flags= table->s->db_type()->alter_table_flags(alter_info->flags);
-    DBUG_PRINT("info", ("alter_flags: %lu", alter_flags));
-    /* Check dropped indexes. */
-    for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
-         idx_p < idx_end_p;
-         idx_p++)
-    {
-      key= table->key_info + *idx_p;
-      DBUG_PRINT("info", ("index dropped: '%s'", key->name));
-      if (key->flags & HA_NOSAME)
-      {
-        /* Unique key. Check for "PRIMARY". */
-        if (! my_strcasecmp(system_charset_info,
-                            key->name, primary_key_name))
-        {
-          /* Primary key. */
-          needed_online_flags|=  HA_ONLINE_DROP_PK_INDEX;
-          needed_fast_flags|= HA_ONLINE_DROP_PK_INDEX_NO_WRITES;
-          pk_changed++;
-        }
-        else
-        {
-          /* Non-primary unique key. */
-          needed_online_flags|=  HA_ONLINE_DROP_UNIQUE_INDEX;
-          needed_fast_flags|= HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES;
-        }
-      }
-      else
-      {
-        /* Non-unique key. */
-        needed_online_flags|=  HA_ONLINE_DROP_INDEX;
-        needed_fast_flags|= HA_ONLINE_DROP_INDEX_NO_WRITES;
-      }
-    }
-
-    /* Check added indexes. */
-    for (idx_p= index_add_buffer, idx_end_p= idx_p + index_add_count;
-         idx_p < idx_end_p;
-         idx_p++)
+                       &alter_table_flags,
+                       &ha_alter_info,
+                       &table_changes))
     {
-      key= key_info_buffer + *idx_p;
-      DBUG_PRINT("info", ("index added: '%s'", key->name));
-      if (key->flags & HA_NOSAME)
-      {
-        /* Unique key. Check for "PRIMARY". */
-        if (! my_strcasecmp(system_charset_info,
-                            key->name, primary_key_name))
-        {
-          /* Primary key. */
-          needed_online_flags|=  HA_ONLINE_ADD_PK_INDEX;
-          needed_fast_flags|= HA_ONLINE_ADD_PK_INDEX_NO_WRITES;
-          pk_changed++;
-        }
-        else
-        {
-          /* Non-primary unique key. */
-          needed_online_flags|=  HA_ONLINE_ADD_UNIQUE_INDEX;
-          needed_fast_flags|= HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES;
-        }
-      }
-      else
-      {
-        /* Non-unique key. */
-        needed_online_flags|=  HA_ONLINE_ADD_INDEX;
-        needed_fast_flags|= HA_ONLINE_ADD_INDEX_NO_WRITES;
-      }
+      DBUG_RETURN(TRUE);
     }
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-    compare_tables(thd, table, &prepared_create_list,
-                   create_info, alter_info, order_num,
-                   varchar,
-                   &alter_table_flags,
-                   &alter_table_info,
-                   &table_changes);
 
-    /* Check if storage engine supports altering the table
-       on-line
+    /*
+      Check if storage engine supports altering the table
+      on-line.
     */
 
 #ifndef DBUG_OFF
@@ -7829,7 +6462,6 @@ view_err:
                           (char *) dbug_string));
     }
 #endif
->>>>>>>
 
     /*
       If table is not renamed, changed database and
@@ -7839,19 +6471,6 @@ view_err:
     if (new_name == table_name && new_db == db &&
         alter_table_flags.is_set())
     {
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-      if ((alter_flags & needed_online_flags) == needed_online_flags)
-      {
-        /* All required online flags are present. */
-        need_copy_table= 0;
-        need_lock_for_indexes= FALSE;
-<<<<<<< local sql/sql_table.cc 1.438
-      if ((alter_flags & needed_online_flags) == needed_online_flags)
-      {
-        /* All required online flags are present. */
-        need_copy_table= ALTER_TABLE_METADATA_ONLY;
-        need_lock_for_indexes= FALSE;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
       /*
         If no table rename,
         check if table can be altered on-line
@@ -7860,202 +6479,59 @@ view_err:
                                                 table,
                                                 new_db,
                                                 create_info,
-                                                prepared_create_list2,
-                                                prepared_key_list2,
+                                                &tmp_alter_info,
                                                 !strcmp(db, new_db))))
         goto err;
-      switch(table->file->check_if_supported_alter(altered_table,
-                                                   create_info,
-                                                   &alter_table_flags,
-                                                   table_changes)) {
-      case(HA_ALTER_NOT_SUPPORTED):
-        need_copy_table= TRUE;
-        break;
-      case(HA_ALTER_SUPPORTED_WAIT_LOCK):
-        need_lock= TRUE;
-      case(HA_ALTER_SUPPORTED_NO_LOCK):
+      switch (table->file->check_if_supported_alter(altered_table,
+                                                    create_info,
+                                                    &alter_table_flags,
+                                                    table_changes)) {
+      case HA_ALTER_SUPPORTED_WAIT_LOCK:
+      case HA_ALTER_SUPPORTED_NO_LOCK:
+        /*
+          @todo: Currently we always acquire an exclusive name
+          lock on the table metadata when performing fast or online
+          ALTER TABLE. In future we may consider this unnecessary,
+          and narrow the scope of the exclusive name lock to only
+          cover manipulation with .frms. Storage engine API
+          call check_if_supported_alter has provision for this
+          already now.
+        */
         need_copy_table= FALSE;
         break;
-      case(HA_ALTER_ERROR):
+      case HA_ALTER_NOT_SUPPORTED:
+        need_copy_table= TRUE;
+        break;
+      case HA_ALTER_ERROR:
       default:
         goto err;
->>>>>>>
       }
 
 #ifndef DBUG_OFF
       {
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-        /* All required fast flags are present. */
-        need_copy_table= 0;
-<<<<<<< local sql/sql_table.cc 1.438
-        /* All required fast flags are present. */
-        need_copy_table= ALTER_TABLE_METADATA_ONLY;
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
         char dbug_string[HA_MAX_ALTER_FLAGS+1];
         alter_table_flags.print(dbug_string);
         DBUG_PRINT("info", ("need_copy_table: %u, Real alter_flags:  %s",
                             need_copy_table,
                             (char *) dbug_string));
->>>>>>>
       }
 #endif
 
     }
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    DBUG_PRINT("info", ("need_copy_table: %u  need_lock: %d",
-                        need_copy_table, need_lock_for_indexes));
-  }
-
-  /*
-    better have a negative test here, instead of positive, like
-    alter_info->flags & ALTER_ADD_COLUMN|ALTER_ADD_INDEX|...
-    so that ALTER TABLE won't break when somebody will add new flag
-  */
-  if (!need_copy_table)
-    create_info->frm_only= 1;
-
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-  if (fast_alter_partition)
-  {
-    DBUG_ASSERT(!name_lock);
-    DBUG_RETURN(fast_alter_partition_table(thd, table, alter_info,
-                                           create_info, table_list,
-                                           &create_list, &key_list,
-                                           db, table_name,
-                                           fast_alter_partition));
-  }
-#endif
-
-  /*
-    Handling of symlinked tables:
-    If no rename:
-      Create new data file and index file on the same disk as the
-      old data and index files.
-      Copy data.
-      Rename new data file over old data file and new index file over
-      old index file.
-      Symlinks are not changed.
-
-   If rename:
-      Create new data file and index file on the same disk as the
-      old data and index files.  Create also symlinks to point at
-      the new tables.
-      Copy data.
-      At end, rename intermediate tables, and symlinks to intermediate
-      table, to final table name.
-      Remove old table and old symlinks
-
-    If rename is made to another database:
-      Create new tables in new database.
-      Copy data.
-      Remove old table and symlinks.
-  */
-  if (!strcmp(db, new_db))		// Ignore symlink if db changed
-  {
-    if (create_info->index_file_name)
-    {
-      /* Fix index_file_name to have 'tmp_name' as basename */
-      strmov(index_file, tmp_name);
-      create_info->index_file_name=fn_same(index_file,
-					   create_info->index_file_name,
-					   1);
-    }
-    if (create_info->data_file_name)
-    {
-      /* Fix data_file_name to have 'tmp_name' as basename */
-      strmov(data_file, tmp_name);
-      create_info->data_file_name=fn_same(data_file,
-					  create_info->data_file_name,
-					  1);
-    }
-<<<<<<< local sql/sql_table.cc 1.438
-    DBUG_PRINT("info", ("need_copy_table: %u  need_lock: %d",
-                        need_copy_table, need_lock_for_indexes));
-  }
-
-  /*
-    better have a negative test here, instead of positive, like
-    alter_info->flags & ALTER_ADD_COLUMN|ALTER_ADD_INDEX|...
-    so that ALTER TABLE won't break when somebody will add new flag
-  */
-  if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
-    create_info->frm_only= 1;
-
-#ifdef WITH_PARTITION_STORAGE_ENGINE
-  if (fast_alter_partition)
-  {
-    DBUG_ASSERT(!name_lock);
-    DBUG_RETURN(fast_alter_partition_table(thd, table, alter_info,
-                                           create_info, table_list,
-                                           db, table_name,
-                                           fast_alter_partition));
-  }
-#endif
-
-  my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx", tmp_file_prefix,
-	      current_pid, thd->thread_id);
-  /* Safety fix for innodb */
-  if (lower_case_table_names)
-    my_casedn_str(files_charset_info, tmp_name);
-
-  /*
-    Handling of symlinked tables:
-    If no rename:
-      Create new data file and index file on the same disk as the
-      old data and index files.
-      Copy data.
-      Rename new data file over old data file and new index file over
-      old index file.
-      Symlinks are not changed.
-
-   If rename:
-      Create new data file and index file on the same disk as the
-      old data and index files.  Create also symlinks to point at
-      the new tables.
-      Copy data.
-      At end, rename intermediate tables, and symlinks to intermediate
-      table, to final table name.
-      Remove old table and old symlinks
-
-    If rename is made to another database:
-      Create new tables in new database.
-      Copy data.
-      Remove old table and symlinks.
-  */
-  if (!strcmp(db, new_db))		// Ignore symlink if db changed
-  {
-    if (create_info->index_file_name)
-    {
-      /* Fix index_file_name to have 'tmp_name' as basename */
-      strmov(index_file, tmp_name);
-      create_info->index_file_name=fn_same(index_file,
-					   create_info->index_file_name,
-					   1);
-    }
-    if (create_info->data_file_name)
-    {
-      /* Fix data_file_name to have 'tmp_name' as basename */
-      strmov(data_file, tmp_name);
-      create_info->data_file_name=fn_same(data_file,
-					  create_info->data_file_name,
-					  1);
-    }
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-  // TODO need to check if changes can be handled as fast ALTER TABLE
+    /* TODO need to check if changes can be handled as fast ALTER TABLE */
     if (!altered_table ||
         !(altered_table->file->ha_table_flags() & HA_ONLINE_ALTER))
       need_copy_table= TRUE;
 
     if (!need_copy_table)
     {
-     error= mysql_fast_or_online_alter_table(thd,
-                                             path,
-                                             table,
-                                             altered_table,
-                                             create_info,
-                                             &alter_table_info,
-                                             &alter_table_flags,
-                                             need_lock);
+      error= mysql_fast_or_online_alter_table(thd,
+                                              path,
+                                              table,
+                                              altered_table,
+                                              create_info,
+                                              &ha_alter_info,
+                                              &alter_table_flags);
       if (thd->lock)
       {
         mysql_unlock_tables(thd, thd->lock);
@@ -8075,7 +6551,7 @@ view_err:
 
   /* Create a temporary table with the new format */
   error= create_temporary_table(thd, table, new_db, tmp_name, create_info,
-                                create_list, key_list, !strcmp(db, new_db));
+                                alter_info, !strcmp(db, new_db));
 
   /* Open the table so we need to copy the data to it. */
   if (table->s->tmp_table)
@@ -8087,121 +6563,8 @@ view_err:
     /* Table is in thd->temporary_tables */
     new_table= open_table(thd, &tbl, thd->mem_root, (bool*) 0,
                           MYSQL_LOCK_IGNORE_FLUSH);
->>>>>>>
   }
   else
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    create_info->data_file_name=create_info->index_file_name=0;
-
-  if (new_db_type == old_db_type)
-  {
-    /*
-      Table has not changed storage engine.
-      If STORAGE and TABLESPACE have not been changed than copy them
-      from the original table
-    */
-    if (!create_info->tablespace && 
-	table->s->tablespace &&
-        create_info->default_storage_media == HA_SM_DEFAULT)
-      create_info->tablespace= table->s->tablespace;
-    if (create_info->default_storage_media == HA_SM_DEFAULT)
-      create_info->default_storage_media= table->s->default_storage_media;
-  }
-  /*
-    Create a table with a temporary name.
-    With create_info->frm_only == 1 this creates a .frm file only.
-    We don't log the statement, it will be logged later.
-  */
-  tmp_disable_binlog(thd);
-  error= mysql_create_table_no_lock(thd, new_db, tmp_name,
-                                    create_info, create_list,
-                                    key_list, 1, 0, 0);
-  reenable_binlog(thd);
-  if (error)
-    goto err;
-
-  /* Open the table if we need to copy the data. */
-  if (need_copy_table)
-  {
-    if (table->s->tmp_table)
-    {
-      TABLE_LIST tbl;
-      bzero((void*) &tbl, sizeof(tbl));
-      tbl.db= new_db;
-      tbl.table_name= tbl.alias= tmp_name;
-      /* Table is in thd->temporary_tables */
-      new_table= open_table(thd, &tbl, thd->mem_root, (bool*) 0,
-                            MYSQL_LOCK_IGNORE_FLUSH);
-    }
-    else
-    {
-      char path[FN_REFLEN];
-      /* table is a normal table: Create temporary table in same directory */
-      build_table_filename(path, sizeof(path), new_db, tmp_name, "",
-                           FN_IS_TMP);
-      /* Open our intermediate table */
-      new_table=open_temporary_table(thd, path, new_db, tmp_name,0);
-    }
-    if (!new_table)
-      goto err1;
-  }
-<<<<<<< local sql/sql_table.cc 1.438
-    create_info->data_file_name=create_info->index_file_name=0;
-
-  if (new_db_type == old_db_type)
-  {
-    /*
-      Table has not changed storage engine.
-      If STORAGE and TABLESPACE have not been changed than copy them
-      from the original table
-    */
-    if (!create_info->tablespace && 
-	table->s->tablespace &&
-        create_info->default_storage_media == HA_SM_DEFAULT)
-      create_info->tablespace= table->s->tablespace;
-    if (create_info->default_storage_media == HA_SM_DEFAULT)
-      create_info->default_storage_media= table->s->default_storage_media;
-  }
-  /*
-    Create a table with a temporary name.
-    With create_info->frm_only == 1 this creates a .frm file only.
-    We don't log the statement, it will be logged later.
-  */
-  tmp_disable_binlog(thd);
-  error= mysql_create_table_no_lock(thd, new_db, tmp_name,
-                                    create_info,
-                                    alter_info,
-                                    1, 0);
-  reenable_binlog(thd);
-  if (error)
-    goto err;
-
-  /* Open the table if we need to copy the data. */
-  if (need_copy_table != ALTER_TABLE_METADATA_ONLY)
-  {
-    if (table->s->tmp_table)
-    {
-      TABLE_LIST tbl;
-      bzero((void*) &tbl, sizeof(tbl));
-      tbl.db= new_db;
-      tbl.table_name= tbl.alias= tmp_name;
-      /* Table is in thd->temporary_tables */
-      new_table= open_table(thd, &tbl, thd->mem_root, (bool*) 0,
-                            MYSQL_LOCK_IGNORE_FLUSH);
-    }
-    else
-    {
-      char path[FN_REFLEN];
-      /* table is a normal table: Create temporary table in same directory */
-      build_table_filename(path, sizeof(path), new_db, tmp_name, "",
-                           FN_IS_TMP);
-      /* Open our intermediate table */
-      new_table=open_temporary_table(thd, path, new_db, tmp_name,0);
-    }
-    if (!new_table)
-      goto err1;
-  }
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
   {
     char path[FN_REFLEN];
     /* table is a normal table: Create temporary table in same directory */
@@ -8212,7 +6575,6 @@ view_err:
   }
   if (!new_table)
     goto err1;
->>>>>>>
 
   /* Copy the data if necessary. */
   thd->count_cuted_fields= CHECK_FIELD_WARN;	// calc cuted fields
@@ -8245,259 +6607,6 @@ view_err:
   }
   thd->count_cuted_fields= CHECK_FIELD_IGNORE;
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  /* If we did not need to copy, we might still need to add/drop indexes. */
-  if (! new_table)
-  {
-    uint          *key_numbers;
-    uint          *keyno_p;
-    KEY           *key_info;
-    KEY           *key;
-    uint          *idx_p;
-    uint          *idx_end_p;
-    KEY_PART_INFO *key_part;
-    KEY_PART_INFO *part_end;
-    DBUG_PRINT("info", ("No new_table, checking add/drop index"));
-
-    table->file->prepare_for_alter();
-    if (index_add_count)
-    {
-#ifdef XXX_TO_BE_DONE_LATER_BY_WL3020_AND_WL1892
-      if (! need_lock_for_indexes)
-      {
-        /* Downgrade the write lock. */
-        mysql_lock_downgrade_write(thd, table, TL_WRITE_ALLOW_WRITE);
-      }
-
-      /* Create a new .frm file for crash recovery. */
-      /* TODO: Must set INDEX_TO_BE_ADDED flags in the frm file. */
-      VOID(pthread_mutex_lock(&LOCK_open));
-      error= (mysql_create_frm(thd, reg_path, db, table_name,
-                               create_info, prepared_create_list, key_count,
-                               key_info_buffer, table->file) ||
-              table->file->create_handler_files(reg_path, NULL, CHF_INDEX_FLAG,
-                                                create_info));
-      VOID(pthread_mutex_unlock(&LOCK_open));
-      if (error)
-        goto err1;
-#endif
-
-      /* The add_index() method takes an array of KEY structs. */
-      key_info= (KEY*) thd->alloc(sizeof(KEY) * index_add_count);
-      key= key_info;
-      for (idx_p= index_add_buffer, idx_end_p= idx_p + index_add_count;
-           idx_p < idx_end_p;
-           idx_p++, key++)
-      {
-        /* Copy the KEY struct. */
-        *key= key_info_buffer[*idx_p];
-        /* Fix the key parts. */
-        part_end= key->key_part + key->key_parts;
-        for (key_part= key->key_part; key_part < part_end; key_part++)
-          key_part->field= table->field[key_part->fieldnr];
-      }
-      /* Add the indexes. */
-      if ((error= table->file->add_index(table, key_info, index_add_count)))
-      {
-        /*
-          Exchange the key_info for the error message. If we exchange
-          key number by key name in the message later, we need correct info.
-        */
-        KEY *save_key_info= table->key_info;
-        table->key_info= key_info;
-        table->file->print_error(error, MYF(0));
-        table->key_info= save_key_info;
-        goto err1;
-      }
-    }
-    /*end of if (index_add_count)*/
-
-    if (index_drop_count)
-    {
-#ifdef XXX_TO_BE_DONE_LATER_BY_WL3020_AND_WL1892
-      /* Create a new .frm file for crash recovery. */
-      /* TODO: Must set INDEX_IS_ADDED in the frm file. */
-      /* TODO: Must set INDEX_TO_BE_DROPPED in the frm file. */
-      VOID(pthread_mutex_lock(&LOCK_open));
-      error= (mysql_create_frm(thd, reg_path, db, table_name,
-                               create_info, prepared_create_list, key_count,
-                               key_info_buffer, table->file) ||
-              table->file->create_handler_files(reg_path, NULL, CHF_INDEX_FLAG,
-                                                create_info));
-      VOID(pthread_mutex_unlock(&LOCK_open));
-      if (error)
-        goto err1;
-
-      if (! need_lock_for_indexes)
-      {
-        LOCK_PARAM_TYPE lpt;
-
-        lpt.thd= thd;
-        lpt.table= table;
-        lpt.db= db;
-        lpt.table_name= table_name;
-        lpt.create_info= create_info;
-        lpt.create_list= &create_list;
-        lpt.key_count= key_count;
-        lpt.key_info_buffer= key_info_buffer;
-        abort_and_upgrade_lock(lpt);
-      }
-#endif
-
-      /* The prepare_drop_index() method takes an array of key numbers. */
-      key_numbers= (uint*) thd->alloc(sizeof(uint) * index_drop_count);
-      keyno_p= key_numbers;
-      /* Get the number of each key. */
-      for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
-           idx_p < idx_end_p;
-           idx_p++, keyno_p++)
-        *keyno_p= *idx_p;
-      /*
-        Tell the handler to prepare for drop indexes.
-        This re-numbers the indexes to get rid of gaps.
-      */
-      if ((error= table->file->prepare_drop_index(table, key_numbers,
-                                                  index_drop_count)))
-      {
-        table->file->print_error(error, MYF(0));
-        goto err1;
-      }
-
-#ifdef XXX_TO_BE_DONE_LATER_BY_WL3020
-      if (! need_lock_for_indexes)
-      {
-        /* Downgrade the lock again. */
-        if (table->reginfo.lock_type == TL_WRITE_ALLOW_READ)
-        {
-          LOCK_PARAM_TYPE lpt;
-
-          lpt.thd= thd;
-          lpt.table= table;
-          lpt.db= db;
-          lpt.table_name= table_name;
-          lpt.create_info= create_info;
-          lpt.create_list= &create_list;
-          lpt.key_count= key_count;
-          lpt.key_info_buffer= key_info_buffer;
-          close_open_tables_and_downgrade(lpt);
-        }
-      }
-#endif
-
-      /* Tell the handler to finally drop the indexes. */
-      if ((error= table->file->final_drop_index(table)))
-      {
-        table->file->print_error(error, MYF(0));
-        goto err1;
-      }
-    }
-    /*end of if (index_drop_count)*/
-
-    /*
-      The final .frm file is already created as a temporary file
-      and will be renamed to the original table name later.
-    */
-
-    /* Need to commit before a table is unlocked (NDB requirement). */
-    DBUG_PRINT("info", ("Committing before unlocking table"));
-    if (ha_commit_stmt(thd) || ha_commit(thd))
-      goto err1;
-    committed= 1;
-  }
-  /*end of if (! new_table) for add/drop index*/
-
-<<<<<<< local sql/sql_table.cc 1.438
-  /* If we did not need to copy, we might still need to add/drop indexes. */
-  if (! new_table)
-  {
-    uint          *key_numbers;
-    uint          *keyno_p;
-    KEY           *key_info;
-    KEY           *key;
-    uint          *idx_p;
-    uint          *idx_end_p;
-    KEY_PART_INFO *key_part;
-    KEY_PART_INFO *part_end;
-    DBUG_PRINT("info", ("No new_table, checking add/drop index"));
-
-    table->file->prepare_for_alter();
-    if (index_add_count)
-    {
-      /* The add_index() method takes an array of KEY structs. */
-      key_info= (KEY*) thd->alloc(sizeof(KEY) * index_add_count);
-      key= key_info;
-      for (idx_p= index_add_buffer, idx_end_p= idx_p + index_add_count;
-           idx_p < idx_end_p;
-           idx_p++, key++)
-      {
-        /* Copy the KEY struct. */
-        *key= key_info_buffer[*idx_p];
-        /* Fix the key parts. */
-        part_end= key->key_part + key->key_parts;
-        for (key_part= key->key_part; key_part < part_end; key_part++)
-          key_part->field= table->field[key_part->fieldnr];
-      }
-      /* Add the indexes. */
-      if ((error= table->file->add_index(table, key_info, index_add_count)))
-      {
-        /*
-          Exchange the key_info for the error message. If we exchange
-          key number by key name in the message later, we need correct info.
-        */
-        KEY *save_key_info= table->key_info;
-        table->key_info= key_info;
-        table->file->print_error(error, MYF(0));
-        table->key_info= save_key_info;
-        goto err1;
-      }
-    }
-    /*end of if (index_add_count)*/
-
-    if (index_drop_count)
-    {
-      /* The prepare_drop_index() method takes an array of key numbers. */
-      key_numbers= (uint*) thd->alloc(sizeof(uint) * index_drop_count);
-      keyno_p= key_numbers;
-      /* Get the number of each key. */
-      for (idx_p= index_drop_buffer, idx_end_p= idx_p + index_drop_count;
-           idx_p < idx_end_p;
-           idx_p++, keyno_p++)
-        *keyno_p= *idx_p;
-      /*
-        Tell the handler to prepare for drop indexes.
-        This re-numbers the indexes to get rid of gaps.
-      */
-      if ((error= table->file->prepare_drop_index(table, key_numbers,
-                                                  index_drop_count)))
-      {
-        table->file->print_error(error, MYF(0));
-        goto err1;
-      }
-
-      /* Tell the handler to finally drop the indexes. */
-      if ((error= table->file->final_drop_index(table)))
-      {
-        table->file->print_error(error, MYF(0));
-        goto err1;
-      }
-    }
-    /*end of if (index_drop_count)*/
-
-    /*
-      The final .frm file is already created as a temporary file
-      and will be renamed to the original table name later.
-    */
-
-    /* Need to commit before a table is unlocked (NDB requirement). */
-    DBUG_PRINT("info", ("Committing before unlocking table"));
-    if (ha_commit_stmt(thd) || ha_commit(thd))
-      goto err1;
-    committed= 1;
-  }
-  /*end of if (! new_table) for add/drop index*/
-
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
->>>>>>>
   if (table->s->tmp_table != NO_TMP_TABLE)
   {
     /* We changed a temporary table */
@@ -8575,18 +6684,6 @@ view_err:
     table is renamed and the SE is also changed, then an intermediate table
     is created and the additional call will not take place.
   */
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-  if (!need_copy_table)
-    new_db_type=old_db_type= NULL; // this type cannot happen in regular ALTER
-<<<<<<< local sql/sql_table.cc 1.438
-  if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
-  {
-    DBUG_ASSERT(new_db_type == old_db_type);
-    /* This type cannot happen in regular ALTER. */
-    new_db_type= old_db_type= NULL;
-  }
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
->>>>>>>
   if (mysql_rename_table(old_db_type, db, table_name, db, old_name,
                          FN_TO_IS_TMP))
   {
@@ -8596,9 +6693,8 @@ view_err:
   else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db,
                               new_alias, FN_FROM_IS_TMP) ||
            (new_name != table_name || new_db != db) && // we also do rename
-           (need_copy_table != ALTER_TABLE_METADATA_ONLY ||
-            mysql_rename_table(save_old_db_type, db, table_name, new_db,
-                               new_alias, NO_FRM_RENAME)) &&
+           mysql_rename_table(save_old_db_type, db, table_name, new_db,
+                               new_alias, NO_FRM_RENAME) &&
            Table_triggers_list::change_table_name(thd, db, table_name,
                                                   new_db, new_alias))
   {
@@ -8612,183 +6708,10 @@ view_err:
 
   if (error)
   {
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    /*
-      This shouldn't happen.  We solve this the safe way by
-      closing the locked table.
-    */
-    if (table)
-    {
-      close_cached_table(thd,table);
-    }
-    VOID(pthread_mutex_unlock(&LOCK_open));
-    goto err;
-  }
-  if (! need_copy_table)
-  {
-    bool needs_unlink= FALSE;
-    if (! table)
-    {
-      if (new_name != table_name || new_db != db)
-      {
-        table_list->alias= new_name;
-        table_list->table_name= new_name;
-        table_list->table_name_length= strlen(new_name);
-        table_list->db= new_db;
-        table_list->db_length= strlen(new_db);
-      }
-      else
-      {
-        /*
-          TODO: Creation of name-lock placeholder here is a temporary
-          work-around. Long term we should change close_cached_table() call
-          which we invoke before table renaming operation in such way that
-          it will leave placeholders for table in table cache/THD::open_tables
-          list. By doing this we will be able easily reopen and relock these
-          tables later and therefore behave under LOCK TABLES in the same way
-          on all platforms.
-        */
-        char  key[MAX_DBKEY_LENGTH];
-        uint  key_length;
-        key_length= create_table_def_key(thd, key, table_list, 0);
-        if (!(name_lock= table_cache_insert_placeholder(thd, key,
-                                                        key_length)))
-        {
-          VOID(pthread_mutex_unlock(&LOCK_open));
-          goto err;
-        }
-        name_lock->next= thd->open_tables;
-        thd->open_tables= name_lock;
-      }
-      table_list->table= name_lock;
-      if (reopen_name_locked_table(thd, table_list, FALSE))
-      {
-        VOID(pthread_mutex_unlock(&LOCK_open));
-        goto err;
-      }
-      table= table_list->table;
-      /*
-        We can't rely on later close_cached_table() calls to close
-        this instance of the table since it was not properly locked.
-      */
-      needs_unlink= TRUE;
-    }
-    /* Tell the handler that a new frm file is in place. */
-    if (table->file->create_handler_files(path, NULL, CHF_INDEX_FLAG,
-                                          create_info))
-    {
-      VOID(pthread_mutex_unlock(&LOCK_open));
-      goto err;
-    }
-    if (needs_unlink)
-    {
-      unlink_open_table(thd, table, FALSE);
-      table= name_lock= 0;
-    }
-  }
-
-  if (thd->lock || new_name != table_name || no_table_reopen)  // True if WIN32
-  {
-    /*
-      Not table locking or alter table with rename.
-      Free locks and remove old table
-    */
-    if (table)
-    {
-      close_cached_table(thd,table);
-    }
-    VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
-  }
-  else
-  {
-    /*
-      Using LOCK TABLES without rename.
-      This code is never executed on WIN32!
-      Remove old renamed table, reopen table and get new locks
-    */
-    if (table)
-    {
-      VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Use new file
-      /* Mark in-use copies old */
-      remove_table_from_cache(thd,db,table_name,RTFC_NO_FLAG);
-      /* end threads waiting on lock */
-      mysql_lock_abort(thd,table, TRUE);
-    }
-    VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
-    if (close_data_tables(thd,db,table_name) ||
-	reopen_tables(thd,1,0))
-    {						// This shouldn't happen
-      if (table)
-      {
-	close_cached_table(thd,table);		// Remove lock for table
-      }
-      VOID(pthread_mutex_unlock(&LOCK_open));
-      goto err;
-    }
-  }
-  VOID(pthread_mutex_unlock(&LOCK_open));
-  broadcast_refresh();
-  /*
-    The ALTER TABLE is always in its own transaction.
-    Commit must not be called while LOCK_open is locked. It could call
-    wait_if_global_read_lock(), which could create a deadlock if called
-    with LOCK_open.
-  */
-  if (!committed)
-  {
-    error = ha_commit_stmt(thd);
-    if (ha_commit(thd))
-      error=1;
-    if (error)
-      goto err;
-  }
-<<<<<<< local sql/sql_table.cc 1.438
     /* This shouldn't happen. But let us play it safe. */
     goto err_with_placeholders;
   }
 
-  if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
-  {
-    /*
-      Now we have to inform handler that new .FRM file is in place.
-      To do this we need to obtain a handler object for it.
-    */
-    TABLE *t_table;
-    if (new_name != table_name || new_db != db)
-    {
-      table_list->alias= new_name;
-      table_list->table_name= new_name;
-      table_list->table_name_length= strlen(new_name);
-      table_list->db= new_db;
-      table_list->db_length= strlen(new_db);
-      table_list->table= name_lock;
-      if (reopen_name_locked_table(thd, table_list, FALSE))
-        goto err_with_placeholders;
-      t_table= table_list->table;
-    }
-    else
-    {
-      if (reopen_table(table))
-        goto err_with_placeholders;
-      t_table= table;
-    }
-    /* Tell the handler that a new frm file is in place. */
-    if (t_table->file->create_handler_files(path, NULL, CHF_INDEX_FLAG,
-                                            create_info))
-      goto err_with_placeholders;
-    if (thd->locked_tables && new_name == table_name && new_db == db)
-    {
-      /*
-        We are going to reopen table down on the road, so we have to restore
-        state of the TABLE object which we used for obtaining of handler
-        object to make it suitable for reopening.
-      */
-      DBUG_ASSERT(t_table == table);
-      table->open_placeholder= 1;
-      close_handle_and_leave_table_as_lock(table);
-    }
-  }
-
   VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
 
   if (thd->locked_tables && new_name == table_name && new_db == db)
@@ -8801,83 +6724,10 @@ view_err:
   }
   VOID(pthread_mutex_unlock(&LOCK_open));
 
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-    /*
-      This shouldn't happen.  We solve this the safe way by
-      closing the locked table.
-    */
-    if (table)
-    {
-      close_cached_table(thd,table);
-    }
-    VOID(pthread_mutex_unlock(&LOCK_open));
-    goto err;
-  }
-
-  if (thd->lock || new_name != table_name || no_table_reopen)  // True if WIN32
-  {
-    /*
-      Not table locking or alter table with rename.
-      Free locks and remove old table
-    */
-    if (table)
-    {
-      close_cached_table(thd,table);
-    }
-    VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
-  }
-  else
-  {
-    /*
-      Using LOCK TABLES without rename.
-      This code is never executed on WIN32!
-      Remove old renamed table, reopen table and get new locks
-    */
-    if (table)
-    {
-      VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Use new file
-      /* Mark in-use copies old */
-      remove_table_from_cache(thd,db,table_name,RTFC_NO_FLAG);
-      /* end threads waiting on lock */
-      mysql_lock_abort(thd,table, TRUE);
-    }
-    VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
-    if (close_data_tables(thd,db,table_name) ||
-	reopen_tables(thd,1,0))
-    {						// This shouldn't happen
-      if (table)
-      {
-	close_cached_table(thd,table);		// Remove lock for table
-      }
-      VOID(pthread_mutex_unlock(&LOCK_open));
-      goto err;
-    }
-  }
-  VOID(pthread_mutex_unlock(&LOCK_open));
-  broadcast_refresh();
-  /*
-    The ALTER TABLE is always in its own transaction.
-    Commit must not be called while LOCK_open is locked. It could call
-    wait_if_global_read_lock(), which could create a deadlock if called
-    with LOCK_open.
-  */
-  if (!committed)
-  {
-    error = ha_commit_stmt(thd);
-    if (ha_commit(thd))
-      error=1;
-    if (error)
-      goto err;
-  }
->>>>>>>
   thd->proc_info="end";
 
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-<<<<<<< local sql/sql_table.cc 1.438
   DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000););
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
 end_online:
->>>>>>>
 
   ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE,
                       thd->query, thd->query_length,
@@ -8898,16 +6748,8 @@ end_online:
     char path[FN_REFLEN];
     TABLE *t_table;
     build_table_filename(path, sizeof(path), new_db, table_name, "", 0);
-<<<<<<< gca sql/sql_table.cc 1.416.6.2
-    table=open_temporary_table(thd, path, new_db, tmp_name,0);
-    if (table)
-<<<<<<< local sql/sql_table.cc 1.438
-    t_table= open_temporary_table(thd, path, new_db, tmp_name, 0);
+    t_table= open_temporary_table(thd, path, new_db, tmp_name, FALSE, OTM_OPEN);
     if (t_table)
-<<<<<<< remote sql/sql_table.cc 1.416.6.4
-    table=open_temporary_table(thd, path, new_db, tmp_name, 0, OTM_OPEN);
-    if (table)
->>>>>>>
     {
       intern_close_table(t_table);
       my_free(t_table, MYF(0));
diff -Nrup a/sql/table.cc b/sql/table.cc
--- a/sql/table.cc	2007-08-10 18:19:12 +04:00
+++ b/sql/table.cc	2007-08-14 18:14:01 +04:00
@@ -1796,7 +1796,7 @@ int open_table_from_share(THD *thd, TABL
     if (!tmp)
     {
       if (work_part_info_used)
-        tmp= fix_partition_func(thd, outparam, is_create_table);
+        tmp= fix_partition_func(thd, outparam, (open_mode != OTM_OPEN));
       outparam->part_info->item_free_list= part_func_arena.free_list;
     }
     if (tmp)
Thread
bk commit into 5.1 tree (kostja:1.2547)konstantin14 Aug