List:Commits« Previous MessageNext Message »
From:smenon Date:September 28 2010 8:45am
Subject:bzr push into mysql-5.1 branch (sunanda.menon:3469 to 3470)
View as plain text  
 3470 karen.langford@stripped	2010-09-28 [merge]
      Merge from mysql-5.1.51-release

    added:
      mysql-test/extra/rpl_tests/rpl_stm_create_if_not_exists.test
      mysql-test/include/not_blackhole.inc
      mysql-test/r/partition_not_blackhole.result
      mysql-test/std_data/parts/t1_blackhole.frm
      mysql-test/std_data/parts/t1_blackhole.par
      mysql-test/suite/binlog/r/binlog_mixed_load_data.result
      mysql-test/suite/binlog/t/binlog_mixed_load_data.test
      mysql-test/suite/rpl/r/rpl_stm_create_if_not_exists.result
      mysql-test/suite/rpl/t/rpl_stm_create_if_not_exists.test
      mysql-test/t/partition_not_blackhole-master.opt
      mysql-test/t/partition_not_blackhole.test
    modified:
      README
      client/mysqltest.cc
      include/Makefile.am
      mysql-test/collections/default.experimental
      mysql-test/extra/rpl_tests/rpl_loaddata.test
      mysql-test/include/mix2.inc
      mysql-test/include/rpl_diff_tables.inc
      mysql-test/lib/My/Config.pm
      mysql-test/lib/My/ConfigFactory.pm
      mysql-test/lib/My/SafeProcess.pm
      mysql-test/lib/mtr_cases.pm
      mysql-test/lib/mtr_report.pm
      mysql-test/mysql-test-run.pl
      mysql-test/r/csv.result
      mysql-test/r/delete.result
      mysql-test/r/func_group.result
      mysql-test/r/func_sapdb.result
      mysql-test/r/func_time.result
      mysql-test/r/gis.result
      mysql-test/r/insert.result
      mysql-test/r/join.result
      mysql-test/r/mysqltest.result
      mysql-test/r/partition_range.result
      mysql-test/r/range.result
      mysql-test/r/subselect4.result
      mysql-test/r/timezone2.result
      mysql-test/r/trigger.result
      mysql-test/r/user_var.result
      mysql-test/suite/binlog/t/binlog_killed_simulate.test
      mysql-test/suite/binlog/t/binlog_stm_blackhole.test
      mysql-test/suite/funcs_1/r/innodb_storedproc_06.result
      mysql-test/suite/funcs_1/r/innodb_storedproc_10.result
      mysql-test/suite/funcs_1/r/innodb_trig_03.result
      mysql-test/suite/funcs_1/r/innodb_trig_03e.result
      mysql-test/suite/funcs_1/r/innodb_trig_0407.result
      mysql-test/suite/funcs_1/r/innodb_trig_08.result
      mysql-test/suite/funcs_1/r/memory_storedproc_06.result
      mysql-test/suite/funcs_1/r/memory_storedproc_10.result
      mysql-test/suite/funcs_1/r/memory_trig_03.result
      mysql-test/suite/funcs_1/r/memory_trig_03e.result
      mysql-test/suite/funcs_1/r/memory_trig_0407.result
      mysql-test/suite/funcs_1/r/memory_trig_08.result
      mysql-test/suite/funcs_1/r/myisam_storedproc_06.result
      mysql-test/suite/funcs_1/r/myisam_storedproc_10.result
      mysql-test/suite/funcs_1/r/myisam_trig_03.result
      mysql-test/suite/funcs_1/r/myisam_trig_03e.result
      mysql-test/suite/funcs_1/r/myisam_trig_0407.result
      mysql-test/suite/funcs_1/r/myisam_trig_08.result
      mysql-test/suite/funcs_1/r/ndb_storedproc_06.result
      mysql-test/suite/funcs_1/r/ndb_storedproc_10.result
      mysql-test/suite/funcs_1/r/ndb_trig_03.result
      mysql-test/suite/funcs_1/r/ndb_trig_03e.result
      mysql-test/suite/funcs_1/r/ndb_trig_0407.result
      mysql-test/suite/funcs_1/r/ndb_trig_08.result
      mysql-test/suite/funcs_1/r/storedproc.result
      mysql-test/suite/funcs_1/storedproc/storedproc_06.inc
      mysql-test/suite/funcs_1/storedproc/storedproc_10.inc
      mysql-test/suite/funcs_1/triggers/triggers_03.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_columns.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_db_level.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_db_table_mix.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_definer.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_global_db_mix.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_prepare.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_table_level.inc
      mysql-test/suite/funcs_1/triggers/triggers_03e_transaction.inc
      mysql-test/suite/funcs_1/triggers/triggers_0407.inc
      mysql-test/suite/funcs_1/triggers/triggers_08.inc
      mysql-test/suite/innodb/r/innodb-autoinc.result
      mysql-test/suite/innodb/r/innodb_mysql.result
      mysql-test/suite/innodb/t/innodb-autoinc.test
      mysql-test/suite/innodb/t/innodb_mysql.test
      mysql-test/suite/innodb_plugin/r/innodb-autoinc.result
      mysql-test/suite/innodb_plugin/t/innodb-autoinc-44030.test
      mysql-test/suite/innodb_plugin/t/innodb-autoinc.test
      mysql-test/suite/rpl/r/rpl_create_if_not_exists.result
      mysql-test/suite/rpl/r/rpl_create_tmp_table_if_not_exists.result
      mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result
      mysql-test/suite/rpl/r/rpl_row_create_table.result
      mysql-test/suite/rpl/t/disabled.def
      mysql-test/suite/rpl/t/rpl_create_if_not_exists.test
      mysql-test/suite/rpl/t/rpl_loaddata_fatal.test
      mysql-test/suite/rpl/t/rpl_loaddata_map.test
      mysql-test/suite/rpl/t/rpl_row_create_table.test
      mysql-test/suite/rpl/t/rpl_slave_load_remove_tmpfile.test
      mysql-test/suite/rpl/t/rpl_stm_log.test
      mysql-test/t/csv.test
      mysql-test/t/delete.test
      mysql-test/t/func_group.test
      mysql-test/t/func_time.test
      mysql-test/t/gis.test
      mysql-test/t/insert.test
      mysql-test/t/join.test
      mysql-test/t/mysqlbinlog.test
      mysql-test/t/mysqltest.test
      mysql-test/t/partition_range.test
      mysql-test/t/range.test
      mysql-test/t/subselect4.test
      mysql-test/t/timezone2.test
      mysql-test/t/user_var.test
      mysys/my_getopt.c
      scripts/make_win_bin_dist
      sql/field.cc
      sql/ha_partition.cc
      sql/item_cmpfunc.cc
      sql/item_func.cc
      sql/item_func.h
      sql/item_geofunc.h
      sql/item_sum.cc
      sql/item_sum.h
      sql/item_timefunc.h
      sql/log.cc
      sql/mysqld.cc
      sql/opt_range.cc
      sql/spatial.cc
      sql/sql_class.h
      sql/sql_insert.cc
      sql/sql_lex.h
      sql/sql_load.cc
      sql/sql_parse.cc
      sql/sql_plugin.cc
      sql/sql_select.cc
      sql/sql_select.h
      sql/sql_show.cc
      sql/sql_string.h
      sql/sql_update.cc
      sql/sql_yacc.yy
      sql/tztime.cc
      storage/innobase/dict/dict0dict.c
      storage/innobase/dict/dict0load.c
      storage/innobase/fil/fil0fil.c
      storage/innobase/fsp/fsp0fsp.c
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/include/db0err.h
      storage/innobase/include/dict0dict.h
      storage/innobase/include/dict0dict.ic
      storage/innobase/include/dict0load.h
      storage/innobase/include/dict0mem.h
      storage/innobase/include/fil0fil.h
      storage/innobase/include/que0que.h
      storage/innobase/include/univ.i
      storage/innobase/row/row0mysql.c
      storage/innodb_plugin/ChangeLog
      storage/innodb_plugin/btr/btr0cur.c
      storage/innodb_plugin/btr/btr0sea.c
      storage/innodb_plugin/dict/dict0dict.c
      storage/innodb_plugin/dict/dict0load.c
      storage/innodb_plugin/ha/ha0ha.c
      storage/innodb_plugin/handler/ha_innodb.cc
      storage/innodb_plugin/include/btr0cur.h
      storage/innodb_plugin/include/btr0sea.h
      storage/innodb_plugin/include/db0err.h
      storage/innodb_plugin/include/dict0dict.h
      storage/innodb_plugin/include/dict0dict.ic
      storage/innodb_plugin/include/dict0load.h
      storage/innodb_plugin/include/dict0mem.h
      storage/innodb_plugin/include/ha0ha.h
      storage/innodb_plugin/include/que0que.h
      storage/innodb_plugin/include/univ.i
      storage/innodb_plugin/include/ut0mem.h
      storage/innodb_plugin/row/row0merge.c
      storage/innodb_plugin/row/row0mysql.c
      storage/innodb_plugin/row/row0sel.c
      storage/innodb_plugin/row/row0upd.c
      storage/innodb_plugin/trx/trx0undo.c
      storage/innodb_plugin/ut/ut0mem.c
      support-files/my-innodb-heavy-4G.cnf.sh
 3469 Georgi Kodinov	2010-09-13
       Raise version number after cloning 5.1.51

    modified:
      configure.in
=== modified file 'README'
--- a/README	2009-08-11 14:25:40 +0000
+++ b/README	2010-08-10 13:39:57 +0000
@@ -1,5 +1,5 @@
-This is a release of MySQL, a dual-license SQL database server.
-MySQL is brought to you by the MySQL team at Sun Microsystems, Inc.
+This is a release of MySQL, a dual-license SQL DBMS.
+MySQL is brought to you by the MySQL team at Oracle Corporation.
 
 License information can be found in these files:
 - For GPL (free) distributions, see the COPYING file and

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2010-07-02 18:30:47 +0000
+++ b/client/mysqltest.cc	2010-08-26 13:14:50 +0000
@@ -188,6 +188,8 @@ static void init_re(void);
 static int match_re(my_regex_t *, char *);
 static void free_re(void);
 
+static uint opt_protocol=0;
+
 DYNAMIC_ARRAY q_lines;
 
 #include "sslopt-vars.h"
@@ -608,8 +610,11 @@ public:
 
       if ((bytes= fread(buf, 1, sizeof(buf), m_file)) <= 0)
       {
-        fprintf(stderr, "Failed to read from '%s', errno: %d\n",
-                m_file_name, errno);
+	// ferror=0 will happen here if no queries executed yet
+	if (ferror(m_file))
+	  fprintf(stderr,
+	          "Failed to read from '%s', errno: %d, feof:%d, ferror:%d\n",
+	          m_file_name, errno, feof(m_file), ferror(m_file));
         DBUG_VOID_RETURN;
       }
 
@@ -1081,8 +1086,9 @@ void handle_command_error(struct st_comm
                           command->first_word_len, command->query, error));
       DBUG_VOID_RETURN;
     }
-    die("command \"%.*s\" failed with wrong error: %d",
-        command->first_word_len, command->query, error);
+    if (command->expected_errors.count > 0)
+      die("command \"%.*s\" failed with wrong error: %d",
+          command->first_word_len, command->query, error);
   }
   else if (command->expected_errors.err[0].type == ERR_ERRNO &&
            command->expected_errors.err[0].code.errnum != 0)
@@ -1352,14 +1358,14 @@ void log_msg(const char *fmt, ...)
 
 */
 
-void cat_file(DYNAMIC_STRING* ds, const char* filename)
+int cat_file(DYNAMIC_STRING* ds, const char* filename)
 {
   int fd;
   size_t len;
   char buff[512];
 
   if ((fd= my_open(filename, O_RDONLY, MYF(0))) < 0)
-    die("Failed to open file '%s'", filename);
+    return 1;
   while((len= my_read(fd, (uchar*)&buff,
                       sizeof(buff), MYF(0))) > 0)
   {
@@ -1383,6 +1389,7 @@ void cat_file(DYNAMIC_STRING* ds, const
     dynstr_append_mem(ds, start, p-start);
   }
   my_close(fd, MYF(0));
+  return 0;
 }
 
 
@@ -2376,6 +2383,9 @@ void eval_expr(VAR *v, const char *p, co
     if ((vp= var_get(p, p_end, 0, 0)))
       var_copy(v, vp);
 
+    /* Apparently it is not safe to assume null-terminated string */
+    v->str_val[v->str_val_len]= 0;
+
     /* Make sure there was just a $variable and nothing else */
     const char* end= *p_end + 1;
     if (end < expected_end)
@@ -2722,8 +2732,9 @@ void do_exec(struct st_command *command)
     else
     {
       dynstr_free(&ds_cmd);
-      die("command \"%s\" failed with wrong error: %d",
-          command->first_argument, status);
+      if (command->expected_errors.count > 0)
+        die("command \"%s\" failed with wrong error: %d",
+            command->first_argument, status);
     }
   }
   else if (command->expected_errors.err[0].type == ERR_ERRNO &&
@@ -2869,6 +2880,41 @@ void do_system(struct st_command *comman
 
 /*
   SYNOPSIS
+  set_wild_chars
+  set  true to set * etc. as wild char, false to reset
+
+  DESCRIPTION
+  Auxiliary function to set "our" wild chars before calling wild_compare
+  This is needed because the default values are changed to SQL syntax
+  in mysqltest_embedded.
+*/
+
+void set_wild_chars (my_bool set)
+{
+  static char old_many= 0, old_one, old_prefix;
+
+  if (set) 
+  {
+    if (wild_many == '*') return; // No need
+    old_many= wild_many;
+    old_one= wild_one;
+    old_prefix= wild_prefix;
+    wild_many= '*';
+    wild_one= '?';
+    wild_prefix= 0;
+  }
+  else 
+  {
+    if (! old_many) return;	// Was not set
+    wild_many= old_many;
+    wild_one= old_one;
+    wild_prefix= old_prefix;
+  }
+}
+
+
+/*
+  SYNOPSIS
   do_remove_file
   command	called command
 
@@ -2943,6 +2989,10 @@ void do_remove_files_wildcard(struct st_
   dir_separator[0]= FN_LIBCHAR;
   dir_separator[1]= 0;
   dynstr_append(&ds_file_to_remove, dir_separator);
+  
+  /* Set default wild chars for wild_compare, is changed in embedded mode */
+  set_wild_chars(1);
+  
   for (i= 0; i < (uint) dir_info->number_off_files; i++)
   {
     file= dir_info->dir_entry + i;
@@ -2962,6 +3012,7 @@ void do_remove_files_wildcard(struct st_
     if (error)
       break;
   }
+  set_wild_chars(0);
   my_dirend(dir_info);
 
 end:
@@ -3203,6 +3254,7 @@ static int get_list_files(DYNAMIC_STRING
   /* Note that my_dir sorts the list if not given any flags */
   if (!(dir_info= my_dir(ds_dirname->str, MYF(0))))
     DBUG_RETURN(1);
+  set_wild_chars(1);
   for (i= 0; i < (uint) dir_info->number_off_files; i++)
   {
     file= dir_info->dir_entry + i;
@@ -3216,6 +3268,7 @@ static int get_list_files(DYNAMIC_STRING
     dynstr_append(ds, file->name);
     dynstr_append(ds, "\n");
   }
+  set_wild_chars(0);
   my_dirend(dir_info);
   DBUG_RETURN(0);
 }
@@ -3498,6 +3551,7 @@ void do_append_file(struct st_command *c
 
 void do_cat_file(struct st_command *command)
 {
+  int error;
   static DYNAMIC_STRING ds_filename;
   const struct command_arg cat_file_args[] = {
     { "filename", ARG_STRING, TRUE, &ds_filename, "File to read from" }
@@ -3512,8 +3566,8 @@ void do_cat_file(struct st_command *comm
 
   DBUG_PRINT("info", ("Reading from, file: %s", ds_filename.str));
 
-  cat_file(&ds_res, ds_filename.str);
-
+  error= cat_file(&ds_res, ds_filename.str);
+  handle_command_error(command, error);
   dynstr_free(&ds_filename);
   DBUG_VOID_RETURN;
 }
@@ -3776,8 +3830,9 @@ void do_perl(struct st_command *command)
     }
     error= pclose(res_file);
 
-    /* Remove the temporary file */
-    my_delete(temp_file_path, MYF(0));
+    /* Remove the temporary file, but keep it if perl failed */
+    if (!error)
+      my_delete(temp_file_path, MYF(0));
 
     handle_command_error(command, WEXITSTATUS(error));
   }
@@ -4920,7 +4975,7 @@ int connect_n_handle_errors(struct st_co
   ds= &ds_res;
 
   /* Only log if an error is expected */
-  if (!command->abort_on_error &&
+  if (command->expected_errors.count > 0 &&
       !disable_query_log)
   {
     /*
@@ -5161,11 +5216,13 @@ void do_connect(struct st_command *comma
 #ifdef __WIN__
   if (con_pipe)
   {
-    uint protocol= MYSQL_PROTOCOL_PIPE;
-    mysql_options(&con_slot->mysql, MYSQL_OPT_PROTOCOL, &protocol);
+    opt_protocol= MYSQL_PROTOCOL_PIPE;
   }
 #endif
 
+  if (opt_protocol)
+    mysql_options(&con_slot->mysql, MYSQL_OPT_PROTOCOL, (char*) &opt_protocol);
+
 #ifdef HAVE_SMEM
   if (con_shm)
   {
@@ -5337,8 +5394,20 @@ void do_block(enum block_cmd cmd, struct
   /* Define inner block */
   cur_block++;
   cur_block->cmd= cmd;
-  cur_block->ok= (v.int_val ? TRUE : FALSE);
+  if (v.int_val)
+  {
+    cur_block->ok= TRUE;
+  } else
+  /* Any non-empty string which does not begin with 0 is also TRUE */
+  {
+    p= v.str_val;
+    /* First skip any leading white space or unary -+ */
+    while (*p && ((my_isspace(charset_info, *p) || *p == '-' || *p == '+')))
+      p++;
 
+    cur_block->ok= (*p && *p != '0') ? TRUE : FALSE;
+  }
+  
   if (not_expr)
     cur_block->ok = !cur_block->ok;
 
@@ -5882,6 +5951,8 @@ static struct my_option my_long_options[
    GET_INT, REQUIRED_ARG, 128, 8, 5120, 0, 0, 0},
   {"password", 'p', "Password to use when connecting to server.",
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"port", 'P', "Port number to use for connection or 0 for default to, in "
    "order of preference, my.cnf, $MYSQL_TCP_PORT, "
 #if MYSQL_PORT_DEFAULT == 0
@@ -6018,7 +6089,7 @@ void read_embedded_server_arguments(cons
 
 
 static my_bool
-get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+get_one_option(int optid, const struct my_option *opt,
 	       char *argument)
 {
   switch(optid) {
@@ -6107,6 +6178,12 @@ get_one_option(int optid, const struct m
   case 'V':
     print_version();
     exit(0);
+  case OPT_MYSQL_PROTOCOL:
+#ifndef EMBEDDED_LIBRARY
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
+#endif
+    break;
   case '?':
     usage();
     exit(0);
@@ -7571,9 +7648,6 @@ void get_command_type(struct st_command*
          sizeof(saved_expected_errors));
   DBUG_PRINT("info", ("There are %d expected errors",
                       command->expected_errors.count));
-  command->abort_on_error= (command->expected_errors.count == 0 &&
-                            abort_on_error);
-
   DBUG_VOID_RETURN;
 }
 
@@ -7860,6 +7934,9 @@ int main(int argc, char **argv)
     mysql_options(&con->mysql, MYSQL_SET_CHARSET_DIR,
                   opt_charsets_dir);
 
+  if (opt_protocol)
+    mysql_options(&con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
+
 #ifdef HAVE_OPENSSL
 
   if (opt_use_ssl)
@@ -7918,6 +7995,10 @@ int main(int argc, char **argv)
       command->type= Q_COMMENT;
     }
 
+    /* (Re-)set abort_on_error for this command */
+    command->abort_on_error= (command->expected_errors.count == 0 &&
+                              abort_on_error);
+    
     /* delimiter needs to be executed so we can continue to parse */
     my_bool ok_to_do= cur_block->ok || command->type == Q_DELIMITER;
     /*
@@ -8292,16 +8373,6 @@ int main(int argc, char **argv)
 	check_result();
       }
     }
-    else
-    {
-      /*
-        No result_file_name specified, the result
-        has been printed to stdout, exit with error
-        unless script has called "exit" to indicate success
-      */
-      if (abort_flag == 0)
-        die("Exit with failure! Call 'exit' in script to return with sucess");
-    }
   }
   else
   {

=== modified file 'include/Makefile.am'
--- a/include/Makefile.am	2010-07-14 12:27:13 +0000
+++ b/include/Makefile.am	2010-08-24 13:48:45 +0000
@@ -26,7 +26,8 @@ pkginclude_HEADERS =	$(HEADERS_ABI) my_d
 			decimal.h errmsg.h my_global.h my_net.h \
 			my_getopt.h sslopt-longopts.h my_dir.h \
 			sslopt-vars.h sslopt-case.h sql_common.h keycache.h \
-			m_ctype.h my_attribute.h $(HEADERS_GEN_CONFIGURE) \
+			m_ctype.h my_attribute.h my_compiler.h \
+			$(HEADERS_GEN_CONFIGURE) \
 			$(HEADERS_GEN_MAKE)
 
 noinst_HEADERS =	config-win.h config-netware.h my_bit.h \
@@ -37,7 +38,7 @@ noinst_HEADERS =	config-win.h config-net
 			my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \
 			thr_lock.h t_ctype.h violite.h my_md5.h base64.h \
 			my_handler.h my_time.h my_vle.h my_user.h \
-			my_libwrap.h my_stacktrace.h my_compiler.h
+			my_libwrap.h my_stacktrace.h
 
 EXTRA_DIST =        mysql.h.pp mysql/plugin.h.pp
 

=== modified file 'mysql-test/collections/default.experimental'
--- a/mysql-test/collections/default.experimental	2010-06-03 08:31:26 +0000
+++ b/mysql-test/collections/default.experimental	2010-09-07 20:16:10 +0000
@@ -12,9 +12,10 @@ funcs_1.ndb*
 
 funcs_2.ndb_charset                      # joro : NDB tests marked as experimental as agreed with bochklin
 
+innodb_plugin.*  @solaris                # Bug#56063 InnoDB Plugin mysql-tests fail on Solaris
+
 main.ctype_gbk_binlog  @solaris          # Bug#46010: main.ctype_gbk_binlog fails sporadically : Table 't2' already exists
 main.func_str  @solaris                  # joro: Bug#40928
-main.plugin_load  @solaris               # Bug#42144
 main.sp @solaris                         # joro : Bug#54138
 main.outfile_loaddata @solaris           # joro : Bug #46895
 
@@ -44,3 +45,6 @@ parts.partition_syntax_ndb
 parts.partition_value_ndb                # joro : NDB tests marked as experimental as agreed with bochklin
 main.mysqlhotcopy_myisam                 # horst: due to bug#54129
 main.mysqlhotcopy_archive                # horst: due to bug#54129
+main.gis-rtree                           # svoj: due to BUG#38965
+main.type_float                          # svoj: due to BUG#38965
+main.type_newdecimal                     # svoj: due to BUG#38965

=== modified file 'mysql-test/extra/rpl_tests/rpl_loaddata.test'
--- a/mysql-test/extra/rpl_tests/rpl_loaddata.test	2010-02-04 11:26:36 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_loaddata.test	2010-08-03 02:22:19 +0000
@@ -1,5 +1,5 @@
 # Requires statement logging
--- source include/have_binlog_format_mixed_or_statement.inc
+-- source include/have_binlog_format_statement.inc
 
 # See if replication of a "LOAD DATA in an autoincrement column"
 # Honours autoincrement values

=== added file 'mysql-test/extra/rpl_tests/rpl_stm_create_if_not_exists.test'
--- a/mysql-test/extra/rpl_tests/rpl_stm_create_if_not_exists.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_stm_create_if_not_exists.test	2010-08-18 04:56:06 +0000
@@ -0,0 +1,235 @@
+--echo
+--echo
+connection master;
+
+if ($is_temporary)
+{
+  --let $_temporary=TEMPORARY
+}
+
+CREATE TABLE t2(c1 INT, c2 char(10));
+INSERT INTO t2 VALUES(1, 'abc'), (2, 'abc');
+
+--echo
+--echo # The original query should be binlogged if the table does not exist.
+--echo # ------------------------------------------------------------------
+--echo
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+eval CREATE $_temporary TABLE IF NOT EXISTS t1 (c1 INT , c2 INT, c3 char(10), c4 INT KEY)
+  SELECT 'abc' AS c3, 1 AS c4;
+source include/show_binlog_events.inc;
+
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+--echo
+--echo # The statement should be binlogged as two events. one is 
+--echo # 'CREATE $_temporary TABLE IF NOT EXISTS ..', another one is
+--echo # 'INSERT ... SELECT'.
+--echo # ------------------------------------------------------------------
+--echo
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  SELECT 'abc', 2;
+source include/show_binlog_events.inc;
+
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+--echo
+--echo # Verify if it can be binlogged with right database name when the table
+--echo # is not in the default database
+--echo
+--disable_warnings
+DROP DATABASE IF EXISTS db1;
+--enable_warnings
+CREATE DATABASE db1;
+USE db1;
+
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+eval CREATE $_temporary TABLE IF NOT EXISTS test.t1
+  SELECT 'abc', 20;
+source include/show_binlog_events.inc;
+
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+USE test;
+DROP DATABASE db1;
+
+--echo
+--echo # It should be binlogged as 'REPLACE ... SELECT'
+--echo # if the original statement has option REPLACE
+--echo
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  REPLACE SELECT '123', 2;
+source include/show_binlog_events.inc;
+
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+--echo
+--echo # It should be binlogged as 'INSERT IGNORE... SELECT'
+--echo # if the original statement has option IGNORE 
+--echo
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  IGNORE SELECT '123', 2;
+source include/show_binlog_events.inc;
+
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+--echo
+--echo # Nothing should be binlogged if error happens and no any row is inserted
+--echo
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+--error ER_DUP_ENTRY
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  SELECT '123', 2;
+source include/show_binlog_events.inc;
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+--echo
+--echo # Verify it can binlog well when there are some braces('(')
+--echo
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  (SELECT '123', 3) UNION (SELECT '123', 4);
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  REPLACE (SELECT 'abc', 3) UNION (SELECT 'abc', 4);
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  IGNORE (SELECT '123', 3) UNION (SELECT '123', 4);
+source include/show_binlog_events.inc;
+
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+if (!$is_temporary)
+{
+  --echo
+  --echo # Throw a warning that table already exists and don't insert anything
+  --echo
+  CREATE VIEW t3 AS SELECT * FROM t2;
+  let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+  CREATE TABLE IF NOT EXISTS t3
+    SELECT '123', 2;
+  source include/show_binlog_events.inc;
+  DROP VIEW t3;
+}
+
+--echo
+--echo # The statement can be binlogged correctly when it is in a SP/EVENT/TRIGGER
+--echo
+
+--disable_warnings
+DROP PROCEDURE IF EXISTS p1;
+--enable_warnings
+eval CREATE PROCEDURE p1(IN a INT)
+  CREATE $_temporary TABLE IF NOT EXISTS t1 SELECT '123', a;
+
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+call p1(500);
+call p1(600);
+source include/show_binlog_events.inc;
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+DROP PROCEDURE p1;
+
+--echo
+--echo # The statement can be binlogged correctly when it is in a prepared statement
+--echo
+eval PREPARE stm FROM "CREATE $_temporary TABLE IF NOT EXISTS t1 SELECT '123', ?";
+
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+SET @a= 700;
+EXECUTE stm USING @a;
+SET @a= 800;
+EXECUTE stm USING @a;
+source include/show_binlog_events.inc;
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+--echo
+--echo # The statement can be binlogged correctly when it is in a conditional comment
+--echo
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+--echo # The whole statement in a conditional comment
+eval /*!CREATE $_temporary TABLE IF NOT EXISTS t1
+  SELECT 'abc', 900*/;
+source include/show_binlog_events.inc;
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+--echo
+--echo # There is an long comment before SELECT
+eval /*!CREATE $_temporary /*blabla*/ TABLE IF NOT EXISTS t1
+  SELECT 'abc', 901*/;
+source include/show_binlog_events.inc;
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+--echo
+--echo # Conditional comment starts just from SELECT
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  /*!SELECT 'abc',*/ 902;
+source include/show_binlog_events.inc;
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+--echo
+--echo # Only SELECT keyword is in the conditional comment
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  /*!SELECT*/ /*!'abc',*/ 904;
+source include/show_binlog_events.inc;
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+--echo
+--echo # Conditional comment is after SELECT keyword
+eval CREATE $_temporary TABLE IF NOT EXISTS t1
+  SELECT /*!'abc',*/ 903;
+source include/show_binlog_events.inc;
+let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+--echo
+--echo # Conditional comment ends just before SELECT keyword
+eval /*!CREATE $_temporary TABLE IF NOT EXISTS t1
+  */SELECT 'abc', 905;
+source include/show_binlog_events.inc;
+
+if (!$is_temporary)
+{
+  let $diff_table= test.t1;
+  source include/rpl_diff_tables.inc;
+}
+
+DROP TABLE t2;
+eval DROP $_temporary TABLE t1;
+

=== modified file 'mysql-test/include/mix2.inc'
--- a/mysql-test/include/mix2.inc	2007-06-06 17:57:07 +0000
+++ b/mysql-test/include/mix2.inc	2010-08-03 14:11:23 +0000
@@ -1910,7 +1910,7 @@ select hex(s1) from t4;
 drop table t1,t2,t3,t4;
 }
 
-if (test_foreign_keys)
+if ($test_foreign_keys)
 {
 eval create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=$engine_type;
 eval create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=$engine_type;
@@ -2405,7 +2405,7 @@ drop table t1, t2, t3, t5, t6, t8, t9;
 }
 # End transactional tests
 
-if (test_foreign_keys)
+if ($test_foreign_keys)
 {
 # bug 18934, "InnoDB crashes when table uses column names like DB_ROW_ID"
 --error 1005

=== added file 'mysql-test/include/not_blackhole.inc'
--- a/mysql-test/include/not_blackhole.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/not_blackhole.inc	2010-07-08 12:36:55 +0000
@@ -0,0 +1,5 @@
+if (`SELECT count(*) FROM information_schema.engines WHERE
+     (support = 'YES' OR support = 'DEFAULT') AND
+     engine = 'blackhole'`){
+  skip Blackhole engine enabled;
+}

=== modified file 'mysql-test/include/rpl_diff_tables.inc'
--- a/mysql-test/include/rpl_diff_tables.inc	2010-07-04 04:02:49 +0000
+++ b/mysql-test/include/rpl_diff_tables.inc	2010-08-18 04:56:06 +0000
@@ -33,3 +33,4 @@ while (`SELECT "XX$_servers" <> "XX"`)
   --source include/diff_tables.inc
   connection $_slave;
 }
+connection $_master;

=== modified file 'mysql-test/lib/My/Config.pm'
--- a/mysql-test/lib/My/Config.pm	2008-09-05 13:31:09 +0000
+++ b/mysql-test/lib/My/Config.pm	2010-06-14 13:34:43 +0000
@@ -188,6 +188,8 @@ sub new {
 
   while (  my $line= <$F> ) {
     chomp($line);
+    # Remove any trailing CR from Windows edited files
+    $line=~ s/\cM$//;
 
     # [group]
     if ( $line =~ /^\[(.*)\]/ ) {

=== modified file 'mysql-test/lib/My/ConfigFactory.pm'
--- a/mysql-test/lib/My/ConfigFactory.pm	2010-02-19 12:45:25 +0000
+++ b/mysql-test/lib/My/ConfigFactory.pm	2010-06-15 09:16:38 +0000
@@ -30,6 +30,13 @@ sub get_basedir {
   return $basedir;
 }
 
+sub get_testdir {
+  my ($self, $group)= @_;
+  my $testdir= $group->if_exist('testdir') ||
+    $self->{ARGS}->{testdir};
+  return $testdir;
+}
+
 
 sub fix_charset_dir {
   my ($self, $config, $group_name, $group)= @_;
@@ -142,8 +149,8 @@ sub fix_secure_file_priv {
 
 sub fix_std_data {
   my ($self, $config, $group_name, $group)= @_;
-  my $basedir= $self->get_basedir($group);
-  return "$basedir/mysql-test/std_data";
+  my $testdir= $self->get_testdir($group);
+  return "$testdir/std_data";
 }
 
 sub ssl_supported {

=== modified file 'mysql-test/lib/My/SafeProcess.pm'
--- a/mysql-test/lib/My/SafeProcess.pm	2009-11-24 08:12:48 +0000
+++ b/mysql-test/lib/My/SafeProcess.pm	2010-03-16 09:45:32 +0000
@@ -60,11 +60,12 @@ use My::Platform;
 
 my %running;
 my $_verbose= 0;
+my $start_exit= 0;
 
 END {
   # Kill any children still running
   for my $proc (values %running){
-    if ( $proc->is_child($$) ){
+    if ( $proc->is_child($$) and ! $start_exit){
       #print "Killing: $proc\n";
       if ($proc->wait_one(0)){
 	$proc->kill();
@@ -149,6 +150,11 @@ sub new {
 
   push(@safe_args, "--");
   push(@safe_args, $path); # The program safe_process should execute
+
+  if ($start_exit) {	 # Bypass safe_process instead, start program directly
+    @safe_args= ();
+    $safe_path= $path;
+  }
   push(@safe_args, @$$args);
 
   print "### safe_path: ", $safe_path, " ", join(" ", @safe_args), "\n"
@@ -528,6 +534,13 @@ sub wait_all {
   }
 }
 
+#
+# Set global flag to tell all safe_process to exit after starting child
+#
+
+sub start_exit {
+  $start_exit= 1;
+}
 
 #
 # Check if any process has exited, but don't wait.

=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	2010-06-15 09:03:52 +0000
+++ b/mysql-test/lib/mtr_cases.pm	2010-08-04 10:19:51 +0000
@@ -266,11 +266,11 @@ sub collect_one_suite($)
     }
     else
     {
-      $suitedir= my_find_dir($::basedir,
-			     ["mysql-test/suite",
-			      "mysql-test",
+      $suitedir= my_find_dir($suitedir,
+			     ["suite",
+			      ".",
 			      # Look in storage engine specific suite dirs
-			      "storage/*/mysql-test-suites"
+			      "../storage/*/mysql-test-suites"
 			     ],
 			     [$suite]);
     }
@@ -584,7 +584,7 @@ sub optimize_cases {
     # Check that engine selected by
     # --default-storage-engine=<engine> is supported
     # =======================================================
-    my %builtin_engines = ('myisam' => 1, 'memory' => 1);
+    my %builtin_engines = ('myisam' => 1, 'memory' => 1, 'csv' => 1);
 
     foreach my $opt ( @{$tinfo->{master_opt}} ) {
       my $default_engine=

=== modified file 'mysql-test/lib/mtr_report.pm'
--- a/mysql-test/lib/mtr_report.pm	2009-11-04 12:42:22 +0000
+++ b/mysql-test/lib/mtr_report.pm	2010-06-10 08:34:16 +0000
@@ -124,7 +124,7 @@ sub mtr_report_test ($) {
     my $timest = format_time();
     my $fail = "fail";
 
-    if ( $::opt_experimental )
+    if ( @$::experimental_test_cases )
     {
       # Find out if this test case is an experimental one, so we can treat
       # the failure as an expected failure instead of a regression.

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2010-07-04 07:12:44 +0000
+++ b/mysql-test/mysql-test-run.pl	2010-08-04 10:19:51 +0000
@@ -187,8 +187,8 @@ our $opt_client_debugger;
 my $config; # The currently running config
 my $current_config_name; # The currently running config file template
 
-our $opt_experimental;
-our $experimental_test_cases;
+our @opt_experimentals;
+our $experimental_test_cases= [];
 
 my $baseport;
 # $opt_build_thread may later be set from $opt_port_base
@@ -218,8 +218,10 @@ sub check_timeout { return $opt_testcase
 
 my $opt_start;
 my $opt_start_dirty;
+my $opt_start_exit;
 my $start_only;
 my $opt_wait_all;
+my $opt_user_args;
 my $opt_repeat= 1;
 my $opt_retry= 3;
 my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2);
@@ -345,6 +347,12 @@ sub main {
     mtr_report("Using parallel: $opt_parallel");
   }
 
+  if ($opt_parallel > 1 && $opt_start_exit) {
+    mtr_warning("Parallel and --start-and-exit cannot be combined\n" .
+               "Setting parallel to 1");
+    $opt_parallel= 1;
+  }
+
   # Create server socket on any free port
   my $server = new IO::Socket::INET
     (
@@ -384,6 +392,8 @@ sub main {
 
   my $completed= run_test_server($server, $tests, $opt_parallel);
 
+  exit(0) if $opt_start_exit;
+
   # Send Ctrl-C to any children still running
   kill("INT", keys(%children));
 
@@ -837,7 +847,7 @@ sub command_line_setup {
              'big-test'                 => \$opt_big_test,
 	     'combination=s'            => \@opt_combinations,
              'skip-combinations'        => \&collect_option,
-             'experimental=s'           => \$opt_experimental,
+             'experimental=s'           => \@opt_experimentals,
 	     'skip-im'                  => \&ignore_option,
 
              # Specify ports
@@ -910,7 +920,9 @@ sub command_line_setup {
              'verbose-restart'          => \&report_option,
              'sleep=i'                  => \$opt_sleep,
              'start-dirty'              => \$opt_start_dirty,
+             'start-and-exit'           => \$opt_start_exit,
              'start'                    => \$opt_start,
+	     'user-args'                => \$opt_user_args,
              'wait-all'                 => \$opt_wait_all,
 	     'print-testcases'          => \&collect_option,
 	     'repeat=i'                 => \$opt_repeat,
@@ -1018,43 +1030,47 @@ sub command_line_setup {
     mtr_print_thick_line('#');
   }
 
-  if ( $opt_experimental )
+  if ( @opt_experimentals )
   {
     # $^O on Windows considered not generic enough
     my $plat= (IS_WINDOWS) ? 'windows' : $^O;
 
-    # read the list of experimental test cases from the file specified on
+    # read the list of experimental test cases from the files specified on
     # the command line
-    open(FILE, "<", $opt_experimental) or mtr_error("Can't read experimental file: $opt_experimental");
-    mtr_report("Using experimental file: $opt_experimental");
     $experimental_test_cases = [];
-    while(<FILE>) {
-      chomp;
-      # remove comments (# foo) at the beginning of the line, or after a 
-      # blank at the end of the line
-      s/( +|^)#.*$//;
-      # If @ platform specifier given, use this entry only if it contains
-      # @<platform> or @!<xxx> where xxx != platform
-      if (/\@.*/)
-      {
-	next if (/\@!$plat/);
-	next unless (/\@$plat/ or /\@!/);
-	# Then remove @ and everything after it
-	s/\@.*$//;
-      }
-      # remove whitespace
-      s/^ +//;              
-      s/ +$//;
-      # if nothing left, don't need to remember this line
-      if ( $_ eq "" ) {
-        next;
+    foreach my $exp_file (@opt_experimentals)
+    {
+      open(FILE, "<", $exp_file)
+	or mtr_error("Can't read experimental file: $exp_file");
+      mtr_report("Using experimental file: $exp_file");
+      while(<FILE>) {
+	chomp;
+	# remove comments (# foo) at the beginning of the line, or after a 
+	# blank at the end of the line
+	s/( +|^)#.*$//;
+	# If @ platform specifier given, use this entry only if it contains
+	# @<platform> or @!<xxx> where xxx != platform
+	if (/\@.*/)
+	{
+	  next if (/\@!$plat/);
+	  next unless (/\@$plat/ or /\@!/);
+	  # Then remove @ and everything after it
+	  s/\@.*$//;
+	}
+	# remove whitespace
+	s/^ +//;              
+	s/ +$//;
+	# if nothing left, don't need to remember this line
+	if ( $_ eq "" ) {
+	  next;
+	}
+	# remember what is left as the name of another test case that should be
+	# treated as experimental
+	print " - $_\n";
+	push @$experimental_test_cases, $_;
       }
-      # remember what is left as the name of another test case that should be
-      # treated as experimental
-      print " - $_\n";
-      push @$experimental_test_cases, $_;
+      close FILE;
     }
-    close FILE;
   }
 
   foreach my $arg ( @ARGV )
@@ -1316,18 +1332,29 @@ sub command_line_setup {
   # --------------------------------------------------------------------------
   # Modified behavior with --start options
   # --------------------------------------------------------------------------
-  if ($opt_start or $opt_start_dirty) {
+  if ($opt_start or $opt_start_dirty or $opt_start_exit) {
     collect_option ('quick-collect', 1);
     $start_only= 1;
   }
 
   # --------------------------------------------------------------------------
+  # Check use of user-args
+  # --------------------------------------------------------------------------
+
+  if ($opt_user_args) {
+    mtr_error("--user-args only valid with --start options")
+      unless $start_only;
+    mtr_error("--user-args cannot be combined with named suites or tests")
+      if $opt_suites || @opt_cases;
+  }
+
+  # --------------------------------------------------------------------------
   # Check use of wait-all
   # --------------------------------------------------------------------------
 
   if ($opt_wait_all && ! $start_only)
   {
-    mtr_error("--wait-all can only be used with --start or --start-dirty");
+    mtr_error("--wait-all can only be used with --start options");
   }
 
   # --------------------------------------------------------------------------
@@ -2741,6 +2768,7 @@ sub default_mysqld {
   my $config= My::ConfigFactory->new_config
     ( {
        basedir         => $basedir,
+       testdir         => $glob_mysql_test_dir,
        template_path   => "include/default_my.cnf",
        vardir          => $opt_vardir,
        tmpdir          => $opt_tmpdir,
@@ -2987,7 +3015,8 @@ sub check_testcase($$)
   my %started;
   foreach my $mysqld ( mysqlds() )
   {
-    if ( defined $mysqld->{'proc'} )
+    # Skip if server has been restarted with additional options
+    if ( defined $mysqld->{'proc'} && ! exists $mysqld->{'restart_opts'} )
     {
       my $proc= start_check_testcase($tinfo, $mode, $mysqld);
       $started{$proc->pid()}= $proc;
@@ -3349,6 +3378,7 @@ sub run_testcase ($) {
       $config= My::ConfigFactory->new_config
 	( {
 	   basedir         => $basedir,
+	   testdir         => $glob_mysql_test_dir,
 	   template_path   => $tinfo->{template_path},
 	   extra_template_path => $tinfo->{extra_template_path},
 	   vardir          => $opt_vardir,
@@ -3409,6 +3439,18 @@ sub run_testcase ($) {
       mtr_print ($mysqld->name() . "  " . $mysqld->value('port') .
 	      "  " . $mysqld->value('socket'));
     }
+    if ( $opt_start_exit )
+    {
+      mtr_print("Server(s) started, not waiting for them to finish");
+      if (IS_WINDOWS)
+      {
+	POSIX::_exit(0);	# exit hangs here in ActiveState Perl
+      }
+      else
+      {
+	exit(0);
+      }
+    }
     mtr_print("Waiting for server(s) to exit...");
     if ( $opt_wait_all ) {
       My::SafeProcess->wait_all();
@@ -3759,7 +3801,8 @@ sub extract_warning_lines ($$) {
     if ($opt_valgrind_mysqld) {
       # Skip valgrind summary from tests where server has been restarted
       # Should this contain memory leaks, the final report will find it
-      $skip_valgrind= 1 if $line =~ /^==\d+== ERROR SUMMARY:/;
+      # Use a generic pattern for summaries
+      $skip_valgrind= 1 if $line =~ /^==\d+== [A-Z ]+ SUMMARY:/;
       $skip_valgrind= 0 unless $line =~ /^==\d+==/;
       next if $skip_valgrind;
     }
@@ -3969,6 +4012,16 @@ sub check_expected_crash_and_restart {
 	  next;
 	}
 
+	# If last line begins "restart:", the rest of the line is read as
+        # extra command line options to add to the restarted mysqld.
+        # Anything other than 'wait' or 'restart:' (with a colon) will
+        # result in a restart with original mysqld options.
+	if ($last_line =~ /restart:(.+)/) {
+	  my @rest_opt= split(' ', $1);
+	  $mysqld->{'restart_opts'}= \@rest_opt;
+	} else {
+	  delete $mysqld->{'restart_opts'};
+	}
 	unlink($expect_file);
 
 	# Start server with same settings as last time
@@ -4239,7 +4292,7 @@ sub mysqld_arguments ($$$) {
     }
   }
 
-  if ( $mysql_version_id >= 50106 )
+  if ( $mysql_version_id >= 50106 && !$opt_user_args)
   {
     # Turn on logging to file
     mtr_add_arg($args, "--log-output=file");
@@ -4277,7 +4330,7 @@ sub mysqld_arguments ($$$) {
     }
   }
   $opt_skip_core = $found_skip_core;
-  if ( !$found_skip_core )
+  if ( !$found_skip_core && !$opt_user_args )
   {
     mtr_add_arg($args, "%s", "--core-file");
   }
@@ -4285,7 +4338,7 @@ sub mysqld_arguments ($$$) {
   # Enable the debug sync facility, set default wait timeout.
   # Facility stays disabled if timeout value is zero.
   mtr_add_arg($args, "--loose-debug-sync-timeout=%s",
-              $opt_debug_sync_timeout);
+              $opt_debug_sync_timeout) unless $opt_user_args;
 
   return $args;
 }
@@ -4313,7 +4366,13 @@ sub mysqld_start ($$) {
   }
 
   mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
-  mysqld_arguments($args,$mysqld,$extra_opts);
+
+  # Add any additional options from an in-test restart
+  my @all_opts= @$extra_opts;
+  if (exists $mysqld->{'restart_opts'}) {
+    push (@all_opts, @{$mysqld->{'restart_opts'}});
+  }
+  mysqld_arguments($args,$mysqld,\@all_opts);
 
   if ( $opt_debug )
   {
@@ -4494,7 +4553,10 @@ sub server_need_restart {
     my $extra_opts= get_extra_opts($server, $tinfo);
     my $started_opts= $server->{'started_opts'};
 
-    if (!My::Options::same($started_opts, $extra_opts) )
+    # Also, always restart if server had been restarted with additional
+    # options within test.
+    if (!My::Options::same($started_opts, $extra_opts) ||
+        exists $server->{'restart_opts'})
     {
       my $use_dynamic_option_switch= 0;
       if (!$use_dynamic_option_switch)
@@ -4583,6 +4645,9 @@ sub envsubst {
 
 
 sub get_extra_opts {
+  # No extra options if --user-args
+  return \@opt_extra_mysqld_opt if $opt_user_args;
+
   my ($mysqld, $tinfo)= @_;
 
   my $opts=
@@ -4653,6 +4718,12 @@ sub stop_servers($$) {
 sub start_servers($) {
   my ($tinfo)= @_;
 
+  # Make sure the safe_process also exits from now on
+  # Could not be done before, as we don't want this for the bootstrap
+  if ($opt_start_exit) {
+    My::SafeProcess->start_exit();
+  }
+
   # Start clusters
   foreach my $cluster ( clusters() )
   {
@@ -5449,8 +5520,13 @@ Misc options
                         startup settings for the first specified test case
                         Example:
                          $0 --start alias &
+  start-and-exit        Same as --start, but mysql-test-run terminates and
+                        leaves just the server running
   start-dirty           Only start the servers (without initialization) for
                         the first specified test case
+  user-args             In combination with start* and no test name, drops
+                        arguments to mysqld except those speficied with
+                        --mysqld (if any)
   wait-all              If --start or --start-dirty option is used, wait for all
                         servers to exit before finishing the process
   fast                  Run as fast as possible, dont't wait for servers

=== modified file 'mysql-test/r/csv.result'
--- a/mysql-test/r/csv.result	2010-02-17 12:13:42 +0000
+++ b/mysql-test/r/csv.result	2010-03-09 15:09:32 +0000
@@ -5138,7 +5138,7 @@ insert t1 values (1),(2),(3),(4),(5);
 truncate table t1;
 affected rows: 0
 drop table t1;
-create table t1 (v varchar(32) not null);
+create table t1 (v varchar(32) not null) engine=csv;
 insert into t1 values ('def'),('abc'),('hij'),('3r4f');
 select * from t1;
 v
@@ -5146,14 +5146,14 @@ def
 abc
 hij
 3r4f
-alter table t1 change v v2 varchar(32);
+alter table t1 change v v2 varchar(32) not null;
 select * from t1;
 v2
 def
 abc
 hij
 3r4f
-alter table t1 change v2 v varchar(64);
+alter table t1 change v2 v varchar(64) not null;
 select * from t1;
 v
 def
@@ -5163,35 +5163,34 @@ hij
 update t1 set v = 'lmn' where v = 'hij';
 select * from t1;
 v
+lmn
 def
 abc
-lmn
 3r4f
-alter table t1 add i int auto_increment not null primary key first;
+alter table t1 add i int not null first;
 select * from t1;
 i	v
-1	def
-2	abc
-3	lmn
-4	3r4f
-update t1 set i=5 where i=3;
+0	lmn
+0	def
+0	abc
+0	3r4f
+update t1 set i=3 where v = 'abc';
 select * from t1;
 i	v
-1	def
-2	abc
-5	lmn
-4	3r4f
-alter table t1 change i i bigint;
+3	abc
+0	lmn
+0	def
+0	3r4f
+alter table t1 change i i bigint not null;
 select * from t1;
 i	v
-1	def
-2	abc
-5	lmn
-4	3r4f
-alter table t1 add unique key (i, v);
-select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
+3	abc
+0	lmn
+0	def
+0	3r4f
+select * from t1 where i between 2 and 4 and v in ('def','3r4f','abc');
 i	v
-4	3r4f
+3	abc
 drop table t1;
 create table bug15205 (val int(11) not null) engine=csv;
 create table bug15205_2 (val int(11) not null) engine=csv;

=== modified file 'mysql-test/r/delete.result'
--- a/mysql-test/r/delete.result	2010-05-14 11:36:27 +0000
+++ b/mysql-test/r/delete.result	2010-08-30 22:16:38 +0000
@@ -358,4 +358,13 @@ INDEX(a), INDEX(b), INDEX(c));
 INSERT INTO t1 VALUES (1,2,3), (4,5,6), (7,8,9);
 DELETE FROM t1 WHERE a = 10 OR b = 20 ORDER BY c LIMIT 1;
 DROP TABLE t1;
+#
+# Bug #53034: Multiple-table DELETE statements not accepting
+#             "Access compatibility" syntax
+#
+CREATE TABLE t1 (id INT);
+CREATE TABLE t2 LIKE t1;
+CREATE TABLE t3 LIKE t1;
+DELETE FROM t1.*, test.t2.*, a.* USING t1, t2, t3 AS a;
+DROP TABLE t1, t2, t3;
 End of 5.1 tests

=== modified file 'mysql-test/r/func_group.result'
--- a/mysql-test/r/func_group.result	2009-11-24 15:26:13 +0000
+++ b/mysql-test/r/func_group.result	2010-08-27 09:44:35 +0000
@@ -1713,4 +1713,15 @@ f1	f2	f3	f4	f1 = f2
 NULL	NULL	NULL	NULL	NULL
 drop table t1;
 #
+# Bug #54465: assert: field_types == 0 || field_types[field_pos] ==
+#             MYSQL_TYPE_LONGLONG
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2);
+SELECT MAX((SELECT 1 FROM t1 ORDER BY @var LIMIT 1)) m FROM t1 t2, t1 
+ORDER BY t1.a;
+m
+1
+DROP TABLE t1;
+#
 End of 5.1 tests

=== modified file 'mysql-test/r/func_sapdb.result'
--- a/mysql-test/r/func_sapdb.result	2009-02-07 15:50:31 +0000
+++ b/mysql-test/r/func_sapdb.result	2010-08-13 13:05:46 +0000
@@ -194,7 +194,7 @@ date("1997-12-31 23:59:59.000001") as f8
 time("1997-12-31 23:59:59.000001") as f9;
 describe t1;
 Field	Type	Null	Key	Default	Extra
-f1	date	NO		0000-00-00	
+f1	date	YES		NULL	
 f2	datetime	YES		NULL	
 f3	time	YES		NULL	
 f4	time	YES		NULL	

=== modified file 'mysql-test/r/func_time.result'
--- a/mysql-test/r/func_time.result	2010-02-09 10:30:50 +0000
+++ b/mysql-test/r/func_time.result	2010-08-13 13:05:46 +0000
@@ -1335,4 +1335,12 @@ date_sub("0069-01-01 00:00:01",INTERVAL
 select date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND);
 date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND)
 0168-12-31 23:59:59
+CREATE TABLE t1(a DOUBLE NOT NULL);
+INSERT INTO t1 VALUES (0),(9.216e-096);
+# should not crash
+SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a);
+1
+1
+1
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/gis.result'
--- a/mysql-test/r/gis.result	2010-02-26 13:16:46 +0000
+++ b/mysql-test/r/gis.result	2010-09-09 09:40:17 +0000
@@ -707,10 +707,7 @@ numgeometries(b) IS NULL, numinteriorrin
 area(b) IS NULL, glength(b) IS NULL, srid(b) IS NULL, x(b) IS NULL, 
 y(b) IS NULL
 from t1;
-geometryfromtext(b) IS NULL	geometryfromwkb(b) IS NULL	astext(b) IS NULL	aswkb(b) IS NULL	geometrytype(b) IS NULL	centroid(b) IS NULL	envelope(b) IS NULL	startpoint(b) IS NULL	endpoint(b) IS NULL	exteriorring(b) IS NULL	pointn(b, 1) IS NULL	geometryn(b, 1) IS NULL	interiorringn(b, 1) IS NULL	multipoint(b) IS NULL	isempty(b) IS NULL	issimple(b) IS NULL	isclosed(b) IS NULL	dimension(b) IS NULL	numgeometries(b) IS NULL	numinteriorrings(b) IS NULL	numpoints(b) IS NULL	area(b) IS NULL	glength(b) IS NULL	srid(b) IS NULL	x(b) IS NULL	y(b) IS NULL
-1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1
-1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1
-1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1	1
+ERROR 22007: Illegal non geometric '`test`.`t1`.`b`' value found during parsing
 select 
 within(b, b) IS NULL, contains(b, b) IS NULL, overlaps(b, b) IS NULL, 
 equals(b, b) IS NULL, disjoint(b, b) IS NULL, touches(b, b) IS NULL, 
@@ -725,10 +722,7 @@ point(b, b) IS NULL, linestring(b) IS NU
 multilinestring(b) IS NULL, multipolygon(b) IS NULL, 
 geometrycollection(b) IS NULL
 from t1;
-point(b, b) IS NULL	linestring(b) IS NULL	polygon(b) IS NULL	multipoint(b) IS NULL	multilinestring(b) IS NULL	multipolygon(b) IS NULL	geometrycollection(b) IS NULL
-0	1	1	1	1	1	1
-1	1	1	1	1	1	1
-0	1	1	1	1	1	1
+ERROR 22007: Illegal non geometric '`test`.`t1`.`b`' value found during parsing
 drop table t1;
 CREATE TABLE t1(a POINT) ENGINE=MyISAM;
 INSERT INTO t1 VALUES (NULL);
@@ -1010,51 +1004,14 @@ f5	datetime	YES		NULL
 drop view v1;
 drop table t1;
 SELECT MultiPoint(12345,'');
-MultiPoint(12345,'')
-NULL
-SELECT MultiPoint(123451,'');
-MultiPoint(123451,'')
-NULL
-SELECT MultiPoint(1234512,'');
-MultiPoint(1234512,'')
-NULL
-SELECT MultiPoint(12345123,'');
-MultiPoint(12345123,'')
-NULL
-SELECT MultiLineString(12345,'');
-MultiLineString(12345,'')
-NULL
-SELECT MultiLineString(123451,'');
-MultiLineString(123451,'')
-NULL
-SELECT MultiLineString(1234512,'');
-MultiLineString(1234512,'')
-NULL
-SELECT MultiLineString(12345123,'');
-MultiLineString(12345123,'')
-NULL
-SELECT LineString(12345,'');
-LineString(12345,'')
-NULL
-SELECT LineString(123451,'');
-LineString(123451,'')
-NULL
-SELECT LineString(1234512,'');
-LineString(1234512,'')
-NULL
-SELECT LineString(12345123,'');
-LineString(12345123,'')
-NULL
-SELECT Polygon(12345,'');
-Polygon(12345,'')
-NULL
-SELECT Polygon(123451,'');
-Polygon(123451,'')
-NULL
-SELECT Polygon(1234512,'');
-Polygon(1234512,'')
-NULL
-SELECT Polygon(12345123,'');
-Polygon(12345123,'')
-NULL
+ERROR 22007: Illegal non geometric '12345' value found during parsing
+SELECT 1 FROM (SELECT GREATEST(1,GEOMETRYCOLLECTION('00000','00000')) b FROM DUAL) AS d WHERE (LINESTRING(d.b));
+ERROR 22007: Illegal non geometric ''00000'' value found during parsing
+#
+# BUG#51875: crash when loading data into geometry function polyfromwkb
+#
+SET @a=0x00000000030000000100000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440;
+SET @a=POLYFROMWKB(@a);
+SET @a=0x00000000030000000000000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440;
+SET @a=POLYFROMWKB(@a);
 End of 5.1 tests

=== modified file 'mysql-test/r/insert.result'
--- a/mysql-test/r/insert.result	2009-07-10 23:12:13 +0000
+++ b/mysql-test/r/insert.result	2010-08-09 11:39:59 +0000
@@ -639,3 +639,18 @@ CREATE TABLE t2(f1 CHAR(1));
 INSERT INTO t2 SELECT f1 FROM t1;
 DROP TABLE t1, t2;
 End of 5.0 tests.
+#
+# Bug#54106 assert in Protocol::end_statement,
+#           INSERT IGNORE ... SELECT ... UNION SELECT ...
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 (a, a) VALUES (1, 1);
+ERROR 42000: Column 'a' specified twice
+INSERT IGNORE t1 (a, a) VALUES (1, 1);
+ERROR 42000: Column 'a' specified twice
+INSERT IGNORE t1 (a, a) SELECT 1,1;
+ERROR 42000: Column 'a' specified twice
+INSERT IGNORE t1 (a, a) SELECT 1,1 UNION SELECT 2,2;
+ERROR 42000: Column 'a' specified twice
+DROP TABLE t1;

=== modified file 'mysql-test/r/join.result'
--- a/mysql-test/r/join.result	2010-04-26 20:46:52 +0000
+++ b/mysql-test/r/join.result	2010-09-07 13:43:00 +0000
@@ -1184,4 +1184,40 @@ NULL
 NULL
 1
 DROP TABLE t1, t2, mm1;
+#
+# Bug #54468: crash after item's print() function when ordering/grouping 
+#             by subquery
+#
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 VALUES (), ();
+SELECT 1 FROM t1
+GROUP BY
+GREATEST(t1.a,
+(SELECT 1 FROM
+(SELECT t1.b FROM t1,t1 t2
+ORDER BY t1.a, t1.a LIMIT 1) AS d)
+);
+1
+1
+DROP TABLE t1;
+#
+# Bug #53544: Server hangs during JOIN query in stored procedure called
+#             twice in a row
+#
+CREATE TABLE t1(c INT);
+INSERT INTO t1 VALUES (1), (2);
+PREPARE stmt FROM "SELECT t2.c AS f1 FROM t1 LEFT JOIN
+                                        t1 t2 ON t1.c=t2.c RIGHT JOIN
+                                        t1 t3 ON t1.c=t3.c 
+                   GROUP BY f1;";
+EXECUTE stmt;
+f1
+1
+2
+EXECUTE stmt;
+f1
+1
+2
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/mysqltest.result'
--- a/mysql-test/r/mysqltest.result	2010-02-09 17:13:57 +0000
+++ b/mysql-test/r/mysqltest.result	2010-08-04 08:52:45 +0000
@@ -325,6 +325,7 @@ outer=2 ifval=0
 outer=1 ifval=1
 here is the sourced script
 ERROR 42S02: Table 'test.nowhere' doesn't exist
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'else' at line 1
 
 In loop
 here is the sourced script
@@ -392,6 +393,9 @@ true-inner again
 true-outer
 Counter is greater than 0, (counter=10)
 Counter is not 0, (counter=0)
+Counter is true, (counter=alpha)
+Beta is true
+while with string, only once
 1
 Testing while with not
 mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest_while.inc": At line 64: Nesting too deeply
@@ -446,7 +450,6 @@ OK
 mysqltest: The test didn't produce any output
 mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest.sql": At line 3: connection 'test_con1' not found in connection pool
 mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest.sql": At line 2: Connection test_con1 already exists
-connect(localhost,root,,test,MASTER_PORT,MASTER_SOCKET);
 show tables;
 ERROR 3D000: No database selected
 Output from mysqltest-x.inc
@@ -572,7 +575,7 @@ if things work as expected
 Some data
 for cat_file command
 of mysqltest
-mysqltest: At line 1: Failed to open file 'non_existing_file'
+mysqltest: At line 1: command "cat_file" failed with error 1
 mysqltest: At line 1: Missing required argument 'filename' to command 'file_exists'
 mysqltest: At line 1: Missing required argument 'from_file' to command 'copy_file'
 mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file'

=== added file 'mysql-test/r/partition_not_blackhole.result'
--- a/mysql-test/r/partition_not_blackhole.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/partition_not_blackhole.result	2010-07-08 12:36:55 +0000
@@ -0,0 +1,16 @@
+DROP TABLE IF EXISTS t1;
+#
+# Bug#46086: crash when dropping a partitioned table and
+#            the original engine is disabled
+# Copy a .frm and .par file which was created with:
+# create table `t1` (`id` int primary key) engine=blackhole
+# partition by key () partitions 1;
+SHOW TABLES;
+Tables_in_test
+t1
+SHOW CREATE TABLE t1;
+ERROR HY000: Incorrect information in file: './test/t1.frm'
+DROP TABLE t1;
+ERROR 42S02: Unknown table 't1'
+t1.frm
+t1.par

=== modified file 'mysql-test/r/partition_range.result'
--- a/mysql-test/r/partition_range.result	2010-03-04 11:09:09 +0000
+++ b/mysql-test/r/partition_range.result	2010-08-11 12:13:59 +0000
@@ -808,3 +808,47 @@ select sum(count) from t2 ch where ch.de
 sum(count)
 579
 drop table t1, t2;
+#
+# Bug#50939: Loose Index Scan unduly relies on engine to remember range 
+# endpoints
+#
+CREATE TABLE t1 (
+a INT,
+b INT,
+KEY ( a, b )
+) PARTITION BY HASH (a) PARTITIONS 1;
+CREATE TABLE t2 (
+a INT,
+b INT,
+KEY ( a, b )
+);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+INSERT INTO t1 SELECT a +  5, b +  5 FROM t1;
+INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
+INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
+INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
+INSERT INTO t2 SELECT * FROM t1;
+# plans should be identical
+EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a	a	5	NULL	1	Using where; Using index for group-by
+EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	a	a	5	NULL	2	Using where; Using index for group-by
+FLUSH status;
+SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
+a	MAX(b)
+10	10
+# Should be no more than 4 reads.
+SHOW status LIKE 'handler_read_key';
+Variable_name	Value
+Handler_read_key	4
+FLUSH status;
+SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
+a	MAX(b)
+10	10
+# Should be no more than 4 reads.
+SHOW status LIKE 'handler_read_key';
+Variable_name	Value
+Handler_read_key	4
+DROP TABLE t1, t2;

=== modified file 'mysql-test/r/range.result'
--- a/mysql-test/r/range.result	2010-05-10 07:23:23 +0000
+++ b/mysql-test/r/range.result	2010-08-24 15:51:32 +0000
@@ -1654,47 +1654,16 @@ a	b
 1	1
 DROP TABLE t1;
 #
-# Bug#50939: Loose Index Scan unduly relies on engine to remember range 
-# endpoints
+# Bug #54802: 'NOT BETWEEN' evaluation is incorrect
 #
-CREATE TABLE t1 (
-a INT,
-b INT,
-KEY ( a, b )
-) PARTITION BY HASH (a) PARTITIONS 1;
-CREATE TABLE t2 (
-a INT,
-b INT,
-KEY ( a, b )
-);
-INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
-INSERT INTO t1 SELECT a +  5, b +  5 FROM t1;
-INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
-INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
-INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
-INSERT INTO t2 SELECT * FROM t1;
-# plans should be identical
-EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
+CREATE TABLE t1 (c_key INT, c_notkey INT, KEY(c_key));
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3);
+EXPLAIN SELECT * FROM t1 WHERE 2 NOT BETWEEN c_notkey AND c_key;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t1	range	a	a	5	NULL	1	Using where; Using index for group-by
-EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
-id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	range	a	a	5	NULL	2	Using where; Using index for group-by
-FLUSH status;
-SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
-a	MAX(b)
-10	10
-# Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
-Variable_name	Value
-Handler_read_key	4
-FLUSH status;
-SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
-a	MAX(b)
-10	10
-# Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
-Variable_name	Value
-Handler_read_key	4
-DROP TABLE t1, t2;
+1	SIMPLE	t1	ALL	c_key	NULL	NULL	NULL	3	Using where
+SELECT * FROM t1 WHERE 2 NOT BETWEEN c_notkey AND c_key;
+c_key	c_notkey
+1	1
+3	3
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/subselect4.result'
--- a/mysql-test/r/subselect4.result	2009-09-28 13:48:40 +0000
+++ b/mysql-test/r/subselect4.result	2010-08-05 10:42:14 +0000
@@ -59,3 +59,24 @@ FROM t3 WHERE 1 = 0 GROUP BY 1;
 (SELECT 1 FROM t1,t2 WHERE t2.b > t3.b)
 DROP TABLE t1,t2,t3;
 End of 5.0 tests.
+#
+# Bug#54568: create view cause Assertion failed: 0, 
+# file .\item_subselect.cc, line 836
+#
+EXPLAIN SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1249	Select 2 was reduced during optimization
+DESCRIBE SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1249	Select 2 was reduced during optimization
+# None of the below should crash
+CREATE VIEW v1 AS SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
+CREATE VIEW v2 AS SELECT 1 LIKE '%' ESCAPE ( 1 IN ( SELECT 1 ) );
+DROP VIEW v1, v2;
+#
+# End of 5.1 tests.
+#

=== modified file 'mysql-test/r/timezone2.result'
--- a/mysql-test/r/timezone2.result	2009-05-15 12:57:51 +0000
+++ b/mysql-test/r/timezone2.result	2010-08-06 19:29:37 +0000
@@ -296,4 +296,16 @@ CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow'
 UPDATE t1 SET t = CONVERT_TZ(t, 'UTC', 'Europe/Moscow');
 UNLOCK TABLES;
 DROP TABLE t1;
+#
+# Bug #55424: convert_tz crashes when fed invalid data
+#
+CREATE TABLE t1 (a SET('x') NOT NULL);
+INSERT INTO t1 VALUES ('');
+SELECT CONVERT_TZ(1, a, 1) FROM t1;
+CONVERT_TZ(1, a, 1)
+NULL
+SELECT CONVERT_TZ(1, 1, a) FROM t1;
+CONVERT_TZ(1, 1, a)
+NULL
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/trigger.result'
--- a/mysql-test/r/trigger.result	2010-07-08 18:46:26 +0000
+++ b/mysql-test/r/trigger.result	2010-08-18 04:56:06 +0000
@@ -1824,11 +1824,8 @@ Note	1050	Table 'v1' already exists
 set @id=last_insert_id();
 select * from t1;
 id	operation
-1	CREATE TABLE ... SELECT, inserting a new key
 select * from t1_op_log;
 operation
-Before INSERT, new=CREATE TABLE ... SELECT, inserting a new key
-After INSERT, new=CREATE TABLE ... SELECT, inserting a new key
 truncate t1_op_log;
 create table if not exists v1 replace
 select @id, "CREATE TABLE ... REPLACE SELECT, deleting a duplicate key";
@@ -1836,13 +1833,8 @@ Warnings:
 Note	1050	Table 'v1' already exists
 select * from t1;
 id	operation
-1	CREATE TABLE ... REPLACE SELECT, deleting a duplicate key
 select * from t1_op_log;
 operation
-Before INSERT, new=CREATE TABLE ... REPLACE SELECT, deleting a duplicate key
-Before DELETE, old=CREATE TABLE ... SELECT, inserting a new key
-After DELETE, old=CREATE TABLE ... SELECT, inserting a new key
-After INSERT, new=CREATE TABLE ... REPLACE SELECT, deleting a duplicate key
 truncate t1;
 truncate t1_op_log;
 insert into v1 (id, operation)

=== modified file 'mysql-test/r/user_var.result'
--- a/mysql-test/r/user_var.result	2009-12-22 10:38:33 +0000
+++ b/mysql-test/r/user_var.result	2010-08-13 11:18:46 +0000
@@ -430,4 +430,21 @@ CREATE TRIGGER t_after_insert AFTER INSE
 INSERT INTO t1 VALUES (1);
 INSERT INTO t1 VALUES (1);
 DROP TABLE t1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0),(0);
+# BUG#55615 : should not crash
+SELECT (@a:=(SELECT @a:=1 FROM t1 LIMIT 1)) AND COUNT(1) FROM t1 GROUP BY @a;
+(@a:=(SELECT @a:=1 FROM t1 LIMIT 1)) AND COUNT(1)
+1
+1
+# BUG#55564 : should not crash
+SELECT IF(
+@v:=LEAST((SELECT 1 FROM t1 t2 LEFT JOIN t1 ON (@v) GROUP BY t1.a), a),
+count(*), 1) 
+FROM t1 GROUP BY a LIMIT 1;
+IF(
+@v:=LEAST((SELECT 1 FROM t1 t2 LEFT JOIN t1 ON (@v) GROUP BY t1.a), a),
+count(*), 1)
+1
+DROP TABLE t1;
 End of 5.1 tests

=== added file 'mysql-test/std_data/parts/t1_blackhole.frm'
Files a/mysql-test/std_data/parts/t1_blackhole.frm	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/parts/t1_blackhole.frm	2010-07-08 12:36:55 +0000 differ

=== added file 'mysql-test/std_data/parts/t1_blackhole.par'
Files a/mysql-test/std_data/parts/t1_blackhole.par	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/parts/t1_blackhole.par	2010-07-08 12:36:55 +0000 differ

=== added file 'mysql-test/suite/binlog/r/binlog_mixed_load_data.result'
--- a/mysql-test/suite/binlog/r/binlog_mixed_load_data.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_mixed_load_data.result	2010-08-03 02:22:19 +0000
@@ -0,0 +1,10 @@
+RESET MASTER;
+CREATE TABLE t1 (word CHAR(20) NOT NULL) ENGINE=MYISAM;
+LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+DROP TABLE t1;

=== modified file 'mysql-test/suite/binlog/t/binlog_killed_simulate.test'
--- a/mysql-test/suite/binlog/t/binlog_killed_simulate.test	2008-10-23 19:27:09 +0000
+++ b/mysql-test/suite/binlog/t/binlog_killed_simulate.test	2010-08-03 02:22:19 +0000
@@ -1,5 +1,5 @@
 -- source include/have_debug.inc
--- source include/have_binlog_format_mixed_or_statement.inc
+-- source include/have_binlog_format_statement.inc
 #
 # bug#27571 asynchronous setting mysql_$query()'s local error and 
 #           Query_log_event::error_code

=== added file 'mysql-test/suite/binlog/t/binlog_mixed_load_data.test'
--- a/mysql-test/suite/binlog/t/binlog_mixed_load_data.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_mixed_load_data.test	2010-08-03 02:22:19 +0000
@@ -0,0 +1,15 @@
+#
+# Bug #34283  mysqlbinlog leaves tmpfile after termination
+# if binlog contains load data infile, so in mixed mode we
+# go to row-based for avoiding the problem.
+#
+
+--source include/have_binlog_format_mixed.inc
+--source include/have_log_bin.inc
+
+RESET MASTER;
+CREATE TABLE t1 (word CHAR(20) NOT NULL) ENGINE=MYISAM;
+let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);
+LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1;
+--source include/show_binlog_events.inc
+DROP TABLE t1;

=== modified file 'mysql-test/suite/binlog/t/binlog_stm_blackhole.test'
--- a/mysql-test/suite/binlog/t/binlog_stm_blackhole.test	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/binlog/t/binlog_stm_blackhole.test	2010-08-03 02:22:19 +0000
@@ -2,5 +2,5 @@
 # For both statement and row based bin logs 9/19/2005 [jbm]
 
 -- source include/not_embedded.inc
--- source include/have_binlog_format_mixed_or_statement.inc
+-- source include/have_binlog_format_statement.inc
 -- source extra/binlog_tests/blackhole.test

=== modified file 'mysql-test/suite/funcs_1/r/innodb_storedproc_06.result'
--- a/mysql-test/suite/funcs_1/r/innodb_storedproc_06.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_storedproc_06.result	2010-03-19 08:56:26 +0000
@@ -78,7 +78,6 @@ grant all on db_storedproc_1.* to 'user_
 revoke create routine on db_storedproc_1.* from 'user_1'@'localhost';
 flush privileges;
 DROP PROCEDURE IF EXISTS sp1;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -91,7 +90,6 @@ USE db_storedproc_1;
 	
 root@localhost	db_storedproc_1
 GRANT CREATE ROUTINE ON db_storedproc_1.* TO 'user_1'@'localhost';
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -112,7 +110,6 @@ Ensure that root always has the GRANT CR
 --------------------------------------------------------------------------------
 grant create routine on db_storedproc_1.* to 'user_1'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 DROP PROCEDURE IF EXISTS sp3;
@@ -149,7 +146,6 @@ CREATE PROCEDURE sp4(v1 char(20))
 BEGIN
 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
 END//
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -191,7 +187,6 @@ grant create routine on db_storedproc_1.
 grant SELECT on db_storedproc_1.* to 'user_2'@'localhost';
 grant execute on db_storedproc_1.* to 'user_2'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp5_s_i () sql security definer
@@ -207,7 +202,6 @@ CREATE PROCEDURE sp5_ins () sql security
 BEGIN
 insert into db_storedproc_1.t3165 values ('inserted', 'from sp5_ins', 1000);
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp5_s_i();
@@ -305,7 +299,6 @@ GRANT CREATE ROUTINE ON db_storedproc_1.
 GRANT SELECT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 GRANT EXECUTE ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp3166_s_i () SQL SECURITY INVOKER
@@ -321,7 +314,6 @@ CREATE PROCEDURE sp3166_ins () SQL SECUR
 BEGIN
 insert into db_storedproc_1.t3166 values ('inserted from sp3166_ins');
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -340,7 +332,6 @@ c1
 inserted outside SP
 GRANT INSERT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -361,7 +352,6 @@ inserted from sp3166_s_i
 inserted from sp3166_ins
 REVOKE SELECT ON db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -379,7 +369,6 @@ inserted from sp3166_ins
 root@localhost	db_storedproc_1
 REVOKE EXECUTE on db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();

=== modified file 'mysql-test/suite/funcs_1/r/innodb_storedproc_10.result'
--- a/mysql-test/suite/funcs_1/r/innodb_storedproc_10.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_storedproc_10.result	2010-03-19 08:56:26 +0000
@@ -81,7 +81,6 @@ create user 'user_2'@'localhost';
 GRANT CREATE ROUTINE ON db_storedproc.* TO 'user_1'@'localhost';
 GRANT SELECT         ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc
 CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
@@ -94,7 +93,6 @@ DECLARE res INT;
 SET res = n * n;
 RETURN res;
 END//
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -113,7 +111,6 @@ fn31105( 9 )
 81
 GRANT EXECUTE ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -134,7 +131,6 @@ a`	a`	1000-01-01	-5000	a`	-5000
 SELECT fn31105( 9 );
 fn31105( 9 )
 81
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();

=== modified file 'mysql-test/suite/funcs_1/r/innodb_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/innodb_trig_03.result	2008-06-03 10:21:48 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_trig_03.result	2010-03-19 08:56:26 +0000
@@ -85,8 +85,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.3.2:
 -----------------
@@ -161,8 +159,6 @@ grant TRIGGER, UPDATE on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT UPDATE, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -222,8 +218,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -296,8 +290,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -351,8 +343,6 @@ grant UPDATE (f1) on priv_db.t1 to test_
 show grants for test_noprivs;
 Grants for test_noprivs@%
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'%'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -407,8 +397,6 @@ grant TRIGGER, SELECT on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -464,8 +452,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -519,8 +505,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -565,8 +549,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT INSERT (f1), UPDATE (f1) ON `priv_db`.`t1` TO 'test_noprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -611,7 +593,6 @@ Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 GRANT SELECT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost

=== modified file 'mysql-test/suite/funcs_1/r/innodb_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/innodb_trig_03e.result	2008-04-04 17:52:48 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_trig_03e.result	2010-03-19 08:56:26 +0000
@@ -24,7 +24,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on db level for create:
 --------------------------------------------
@@ -32,7 +31,6 @@ use priv_db;
 create trigger trg1_1 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-no';
 ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv_db;
 insert into t1 (f1) values ('insert-yes');
 select f1 from t1 order by f1;
@@ -253,8 +251,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_noprivs@localhost;
 set password for test_noprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on table level for create:
 -----------------------------------------------
@@ -513,8 +509,6 @@ grant SELECT,INSERT  on *.* to test_nopr
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT SELECT, INSERT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -563,7 +557,6 @@ revoke TRIGGER on *.* from test_yesprivs
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -698,7 +691,6 @@ select f1 from t1 order by f1;
 f1
 insert-yes
 insert-yes
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -767,9 +759,7 @@ Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT, UPDATE ON `priv1_db`.* TO 'test_noprivs'@'localhost'
 GRANT SELECT, INSERT ON `priv2_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
 
 trigger privilege on one db1 db level, not on db2
@@ -982,7 +972,6 @@ create User test_useprivs@localhost;
 set password for test_useprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1010,7 +999,6 @@ select f1 from t1 order by f1;
 f1
 trig 1_1-yes
 prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
-connect(localhost,test_useprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_useprivs@localhost
@@ -1206,7 +1194,6 @@ create table t1 (f1 char(20)) engine= in
 create User test_yesprivs@localhost;
 set password for test_yesprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1303,7 +1290,6 @@ create table t1 (f1 char(20)) engine= in
 create User test_yesprivs@localhost;
 set password for test_yesprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1375,8 +1361,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, UPDATE ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 update only on column:
 ----------------------

=== modified file 'mysql-test/suite/funcs_1/r/innodb_trig_0407.result'
--- a/mysql-test/suite/funcs_1/r/innodb_trig_0407.result	2009-02-13 18:07:56 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_trig_0407.result	2010-03-19 08:56:26 +0000
@@ -67,8 +67,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.4:
 ---------------

=== modified file 'mysql-test/suite/funcs_1/r/innodb_trig_08.result'
--- a/mysql-test/suite/funcs_1/r/innodb_trig_08.result	2008-06-03 10:21:48 +0000
+++ b/mysql-test/suite/funcs_1/r/innodb_trig_08.result	2010-03-19 08:56:26 +0000
@@ -67,8 +67,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.8.1: (implied in previous tests)
 ---------------------------------------------

=== modified file 'mysql-test/suite/funcs_1/r/memory_storedproc_06.result'
--- a/mysql-test/suite/funcs_1/r/memory_storedproc_06.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_storedproc_06.result	2010-03-19 08:56:26 +0000
@@ -79,7 +79,6 @@ grant all on db_storedproc_1.* to 'user_
 revoke create routine on db_storedproc_1.* from 'user_1'@'localhost';
 flush privileges;
 DROP PROCEDURE IF EXISTS sp1;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -92,7 +91,6 @@ USE db_storedproc_1;
 	
 root@localhost	db_storedproc_1
 GRANT CREATE ROUTINE ON db_storedproc_1.* TO 'user_1'@'localhost';
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -113,7 +111,6 @@ Ensure that root always has the GRANT CR
 --------------------------------------------------------------------------------
 grant create routine on db_storedproc_1.* to 'user_1'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 DROP PROCEDURE IF EXISTS sp3;
@@ -150,7 +147,6 @@ CREATE PROCEDURE sp4(v1 char(20))
 BEGIN
 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
 END//
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -192,7 +188,6 @@ grant create routine on db_storedproc_1.
 grant SELECT on db_storedproc_1.* to 'user_2'@'localhost';
 grant execute on db_storedproc_1.* to 'user_2'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp5_s_i () sql security definer
@@ -208,7 +203,6 @@ CREATE PROCEDURE sp5_ins () sql security
 BEGIN
 insert into db_storedproc_1.t3165 values ('inserted', 'from sp5_ins', 1000);
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp5_s_i();
@@ -306,7 +300,6 @@ GRANT CREATE ROUTINE ON db_storedproc_1.
 GRANT SELECT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 GRANT EXECUTE ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp3166_s_i () SQL SECURITY INVOKER
@@ -322,7 +315,6 @@ CREATE PROCEDURE sp3166_ins () SQL SECUR
 BEGIN
 insert into db_storedproc_1.t3166 values ('inserted from sp3166_ins');
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -341,7 +333,6 @@ c1
 inserted outside SP
 GRANT INSERT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -362,7 +353,6 @@ inserted from sp3166_s_i
 inserted from sp3166_ins
 REVOKE SELECT ON db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -380,7 +370,6 @@ inserted from sp3166_ins
 root@localhost	db_storedproc_1
 REVOKE EXECUTE on db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();

=== modified file 'mysql-test/suite/funcs_1/r/memory_storedproc_10.result'
--- a/mysql-test/suite/funcs_1/r/memory_storedproc_10.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_storedproc_10.result	2010-03-19 08:56:26 +0000
@@ -82,7 +82,6 @@ create user 'user_2'@'localhost';
 GRANT CREATE ROUTINE ON db_storedproc.* TO 'user_1'@'localhost';
 GRANT SELECT         ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc
 CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
@@ -95,7 +94,6 @@ DECLARE res INT;
 SET res = n * n;
 RETURN res;
 END//
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -114,7 +112,6 @@ fn31105( 9 )
 81
 GRANT EXECUTE ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -135,7 +132,6 @@ a`	a`	1000-01-01	-5000	a`	-5000
 SELECT fn31105( 9 );
 fn31105( 9 )
 81
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();

=== modified file 'mysql-test/suite/funcs_1/r/memory_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/memory_trig_03.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_trig_03.result	2010-03-19 08:56:26 +0000
@@ -86,8 +86,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.3.2:
 -----------------
@@ -162,8 +160,6 @@ grant TRIGGER, UPDATE on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT UPDATE, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -223,8 +219,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -297,8 +291,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -352,8 +344,6 @@ grant UPDATE (f1) on priv_db.t1 to test_
 show grants for test_noprivs;
 Grants for test_noprivs@%
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'%'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -408,8 +398,6 @@ grant TRIGGER, SELECT on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -465,8 +453,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -520,8 +506,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -566,8 +550,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT INSERT (f1), UPDATE (f1) ON `priv_db`.`t1` TO 'test_noprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -612,7 +594,6 @@ Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 GRANT SELECT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost

=== modified file 'mysql-test/suite/funcs_1/r/memory_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/memory_trig_03e.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_trig_03e.result	2010-03-19 08:56:26 +0000
@@ -25,7 +25,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on db level for create:
 --------------------------------------------
@@ -33,7 +32,6 @@ use priv_db;
 create trigger trg1_1 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-no';
 ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv_db;
 insert into t1 (f1) values ('insert-yes');
 select f1 from t1 order by f1;
@@ -254,8 +252,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_noprivs@localhost;
 set password for test_noprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on table level for create:
 -----------------------------------------------
@@ -514,8 +510,6 @@ grant SELECT,INSERT  on *.* to test_nopr
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT SELECT, INSERT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -564,7 +558,6 @@ revoke TRIGGER on *.* from test_yesprivs
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -699,7 +692,6 @@ select f1 from t1 order by f1;
 f1
 insert-yes
 insert-yes
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -768,9 +760,7 @@ Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT, UPDATE ON `priv1_db`.* TO 'test_noprivs'@'localhost'
 GRANT SELECT, INSERT ON `priv2_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
 
 trigger privilege on one db1 db level, not on db2
@@ -983,7 +973,6 @@ create User test_useprivs@localhost;
 set password for test_useprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1011,7 +1000,6 @@ select f1 from t1 order by f1;
 f1
 trig 1_1-yes
 prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
-connect(localhost,test_useprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_useprivs@localhost
@@ -1207,7 +1195,6 @@ create table t1 (f1 char(20)) engine= me
 create User test_yesprivs@localhost;
 set password for test_yesprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1319,8 +1306,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, UPDATE ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 update only on column:
 ----------------------

=== modified file 'mysql-test/suite/funcs_1/r/memory_trig_0407.result'
--- a/mysql-test/suite/funcs_1/r/memory_trig_0407.result	2009-02-13 18:07:56 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_trig_0407.result	2010-03-19 08:56:26 +0000
@@ -68,8 +68,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.4:
 ---------------

=== modified file 'mysql-test/suite/funcs_1/r/memory_trig_08.result'
--- a/mysql-test/suite/funcs_1/r/memory_trig_08.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/memory_trig_08.result	2010-03-19 08:56:26 +0000
@@ -68,8 +68,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.8.1: (implied in previous tests)
 ---------------------------------------------

=== modified file 'mysql-test/suite/funcs_1/r/myisam_storedproc_06.result'
--- a/mysql-test/suite/funcs_1/r/myisam_storedproc_06.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_storedproc_06.result	2010-03-19 08:56:26 +0000
@@ -79,7 +79,6 @@ grant all on db_storedproc_1.* to 'user_
 revoke create routine on db_storedproc_1.* from 'user_1'@'localhost';
 flush privileges;
 DROP PROCEDURE IF EXISTS sp1;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -92,7 +91,6 @@ USE db_storedproc_1;
 	
 root@localhost	db_storedproc_1
 GRANT CREATE ROUTINE ON db_storedproc_1.* TO 'user_1'@'localhost';
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -113,7 +111,6 @@ Ensure that root always has the GRANT CR
 --------------------------------------------------------------------------------
 grant create routine on db_storedproc_1.* to 'user_1'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 DROP PROCEDURE IF EXISTS sp3;
@@ -150,7 +147,6 @@ CREATE PROCEDURE sp4(v1 char(20))
 BEGIN
 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
 END//
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -192,7 +188,6 @@ grant create routine on db_storedproc_1.
 grant SELECT on db_storedproc_1.* to 'user_2'@'localhost';
 grant execute on db_storedproc_1.* to 'user_2'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp5_s_i () sql security definer
@@ -208,7 +203,6 @@ CREATE PROCEDURE sp5_ins () sql security
 BEGIN
 insert into db_storedproc_1.t3165 values ('inserted', 'from sp5_ins', 1000);
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp5_s_i();
@@ -306,7 +300,6 @@ GRANT CREATE ROUTINE ON db_storedproc_1.
 GRANT SELECT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 GRANT EXECUTE ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp3166_s_i () SQL SECURITY INVOKER
@@ -322,7 +315,6 @@ CREATE PROCEDURE sp3166_ins () SQL SECUR
 BEGIN
 insert into db_storedproc_1.t3166 values ('inserted from sp3166_ins');
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -341,7 +333,6 @@ c1
 inserted outside SP
 GRANT INSERT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -362,7 +353,6 @@ inserted from sp3166_s_i
 inserted from sp3166_ins
 REVOKE SELECT ON db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -380,7 +370,6 @@ inserted from sp3166_ins
 root@localhost	db_storedproc_1
 REVOKE EXECUTE on db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();

=== modified file 'mysql-test/suite/funcs_1/r/myisam_storedproc_10.result'
--- a/mysql-test/suite/funcs_1/r/myisam_storedproc_10.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_storedproc_10.result	2010-03-19 08:56:26 +0000
@@ -82,7 +82,6 @@ create user 'user_2'@'localhost';
 GRANT CREATE ROUTINE ON db_storedproc.* TO 'user_1'@'localhost';
 GRANT SELECT         ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc
 CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
@@ -95,7 +94,6 @@ DECLARE res INT;
 SET res = n * n;
 RETURN res;
 END//
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -114,7 +112,6 @@ fn31105( 9 )
 81
 GRANT EXECUTE ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -135,7 +132,6 @@ a`	a`	1000-01-01	-5000	a`	-5000
 SELECT fn31105( 9 );
 fn31105( 9 )
 81
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();

=== modified file 'mysql-test/suite/funcs_1/r/myisam_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/myisam_trig_03.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_trig_03.result	2010-03-19 08:56:26 +0000
@@ -86,8 +86,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.3.2:
 -----------------
@@ -162,8 +160,6 @@ grant TRIGGER, UPDATE on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT UPDATE, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -223,8 +219,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -297,8 +291,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -352,8 +344,6 @@ grant UPDATE (f1) on priv_db.t1 to test_
 show grants for test_noprivs;
 Grants for test_noprivs@%
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'%'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -408,8 +398,6 @@ grant TRIGGER, SELECT on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -465,8 +453,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -520,8 +506,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -566,8 +550,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT INSERT (f1), UPDATE (f1) ON `priv_db`.`t1` TO 'test_noprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -612,7 +594,6 @@ Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 GRANT SELECT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost

=== modified file 'mysql-test/suite/funcs_1/r/myisam_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/myisam_trig_03e.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_trig_03e.result	2010-03-19 08:56:26 +0000
@@ -25,7 +25,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on db level for create:
 --------------------------------------------
@@ -33,7 +32,6 @@ use priv_db;
 create trigger trg1_1 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-no';
 ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv_db;
 insert into t1 (f1) values ('insert-yes');
 select f1 from t1 order by f1;
@@ -254,8 +252,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_noprivs@localhost;
 set password for test_noprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on table level for create:
 -----------------------------------------------
@@ -514,8 +510,6 @@ grant SELECT,INSERT  on *.* to test_nopr
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT SELECT, INSERT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -564,7 +558,6 @@ revoke TRIGGER on *.* from test_yesprivs
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -699,7 +692,6 @@ select f1 from t1 order by f1;
 f1
 insert-yes
 insert-yes
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -768,9 +760,7 @@ Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT, UPDATE ON `priv1_db`.* TO 'test_noprivs'@'localhost'
 GRANT SELECT, INSERT ON `priv2_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
 
 trigger privilege on one db1 db level, not on db2
@@ -983,7 +973,6 @@ create User test_useprivs@localhost;
 set password for test_useprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1011,7 +1000,6 @@ select f1 from t1 order by f1;
 f1
 trig 1_1-yes
 prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
-connect(localhost,test_useprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_useprivs@localhost
@@ -1207,7 +1195,6 @@ create table t1 (f1 char(20)) engine= my
 create User test_yesprivs@localhost;
 set password for test_yesprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1319,8 +1306,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, UPDATE ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 update only on column:
 ----------------------

=== modified file 'mysql-test/suite/funcs_1/r/myisam_trig_0407.result'
--- a/mysql-test/suite/funcs_1/r/myisam_trig_0407.result	2009-02-13 18:07:56 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_trig_0407.result	2010-03-19 08:56:26 +0000
@@ -68,8 +68,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.4:
 ---------------

=== modified file 'mysql-test/suite/funcs_1/r/myisam_trig_08.result'
--- a/mysql-test/suite/funcs_1/r/myisam_trig_08.result	2008-06-18 17:23:55 +0000
+++ b/mysql-test/suite/funcs_1/r/myisam_trig_08.result	2010-03-19 08:56:26 +0000
@@ -68,8 +68,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.8.1: (implied in previous tests)
 ---------------------------------------------

=== modified file 'mysql-test/suite/funcs_1/r/ndb_storedproc_06.result'
--- a/mysql-test/suite/funcs_1/r/ndb_storedproc_06.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_storedproc_06.result	2010-03-22 10:32:17 +0000
@@ -78,7 +78,6 @@ grant all on db_storedproc_1.* to 'user_
 revoke create routine on db_storedproc_1.* from 'user_1'@'localhost';
 flush privileges;
 DROP PROCEDURE IF EXISTS sp1;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -91,7 +90,6 @@ USE db_storedproc_1;
 	
 root@localhost	db_storedproc_1
 GRANT CREATE ROUTINE ON db_storedproc_1.* TO 'user_1'@'localhost';
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -112,7 +110,6 @@ Ensure that root always has the GRANT CR
 --------------------------------------------------------------------------------
 grant create routine on db_storedproc_1.* to 'user_1'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 DROP PROCEDURE IF EXISTS sp3;
@@ -149,7 +146,6 @@ CREATE PROCEDURE sp4(v1 char(20))
 BEGIN
 SELECT * from db_storedproc_1.t6 where t6.f2= 'xyz';
 END//
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 USE db_storedproc_1;
@@ -191,7 +187,6 @@ grant create routine on db_storedproc_1.
 grant SELECT on db_storedproc_1.* to 'user_2'@'localhost';
 grant execute on db_storedproc_1.* to 'user_2'@'localhost';
 flush privileges;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp5_s_i () sql security definer
@@ -207,7 +202,6 @@ CREATE PROCEDURE sp5_ins () sql security
 BEGIN
 insert into db_storedproc_1.t3165 values ('inserted', 'from sp5_ins', 1000);
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp5_s_i();
@@ -305,7 +299,6 @@ GRANT CREATE ROUTINE ON db_storedproc_1.
 GRANT SELECT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 GRANT EXECUTE ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc_1
 CREATE PROCEDURE sp3166_s_i () SQL SECURITY INVOKER
@@ -321,7 +314,6 @@ CREATE PROCEDURE sp3166_ins () SQL SECUR
 BEGIN
 insert into db_storedproc_1.t3166 values ('inserted from sp3166_ins');
 END//
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -340,7 +332,6 @@ c1
 inserted outside SP
 GRANT INSERT  ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -361,7 +352,6 @@ inserted from sp3166_s_i
 inserted from sp3166_ins
 REVOKE SELECT ON db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();
@@ -379,7 +369,6 @@ inserted from sp3166_ins
 root@localhost	db_storedproc_1
 REVOKE EXECUTE on db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc_1,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc_1
 CALL sp3166_s_i();

=== modified file 'mysql-test/suite/funcs_1/r/ndb_storedproc_10.result'
--- a/mysql-test/suite/funcs_1/r/ndb_storedproc_10.result	2009-01-31 19:22:59 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_storedproc_10.result	2010-03-22 10:32:17 +0000
@@ -81,7 +81,6 @@ create user 'user_2'@'localhost';
 GRANT CREATE ROUTINE ON db_storedproc.* TO 'user_1'@'localhost';
 GRANT SELECT         ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_1,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc
 CREATE PROCEDURE sp31102 () SQL SECURITY INVOKER
@@ -94,7 +93,6 @@ DECLARE res INT;
 SET res = n * n;
 RETURN res;
 END//
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -113,7 +111,6 @@ fn31105( 9 )
 81
 GRANT EXECUTE ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();
@@ -134,7 +131,6 @@ a`	a`	1000-01-01	-5000	a`	-5000
 SELECT fn31105( 9 );
 fn31105( 9 )
 81
-connect(localhost,user_2,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_2@localhost	db_storedproc
 CALL sp31102();

=== modified file 'mysql-test/suite/funcs_1/r/ndb_trig_03.result'
--- a/mysql-test/suite/funcs_1/r/ndb_trig_03.result	2008-06-03 10:21:48 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_03.result	2010-03-19 08:56:26 +0000
@@ -85,8 +85,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.3.2:
 -----------------
@@ -161,8 +159,6 @@ grant TRIGGER, UPDATE on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT UPDATE, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -222,8 +218,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -296,8 +290,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -351,8 +343,6 @@ grant UPDATE (f1) on priv_db.t1 to test_
 show grants for test_noprivs;
 Grants for test_noprivs@%
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'%'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -407,8 +397,6 @@ grant TRIGGER, SELECT on *.* to test_yes
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_noprivs@localhost
@@ -464,8 +452,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.* TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -519,8 +505,6 @@ show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -565,8 +549,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT INSERT (f1), UPDATE (f1) ON `priv_db`.`t1` TO 'test_noprivs'@'localhost'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 show grants;
 Grants for test_noprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
@@ -611,7 +593,6 @@ Grants for test_yesprivs@localhost
 GRANT TRIGGER ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 GRANT SELECT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost

=== modified file 'mysql-test/suite/funcs_1/r/ndb_trig_03e.result'
--- a/mysql-test/suite/funcs_1/r/ndb_trig_03e.result	2008-04-04 17:52:48 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_03e.result	2010-03-19 08:56:26 +0000
@@ -24,7 +24,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on db level for create:
 --------------------------------------------
@@ -32,7 +31,6 @@ use priv_db;
 create trigger trg1_1 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-no';
 ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv_db;
 insert into t1 (f1) values ('insert-yes');
 select f1 from t1 order by f1;
@@ -253,8 +251,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_noprivs@localhost;
 set password for test_noprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 no trigger privilege on table level for create:
 -----------------------------------------------
@@ -513,8 +509,6 @@ grant SELECT,INSERT  on *.* to test_nopr
 show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT SELECT, INSERT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -563,7 +557,6 @@ revoke TRIGGER on *.* from test_yesprivs
 show grants for test_yesprivs@localhost;
 Grants for test_yesprivs@localhost
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -698,7 +691,6 @@ select f1 from t1 order by f1;
 f1
 insert-yes
 insert-yes
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_yesprivs@localhost
@@ -767,9 +759,7 @@ Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, INSERT, UPDATE ON `priv1_db`.* TO 'test_noprivs'@'localhost'
 GRANT SELECT, INSERT ON `priv2_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 use priv1_db;
 
 trigger privilege on one db1 db level, not on db2
@@ -982,7 +972,6 @@ create User test_useprivs@localhost;
 set password for test_useprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1010,7 +999,6 @@ select f1 from t1 order by f1;
 f1
 trig 1_1-yes
 prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
-connect(localhost,test_useprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 test_useprivs@localhost
@@ -1206,7 +1194,6 @@ create table t1 (f1 char(20)) engine= nd
 create User test_yesprivs@localhost;
 set password for test_yesprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1303,7 +1290,6 @@ create table t1 (f1 char(20)) engine= nd
 create User test_yesprivs@localhost;
 set password for test_yesprivs@localhost = password('PWD');
 revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 select current_user;
 current_user
 root@localhost
@@ -1375,8 +1361,6 @@ show grants for test_noprivs@localhost;
 Grants for test_noprivs@localhost
 GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 GRANT SELECT, UPDATE ON `priv_db`.* TO 'test_noprivs'@'localhost'
-connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 update only on column:
 ----------------------

=== modified file 'mysql-test/suite/funcs_1/r/ndb_trig_0407.result'
--- a/mysql-test/suite/funcs_1/r/ndb_trig_0407.result	2009-02-13 18:07:56 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_0407.result	2010-03-19 08:56:26 +0000
@@ -67,8 +67,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.4:
 ---------------

=== modified file 'mysql-test/suite/funcs_1/r/ndb_trig_08.result'
--- a/mysql-test/suite/funcs_1/r/ndb_trig_08.result	2008-06-02 19:57:11 +0000
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_08.result	2010-03-19 08:56:26 +0000
@@ -67,8 +67,6 @@ revoke ALL PRIVILEGES, GRANT OPTION FROM
 create User test_super@localhost;
 set password for test_super@localhost = password('PWD');
 grant ALL on *.* to test_super@localhost with grant OPTION;
-connect(localhost,test_general,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
-connect(localhost,test_super,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
 Testcase 3.5.8.1: (implied in previous tests)
 ---------------------------------------------

=== modified file 'mysql-test/suite/funcs_1/r/storedproc.result'
--- a/mysql-test/suite/funcs_1/r/storedproc.result	2009-06-23 12:32:14 +0000
+++ b/mysql-test/suite/funcs_1/r/storedproc.result	2010-03-19 08:56:26 +0000
@@ -1834,7 +1834,6 @@ CREATE PROCEDURE sp11() insert into mysq
 SELECT security_type from mysql.proc where specific_name='sp11';
 security_type
 DEFINER
-connect(localhost,user_1,,db_storedproc,MYSQL_PORT,MYSQL_SOCK);
 	
 user_1@localhost	db_storedproc
 CALL sp11();

=== modified file 'mysql-test/suite/funcs_1/storedproc/storedproc_06.inc'
--- a/mysql-test/suite/funcs_1/storedproc/storedproc_06.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/storedproc/storedproc_06.inc	2010-03-19 08:56:26 +0000
@@ -53,7 +53,6 @@ flush privileges;
 DROP PROCEDURE IF EXISTS sp1;
 --enable_warnings
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user1a, localhost, user_1, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -75,7 +74,6 @@ USE db_storedproc_1;
 --source suite/funcs_1/include/show_connection.inc
 
 GRANT CREATE ROUTINE ON db_storedproc_1.* TO 'user_1'@'localhost';
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user1b, localhost, user_1, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -120,7 +118,6 @@ grant create routine on db_storedproc_1.
 flush privileges;
 
 #  disconnect default;
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user2, localhost, user_1, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -187,7 +184,6 @@ delimiter ;//
 
 #disconnect default;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user3, localhost, user_1, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -234,7 +230,6 @@ grant SELECT on db_storedproc_1.* to 'us
 grant execute on db_storedproc_1.* to 'user_2'@'localhost';
 flush privileges;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user5_1, localhost, user_1, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -258,7 +253,6 @@ delimiter ;//
 
 disconnect user5_1;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user5_2, localhost, user_2, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -365,7 +359,6 @@ GRANT SELECT  ON db_storedproc_1.* TO 'u
 GRANT EXECUTE ON db_storedproc_1.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user6_1, localhost, user_1, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -389,7 +382,6 @@ delimiter ;//
 
 disconnect user6_1;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user6_2, localhost, user_2, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -407,7 +399,6 @@ GRANT INSERT  ON db_storedproc_1.* TO 'u
 FLUSH PRIVILEGES;
 disconnect user6_2;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user6_3, localhost, user_2, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 CALL sp3166_s_i();
@@ -422,7 +413,6 @@ CALL sp3166_sel();
 REVOKE SELECT ON db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user6_4, localhost, user_2, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 --error ER_TABLEACCESS_DENIED_ERROR
@@ -439,7 +429,6 @@ CALL sp3166_s_i();
 REVOKE EXECUTE on db_storedproc_1.* FROM 'user_2'@'localhost';
 FLUSH PRIVILEGES;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user6_5, localhost, user_2, , db_storedproc_1);
 --source suite/funcs_1/include/show_connection.inc
 --error ER_PROCACCESS_DENIED_ERROR

=== modified file 'mysql-test/suite/funcs_1/storedproc/storedproc_10.inc'
--- a/mysql-test/suite/funcs_1/storedproc/storedproc_10.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/storedproc/storedproc_10.inc	2010-03-19 08:56:26 +0000
@@ -58,7 +58,6 @@ GRANT CREATE ROUTINE ON db_storedproc.*
 GRANT SELECT         ON db_storedproc.* TO 'user_2'@'localhost';
 FLUSH PRIVILEGES;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user2_1, localhost, user_1, , db_storedproc);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -80,7 +79,6 @@ delimiter ;//
 
 disconnect user2_1;
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user2_2, localhost, user_2, , db_storedproc);
 --source suite/funcs_1/include/show_connection.inc
 
@@ -102,7 +100,6 @@ FLUSH PRIVILEGES;
 disconnect user2_2;
 
 # new connection
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user2_3, localhost, user_2, , db_storedproc);
 --source suite/funcs_1/include/show_connection.inc
 CALL sp31102();
@@ -121,7 +118,6 @@ FLUSH PRIVILEGES;
 CALL sp31102();
 SELECT fn31105( 9 );
 
---replace_result $MASTER_MYPORT MYSQL_PORT $MASTER_MYSOCK MYSQL_SOCK
 connect (user2_4, localhost, user_2, , db_storedproc);
 --source suite/funcs_1/include/show_connection.inc
 CALL sp31102();

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03.inc	2010-03-19 08:56:26 +0000
@@ -62,9 +62,7 @@ let $message= Testcase 3.5.3.2/6:;
 	grant SELECT on priv_db.t1 to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -155,9 +153,7 @@ let $message=Testcase 3.5.3.7a:;
 	grant TRIGGER, UPDATE on *.* to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_424a,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_424a,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 	connection no_privs_424a;
@@ -209,9 +205,7 @@ let $message= Testcase 3.5.3.7b:;
 	grant UPDATE on priv_db.* to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_424b,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_424b,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -263,9 +257,7 @@ let $message= Testcase 3.5.3.7c;
 	grant UPDATE on priv_db.t1 to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_424c,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_424c,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -316,9 +308,7 @@ let $message= Testcase 3.5.3.7d:;
 	grant UPDATE (f1) on priv_db.t1 to test_yesprivs@localhost;
 	show grants for test_noprivs;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_424d,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_424d,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -369,9 +359,7 @@ let $message= Testcase 3.5.3.8a:;
 	grant TRIGGER, SELECT on *.* to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_425a,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_425a,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -426,9 +414,7 @@ let $message= Testcase: 3.5.3.8b;
 	grant SELECT on priv_db.* to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_425b,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_425b,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -482,9 +468,7 @@ let $message= Testcase 3.5.3.8c:;
 	grant SELECT on priv_db.t1 to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_425c,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_425c,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -534,9 +518,7 @@ let $message=Testcase: 3.5.3.8d:;
 	grant SELECT (f1) on priv_db.t1 to test_yesprivs@localhost;
 	show grants for test_noprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs_425d,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs_425d,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 
@@ -592,7 +574,6 @@ let $message=Testcase: 3.5.3.x:;
 	grant SELECT on priv_db.t2 to test_yesprivs@localhost;
 	show grants for test_yesprivs@localhost;
 
-       --replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
        connect (yes_353x,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 	connection yes_353x;

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_columns.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_columns.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_columns.inc	2010-03-19 08:56:26 +0000
@@ -36,10 +36,8 @@ let $message= ####### Testcase for colum
         grant SELECT,UPDATE on priv_db.* to test_noprivs@localhost;
         show grants for test_noprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 # grant TRIGGER and UPDATE on column -> succeed

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_db_level.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_db_level.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_db_level.inc	2010-03-19 08:56:26 +0000
@@ -37,7 +37,6 @@ let $message= Testcase for db level:;
         show grants for test_noprivs@localhost;
 
 # no trigger privilege->create trigger must fail:
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 let $message= no trigger privilege on db level for create:;
 --source include/show_msg.inc
@@ -47,7 +46,6 @@ let $message= no trigger privilege on db
 		set new.f1 = 'trig 1_1-no';
 
 # user with minimum privs on t1->no trigger executed;
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	use priv_db;
 	insert into t1 (f1) values ('insert-yes');

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_db_table_mix.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_db_table_mix.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_db_table_mix.inc	2010-03-19 08:56:26 +0000
@@ -41,10 +41,8 @@ let $message= ####### Testcase for mix o
         grant SELECT,INSERT on priv2_db.* to test_noprivs@localhost;
         show grants for test_noprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	use priv1_db;
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	use priv1_db;
 

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_definer.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_definer.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_definer.inc	2010-03-19 08:56:26 +0000
@@ -27,7 +27,6 @@ let $message= #########      Testcase fo
 
 	revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 # create trigger with not existing definer shall deliver a warning:

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_global_db_mix.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_global_db_mix.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_global_db_mix.inc	2010-03-19 08:56:26 +0000
@@ -38,10 +38,8 @@ let $message= #### Testcase for mix of u
         grant SELECT,INSERT  on *.* to test_noprivs@localhost;
         show grants for test_noprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 	connection yes_privs;
@@ -83,7 +81,6 @@ let $message= trigger privilege on user
 	--disable_warnings
         disconnect yes_privs;
 	--enable_warnings
-        --replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
         connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	select current_user;
         use priv_db;
@@ -184,7 +181,6 @@ let $message= trigger privilege on db le
 	--disable_warnings
         disconnect yes_privs;
 	--enable_warnings
-        --replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
         connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
         select current_user;
 	use no_priv_db;

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_prepare.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_prepare.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_prepare.inc	2010-03-19 08:56:26 +0000
@@ -32,7 +32,6 @@ let $message= #### Testcase for trigger
 	revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
         revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 	connection default;
@@ -56,7 +55,6 @@ let $message= #### Testcase for trigger
 	select f1 from t1 order by f1;
         prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
 
-        --replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
         connect (use_privs,localhost,test_useprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	select current_user;
 	use priv_db;

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_table_level.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_table_level.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_table_level.inc	2010-03-19 08:56:26 +0000
@@ -30,10 +30,8 @@ let $message= #########      Testcase fo
         set password for test_noprivs@localhost = password('PWD');
         revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (no_privs,localhost,test_noprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 ################ Section 3.5.3 ############

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_03e_transaction.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_03e_transaction.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_03e_transaction.inc	2010-03-19 08:56:26 +0000
@@ -27,7 +27,6 @@ let $message= #########      Testcase fo
 
 	revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (yes_privs,localhost,test_yesprivs,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
 	connection default;

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_0407.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_0407.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_0407.inc	2010-03-19 08:56:26 +0000
@@ -22,9 +22,7 @@ let $message= Testcase: 3.5:;
 	create User test_super@localhost;
 	set password for test_super@localhost = password('PWD');
 	grant ALL on *.* to test_super@localhost with grant OPTION;
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (con1_general,localhost,test_general,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (con1_super,localhost,test_super,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 

=== modified file 'mysql-test/suite/funcs_1/triggers/triggers_08.inc'
--- a/mysql-test/suite/funcs_1/triggers/triggers_08.inc	2009-06-09 16:09:16 +0000
+++ b/mysql-test/suite/funcs_1/triggers/triggers_08.inc	2010-03-19 08:56:26 +0000
@@ -23,9 +23,7 @@ let $message= Testcase: 3.5:;
 	create User test_super@localhost;
 	set password for test_super@localhost = password('PWD');
 	grant ALL on *.* to test_super@localhost with grant OPTION;
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (con2_general,localhost,test_general,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
-	--replace_result $MASTER_MYPORT MASTER_MYPORT $MASTER_MYSOCK MASTER_MYSOCK
 	connect (con2_super,localhost,test_super,PWD,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 	connection default;
 

=== modified file 'mysql-test/suite/innodb/r/innodb-autoinc.result'
--- a/mysql-test/suite/innodb/r/innodb-autoinc.result	2010-04-12 11:56:24 +0000
+++ b/mysql-test/suite/innodb/r/innodb-autoinc.result	2010-08-05 09:24:34 +0000
@@ -1244,3 +1244,16 @@ t1	CREATE TABLE `t1` (
   PRIMARY KEY (`c1`)
 ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
 DROP TABLE t1;
+DROP TABLE IF EXISTS t1;
+Warnings:
+Note	1051	Unknown table 't1'
+CREATE TABLE t1(c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL);
+INSERT INTO t1 VALUES (18446744073709551615);
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `c1` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB AUTO_INCREMENT=18446744073709551615 DEFAULT CHARSET=latin1
+DROP TABLE t1;

=== modified file 'mysql-test/suite/innodb/r/innodb_mysql.result'
--- a/mysql-test/suite/innodb/r/innodb_mysql.result	2010-07-07 11:55:09 +0000
+++ b/mysql-test/suite/innodb/r/innodb_mysql.result	2010-09-02 00:43:02 +0000
@@ -2507,4 +2507,96 @@ LOCK TABLES t1 READ;
 ALTER TABLE t1 COMMENT 'test';
 UNLOCK TABLES;
 DROP TABLE t1;
+#
+# Bug#55826: create table .. select crashes with when KILL_BAD_DATA 
+#  is returned
+#
+CREATE TABLE t1(a INT) ENGINE=innodb;
+INSERT INTO t1 VALUES (0);
+SET SQL_MODE='STRICT_ALL_TABLES';
+CREATE TABLE t2 
+SELECT LEAST((SELECT '' FROM t1),NOW()) FROM `t1`;
+ERROR 22007: Incorrect datetime value: '' for column 'NOW()' at row 1
+DROP TABLE t1;
+SET SQL_MODE=DEFAULT;
+#
+# Bug#55580: segfault in read_view_sees_trx_id
+#
+CREATE TABLE t1 (a INT) ENGINE=Innodb;
+CREATE TABLE t2 (a INT) ENGINE=Innodb;
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES (1),(2);
+START TRANSACTION;
+SELECT * FROM t2 LOCK IN SHARE MODE;
+a
+1
+2
+START TRANSACTION;
+SELECT * FROM t1 LOCK IN SHARE MODE;
+a
+1
+2
+SELECT * FROM t1 FOR UPDATE;
+# should not crash
+SELECT * FROM t1 GROUP BY (SELECT a FROM t2 LIMIT 1 FOR UPDATE) + t1.a;
+ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
+DROP TABLE t1,t2;
+#
+# Bug#55656: mysqldump can be slower after bug #39653 fix
+#
+CREATE TABLE t1 (a INT , b INT, c INT, d INT,
+KEY (b), PRIMARY KEY (a,b)) ENGINE=INNODB;
+INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3);
+EXPLAIN SELECT COUNT(*) FROM t1;
+id	1
+select_type	SIMPLE
+table	t1
+type	index
+possible_keys	NULL
+key	b
+key_len	4
+ref	NULL
+rows	3
+Extra	Using index
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b);
+EXPLAIN SELECT COUNT(*) FROM t1;
+id	1
+select_type	SIMPLE
+table	t1
+type	index
+possible_keys	NULL
+key	b
+key_len	8
+ref	NULL
+rows	3
+Extra	Using index
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b,c);
+EXPLAIN SELECT COUNT(*) FROM t1;
+id	1
+select_type	SIMPLE
+table	t1
+type	index
+possible_keys	NULL
+key	b
+key_len	13
+ref	NULL
+rows	3
+Extra	Using index
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b,c,d);
+EXPLAIN SELECT COUNT(*) FROM t1;
+id	1
+select_type	SIMPLE
+table	t1
+type	index
+possible_keys	NULL
+key	PRIMARY
+key_len	8
+ref	NULL
+rows	3
+Extra	Using index
+DROP TABLE t1;
+#
 End of 5.1 tests

=== modified file 'mysql-test/suite/innodb/t/innodb-autoinc.test'
--- a/mysql-test/suite/innodb/t/innodb-autoinc.test	2010-04-12 11:56:24 +0000
+++ b/mysql-test/suite/innodb/t/innodb-autoinc.test	2010-08-05 09:24:34 +0000
@@ -662,3 +662,15 @@ INSERT INTO  t1 VALUES (1), (2), (-68511
 SELECT * FROM t1;
 SHOW CREATE TABLE t1;
 DROP TABLE t1;
+
+##
+# 55277: Failing assertion: auto_inc > 0
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL);
+INSERT INTO t1 VALUES (18446744073709551615);
+# Restart the server
+-- source include/restart_mysqld.inc
+SHOW CREATE TABLE t1;
+DROP TABLE t1;

=== modified file 'mysql-test/suite/innodb/t/innodb_mysql.test'
--- a/mysql-test/suite/innodb/t/innodb_mysql.test	2010-07-07 11:55:09 +0000
+++ b/mysql-test/suite/innodb/t/innodb_mysql.test	2010-09-02 00:43:02 +0000
@@ -500,11 +500,7 @@ INSERT INTO t2 VALUES (),();
 CREATE OR REPLACE VIEW v1 AS SELECT 1 FROM t2 
   WHERE b =(SELECT a FROM t1 LIMIT 1);
 
---disable_query_log
---disable_result_log
 CONNECT (con1, localhost, root,,);
---enable_query_log
---enable_result_log
 CONNECTION default;
 
 DELIMITER |;
@@ -751,4 +747,83 @@ UNLOCK TABLES;
 DROP TABLE t1;
 
 
+--echo #
+--echo # Bug#55826: create table .. select crashes with when KILL_BAD_DATA 
+--echo #  is returned
+--echo #
+CREATE TABLE t1(a INT) ENGINE=innodb;
+INSERT INTO t1 VALUES (0);
+SET SQL_MODE='STRICT_ALL_TABLES';
+--error ER_TRUNCATED_WRONG_VALUE
+CREATE TABLE t2 
+  SELECT LEAST((SELECT '' FROM t1),NOW()) FROM `t1`;
+DROP TABLE t1;  
+SET SQL_MODE=DEFAULT;
+
+
+
+--echo #
+--echo # Bug#55580: segfault in read_view_sees_trx_id
+--echo #
+CREATE TABLE t1 (a INT) ENGINE=Innodb;
+CREATE TABLE t2 (a INT) ENGINE=Innodb;
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES (1),(2);
+
+connect (con1,localhost,root,,test);
+connect (con2,localhost,root,,test);
+
+connection con1;
+START TRANSACTION;
+SELECT * FROM t2 LOCK IN SHARE MODE;
+
+connection con2;
+START TRANSACTION;
+SELECT * FROM t1 LOCK IN SHARE MODE;
+
+connection con1;
+let $conn_id= `SELECT CONNECTION_ID()`;
+--send SELECT * FROM t1 FOR UPDATE
+
+connection con2;
+let $wait_timeout= 2;
+let $wait_condition= SELECT 1 FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE ID=$conn_id AND STATE='Sending data';
+--source include/wait_condition.inc
+--echo # should not crash
+--error ER_LOCK_DEADLOCK
+SELECT * FROM t1 GROUP BY (SELECT a FROM t2 LIMIT 1 FOR UPDATE) + t1.a;
+
+connection default;
+disconnect con1;
+disconnect con2;
+
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Bug#55656: mysqldump can be slower after bug #39653 fix
+--echo #
+
+CREATE TABLE t1 (a INT , b INT, c INT, d INT,
+  KEY (b), PRIMARY KEY (a,b)) ENGINE=INNODB;
+INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b,c);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP INDEX b ON t1;
+CREATE INDEX b ON t1(a,b,c,d);
+--query_vertical EXPLAIN SELECT COUNT(*) FROM t1
+
+DROP TABLE t1;
+
+--echo #
+
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/suite/innodb_plugin/r/innodb-autoinc.result'
--- a/mysql-test/suite/innodb_plugin/r/innodb-autoinc.result	2010-04-09 12:56:51 +0000
+++ b/mysql-test/suite/innodb_plugin/r/innodb-autoinc.result	2010-08-16 00:12:22 +0000
@@ -1244,3 +1244,16 @@ t1	CREATE TABLE `t1` (
   PRIMARY KEY (`c1`)
 ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
 DROP TABLE t1;
+DROP TABLE IF EXISTS t1;
+Warnings:
+Note	1051	Unknown table 't1'
+CREATE TABLE t1(c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL);
+INSERT INTO t1 VALUES (18446744073709551615);
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `c1` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB AUTO_INCREMENT=18446744073709551615 DEFAULT CHARSET=latin1
+DROP TABLE t1;

=== modified file 'mysql-test/suite/innodb_plugin/t/innodb-autoinc-44030.test'
--- a/mysql-test/suite/innodb_plugin/t/innodb-autoinc-44030.test	2010-07-30 14:09:24 +0000
+++ b/mysql-test/suite/innodb_plugin/t/innodb-autoinc-44030.test	2010-08-06 09:35:17 +0000
@@ -1,8 +1,6 @@
 -- source include/have_innodb_plugin.inc
 # embedded server ignores 'delayed', so skip this
 -- source include/not_embedded.inc
-# remove the next line after bug #55503 is fixed
--- source include/not_valgrind.inc
 
 let $innodb_file_format_check_orig=`select @@innodb_file_format_check`;
 

=== modified file 'mysql-test/suite/innodb_plugin/t/innodb-autoinc.test'
--- a/mysql-test/suite/innodb_plugin/t/innodb-autoinc.test	2010-07-30 14:09:24 +0000
+++ b/mysql-test/suite/innodb_plugin/t/innodb-autoinc.test	2010-08-20 12:08:01 +0000
@@ -1,8 +1,6 @@
 -- source include/have_innodb_plugin.inc
 # embedded server ignores 'delayed', so skip this
 -- source include/not_embedded.inc
-# remove the next line after bug #55503 is fixed
--- source include/not_valgrind.inc
 
 let $innodb_file_format_check_orig=`select @@innodb_file_format_check`;
 
@@ -667,6 +665,18 @@ SELECT * FROM t1;
 SHOW CREATE TABLE t1;
 DROP TABLE t1;
 
+##
+# 55277: Failing assertion: auto_inc > 0
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (NULL);
+INSERT INTO t1 VALUES (18446744073709551615);
+# Restart the server
+-- source include/restart_mysqld.inc
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
 #
 # restore environment to the state it was before this test execution
 #

=== modified file 'mysql-test/suite/rpl/r/rpl_create_if_not_exists.result'
--- a/mysql-test/suite/rpl/r/rpl_create_if_not_exists.result	2010-01-16 07:44:24 +0000
+++ b/mysql-test/suite/rpl/r/rpl_create_if_not_exists.result	2010-08-18 04:56:06 +0000
@@ -65,3 +65,12 @@ c1
 DROP TABLE t1;
 DROP TABLE t2;
 DROP TABLE t3;
+
+# Bug#55616 Killing thread or query during CREATE IF NOT EXISTS makes
+# slave SQL thread abort
+
+CREATE TABLE t1 ( i INT );
+CREATE TABLE IF NOT EXISTS t1
+AS SELECT SLEEP(3);
+KILL QUERY master1;
+DROP TABLE t1;

=== modified file 'mysql-test/suite/rpl/r/rpl_create_tmp_table_if_not_exists.result'
--- a/mysql-test/suite/rpl/r/rpl_create_tmp_table_if_not_exists.result	2009-08-13 02:48:57 +0000
+++ b/mysql-test/suite/rpl/r/rpl_create_tmp_table_if_not_exists.result	2010-08-18 04:56:06 +0000
@@ -19,4 +19,9 @@ master-bin.000001	#	Query	#	#	use `test`
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS tmp1 LIKE tmp
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS tmp1 LIKE tmp
 master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS tmp2 SELECT * FROM tmp
-master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS tmp2 SELECT * FROM tmp
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `tmp2` (
+  `c1` int(11) DEFAULT NULL
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`tmp2` (`c1`) SELECT * FROM tmp
+master-bin.000001	#	Query	#	#	COMMIT

=== modified file 'mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result'
--- a/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result	2010-07-04 04:02:49 +0000
+++ b/mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result	2010-08-03 02:22:19 +0000
@@ -883,8 +883,8 @@ master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test_rpl`; DELETE FROM t2
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 master-bin.000001	#	Query	#	#	BEGIN
-master-bin.000001	#	Begin_load_query	#	#	;file_id=#;block_len=#
-master-bin.000001	#	Execute_load_query	#	#	use `test_rpl`; LOAD DATA INFILE 'MYSQLTEST_VARDIR/std_data/rpl_mixed.dat' INTO TABLE `t1` FIELDS TERMINATED BY '|' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`a`, `b`) ;file_id=#
+master-bin.000001	#	Table_map	#	#	table_id: # (test_rpl.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 master-bin.000001	#	Query	#	#	BEGIN
 master-bin.000001	#	Query	#	#	use `test_rpl`; DELETE FROM t1

=== modified file 'mysql-test/suite/rpl/r/rpl_row_create_table.result'
--- a/mysql-test/suite/rpl/r/rpl_row_create_table.result	2010-05-24 13:54:08 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_create_table.result	2010-08-18 04:56:06 +0000
@@ -467,4 +467,10 @@ DROP VIEW IF EXISTS bug48506_t1, bug4850
 DROP TEMPORARY TABLES t7;
 DROP TABLES t4, t5;
 DROP TABLES IF EXISTS bug48506_t4;
+CREATE TABLE t1 SELECT 1;
+CREATE TABLE IF NOT EXISTS t1 SELECT 1;
+Warnings:
+Note	1050	Table 't1' already exists
+Comparing tables master:test.t1 and slave:test.t1
+DROP TABLE t1;
 end of the tests

=== added file 'mysql-test/suite/rpl/r/rpl_stm_create_if_not_exists.result'
--- a/mysql-test/suite/rpl/r/rpl_stm_create_if_not_exists.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_stm_create_if_not_exists.result	2010-08-18 04:56:06 +0000
@@ -0,0 +1,704 @@
+# WL#5370 Keep forward-compatibility when changing 'CREATE TABLE IF NOT
+# EXISTS ... SELECT' behaviour
+#
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+
+
+CREATE TABLE t2(c1 INT, c2 char(10));
+INSERT INTO t2 VALUES(1, 'abc'), (2, 'abc');
+
+# The original query should be binlogged if the table does not exist.
+# ------------------------------------------------------------------
+
+CREATE  TABLE IF NOT EXISTS t1 (c1 INT , c2 INT, c3 char(10), c4 INT KEY)
+SELECT 'abc' AS c3, 1 AS c4;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE  TABLE IF NOT EXISTS t1 (c1 INT , c2 INT, c3 char(10), c4 INT KEY)
+SELECT 'abc' AS c3, 1 AS c4
+Comparing tables master:test.t1 and slave:test.t1
+
+# The statement should be binlogged as two events. one is 
+# 'CREATE  TABLE IF NOT EXISTS ..', another one is
+# 'INSERT ... SELECT'.
+# ------------------------------------------------------------------
+
+CREATE  TABLE IF NOT EXISTS t1
+SELECT 'abc', 2;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 2
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+
+# Verify if it can be binlogged with right database name when the table
+# is not in the default database
+
+DROP DATABASE IF EXISTS db1;
+CREATE DATABASE db1;
+USE db1;
+CREATE  TABLE IF NOT EXISTS test.t1
+SELECT 'abc', 20;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `db1`; CREATE TABLE IF NOT EXISTS `test`.`t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 20
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+USE test;
+DROP DATABASE db1;
+
+# It should be binlogged as 'REPLACE ... SELECT'
+# if the original statement has option REPLACE
+
+CREATE  TABLE IF NOT EXISTS t1
+REPLACE SELECT '123', 2;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; REPLACE INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 2
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+
+# It should be binlogged as 'INSERT IGNORE... SELECT'
+# if the original statement has option IGNORE 
+
+CREATE  TABLE IF NOT EXISTS t1
+IGNORE SELECT '123', 2;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT IGNORE INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 2
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+
+# Nothing should be binlogged if error happens and no any row is inserted
+
+CREATE  TABLE IF NOT EXISTS t1
+SELECT '123', 2;
+ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+Comparing tables master:test.t1 and slave:test.t1
+
+# Verify it can binlog well when there are some braces('(')
+
+CREATE  TABLE IF NOT EXISTS t1
+(SELECT '123', 3) UNION (SELECT '123', 4);
+Warnings:
+Note	1050	Table 't1' already exists
+CREATE  TABLE IF NOT EXISTS t1
+REPLACE (SELECT 'abc', 3) UNION (SELECT 'abc', 4);
+Warnings:
+Note	1050	Table 't1' already exists
+CREATE  TABLE IF NOT EXISTS t1
+IGNORE (SELECT '123', 3) UNION (SELECT '123', 4);
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) (SELECT '123', 3) UNION (SELECT '123', 4)
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; REPLACE INTO `test`.`t1` (`c3`,`c4`) (SELECT 'abc', 3) UNION (SELECT 'abc', 4)
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT IGNORE INTO `test`.`t1` (`c3`,`c4`) (SELECT '123', 3) UNION (SELECT '123', 4)
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+
+# Throw a warning that table already exists and don't insert anything
+
+CREATE VIEW t3 AS SELECT * FROM t2;
+CREATE TABLE IF NOT EXISTS t3
+SELECT '123', 2;
+Warnings:
+Note	1050	Table 't3' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+DROP VIEW t3;
+
+# The statement can be binlogged correctly when it is in a SP/EVENT/TRIGGER
+
+DROP PROCEDURE IF EXISTS p1;
+CREATE PROCEDURE p1(IN a INT)
+CREATE  TABLE IF NOT EXISTS t1 SELECT '123', a;
+call p1(500);
+Warnings:
+Note	1050	Table 't1' already exists
+call p1(600);
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123',  NAME_CONST('a',500)
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123',  NAME_CONST('a',600)
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+DROP PROCEDURE p1;
+
+# The statement can be binlogged correctly when it is in a prepared statement
+
+PREPARE stm FROM "CREATE  TABLE IF NOT EXISTS t1 SELECT '123', ?";
+SET @a= 700;
+EXECUTE stm USING @a;
+Warnings:
+Note	1050	Table 't1' already exists
+SET @a= 800;
+EXECUTE stm USING @a;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 700
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 800
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+
+# The statement can be binlogged correctly when it is in a conditional comment
+
+# The whole statement in a conditional comment
+/*!CREATE  TABLE IF NOT EXISTS t1
+SELECT 'abc', 900*/;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 900*/
+master-bin.000001	#	Query	#	#	COMMIT
+
+# There is an long comment before SELECT
+/*!CREATE  /*blabla*/ TABLE IF NOT EXISTS t1
+SELECT 'abc', 901*/;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 901*/
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Conditional comment starts just from SELECT
+CREATE  TABLE IF NOT EXISTS t1
+/*!SELECT 'abc',*/ 902;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc',*/ 902
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Only SELECT keyword is in the conditional comment
+CREATE  TABLE IF NOT EXISTS t1
+/*!SELECT*/ /*!'abc',*/ 904;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT*/ /*!'abc',*/ 904
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Conditional comment is after SELECT keyword
+CREATE  TABLE IF NOT EXISTS t1
+SELECT /*!'abc',*/ 903;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT /*!'abc',*/ 903
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Conditional comment ends just before SELECT keyword
+/*!CREATE  TABLE IF NOT EXISTS t1
+*/SELECT 'abc', 905;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 905
+master-bin.000001	#	Query	#	#	COMMIT
+Comparing tables master:test.t1 and slave:test.t1
+DROP TABLE t2;
+DROP  TABLE t1;
+
+
+CREATE TABLE t2(c1 INT, c2 char(10));
+INSERT INTO t2 VALUES(1, 'abc'), (2, 'abc');
+
+# The original query should be binlogged if the table does not exist.
+# ------------------------------------------------------------------
+
+CREATE TEMPORARY TABLE IF NOT EXISTS t1 (c1 INT , c2 INT, c3 char(10), c4 INT KEY)
+SELECT 'abc' AS c3, 1 AS c4;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS t1 (c1 INT , c2 INT, c3 char(10), c4 INT KEY)
+SELECT 'abc' AS c3, 1 AS c4
+
+# The statement should be binlogged as two events. one is 
+# 'CREATE TEMPORARY TABLE IF NOT EXISTS ..', another one is
+# 'INSERT ... SELECT'.
+# ------------------------------------------------------------------
+
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+SELECT 'abc', 2;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 2
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Verify if it can be binlogged with right database name when the table
+# is not in the default database
+
+DROP DATABASE IF EXISTS db1;
+CREATE DATABASE db1;
+USE db1;
+CREATE TEMPORARY TABLE IF NOT EXISTS test.t1
+SELECT 'abc', 20;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `db1`; CREATE TEMPORARY TABLE IF NOT EXISTS `test`.`t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `db1`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 20
+master-bin.000001	#	Query	#	#	COMMIT
+USE test;
+DROP DATABASE db1;
+
+# It should be binlogged as 'REPLACE ... SELECT'
+# if the original statement has option REPLACE
+
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+REPLACE SELECT '123', 2;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; REPLACE INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 2
+master-bin.000001	#	Query	#	#	COMMIT
+
+# It should be binlogged as 'INSERT IGNORE... SELECT'
+# if the original statement has option IGNORE 
+
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+IGNORE SELECT '123', 2;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT IGNORE INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 2
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Nothing should be binlogged if error happens and no any row is inserted
+
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+SELECT '123', 2;
+ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+
+# Verify it can binlog well when there are some braces('(')
+
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+(SELECT '123', 3) UNION (SELECT '123', 4);
+Warnings:
+Note	1050	Table 't1' already exists
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+REPLACE (SELECT 'abc', 3) UNION (SELECT 'abc', 4);
+Warnings:
+Note	1050	Table 't1' already exists
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+IGNORE (SELECT '123', 3) UNION (SELECT '123', 4);
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) (SELECT '123', 3) UNION (SELECT '123', 4)
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; REPLACE INTO `test`.`t1` (`c3`,`c4`) (SELECT 'abc', 3) UNION (SELECT 'abc', 4)
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT IGNORE INTO `test`.`t1` (`c3`,`c4`) (SELECT '123', 3) UNION (SELECT '123', 4)
+master-bin.000001	#	Query	#	#	COMMIT
+
+# The statement can be binlogged correctly when it is in a SP/EVENT/TRIGGER
+
+DROP PROCEDURE IF EXISTS p1;
+CREATE PROCEDURE p1(IN a INT)
+CREATE TEMPORARY TABLE IF NOT EXISTS t1 SELECT '123', a;
+call p1(500);
+Warnings:
+Note	1050	Table 't1' already exists
+call p1(600);
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123',  NAME_CONST('a',500)
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123',  NAME_CONST('a',600)
+master-bin.000001	#	Query	#	#	COMMIT
+DROP PROCEDURE p1;
+
+# The statement can be binlogged correctly when it is in a prepared statement
+
+PREPARE stm FROM "CREATE TEMPORARY TABLE IF NOT EXISTS t1 SELECT '123', ?";
+SET @a= 700;
+EXECUTE stm USING @a;
+Warnings:
+Note	1050	Table 't1' already exists
+SET @a= 800;
+EXECUTE stm USING @a;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 700
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT '123', 800
+master-bin.000001	#	Query	#	#	COMMIT
+
+# The statement can be binlogged correctly when it is in a conditional comment
+
+# The whole statement in a conditional comment
+/*!CREATE TEMPORARY TABLE IF NOT EXISTS t1
+SELECT 'abc', 900*/;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 900*/
+master-bin.000001	#	Query	#	#	COMMIT
+
+# There is an long comment before SELECT
+/*!CREATE TEMPORARY /*blabla*/ TABLE IF NOT EXISTS t1
+SELECT 'abc', 901*/;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 901*/
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Conditional comment starts just from SELECT
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+/*!SELECT 'abc',*/ 902;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc',*/ 902
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Only SELECT keyword is in the conditional comment
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+/*!SELECT*/ /*!'abc',*/ 904;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; /*! INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT*/ /*!'abc',*/ 904
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Conditional comment is after SELECT keyword
+CREATE TEMPORARY TABLE IF NOT EXISTS t1
+SELECT /*!'abc',*/ 903;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT /*!'abc',*/ 903
+master-bin.000001	#	Query	#	#	COMMIT
+
+# Conditional comment ends just before SELECT keyword
+/*!CREATE TEMPORARY TABLE IF NOT EXISTS t1
+*/SELECT 'abc', 905;
+Warnings:
+Note	1050	Table 't1' already exists
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE IF NOT EXISTS `t1` (
+  `c1` int(11) DEFAULT NULL,
+  `c2` int(11) DEFAULT NULL,
+  `c3` char(10) DEFAULT NULL,
+  `c4` int(11) NOT NULL,
+  PRIMARY KEY (`c4`)
+)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO `test`.`t1` (`c3`,`c4`) SELECT 'abc', 905
+master-bin.000001	#	Query	#	#	COMMIT
+DROP TABLE t2;
+DROP TEMPORARY TABLE t1;

=== modified file 'mysql-test/suite/rpl/t/disabled.def'
--- a/mysql-test/suite/rpl/t/disabled.def	2010-02-27 15:08:53 +0000
+++ b/mysql-test/suite/rpl/t/disabled.def	2010-09-10 10:49:57 +0000
@@ -11,3 +11,4 @@
 ##############################################################################
 
 rpl_row_create_table : Bug#51574 Feb 27 2010 andrei failed different way than earlier with bug#45576
+rpl_log_pos : BUG#55675 Sep 10 2010 27 2010 alfranio rpl.rpl_log_pos fails sporadically with error binlog truncated in the middle

=== modified file 'mysql-test/suite/rpl/t/rpl_create_if_not_exists.test'
--- a/mysql-test/suite/rpl/t/rpl_create_if_not_exists.test	2010-01-16 07:44:24 +0000
+++ b/mysql-test/suite/rpl/t/rpl_create_if_not_exists.test	2010-08-18 04:56:06 +0000
@@ -119,5 +119,32 @@ SELECT * FROM t2;
 DROP TABLE t1;
 DROP TABLE t2;
 DROP TABLE t3;
+sync_slave_with_master;
+
+--echo
+--echo # Bug#55616 Killing thread or query during CREATE IF NOT EXISTS makes
+--echo # slave SQL thread abort
+--echo
+
+--connection master1
+let $con_id = `SELECT CONNECTION_ID()`;
+
+CREATE TABLE t1 ( i INT );
+send CREATE TABLE IF NOT EXISTS t1
+  AS SELECT SLEEP(3);
+
+connection master;
+let $wait_timeout = 3;
+let $show_statement = SHOW PROCESSLIST;
+let $field = State;
+let $condition = = 'User sleep';
+source include/wait_show_condition.inc;
+
+--replace_result $con_id master1
+eval KILL QUERY $con_id;
+sync_slave_with_master;
+
+connection master;
+DROP TABLE t1;
 
 source include/master-slave-end.inc;

=== modified file 'mysql-test/suite/rpl/t/rpl_loaddata_fatal.test'
--- a/mysql-test/suite/rpl/t/rpl_loaddata_fatal.test	2010-05-24 13:54:08 +0000
+++ b/mysql-test/suite/rpl/t/rpl_loaddata_fatal.test	2010-08-03 02:22:19 +0000
@@ -1,4 +1,4 @@
-source include/have_binlog_format_mixed_or_statement.inc;
+source include/have_binlog_format_statement.inc;
 source include/have_debug.inc;
 source include/master-slave.inc;
 

=== modified file 'mysql-test/suite/rpl/t/rpl_loaddata_map.test'
--- a/mysql-test/suite/rpl/t/rpl_loaddata_map.test	2008-07-18 11:34:19 +0000
+++ b/mysql-test/suite/rpl/t/rpl_loaddata_map.test	2010-08-03 02:22:19 +0000
@@ -16,7 +16,7 @@
 #  BUG#33413 show binlog events fails if binlog has event size of close
 #            to max_allowed_packet
 
-source include/have_binlog_format_mixed_or_statement.inc;
+source include/have_binlog_format_statement.inc;
 source include/master-slave.inc;
 
 

=== modified file 'mysql-test/suite/rpl/t/rpl_row_create_table.test'
--- a/mysql-test/suite/rpl/t/rpl_row_create_table.test	2010-05-24 13:54:08 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_create_table.test	2010-08-18 04:56:06 +0000
@@ -299,5 +299,18 @@ DROP VIEW IF EXISTS bug48506_t1, bug4850
 DROP TEMPORARY TABLES t7;
 DROP TABLES t4, t5;
 DROP TABLES IF EXISTS bug48506_t4;
+sync_slave_with_master;
+
+#
+# Bug#55598 RBR: CREATE TABLE IF NOT EXISTS and INSERT written to binary log
+# twice
+#
+connection master;
+CREATE TABLE t1 SELECT 1;
+CREATE TABLE IF NOT EXISTS t1 SELECT 1;
+let $diff_table=test.t1;
+source include/rpl_diff_tables.inc;
+DROP TABLE t1;
+
 source include/master-slave-end.inc;
 --echo end of the tests

=== modified file 'mysql-test/suite/rpl/t/rpl_slave_load_remove_tmpfile.test'
--- a/mysql-test/suite/rpl/t/rpl_slave_load_remove_tmpfile.test	2010-05-24 13:54:08 +0000
+++ b/mysql-test/suite/rpl/t/rpl_slave_load_remove_tmpfile.test	2010-08-03 02:22:19 +0000
@@ -8,7 +8,7 @@
 #    2 - Catches error.
 ##########################################################################
 
---source include/have_binlog_format_mixed_or_statement.inc
+--source include/have_binlog_format_statement.inc
 --source include/have_innodb.inc
 --source include/have_debug.inc
 --source include/master-slave.inc

=== added file 'mysql-test/suite/rpl/t/rpl_stm_create_if_not_exists.test'
--- a/mysql-test/suite/rpl/t/rpl_stm_create_if_not_exists.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_stm_create_if_not_exists.test	2010-08-18 04:56:06 +0000
@@ -0,0 +1,14 @@
+#
+--echo # WL#5370 Keep forward-compatibility when changing 'CREATE TABLE IF NOT
+--echo # EXISTS ... SELECT' behaviour
+--echo #
+
+source include/master-slave.inc;
+source include/have_binlog_format_statement.inc;
+
+source extra/rpl_tests/rpl_stm_create_if_not_exists.test;
+
+let $is_temporary=1;
+source extra/rpl_tests/rpl_stm_create_if_not_exists.test;
+
+source include/master-slave-end.inc;

=== modified file 'mysql-test/suite/rpl/t/rpl_stm_log.test'
--- a/mysql-test/suite/rpl/t/rpl_stm_log.test	2007-06-27 12:29:10 +0000
+++ b/mysql-test/suite/rpl/t/rpl_stm_log.test	2010-08-03 02:22:19 +0000
@@ -1,5 +1,5 @@
 # Requires statement logging
--- source include/have_binlog_format_mixed_or_statement.inc
+-- source include/have_binlog_format_statement.inc
 -- source include/master-slave.inc
 let $engine_type=MyISAM;
 -- source extra/rpl_tests/rpl_log.test

=== modified file 'mysql-test/t/csv.test'
--- a/mysql-test/t/csv.test	2010-02-17 12:13:42 +0000
+++ b/mysql-test/t/csv.test	2010-03-09 15:09:32 +0000
@@ -1553,26 +1553,25 @@ drop table t1;
 # whole alter table code is being tested all around the test suite already.
 #
 
-create table t1 (v varchar(32) not null);
+create table t1 (v varchar(32) not null) engine=csv;
 insert into t1 values ('def'),('abc'),('hij'),('3r4f');
 select * from t1;
 # Fast alter, no copy performed
-alter table t1 change v v2 varchar(32);
+alter table t1 change v v2 varchar(32) not null;
 select * from t1;
 # Fast alter, no copy performed
-alter table t1 change v2 v varchar(64);
+alter table t1 change v2 v varchar(64) not null;
 select * from t1;
 update t1 set v = 'lmn' where v = 'hij';
 select * from t1;
 # Regular alter table
-alter table t1 add i int auto_increment not null primary key first;
+alter table t1 add i int not null first;
 select * from t1;
-update t1 set i=5 where i=3;
+update t1 set i=3 where v = 'abc';
 select * from t1;
-alter table t1 change i i bigint;
+alter table t1 change i i bigint not null;
 select * from t1;
-alter table t1 add unique key (i, v);
-select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
+select * from t1 where i between 2 and 4 and v in ('def','3r4f','abc');
 drop table t1;
 
 #

=== modified file 'mysql-test/t/delete.test'
--- a/mysql-test/t/delete.test	2010-05-14 11:36:27 +0000
+++ b/mysql-test/t/delete.test	2010-08-30 22:16:38 +0000
@@ -387,4 +387,17 @@ DELETE FROM t1 WHERE a = 10 OR b = 20 OR
 
 DROP TABLE t1;
 
+--echo #
+--echo # Bug #53034: Multiple-table DELETE statements not accepting
+--echo #             "Access compatibility" syntax
+--echo #
+
+CREATE TABLE t1 (id INT);
+CREATE TABLE t2 LIKE t1;
+CREATE TABLE t3 LIKE t1;
+
+DELETE FROM t1.*, test.t2.*, a.* USING t1, t2, t3 AS a;
+
+DROP TABLE t1, t2, t3;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/func_group.test'
--- a/mysql-test/t/func_group.test	2009-11-24 15:26:13 +0000
+++ b/mysql-test/t/func_group.test	2010-08-27 09:44:35 +0000
@@ -1082,6 +1082,20 @@ select a.f1 as a, b.f4 as b, a.f1 > b.f4
 from t1 a, t1 b;
 select *, f1 = f2 from t1;
 drop table t1;
+
+--echo #
+--echo # Bug #54465: assert: field_types == 0 || field_types[field_pos] ==
+--echo #             MYSQL_TYPE_LONGLONG
+--echo #
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2);
+
+SELECT MAX((SELECT 1 FROM t1 ORDER BY @var LIMIT 1)) m FROM t1 t2, t1 
+       ORDER BY t1.a;
+
+DROP TABLE t1;
+
 --echo #
 --echo End of 5.1 tests
 

=== modified file 'mysql-test/t/func_time.test'
--- a/mysql-test/t/func_time.test	2009-01-23 12:22:05 +0000
+++ b/mysql-test/t/func_time.test	2010-08-13 13:05:46 +0000
@@ -838,4 +838,15 @@ select date_sub("0069-01-01 00:00:01",IN
 select date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND);
 
 
+#
+# Bug #55565: debug assertion when ordering by expressions with user
+# variable assignments
+#
+
+CREATE TABLE t1(a DOUBLE NOT NULL);
+INSERT INTO t1 VALUES (0),(9.216e-096);
+--echo # should not crash
+SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a);
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/gis.test'
--- a/mysql-test/t/gis.test	2010-02-26 13:16:46 +0000
+++ b/mysql-test/t/gis.test	2010-09-07 11:34:18 +0000
@@ -401,6 +401,7 @@ create table t1 (a int, b blob);
 insert into t1 values (1, ''), (2, NULL), (3, '1');
 select * from t1;
 
+--error ER_ILLEGAL_VALUE_FOR_TYPE
 select
   geometryfromtext(b) IS NULL, geometryfromwkb(b) IS NULL, astext(b) IS NULL, 
   aswkb(b) IS NULL, geometrytype(b) IS NULL, centroid(b) IS NULL,
@@ -419,6 +420,7 @@ select
   intersects(b, b) IS NULL, crosses(b, b) IS NULL
 from t1;
 
+--error ER_ILLEGAL_VALUE_FOR_TYPE
 select 
   point(b, b) IS NULL, linestring(b) IS NULL, polygon(b) IS NULL, multipoint(b) IS NULL, 
   multilinestring(b) IS NULL, multipolygon(b) IS NULL, 
@@ -702,24 +704,44 @@ drop table t1;
 # Bug#44684: valgrind reports invalid reads in 
 # Item_func_spatial_collection::val_str
 #
+--error ER_ILLEGAL_VALUE_FOR_TYPE
 SELECT MultiPoint(12345,'');
-SELECT MultiPoint(123451,'');
-SELECT MultiPoint(1234512,'');
-SELECT MultiPoint(12345123,'');
-
-SELECT MultiLineString(12345,'');
-SELECT MultiLineString(123451,'');
-SELECT MultiLineString(1234512,'');
-SELECT MultiLineString(12345123,'');
-
-SELECT LineString(12345,'');
-SELECT LineString(123451,'');
-SELECT LineString(1234512,'');
-SELECT LineString(12345123,'');
-
-SELECT Polygon(12345,'');
-SELECT Polygon(123451,'');
-SELECT Polygon(1234512,'');
-SELECT Polygon(12345123,'');
+#SELECT MultiPoint(123451,'');
+#SELECT MultiPoint(1234512,'');
+#SELECT MultiPoint(12345123,'');
+
+--error ER_ILLEGAL_VALUE_FOR_TYPE
+#SELECT MultiLineString(12345,'');
+#SELECT MultiLineString(123451,'');
+#SELECT MultiLineString(1234512,'');
+#SELECT MultiLineString(12345123,'');
+
+--error ER_ILLEGAL_VALUE_FOR_TYPE
+#SELECT LineString(12345,'');
+#SELECT LineString(123451,'');
+#SELECT LineString(1234512,'');
+#SELECT LineString(12345123,'');
+
+--error ER_ILLEGAL_VALUE_FOR_TYPE
+#SELECT Polygon(12345,'');
+#SELECT Polygon(123451,'');
+#SELECT Polygon(1234512,'');
+#SELECT Polygon(12345123,'');
+
+#
+# Bug55531 crash with conversions of geometry types / strings
+#
+--error ER_ILLEGAL_VALUE_FOR_TYPE
+SELECT 1 FROM (SELECT GREATEST(1,GEOMETRYCOLLECTION('00000','00000')) b FROM DUAL) AS d WHERE (LINESTRING(d.b));
+
+
+--echo #
+--echo # BUG#51875: crash when loading data into geometry function polyfromwkb
+--echo #
+SET @a=0x00000000030000000100000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440;
+SET @a=POLYFROMWKB(@a);
+SET @a=0x00000000030000000000000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440;
+SET @a=POLYFROMWKB(@a);
+
 
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/insert.test'
--- a/mysql-test/t/insert.test	2009-07-10 23:12:13 +0000
+++ b/mysql-test/t/insert.test	2010-08-09 11:39:59 +0000
@@ -499,3 +499,28 @@ DROP TABLE t1, t2;
 
 --echo End of 5.0 tests.
 
+
+--echo #
+--echo # Bug#54106 assert in Protocol::end_statement,
+--echo #           INSERT IGNORE ... SELECT ... UNION SELECT ...
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (a INT);
+
+--error ER_FIELD_SPECIFIED_TWICE
+INSERT INTO t1 (a, a) VALUES (1, 1);
+# Verify that ER_FIELD_SPECIFIED_TWICE is not ignorable
+--error ER_FIELD_SPECIFIED_TWICE
+INSERT IGNORE t1 (a, a) VALUES (1, 1);
+
+--error ER_FIELD_SPECIFIED_TWICE
+INSERT IGNORE t1 (a, a) SELECT 1,1;
+# Used to cause an assert
+--error ER_FIELD_SPECIFIED_TWICE
+INSERT IGNORE t1 (a, a) SELECT 1,1 UNION SELECT 2,2;
+
+DROP TABLE t1;

=== modified file 'mysql-test/t/join.test'
--- a/mysql-test/t/join.test	2010-04-26 20:46:52 +0000
+++ b/mysql-test/t/join.test	2010-09-07 13:43:00 +0000
@@ -851,4 +851,74 @@ ENGINE=MERGE  UNION=(t1,t2);
 SELECT t1.a FROM mm1,t1;
 DROP TABLE t1, t2, mm1;
 
+#--echo #
+#--echo # Bug #55568: user variable assignments crash server when used within
+#--echo #             query
+#--echo #
+#
+#
+# This test case is invalidated because of fix of bug 55531
+# The reason is that {1} is not a valid geometric collection.
+#
+#CREATE TABLE t1 (a INT);
+
+#INSERT INTO t1 VALUES (0), (1);
+
+#let $i=2;
+#while ($i)
+#{
+#  SELECT MULTIPOINT(
+#    1,
+#    (
+#      SELECT MULTIPOINT(
+#        MULTIPOINT(
+#          1,
+#          (SELECT COUNT(*) FROM (SELECT 1 FROM t1 GROUP BY a,a) d)
+#        )
+#      ) FROM t1
+#    )
+#  ) != COUNT(*) q FROM t1 GROUP BY a;
+#  dec $i;
+#}
+#
+#DROP TABLE t1;
+
+--echo #
+--echo # Bug #54468: crash after item's print() function when ordering/grouping 
+--echo #             by subquery
+--echo #
+
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 VALUES (), ();
+
+SELECT 1 FROM t1
+GROUP BY
+GREATEST(t1.a,
+         (SELECT 1 FROM
+          (SELECT t1.b FROM t1,t1 t2
+           ORDER BY t1.a, t1.a LIMIT 1) AS d)
+        );
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #53544: Server hangs during JOIN query in stored procedure called
+--echo #             twice in a row
+--echo #
+
+CREATE TABLE t1(c INT);
+
+INSERT INTO t1 VALUES (1), (2);
+
+PREPARE stmt FROM "SELECT t2.c AS f1 FROM t1 LEFT JOIN
+                                        t1 t2 ON t1.c=t2.c RIGHT JOIN
+                                        t1 t3 ON t1.c=t3.c 
+                   GROUP BY f1;";
+
+EXECUTE stmt;
+EXECUTE stmt;
+
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/mysqlbinlog.test'
--- a/mysql-test/t/mysqlbinlog.test	2010-03-28 11:57:33 +0000
+++ b/mysql-test/t/mysqlbinlog.test	2010-08-03 10:27:45 +0000
@@ -1,6 +1,6 @@
 # We are using .opt file since we need small binlog size
 # TODO: Need to look at making a row based version once the new row based client is completed. [jbm]
--- source include/have_binlog_format_mixed_or_statement.inc
+-- source include/have_binlog_format_statement.inc
 
 -- source include/have_log_bin.inc
 

=== modified file 'mysql-test/t/mysqltest.test'
--- a/mysql-test/t/mysqltest.test	2010-02-09 17:13:57 +0000
+++ b/mysql-test/t/mysqltest.test	2010-08-04 08:52:45 +0000
@@ -326,6 +326,15 @@ eval select $mysql_errno as "after_!errn
 --exec echo "disable_abort_on_error; error 1000; select 3 from t1; error 1000; select 3 from t1;" | $MYSQL_TEST  2>&1
 
 # ----------------------------------------------------------------------------
+# Check some non-query statements that would fail
+# ----------------------------------------------------------------------------
+--exec illegal_command
+--cat_file does_not_exist
+--perl
+  exit(1);
+EOF
+
+# ----------------------------------------------------------------------------
 # Switch the abort on error on and check the effect on $mysql_errno
 # ----------------------------------------------------------------------------
 --error ER_PARSE_ERROR
@@ -863,7 +872,7 @@ while ($outer)
 }
 
 # Test source in an if in a while which is false on 1st iteration
-# Also test --error in same context
+# Also test --error and --disable_abort_on_error in same context
 let $outer= 2; # Number of outer loops
 let $ifval= 0; # false 1st time
 while ($outer)
@@ -874,6 +883,10 @@ while ($outer)
     --source $MYSQLTEST_VARDIR/tmp/sourced.inc
     --error ER_NO_SUCH_TABLE
     SELECT * from nowhere;
+    --disable_abort_on_error
+# Statement giving a different error, to make sure we don't mask it
+    SELECT * FROM nowhere else;
+    --enable_abort_on_error
   }
   dec $outer;
   inc $ifval;
@@ -1093,6 +1106,36 @@ if (!$counter)
 }
 
 # ----------------------------------------------------------------------------
+# Test if with some non-numerics
+# ----------------------------------------------------------------------------
+
+let $counter=alpha;
+if ($counter)
+{
+  echo Counter is true, (counter=alpha);
+}
+let $counter=   ;
+if ($counter)
+{
+  echo oops, space is true;
+}
+let $counter=-0;
+if ($counter)
+{
+  echo oops, -0 is true;
+}
+if (beta)
+{
+  echo Beta is true;
+}
+let $counter=gamma;
+while ($counter)
+{
+  echo while with string, only once;
+  let $counter=000;
+}
+
+# ----------------------------------------------------------------------------
 # Test while, { and }
 # ----------------------------------------------------------------------------
 
@@ -1437,7 +1480,6 @@ EOF
 remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
 
 # connect when "disable_abort_on_error" caused "connection not found"
---replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
 --disable_abort_on_error
 connect (con1,localhost,root,,);
 connection default;
@@ -1724,7 +1766,16 @@ select 1;
 --reap
 EOF
 --error 1
---exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.in 2>&1
+# Must filter unpredictable extra warning from output
+--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.in > $MYSQL_TMP_DIR/mysqltest.out 2>&1
+--perl
+  my $dir= $ENV{'MYSQL_TMP_DIR'};
+  open (FILE, "$dir/mysqltest.out");
+  while (<FILE>) {
+    print unless /Note: net_clear/; # This shows up on rare occations
+  }
+EOF
+remove_file $MYSQL_TMP_DIR/mysqltest.out;
 remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.in;
 
 drop table t1;

=== added file 'mysql-test/t/partition_not_blackhole-master.opt'
--- a/mysql-test/t/partition_not_blackhole-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/partition_not_blackhole-master.opt	2010-07-08 12:36:55 +0000
@@ -0,0 +1 @@
+--loose-skip-blackhole

=== added file 'mysql-test/t/partition_not_blackhole.test'
--- a/mysql-test/t/partition_not_blackhole.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/partition_not_blackhole.test	2010-08-20 19:17:51 +0000
@@ -0,0 +1,26 @@
+--source include/have_partition.inc
+--source include/not_blackhole.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+
+--echo #
+--echo # Bug#46086: crash when dropping a partitioned table and
+--echo #            the original engine is disabled
+--echo # Copy a .frm and .par file which was created with:
+--echo # create table `t1` (`id` int primary key) engine=blackhole
+--echo # partition by key () partitions 1;
+--copy_file std_data/parts/t1_blackhole.frm $MYSQLD_DATADIR/test/t1.frm
+--copy_file std_data/parts/t1_blackhole.par $MYSQLD_DATADIR/test/t1.par
+SHOW TABLES;
+--replace_result $MYSQLD_DATADIR ./
+--error ER_NOT_FORM_FILE
+SHOW CREATE TABLE t1;
+--error ER_BAD_TABLE_ERROR
+DROP TABLE t1;
+--list_files $MYSQLD_DATADIR/test t1*
+--remove_file $MYSQLD_DATADIR/test/t1.frm
+--remove_file $MYSQLD_DATADIR/test/t1.par

=== modified file 'mysql-test/t/partition_range.test'
--- a/mysql-test/t/partition_range.test	2010-03-04 11:09:09 +0000
+++ b/mysql-test/t/partition_range.test	2010-08-11 12:13:59 +0000
@@ -846,3 +846,44 @@ insert into t2 values(52, 20070322, 456,
 select sum(count) from t2 ch where ch.defid in (50,52) and ch.day between 20070320 and 20070401 group by defid;
 drop table t1, t2;
 
+
+--echo #
+--echo # Bug#50939: Loose Index Scan unduly relies on engine to remember range 
+--echo # endpoints
+--echo #
+CREATE TABLE t1 (
+ a INT,
+ b INT,
+ KEY ( a, b )
+) PARTITION BY HASH (a) PARTITIONS 1;
+
+CREATE TABLE t2 (
+ a INT,
+ b INT,
+ KEY ( a, b )
+);
+
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+
+INSERT INTO t1 SELECT a +  5, b +  5 FROM t1;
+INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
+INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
+INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
+
+INSERT INTO t2 SELECT * FROM t1;
+
+--echo # plans should be identical
+EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
+EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
+
+FLUSH status;
+SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
+--echo # Should be no more than 4 reads.
+SHOW status LIKE 'handler_read_key';
+
+FLUSH status;
+SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
+--echo # Should be no more than 4 reads.
+SHOW status LIKE 'handler_read_key';
+
+DROP TABLE t1, t2;

=== modified file 'mysql-test/t/range.test'
--- a/mysql-test/t/range.test	2010-05-10 07:23:23 +0000
+++ b/mysql-test/t/range.test	2010-08-24 15:51:32 +0000
@@ -1314,44 +1314,15 @@ SELECT * FROM t1 FORCE INDEX (PRIMARY)
 DROP TABLE t1;
 
 --echo #
---echo # Bug#50939: Loose Index Scan unduly relies on engine to remember range 
---echo # endpoints
+--echo # Bug #54802: 'NOT BETWEEN' evaluation is incorrect
 --echo #
-CREATE TABLE t1 (
- a INT,
- b INT,
- KEY ( a, b )
-) PARTITION BY HASH (a) PARTITIONS 1;
 
-CREATE TABLE t2 (
- a INT,
- b INT,
- KEY ( a, b )
-);
+CREATE TABLE t1 (c_key INT, c_notkey INT, KEY(c_key));
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3);
 
-INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+EXPLAIN SELECT * FROM t1 WHERE 2 NOT BETWEEN c_notkey AND c_key;
+SELECT * FROM t1 WHERE 2 NOT BETWEEN c_notkey AND c_key;
 
-INSERT INTO t1 SELECT a +  5, b +  5 FROM t1;
-INSERT INTO t1 SELECT a + 10, b + 10 FROM t1;
-INSERT INTO t1 SELECT a + 20, b + 20 FROM t1;
-INSERT INTO t1 SELECT a + 40, b + 40 FROM t1;
-
-INSERT INTO t2 SELECT * FROM t1;
-
---echo # plans should be identical
-EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10,100) GROUP BY a;
-EXPLAIN SELECT a, MAX(b) FROM t2 WHERE a IN (10,100) GROUP BY a;
-
-FLUSH status;
-SELECT a, MAX(b) FROM t1 WHERE a IN (10, 100) GROUP BY a;
---echo # Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
-
-FLUSH status;
-SELECT a, MAX(b) FROM t2 WHERE a IN (10, 100) GROUP BY a;
---echo # Should be no more than 4 reads.
-SHOW status LIKE 'handler_read_key';
-
-DROP TABLE t1, t2;
+DROP TABLE t1;
 
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/subselect4.test'
--- a/mysql-test/t/subselect4.test	2009-09-18 09:34:08 +0000
+++ b/mysql-test/t/subselect4.test	2010-08-05 10:42:14 +0000
@@ -62,3 +62,19 @@ FROM t3 WHERE 1 = 0 GROUP BY 1;
 DROP TABLE t1,t2,t3;
 
 --echo End of 5.0 tests.
+
+--echo #
+--echo # Bug#54568: create view cause Assertion failed: 0, 
+--echo # file .\item_subselect.cc, line 836
+--echo #
+EXPLAIN SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
+DESCRIBE SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
+--echo # None of the below should crash
+CREATE VIEW v1 AS SELECT 1 LIKE ( 1 IN ( SELECT 1 ) );
+CREATE VIEW v2 AS SELECT 1 LIKE '%' ESCAPE ( 1 IN ( SELECT 1 ) );
+DROP VIEW v1, v2;
+
+
+--echo #
+--echo # End of 5.1 tests.
+--echo #

=== modified file 'mysql-test/t/timezone2.test'
--- a/mysql-test/t/timezone2.test	2008-07-10 16:09:39 +0000
+++ b/mysql-test/t/timezone2.test	2010-08-06 19:29:37 +0000
@@ -273,5 +273,14 @@ UNLOCK TABLES;
 
 DROP TABLE t1;
 
+--echo #
+--echo # Bug #55424: convert_tz crashes when fed invalid data
+--echo #
+
+CREATE TABLE t1 (a SET('x') NOT NULL);
+INSERT INTO t1 VALUES ('');
+SELECT CONVERT_TZ(1, a, 1) FROM t1;
+SELECT CONVERT_TZ(1, 1, a) FROM t1;
+DROP TABLE t1;
 
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/user_var.test'
--- a/mysql-test/t/user_var.test	2009-12-22 10:38:33 +0000
+++ b/mysql-test/t/user_var.test	2010-08-13 11:18:46 +0000
@@ -328,4 +328,22 @@ INSERT INTO t1 VALUES (1);
 INSERT INTO t1 VALUES (1);
 DROP TABLE t1;
 
+#
+# Bug #55615: debug assertion after using variable in assignment and
+# referred to
+# Bug #55564: crash with user variables, assignments, joins...
+#
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0),(0);
+--echo # BUG#55615 : should not crash
+SELECT (@a:=(SELECT @a:=1 FROM t1 LIMIT 1)) AND COUNT(1) FROM t1 GROUP BY @a;
+--echo # BUG#55564 : should not crash
+SELECT IF(
+  @v:=LEAST((SELECT 1 FROM t1 t2 LEFT JOIN t1 ON (@v) GROUP BY t1.a), a),
+  count(*), 1) 
+FROM t1 GROUP BY a LIMIT 1;
+
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysys/my_getopt.c'
--- a/mysys/my_getopt.c	2010-07-02 18:30:47 +0000
+++ b/mysys/my_getopt.c	2010-08-04 12:58:09 +0000
@@ -656,17 +656,21 @@ static int setval(const struct my_option
 	return EXIT_OUT_OF_MEMORY;
       break;
     case GET_ENUM:
-      if (((*(int*)result_pos)=
-             find_type(argument, opts->typelib, 2) - 1) < 0)
       {
-        /*
-          Accept an integer representation of the enumerated item.
-        */
-        char *endptr;
-        unsigned int arg= (unsigned int) strtol(argument, &endptr, 10);
-        if (*endptr || arg >= opts->typelib->count)
-          return EXIT_ARGUMENT_INVALID;
-        *(int*)result_pos= arg;
+        int type= find_type(argument, opts->typelib, 2);
+        if (type < 1)
+        {
+          /*
+            Accept an integer representation of the enumerated item.
+          */
+          char *endptr;
+          ulong arg= strtoul(argument, &endptr, 10);
+          if (*endptr || arg >= opts->typelib->count)
+            return EXIT_ARGUMENT_INVALID;
+          *((ulong*) result_pos)= arg;
+        }
+        else
+          *((ulong*) result_pos)= type - 1;
       }
       break;
     case GET_SET:
@@ -1004,7 +1008,7 @@ static void init_one_value(const struct
     *((int*) variable)= (int) getopt_ll_limit_value((int) value, option, NULL);
     break;
   case GET_ENUM:
-    *((uint*) variable)= (uint) value;
+    *((ulong*) variable)= (ulong) value;
     break;
   case GET_UINT:
     *((uint*) variable)= (uint) getopt_ull_limit_value((uint) value, option, NULL);
@@ -1244,7 +1248,7 @@ void my_print_variables(const struct my_
 	}
 	break;
       case GET_ENUM:
-        printf("%s\n", get_type(optp->typelib, *(uint*) value));
+        printf("%s\n", get_type(optp->typelib, *(ulong*) value));
 	break;
       case GET_STR:
       case GET_STR_ALLOC:                    /* fall through */

=== modified file 'scripts/make_win_bin_dist'
--- a/scripts/make_win_bin_dist	2009-11-17 16:53:45 +0000
+++ b/scripts/make_win_bin_dist	2010-08-24 13:48:45 +0000
@@ -263,6 +263,7 @@ cp include/mysql.h \
    include/keycache.h \
    include/m_ctype.h \
    include/my_attribute.h \
+   include/my_compiler.h \
    include/mysqld_error.h \
    include/sql_state.h \
    include/mysqld_ername.h \

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2010-07-20 18:07:36 +0000
+++ b/sql/field.cc	2010-09-07 09:37:46 +0000
@@ -1535,7 +1535,7 @@ void Field::make_field(Send_field *field
   }
   else
     field->org_table_name= field->db_name= "";
-  if (orig_table)
+  if (orig_table && orig_table->alias)
   {
     field->table_name= orig_table->alias;
     field->org_col_name= field_name;
@@ -4561,7 +4561,7 @@ String *Field_double::val_str(String *va
 #endif
     doubleget(nr,ptr);
 
-  uint to_length=max(field_length, DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE);
+  uint to_length= DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE;
   val_buffer->alloc(to_length);
   char *to=(char*) val_buffer->ptr();
 

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2010-07-08 23:09:31 +0000
+++ b/sql/ha_partition.cc	2010-08-19 07:20:17 +0000
@@ -2403,9 +2403,14 @@ bool ha_partition::get_from_handler_file
   tot_partition_words= (m_tot_parts + 3) / 4;
   engine_array= (handlerton **) my_alloca(m_tot_parts * sizeof(handlerton*));
   for (i= 0; i < m_tot_parts; i++)
+  {
     engine_array[i]= ha_resolve_by_legacy_type(ha_thd(),
                                                (enum legacy_db_type)
-                                               *(uchar *) ((file_buffer) + 12 + i));
+                                               *(uchar *) ((file_buffer) +
+                                                           12 + i));
+    if (!engine_array[i])
+      goto err3;
+  }
   address_tot_name_len= file_buffer + 12 + 4 * tot_partition_words;
   tot_name_words= (uint4korr(address_tot_name_len) + 3) / 4;
   if (len_words != (tot_partition_words + tot_name_words + 4))

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2010-06-24 11:26:14 +0000
+++ b/sql/item_cmpfunc.cc	2010-08-05 10:42:14 +0000
@@ -4606,7 +4606,7 @@ bool Item_func_like::fix_fields(THD *thd
     return TRUE;
   }
   
-  if (escape_item->const_item())
+  if (escape_item->const_item() && !thd->lex->view_prepare_mode)
   {
     /* If we are on execution stage */
     String *escape_str= escape_item->val_str(&cmp.value1);

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2010-08-01 18:12:36 +0000
+++ b/sql/item_func.cc	2010-08-20 08:52:16 +0000
@@ -2263,7 +2263,7 @@ void Item_func_min_max::fix_length_and_d
     stored to the value pointer, if latter is provided.
 
   RETURN
-   0	If one of arguments is NULL
+   0	If one of arguments is NULL or there was a execution error
    #	index of the least/greatest argument
 */
 
@@ -2277,6 +2277,14 @@ uint Item_func_min_max::cmp_datetimes(ul
     Item **arg= args + i;
     bool is_null;
     longlong res= get_datetime_value(thd, &arg, 0, datetime_item, &is_null);
+
+    /* Check if we need to stop (because of error or KILL)  and stop the loop */
+    if (thd->is_error())
+    {
+      null_value= 1;
+      return 0;
+    }
+
     if ((null_value= args[i]->null_value))
       return 0;
     if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
@@ -2305,6 +2313,12 @@ String *Item_func_min_max::val_str(Strin
     if (null_value)
       return 0;
     str_res= args[min_max_idx]->val_str(str);
+    if (args[min_max_idx]->null_value)
+    {
+      // check if the call to val_str() above returns a NULL value
+      null_value= 1;
+      return NULL;
+    }
     str_res->set_charset(collation.collation);
     return str_res;
   }
@@ -4263,6 +4277,14 @@ longlong Item_func_set_user_var::val_int
   return entry->val_int(&null_value);
 }
 
+bool Item_func_set_user_var::val_bool_result()
+{
+  DBUG_ASSERT(fixed == 1);
+  check(TRUE);
+  update();					// Store expression
+  return entry->val_int(&null_value) != 0;
+}
+
 String *Item_func_set_user_var::str_result(String *str)
 {
   DBUG_ASSERT(fixed == 1);

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2010-01-13 10:28:42 +0000
+++ b/sql/item_func.h	2010-08-13 11:18:46 +0000
@@ -1353,6 +1353,7 @@ public:
   my_decimal *val_decimal(my_decimal *);
   double val_result();
   longlong val_int_result();
+  bool val_bool_result();
   String *str_result(String *str);
   my_decimal *val_decimal_result(my_decimal *);
   bool is_null_result();

=== modified file 'sql/item_geofunc.h'
--- a/sql/item_geofunc.h	2008-02-22 10:30:33 +0000
+++ b/sql/item_geofunc.h	2010-09-09 09:40:17 +0000
@@ -175,6 +175,21 @@ public:
     item_type=it;
   }
   String *val_str(String *);
+  void fix_length_and_dec()
+  {
+    for (unsigned int i= 0; i < arg_count; ++i)
+    {
+      if (args[i]->fixed && args[i]->field_type() != MYSQL_TYPE_GEOMETRY)
+      {
+        String str;
+        args[i]->print(&str, QT_ORDINARY);
+        str.append('\0');
+        my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "non geometric",
+                 str.ptr());
+      }
+    }
+  }
+ 
   const char *func_name() const { return "multipoint"; }
 };
 

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2010-07-23 11:52:54 +0000
+++ b/sql/item_sum.cc	2010-08-27 09:44:35 +0000
@@ -417,26 +417,6 @@ void Item_sum::mark_as_sum_func()
 }
 
 
-void Item_sum::make_field(Send_field *tmp_field)
-{
-  if (args[0]->type() == Item::FIELD_ITEM && keep_field_type())
-  {
-    ((Item_field*) args[0])->field->make_field(tmp_field);
-    /* For expressions only col_name should be non-empty string. */
-    char *empty_string= (char*)"";
-    tmp_field->db_name= empty_string;
-    tmp_field->org_table_name= empty_string;
-    tmp_field->table_name= empty_string;
-    tmp_field->org_col_name= empty_string;
-    tmp_field->col_name= name;
-    if (maybe_null)
-      tmp_field->flags&= ~NOT_NULL_FLAG;
-  }
-  else
-    init_make_field(tmp_field, field_type());
-}
-
-
 void Item_sum::print(String *str, enum_query_type query_type)
 {
   /* orig_args is not filled with valid values until fix_fields() */
@@ -2556,7 +2536,8 @@ bool Item_sum_count_distinct::add()
   if (always_null)
     return 0;
   copy_fields(tmp_table_param);
-  copy_funcs(tmp_table_param->items_to_copy);
+  if (copy_funcs(tmp_table_param->items_to_copy, table->in_use))
+    return TRUE;
 
   for (Field **field=table->field ; *field ; field++)
     if ((*field)->is_real_null(0))
@@ -3145,7 +3126,8 @@ bool Item_func_group_concat::add()
   if (always_null)
     return 0;
   copy_fields(tmp_table_param);
-  copy_funcs(tmp_table_param->items_to_copy);
+  if (copy_funcs(tmp_table_param->items_to_copy, table->in_use))
+    return TRUE;
 
   for (uint i= 0; i < arg_count_field; i++)
   {

=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h	2010-06-10 20:45:22 +0000
+++ b/sql/item_sum.h	2010-08-27 09:44:35 +0000
@@ -339,7 +339,6 @@ public:
     forced_const= TRUE; 
   }
   virtual bool const_item() const { return forced_const; }
-  void make_field(Send_field *field);
   virtual void print(String *str, enum_query_type query_type);
   void fix_num_length_and_dec();
 

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2009-12-13 20:29:50 +0000
+++ b/sql/item_timefunc.h	2010-08-13 13:05:46 +0000
@@ -881,6 +881,8 @@ public:
   { 
     decimals=0;
     max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
+    /* It returns NULL when the second argument is less or equal to 0 */
+    maybe_null= 1;
   }
   longlong val_int();
 };

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2010-08-02 19:48:56 +0000
+++ b/sql/log.cc	2010-08-25 08:47:45 +0000
@@ -5063,70 +5063,93 @@ void sql_perror(const char *message)
 }
 
 
+#ifdef __WIN__
+extern "C" my_bool reopen_fstreams(const char *filename,
+                                   FILE *outstream, FILE *errstream)
+{
+  int handle_fd;
+  int stream_fd;
+  HANDLE osfh;
+
+  DBUG_ASSERT(filename && (outstream || errstream));
+
+  if ((osfh= CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
+                        FILE_SHARE_READ | FILE_SHARE_WRITE |
+                        FILE_SHARE_DELETE, NULL,
+                        OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
+                        NULL)) == INVALID_HANDLE_VALUE)
+    return TRUE;
+
+  if ((handle_fd= _open_osfhandle((intptr_t)osfh,
+                                  _O_APPEND | _O_TEXT)) == -1)
+  {
+    CloseHandle(osfh);
+    return TRUE;
+  }
+
+  if (outstream)
+  {
+    stream_fd= _fileno(outstream);
+    if (_dup2(handle_fd, stream_fd) < 0)
+    {
+      CloseHandle(osfh);
+      return TRUE;
+    }
+  }
+
+  if (errstream)
+  {
+    stream_fd= _fileno(errstream);
+    if (_dup2(handle_fd, stream_fd) < 0)
+    {
+      CloseHandle(osfh);
+      return TRUE;
+    }
+  }
+
+  _close(handle_fd);
+  return FALSE;
+}
+#else
+extern "C" my_bool reopen_fstreams(const char *filename,
+                                   FILE *outstream, FILE *errstream)
+{
+  if (outstream && !freopen(filename, "a+", outstream))
+    return TRUE;
+
+  if (errstream && !freopen(filename, "a+", errstream))
+    return TRUE;
+
+  return FALSE;
+}
+#endif
+
+
 /*
   Unfortunately, there seems to be no good way
   to restore the original streams upon failure.
 */
 static bool redirect_std_streams(const char *file)
 {
-  if (freopen(file, "a+", stdout) && freopen(file, "a+", stderr))
-  {
-    setbuf(stderr, NULL);
-    return FALSE;
-  }
+  if (reopen_fstreams(file, stdout, stderr))
+    return TRUE;
 
-  return TRUE;
+  setbuf(stderr, NULL);
+  return FALSE;
 }
 
 
 bool flush_error_log()
 {
-  bool result=0;
+  bool result= 0;
   if (opt_error_log)
   {
-    char err_renamed[FN_REFLEN], *end;
-    end= strmake(err_renamed,log_error_file,FN_REFLEN-5);
-    strmov(end, "-old");
     VOID(pthread_mutex_lock(&LOCK_error_log));
-#ifdef __WIN__
-    char err_temp[FN_REFLEN+5];
-    /*
-     On Windows is necessary a temporary file for to rename
-     the current error file.
-    */
-    strxmov(err_temp, err_renamed,"-tmp",NullS);
-    (void) my_delete(err_temp, MYF(0)); 
-    if (freopen(err_temp,"a+",stdout))
-    {
-      int fd;
-      size_t bytes;
-      uchar buf[IO_SIZE];
-
-      freopen(err_temp,"a+",stderr);
-      setbuf(stderr, NULL);
-      (void) my_delete(err_renamed, MYF(0));
-      my_rename(log_error_file,err_renamed,MYF(0));
-      redirect_std_streams(log_error_file);
-
-      if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0)
-      {
-        while ((bytes= my_read(fd, buf, IO_SIZE, MYF(0))) &&
-               bytes != MY_FILE_ERROR)
-          my_fwrite(stderr, buf, bytes, MYF(0));
-        my_close(fd, MYF(0));
-      }
-      (void) my_delete(err_temp, MYF(0)); 
-    }
-    else
-     result= 1;
-#else
-   my_rename(log_error_file,err_renamed,MYF(0));
-   if (redirect_std_streams(log_error_file))
-     result= 1;
-#endif
+    if (redirect_std_streams(log_error_file))
+      result= 1;
     VOID(pthread_mutex_unlock(&LOCK_error_log));
   }
-   return result;
+  return result;
 }
 
 void MYSQL_BIN_LOG::signal_update()

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2010-07-21 10:14:11 +0000
+++ b/sql/mysqld.cc	2010-08-25 08:47:45 +0000
@@ -199,6 +199,9 @@ typedef fp_except fp_except_t;
 # endif
 #endif
 
+extern "C" my_bool reopen_fstreams(const char *filename,
+                                   FILE *outstream, FILE *errstream);
+
 inline void setup_fpu()
 {
 #if defined(__FreeBSD__) && defined(HAVE_IEEEFP_H)
@@ -3821,13 +3824,15 @@ static int init_server_components()
       opt_error_log= 1;				// Too long file name
     else
     {
+      my_bool res;
 #ifndef EMBEDDED_LIBRARY
-      if (freopen(log_error_file, "a+", stdout))
+      res= reopen_fstreams(log_error_file, stdout, stderr);
+#else
+      res= reopen_fstreams(log_error_file, NULL, stderr);
 #endif
-      {
-        if (freopen(log_error_file, "a+", stderr))
-          setbuf(stderr, NULL);
-      }
+
+      if (!res)
+        setbuf(stderr, NULL);
     }
   }
 
@@ -4475,8 +4480,8 @@ we force server id to 2, but this MySQL
 #ifdef __WIN__
   if (!opt_console)
   {
-    freopen(log_error_file,"a+",stdout);
-    freopen(log_error_file,"a+",stderr);
+    if (reopen_fstreams(log_error_file, stdout, stderr))
+      unireg_abort(1);
     setbuf(stderr, NULL);
     FreeConsole();				// Remove window
   }

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-07-15 13:01:44 +0000
+++ b/sql/opt_range.cc	2010-08-24 15:51:32 +0000
@@ -5526,7 +5526,11 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_P
         SEL_TREE *tmp= get_full_func_mm_tree(param, cond_func, 
                                     field_item, (Item*)(intptr)i, inv);
         if (inv)
+        {
           tree= !tree ? tmp : tree_or(param, tree, tmp);
+          if (tree == NULL)
+            break;
+        }
         else 
           tree= tree_and(param, tree, tmp);
       }

=== modified file 'sql/spatial.cc'
--- a/sql/spatial.cc	2010-07-20 18:07:36 +0000
+++ b/sql/spatial.cc	2010-08-30 07:51:46 +0000
@@ -528,7 +528,7 @@ uint Gis_line_string::init_from_wkb(cons
   n_points= wkb_get_uint(wkb, bo);
   proper_length= 4 + n_points * POINT_DATA_SIZE;
 
-  if (len < proper_length || res->reserve(proper_length))
+  if (!n_points || len < proper_length || res->reserve(proper_length))
     return 0;
 
   res->q_append(n_points);
@@ -746,7 +746,9 @@ uint Gis_polygon::init_from_wkb(const ch
   if (len < 4)
     return 0;
 
-  n_linear_rings= wkb_get_uint(wkb, bo);
+  if (!(n_linear_rings= wkb_get_uint(wkb, bo)))
+    return 0;
+
   if (res->reserve(4, 512))
     return 0;
   wkb+= 4;

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2010-07-14 08:50:17 +0000
+++ b/sql/sql_class.h	2010-08-18 04:56:06 +0000
@@ -2622,7 +2622,9 @@ public:
 
 
 class select_insert :public select_result_interceptor {
- public:
+protected:
+  virtual int write_to_binlog(bool is_trans, int errcode);
+public:
   TABLE_LIST *table_list;
   TABLE *table;
   List<Item> *fields;
@@ -2658,6 +2660,8 @@ class select_create: public select_inser
   MYSQL_LOCK *m_lock;
   /* m_lock or thd->extra_lock */
   MYSQL_LOCK **m_plock;
+
+  virtual int write_to_binlog(bool is_trans, int errcode);
 public:
   select_create (TABLE_LIST *table_arg,
 		 HA_CREATE_INFO *create_info_par,
@@ -2673,7 +2677,7 @@ public:
     {}
   int prepare(List<Item> &list, SELECT_LEX_UNIT *u);
 
-  int binlog_show_create_table(TABLE **tables, uint count);
+  int binlog_show_create_table(TABLE **tables, uint count, int errcode);
   void store_values(List<Item> &values);
   void send_error(uint errcode,const char *err);
   bool send_eof();

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2010-08-02 19:48:56 +0000
+++ b/sql/sql_insert.cc	2010-08-20 09:09:17 +0000
@@ -2961,6 +2961,9 @@ select_insert::prepare(List<Item> &value
     we are fixing fields from insert list.
   */
   lex->current_select= &lex->select_lex;
+
+  /* Errors during check_insert_fields() should not be ignored. */
+  lex->current_select->no_error= FALSE;
   res= check_insert_fields(thd, table_list, *fields, values,
                            !insert_into_view, &map) ||
        setup_fields(thd, 0, values, MARK_COLUMNS_READ, 0, 0);
@@ -3265,7 +3268,7 @@ bool select_insert::send_eof()
 
   /*
     Write to binlog before commiting transaction.  No statement will
-    be written by the binlog_query() below in RBR mode.  All the
+    be written by the write_to_binlog() below in RBR mode.  All the
     events are in the transaction cache and will be written when
     ha_autocommit_or_rollback() is issued below.
   */
@@ -3277,9 +3280,8 @@ bool select_insert::send_eof()
       thd->clear_error();
     else
       errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
-    if (thd->binlog_query(THD::ROW_QUERY_TYPE,
-                      thd->query(), thd->query_length(),
-                      trans_table, FALSE, errcode))
+
+    if (write_to_binlog(trans_table, errcode))
     {
       table->file->ha_release_auto_increment();
       DBUG_RETURN(1);
@@ -3353,9 +3355,7 @@ void select_insert::abort() {
         {
           int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
           /* error of writing binary log is ignored */
-          (void) thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query(),
-                                   thd->query_length(),
-                                   transactional_table, FALSE, errcode);
+          write_to_binlog(transactional_table, errcode);
         }
         if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
           thd->transaction.all.modified_non_trans_table= TRUE;
@@ -3370,6 +3370,103 @@ void select_insert::abort() {
   DBUG_VOID_RETURN;
 }
 
+int select_insert::write_to_binlog(bool is_trans, int errcode)
+{
+  /* It is only for statement mode */
+  if (thd->current_stmt_binlog_row_based)
+    return 0;
+
+  return thd->binlog_query(THD::ROW_QUERY_TYPE,
+                           thd->query(), thd->query_length(),
+                           is_trans, FALSE, errcode);
+}
+
+/* Override the select_insert::write_to_binlog */
+int select_create::write_to_binlog(bool is_trans, int errcode)
+{
+  /* It is only for statement mode */
+  if (thd->current_stmt_binlog_row_based)
+    return 0;
+
+  /*
+    WL#5370 Keep the compatibility between 5.1 master and 5.5 slave.
+    Binlog a 'INSERT ... SELECT' statement only when it has the option
+    'IF NOT EXISTS' and the table already exists as a base table.
+  */
+  if ((create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS) &&
+      create_info->table_existed)
+  {
+    String query;
+    int result;
+
+    thd->binlog_start_trans_and_stmt();
+    /* Binlog the CREATE TABLE IF NOT EXISTS statement */
+    result= binlog_show_create_table(&table, 1, 0);
+    if (result)
+      return result;
+
+    uint db_len= strlen(create_table->db);
+    uint table_len= strlen(create_info->alias);
+    uint select_len= thd->query_length() - thd->lex->create_select_pos;
+    uint field_len= (table->s->fields - (field - table->field)) *
+      (MAX_FIELD_NAME + 3);
+
+    /*
+      pre-allocating memory reduces the times of reallocating memory,
+      when calling query.appen().
+      40bytes is enough for other words("INSERT IGNORE INTO", etc.).
+     */
+    if (query.real_alloc(40 + db_len + table_len + field_len + select_len))
+      return 1;
+
+    if (thd->lex->create_select_in_comment)
+      query.append(STRING_WITH_LEN("/*! "));
+    if (thd->lex->ignore)
+      query.append(STRING_WITH_LEN("INSERT IGNORE INTO `"));
+    else if (thd->lex->duplicates == DUP_REPLACE)
+      query.append(STRING_WITH_LEN("REPLACE INTO `"));
+    else
+      query.append(STRING_WITH_LEN("INSERT INTO `"));
+
+    query.append(create_table->db, db_len);
+    query.append(STRING_WITH_LEN("`.`"));
+    query.append(create_info->alias, table_len);
+    query.append(STRING_WITH_LEN("` "));
+
+    /*
+      The insert items.
+      Field is the the rightmost columns that the rows are inster in.
+    */
+    query.append(STRING_WITH_LEN("("));
+    for (Field **f= field ; *f ; f++)
+    {
+      if (f != field)
+        query.append(STRING_WITH_LEN(","));
+
+      query.append(STRING_WITH_LEN("`"));
+      query.append((*f)->field_name, strlen((*f)->field_name));
+      query.append(STRING_WITH_LEN("`"));
+    }
+    query.append(STRING_WITH_LEN(") "));
+
+    /* The SELECT clause*/
+    DBUG_ASSERT(thd->lex->create_select_pos);
+    if (thd->lex->create_select_start_with_brace)
+      query.append(STRING_WITH_LEN("("));
+    if (query.append(thd->query() + thd->lex->create_select_pos, select_len))
+      return 1;
+
+    /*
+      Avoid to use thd->binlog_query() twice, otherwise it will print the unsafe
+      warning twice.
+    */
+    Query_log_event ev(thd, query.c_ptr_safe(), query.length(), is_trans,
+                       FALSE, errcode);
+    return mysql_bin_log.write(&ev);
+  }
+  else
+    return select_insert::write_to_binlog(is_trans, errcode);
+}
 
 /***************************************************************************
   CREATE TABLE (SELECT) ...
@@ -3610,7 +3707,8 @@ select_create::prepare(List<Item> &value
           !table->s->tmp_table &&
           !ptr->get_create_info()->table_existed)
       {
-        if (int error= ptr->binlog_show_create_table(tables, count))
+        int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
+        if (int error= ptr->binlog_show_create_table(tables, count, errcode))
           return error;
       }
       return 0;
@@ -3651,7 +3749,10 @@ select_create::prepare(List<Item> &value
                           ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
                           create_table->table_name);
       if (thd->current_stmt_binlog_row_based)
-        binlog_show_create_table(&(create_table->table), 1);
+      {
+        int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
+        binlog_show_create_table(&(create_table->table), 1, errcode);
+      }
       table= create_table->table;
     }
     else
@@ -3719,10 +3820,10 @@ select_create::prepare(List<Item> &value
 }
 
 int
-select_create::binlog_show_create_table(TABLE **tables, uint count)
+select_create::binlog_show_create_table(TABLE **tables, uint count, int errcode)
 {
   /*
-    Note 1: In RBR mode, we generate a CREATE TABLE statement for the
+    Note 1: We generate a CREATE TABLE statement for the
     created table by calling store_create_info() (behaves as SHOW
     CREATE TABLE).  In the event of an error, nothing should be
     written to the binary log, even if the table is non-transactional;
@@ -3738,7 +3839,6 @@ select_create::binlog_show_create_table(
     schema that will do a close_thread_tables(), destroying the
     statement transaction cache.
   */
-  DBUG_ASSERT(thd->current_stmt_binlog_row_based);
   DBUG_ASSERT(tables && *tables && count > 0);
 
   char buf[2048];
@@ -3756,7 +3856,6 @@ select_create::binlog_show_create_table(
 
   if (mysql_bin_log.is_open())
   {
-    int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
     result= thd->binlog_query(THD::STMT_QUERY_TYPE,
                               query.ptr(), query.length(),
                               /* is_trans */ TRUE,

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2010-07-29 03:00:57 +0000
+++ b/sql/sql_lex.h	2010-08-18 04:56:06 +0000
@@ -1817,6 +1817,23 @@ typedef struct st_lex : public Query_tab
   */
   bool protect_against_global_read_lock;
 
+  /*
+    The following three variables are used in 'CREATE TABLE IF NOT EXISTS ...
+    SELECT' statement. They are used to binlog the statement.
+
+    create_select_start_with_brace will be set if there is a '(' before
+    the first SELECT clause
+
+    create_select_pos records the relative position of the SELECT clause
+    in the whole statement.
+
+    create_select_in_comment will be set if SELECT keyword is in conditional
+    comment.
+   */
+  bool create_select_start_with_brace;
+  uint create_select_pos;
+  bool create_select_in_comment;
+
   st_lex();
 
   virtual ~st_lex()

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2010-07-30 13:44:39 +0000
+++ b/sql/sql_load.cc	2010-08-03 02:22:19 +0000
@@ -141,6 +141,14 @@ int mysql_load(THD *thd,sql_exchange *ex
   bool transactional_table;
   DBUG_ENTER("mysql_load");
 
+  /*
+    Bug #34283
+    mysqlbinlog leaves tmpfile after termination if binlog contains
+    load data infile, so in mixed mode we go to row-based for
+    avoiding the problem.
+  */
+  thd->set_current_stmt_binlog_row_based_if_mixed();
+
 #ifdef EMBEDDED_LIBRARY
   read_file_from_client  = 0; //server is always in the same process 
 #endif

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2010-07-29 03:00:57 +0000
+++ b/sql/sql_parse.cc	2010-08-18 04:56:06 +0000
@@ -2717,6 +2717,25 @@ mysql_execute_command(THD *thd)
         {
           TABLE_LIST *duplicate;
           create_table= lex->unlink_first_table(&link_to_local);
+
+          if (create_table->view)
+          {
+            if (create_info.options & HA_LEX_CREATE_IF_NOT_EXISTS)
+            {
+              push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+                                  ER_TABLE_EXISTS_ERROR,
+                                  ER(ER_TABLE_EXISTS_ERROR),
+                                  create_info.alias);
+              my_ok(thd);
+            }
+            else
+            {
+              my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_info.alias);
+              res= 1;
+            }
+            goto end_with_restore_list;
+          }
+
           if ((duplicate= unique_table(thd, create_table, select_tables, 0)))
           {
             update_non_unique_table_error(create_table, "CREATE", duplicate);

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2010-06-10 20:16:43 +0000
+++ b/sql/sql_plugin.cc	2010-08-05 12:10:24 +0000
@@ -3030,12 +3030,12 @@ static int construct_options(MEM_ROOT *m
     Allocate temporary space for the value of the tristate.
     This option will have a limited lifetime and is not used beyond
     server initialization.
-    GET_ENUM value is an integer.
+    GET_ENUM value is a unsigned long integer.
   */
   options[0].value= options[1].value= (uchar **)alloc_root(mem_root,
-                                                          sizeof(int));
-  *((uint*) options[0].value)= *((uint*) options[1].value)=
-    (uint) options[0].def_value;
+                                                          sizeof(ulong));
+  *((ulong*) options[0].value)= *((ulong*) options[1].value)=
+    (ulong) options[0].def_value;
 
   options+= 2;
 
@@ -3319,7 +3319,7 @@ static int test_plugin_options(MEM_ROOT
      Set plugin loading policy from option value. First element in the option
      list is always the <plugin name> option value.
     */
-    plugin_load_policy= (enum_plugin_load_policy)*(uint*)opts[0].value;
+    plugin_load_policy= (enum_plugin_load_policy)*(ulong*)opts[0].value;
   }
 
   disable_plugin= (plugin_load_policy == PLUGIN_OFF);

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-07-19 18:34:28 +0000
+++ b/sql/sql_select.cc	2010-09-02 00:43:02 +0000
@@ -2378,13 +2378,8 @@ JOIN::destroy()
 
   cleanup(1);
  /* Cleanup items referencing temporary table columns */
-  if (!tmp_all_fields3.is_empty())
-  {
-    List_iterator_fast<Item> it(tmp_all_fields3);
-    Item *item;
-    while ((item= it++))
-      item->cleanup();
-  }
+  cleanup_item_list(tmp_all_fields1);
+  cleanup_item_list(tmp_all_fields3);
   if (exec_tmp_table1)
     free_tmp_table(thd, exec_tmp_table1);
   if (exec_tmp_table2)
@@ -2395,6 +2390,19 @@ JOIN::destroy()
   DBUG_RETURN(error);
 }
 
+
+void JOIN::cleanup_item_list(List<Item> &items) const
+{
+  if (!items.is_empty())
+  {
+    List_iterator_fast<Item> it(items);
+    Item *item;
+    while ((item= it++))
+      item->cleanup();
+  }
+}
+
+
 /**
   An entry point to single-unit select (a select without UNION).
 
@@ -6819,6 +6827,8 @@ bool error_if_full_join(JOIN *join)
   {
     if (tab->type == JT_ALL && (!tab->select || !tab->select->quick))
     {
+      /* This error should not be ignored. */
+      join->select_lex->no_error= FALSE;
       my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
                  ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
       return(1);
@@ -8875,10 +8885,10 @@ simplify_joins(JOIN *join, List<TABLE_LI
     
   /* Flatten nested joins that can be flattened. */
   TABLE_LIST *right_neighbor= NULL;
-  bool fix_name_res= FALSE;
   li.rewind();
   while ((table= li++))
   {
+    bool fix_name_res= FALSE;
     nested_join= table->nested_join;
     if (nested_join && !table->on_expr)
     {
@@ -12485,7 +12495,9 @@ end_write(JOIN *join, JOIN_TAB *join_tab
   if (!end_of_records)
   {
     copy_fields(&join->tmp_table_param);
-    copy_funcs(join->tmp_table_param.items_to_copy);
+    if (copy_funcs(join->tmp_table_param.items_to_copy, join->thd))
+      DBUG_RETURN(NESTED_LOOP_ERROR);           /* purecov: inspected */
+
 #ifdef TO_BE_DELETED
     if (!table->uniques)			// If not unique handling
     {
@@ -12591,7 +12603,8 @@ end_update(JOIN *join, JOIN_TAB *join_ta
       memcpy(table->record[0]+key_part->offset, group->buff, 1);
   }
   init_tmptable_sum_functions(join->sum_funcs);
-  copy_funcs(join->tmp_table_param.items_to_copy);
+  if (copy_funcs(join->tmp_table_param.items_to_copy, join->thd))
+    DBUG_RETURN(NESTED_LOOP_ERROR);           /* purecov: inspected */
   if ((error=table->file->ha_write_row(table->record[0])))
   {
     if (create_myisam_from_heap(join->thd, table, &join->tmp_table_param,
@@ -12626,7 +12639,8 @@ end_unique_update(JOIN *join, JOIN_TAB *
 
   init_tmptable_sum_functions(join->sum_funcs);
   copy_fields(&join->tmp_table_param);		// Groups are copied twice.
-  copy_funcs(join->tmp_table_param.items_to_copy);
+  if (copy_funcs(join->tmp_table_param.items_to_copy, join->thd))
+    DBUG_RETURN(NESTED_LOOP_ERROR);           /* purecov: inspected */
 
   if (!(error=table->file->ha_write_row(table->record[0])))
     join->send_records++;			// New group
@@ -12713,7 +12727,8 @@ end_write_group(JOIN *join, JOIN_TAB *jo
     if (idx < (int) join->send_group_parts)
     {
       copy_fields(&join->tmp_table_param);
-      copy_funcs(join->tmp_table_param.items_to_copy);
+      if (copy_funcs(join->tmp_table_param.items_to_copy, join->thd))
+	DBUG_RETURN(NESTED_LOOP_ERROR);
       if (init_sum_functions(join->sum_funcs, join->sum_funcs_end[idx+1]))
 	DBUG_RETURN(NESTED_LOOP_ERROR);
       if (join->procedure)
@@ -13010,6 +13025,34 @@ static int test_if_order_by_key(ORDER *o
 }
 
 
+/**
+  Find shortest key suitable for full table scan.
+
+  @param table                 Table to scan
+  @param usable_keys           Allowed keys
+
+  @note
+     As far as 
+     1) clustered primary key entry data set is a set of all record
+        fields (key fields and not key fields) and
+     2) secondary index entry data is a union of its key fields and
+        primary key fields (at least InnoDB and its derivatives don't
+        duplicate primary key fields there, even if the primary and
+        the secondary keys have a common subset of key fields),
+     then secondary index entry data is always a subset of primary key entry.
+     Unfortunately, key_info[nr].key_length doesn't show the length
+     of key/pointer pair but a sum of key field lengths only, thus
+     we can't estimate index IO volume comparing only this key_length
+     value of secondary keys and clustered PK.
+     So, try secondary keys first, and choose PK only if there are no
+     usable secondary covering keys or found best secondary key include
+     all table fields (i.e. same as PK):
+
+  @return
+    MAX_KEY     no suitable key found
+    key index   otherwise
+*/
+
 uint find_shortest_key(TABLE *table, const key_map *usable_keys)
 {
   uint best= MAX_KEY;
@@ -13022,23 +13065,6 @@ uint find_shortest_key(TABLE *table, con
     uint min_length= (uint) ~0;
     for (uint nr=0; nr < table->s->keys ; nr++)
     {
-      /*
-       As far as 
-       1) clustered primary key entry data set is a set of all record
-          fields (key fields and not key fields) and
-       2) secondary index entry data is a union of its key fields and
-          primary key fields (at least InnoDB and its derivatives don't
-          duplicate primary key fields there, even if the primary and
-          the secondary keys have a common subset of key fields),
-       then secondary index entry data is always a subset of primary key
-       entry, and the PK is always longer.
-       Unfortunately, key_info[nr].key_length doesn't show the length
-       of key/pointer pair but a sum of key field lengths only, thus
-       we can't estimate index IO volume comparing only this key_length
-       value of seconday keys and clustered PK.
-       So, try secondary keys first, and choose PK only if there are no
-       usable secondary covering keys:
-      */
       if (nr == usable_clustered_pk)
         continue;
       if (usable_keys->is_set(nr))
@@ -13051,7 +13077,20 @@ uint find_shortest_key(TABLE *table, con
       }
     }
   }
-  return best != MAX_KEY ? best : usable_clustered_pk;
+  if (usable_clustered_pk != MAX_KEY)
+  {
+    /*
+     If the primary key is clustered and found shorter key covers all table
+     fields then primary key scan normally would be faster because amount of
+     data to scan is the same but PK is clustered.
+     It's safe to compare key parts with table fields since duplicate key
+     parts aren't allowed.
+     */
+    if (best == MAX_KEY ||
+        table->key_info[best].key_parts >= table->s->fields)
+      best= usable_clustered_pk;
+  }
+  return best;
 }
 
 /**
@@ -15773,14 +15812,39 @@ update_sum_func(Item_sum **func_ptr)
   return 0;
 }
 
-/** Copy result of functions to record in tmp_table. */
+/** 
+  Copy result of functions to record in tmp_table. 
 
-void
-copy_funcs(Item **func_ptr)
+  Uses the thread pointer to check for errors in 
+  some of the val_xxx() methods called by the 
+  save_in_result_field() function.
+  TODO: make the Item::val_xxx() return error code
+
+  @param func_ptr  array of the function Items to copy to the tmp table
+  @param thd       pointer to the current thread for error checking
+  @retval
+    FALSE if OK
+  @retval
+    TRUE on error  
+*/
+
+bool
+copy_funcs(Item **func_ptr, const THD *thd)
 {
   Item *func;
   for (; (func = *func_ptr) ; func_ptr++)
+  {
     func->save_in_result_field(1);
+    /*
+      Need to check the THD error state because Item::val_xxx() don't
+      return error code, but can generate errors
+      TODO: change it for a real status check when Item::val_xxx()
+      are extended to return status code.
+    */  
+    if (thd->is_error())
+      return TRUE;
+  }
+  return FALSE;
 }
 
 

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2010-02-26 13:16:46 +0000
+++ b/sql/sql_select.h	2010-08-24 10:44:15 +0000
@@ -577,6 +577,7 @@ private:
   */
   bool implicit_grouping; 
   bool make_simple_join(JOIN *join, TABLE *tmp_table);
+  void cleanup_item_list(List<Item> &items) const;
 };
 
 
@@ -601,7 +602,7 @@ bool setup_copy_fields(THD *thd, TMP_TAB
 		       List<Item> &new_list1, List<Item> &new_list2,
 		       uint elements, List<Item> &fields);
 void copy_fields(TMP_TABLE_PARAM *param);
-void copy_funcs(Item **func_ptr);
+bool copy_funcs(Item **func_ptr, const THD *thd);
 bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
 			     int error, bool ignore_last_dupp_error);
 uint find_shortest_key(TABLE *table, const key_map *usable_keys);

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2010-07-22 16:17:26 +0000
+++ b/sql/sql_show.cc	2010-08-27 07:44:06 +0000
@@ -6930,13 +6930,16 @@ int finalize_schema_table(st_plugin_int
   ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
   DBUG_ENTER("finalize_schema_table");
 
-  if (schema_table && plugin->plugin->deinit)
+  if (schema_table)
   {
-    DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
-    if (plugin->plugin->deinit(NULL))
+    if (plugin->plugin->deinit)
     {
-      DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
-                             plugin->name.str));
+      DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
+      if (plugin->plugin->deinit(NULL))
+      {
+        DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
+                               plugin->name.str));
+      }
     }
     my_free(schema_table, MYF(0));
   }

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2009-07-31 17:14:52 +0000
+++ b/sql/sql_string.h	2010-08-06 19:29:37 +0000
@@ -97,7 +97,7 @@ public:
   inline uint32 alloced_length() const { return Alloced_length;}
   inline char& operator [] (uint32 i) const { return Ptr[i]; }
   inline void length(uint32 len) { str_length=len ; }
-  inline bool is_empty() { return (str_length == 0); }
+  inline bool is_empty() const { return (str_length == 0); }
   inline void mark_as_const() { Alloced_length= 0;}
   inline const char *ptr() const { return Ptr; }
   inline char *c_ptr()

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2010-07-19 09:03:52 +0000
+++ b/sql/sql_update.cc	2010-08-09 11:39:59 +0000
@@ -1199,56 +1199,6 @@ reopen_tables:
 }
 
 
-/**
-   Implementation of the safe update options during UPDATE IGNORE. This syntax
-   causes an UPDATE statement to ignore all errors. In safe update mode,
-   however, we must never ignore the ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE. There
-   is a special hook in my_message_sql that will otherwise delete all errors
-   when the IGNORE option is specified. 
-
-   In the future, all IGNORE handling should be used with this class and all
-   traces of the hack outlined below should be removed.
-
-   - The parser detects IGNORE option and sets thd->lex->ignore= 1
-   
-   - In JOIN::optimize, if this is set, then 
-     thd->lex->current_select->no_error gets set.
-
-   - In my_message_sql(), if the flag above is set then any error is
-     unconditionally converted to a warning.
-
-   We are moving in the direction of using Internal_error_handler subclasses
-   to do all such error tweaking, please continue this effort if new bugs
-   appear.
- */
-class Safe_dml_handler : public Internal_error_handler {
-
-private:
-  bool m_handled_error;
-
-public:
-  explicit Safe_dml_handler() : m_handled_error(FALSE) {}
-
-  bool handle_error(uint sql_errno,
-                    const char *message,
-                    MYSQL_ERROR::enum_warning_level level,
-                    THD *thd)
-  {
-    if (level == MYSQL_ERROR::WARN_LEVEL_ERROR &&
-        sql_errno == ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE)
-        
-    {      
-      thd->main_da.set_error_status(thd, sql_errno, message);
-      m_handled_error= TRUE;
-      return TRUE;
-    }
-    return FALSE;
-  }
-
-  bool handled_error() { return m_handled_error; }
-
-};
-
 /*
   Setup multi-update handling and call SELECT to do the join
 */
@@ -1278,11 +1228,6 @@ bool mysql_multi_update(THD *thd,
 
   List<Item> total_list;
 
-  Safe_dml_handler handler;
-  bool using_handler= thd->options & OPTION_SAFE_UPDATES;
-  if (using_handler)
-    thd->push_internal_handler(&handler);
-
   res= mysql_select(thd, &select_lex->ref_pointer_array,
                     table_list, select_lex->with_wild,
                     total_list,
@@ -1292,21 +1237,9 @@ bool mysql_multi_update(THD *thd,
                     OPTION_SETUP_TABLES_DONE,
                     result, unit, select_lex);
 
-  if (using_handler)
-  {
-    Internal_error_handler *top_handler;
-    top_handler= thd->pop_internal_handler();
-    DBUG_ASSERT(&handler == top_handler);
-  }
-
   DBUG_PRINT("info",("res: %d  report_error: %d", res, (int) thd->is_error()));
   res|= thd->is_error();
-  /*
-    Todo: remove below code and make Safe_dml_handler do error processing
-    instead. That way we can return the actual error instead of
-    ER_UNKNOWN_ERROR.
-  */
-  if (unlikely(res) && (!using_handler || !handler.handled_error()))
+  if (unlikely(res))
   {
     /* If we had a another error reported earlier then this will be ignored */
     result->send_error(ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR));

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2010-07-19 14:30:34 +0000
+++ b/sql/sql_yacc.yy	2010-08-30 22:16:38 +0000
@@ -1297,6 +1297,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
 
 %type <table>
         table_ident table_ident_nodb references xid
+        table_ident_opt_wild
 
 %type <simple_string>
         remember_name remember_end opt_ident opt_db text_or_password
@@ -3881,17 +3882,26 @@ create2a:
           create3 {}
         |  opt_partitioning
            create_select ')'
-           { Select->set_braces(1);}
+           {
+             Select->set_braces(1);
+             Lex->create_select_start_with_brace= TRUE;
+           }
            union_opt {}
         ;
 
 create3:
           /* empty */ {}
         | opt_duplicate opt_as create_select
-          { Select->set_braces(0);}
+          {
+            Select->set_braces(0);
+            Lex->create_select_start_with_brace= FALSE;
+          }
           union_clause {}
         | opt_duplicate opt_as '(' create_select ')'
-          { Select->set_braces(1);}
+          {
+            Select->set_braces(1);
+            Lex->create_select_start_with_brace= TRUE;
+          }
           union_opt {}
         ;
 
@@ -4516,6 +4526,19 @@ create_select:
             lex->current_select->table_list.save_and_clear(&lex->save_list);
             mysql_init_select(lex);
             lex->current_select->parsing_place= SELECT_LIST;
+
+            if (lex->sql_command == SQLCOM_CREATE_TABLE &&
+                (lex->create_info.options & HA_LEX_CREATE_IF_NOT_EXISTS))
+            {
+              Lex_input_stream *lip= YYLIP;
+
+              if (lex->spcont)
+                lex->create_select_pos= lip->get_tok_start() -
+                  lex->sphead->m_tmp_query;
+              else
+                lex->create_select_pos= lip->get_tok_start() - lip->get_buf();
+              lex->create_select_in_comment= (lip->in_comment == DISCARD_COMMENT);
+            }
           }
           select_options select_item_list
           {
@@ -9600,7 +9623,7 @@ table_alias_ref_list:
         ;
 
 table_alias_ref:
-          table_ident
+          table_ident_opt_wild
           {
             if (!Select->add_table_to_list(YYTHD, $1, NULL,
                                            TL_OPTION_UPDATING | TL_OPTION_ALIAS,
@@ -11381,6 +11404,21 @@ table_ident:
             if ($$ == NULL)
               MYSQL_YYABORT;
           }
+        ;
+
+table_ident_opt_wild:
+          ident opt_wild
+          {
+            $$= new Table_ident($1);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
+        | ident '.' ident opt_wild
+          {
+            $$= new Table_ident(YYTHD, $1,$3,0);
+            if ($$ == NULL)
+              MYSQL_YYABORT;
+          }
         ;
 
 table_ident_nodb:

=== modified file 'sql/tztime.cc'
--- a/sql/tztime.cc	2009-06-17 14:56:44 +0000
+++ b/sql/tztime.cc	2010-08-06 19:29:37 +0000
@@ -2259,7 +2259,7 @@ my_tz_find(THD *thd, const String *name)
   DBUG_PRINT("enter", ("time zone name='%s'",
                        name ? ((String *)name)->c_ptr_safe() : "NULL"));
 
-  if (!name)
+  if (!name || name->is_empty())
     DBUG_RETURN(0);
 
   VOID(pthread_mutex_lock(&tz_LOCK));

=== modified file 'storage/innobase/dict/dict0dict.c'
--- a/storage/innobase/dict/dict0dict.c	2010-06-25 08:18:41 +0000
+++ b/storage/innobase/dict/dict0dict.c	2010-08-23 10:28:54 +0000
@@ -616,8 +616,7 @@ dict_table_get_on_id(
 {
 	dict_table_t*	table;
 
-	if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0
-	    || trx->dict_operation_lock_mode == RW_X_LATCH) {
+	if (trx->dict_operation_lock_mode == RW_X_LATCH) {
 
 		/* Note: An X latch implies that the transaction
 		already owns the dictionary mutex. */
@@ -2140,7 +2139,7 @@ dict_foreign_add_to_cache(
 				mem_heap_free(foreign->heap);
 			}
 
-			return(DB_CANNOT_ADD_CONSTRAINT);
+			return(DB_FOREIGN_NO_INDEX);
 		}
 
 		for_in_cache->referenced_table = ref_table;
@@ -2184,7 +2183,7 @@ dict_foreign_add_to_cache(
 				mem_heap_free(foreign->heap);
 			}
 
-			return(DB_CANNOT_ADD_CONSTRAINT);
+			return(DB_REFERENCING_NO_INDEX);
 		}
 
 		for_in_cache->foreign_table = for_table;
@@ -3754,7 +3753,6 @@ dict_update_statistics_low(
 					dictionary mutex */
 {
 	dict_index_t*	index;
-	ulint		size;
 	ulint		sum_of_index_sizes	= 0;
 
 	if (table->ibd_file_missing) {
@@ -3770,14 +3768,6 @@ dict_update_statistics_low(
 		return;
 	}
 
-	/* If we have set a high innodb_force_recovery level, do not calculate
-	statistics, as a badly corrupted index can cause a crash in it. */
-
-	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
-
-		return;
-	}
-
 	/* Find out the sizes of the indexes and how many different values
 	for the key they approximately have */
 
@@ -3789,26 +3779,48 @@ dict_update_statistics_low(
 		return;
 	}
 
-	while (index) {
-		size = btr_get_size(index, BTR_TOTAL_SIZE);
 
-		index->stat_index_size = size;
-
-		sum_of_index_sizes += size;
+	do {
+		if (UNIV_LIKELY
+		    (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE
+		     || (srv_force_recovery < SRV_FORCE_NO_LOG_REDO
+			 && (index->type & DICT_CLUSTERED)))) {
+			ulint	size;
+			size = btr_get_size(index, BTR_TOTAL_SIZE);
+
+			index->stat_index_size = size;
+
+			sum_of_index_sizes += size;
+
+			size = btr_get_size(index, BTR_N_LEAF_PAGES);
+
+			if (size == 0) {
+				/* The root node of the tree is a leaf */
+				size = 1;
+			}
 
-		size = btr_get_size(index, BTR_N_LEAF_PAGES);
+			index->stat_n_leaf_pages = size;
 
-		if (size == 0) {
-			/* The root node of the tree is a leaf */
-			size = 1;
-		}
+			btr_estimate_number_of_different_key_vals(index);
+		} else {
+			/* If we have set a high innodb_force_recovery
+			level, do not calculate statistics, as a badly
+			corrupted index can cause a crash in it.
+			Initialize some bogus index cardinality
+			statistics, so that the data can be queried in
+			various means, also via secondary indexes. */
+			ulint	i;
 
-		index->stat_n_leaf_pages = size;
+			sum_of_index_sizes++;
+			index->stat_index_size = index->stat_n_leaf_pages = 1;
 
-		btr_estimate_number_of_different_key_vals(index);
+			for (i = dict_index_get_n_unique(index); i; ) {
+				index->stat_n_diff_key_vals[i--] = 1;
+			}
+		}
 
 		index = dict_table_get_next_index(index);
-	}
+	} while (index);
 
 	index = dict_table_get_first_index(table);
 

=== modified file 'storage/innobase/dict/dict0load.c'
--- a/storage/innobase/dict/dict0load.c	2010-06-29 02:41:37 +0000
+++ b/storage/innobase/dict/dict0load.c	2010-08-04 10:11:33 +0000
@@ -864,16 +864,27 @@ err_exit:
 
 	err = dict_load_indexes(table, heap);
 
+	/* Initialize table foreign_child value. Its value could be
+	changed when dict_load_foreigns() is called below */
+	table->fk_max_recusive_level = 0;
+
 	/* If the force recovery flag is set, we open the table irrespective
 	of the error condition, since the user may want to dump data from the
 	clustered index. However we load the foreign key information only if
 	all indexes were loaded. */
 	if (err == DB_SUCCESS) {
-		err = dict_load_foreigns(table->name, TRUE);
+		err = dict_load_foreigns(table->name, TRUE, TRUE);
+
+		if (err != DB_SUCCESS) {
+			dict_table_remove_from_cache(table);
+			table = NULL;
+		}
 	} else if (!srv_force_recovery) {
 		dict_table_remove_from_cache(table);
 		table = NULL;
 	}
+
+	table->fk_max_recusive_level = 0;
 #if 0
 	if (err != DB_SUCCESS && table != NULL) {
 
@@ -1095,8 +1106,12 @@ dict_load_foreign(
 				/* out: DB_SUCCESS or error code */
 	const char*	id,	/* in: foreign constraint id as a
 				null-terminated string */
-	ibool		check_charsets)
+	ibool		check_charsets,
 				/* in: TRUE=check charset compatibility */
+	ibool		check_recursive)
+				/* in: Whether to record the foreign table
+				parent count to avoid unlimited recursive
+				load of chained foreign tables */
 {
 	dict_foreign_t*	foreign;
 	dict_table_t*	sys_foreign;
@@ -1110,6 +1125,8 @@ dict_load_foreign(
 	ulint		len;
 	ulint		n_fields_and_type;
 	mtr_t		mtr;
+	dict_table_t*	for_table;
+	dict_table_t*	ref_table;
 
 	ut_ad(mutex_own(&(dict_sys->mutex)));
 
@@ -1194,11 +1211,54 @@ dict_load_foreign(
 
 	dict_load_foreign_cols(id, foreign);
 
-	/* If the foreign table is not yet in the dictionary cache, we
-	have to load it so that we are able to make type comparisons
-	in the next function call. */
+	ref_table = dict_table_check_if_in_cache_low(
+			foreign->referenced_table_name);
 
-	dict_table_get_low(foreign->foreign_table_name);
+	/* We could possibly wind up in a deep recursive calls if
+	we call dict_table_get_low() again here if there
+	is a chain of tables concatenated together with
+	foreign constraints. In such case, each table is
+	both a parent and child of the other tables, and
+	act as a "link" in such table chains.
+	To avoid such scenario, we would need to check the
+	number of ancesters the current table has. If that
+	exceeds DICT_FK_MAX_CHAIN_LEN, we will stop loading
+	the child table.
+	Foreign constraints are loaded in a Breath First fashion,
+	that is, the index on FOR_NAME is scanned first, and then
+	index on REF_NAME. So foreign constrains in which
+	current table is a child (foreign table) are loaded first,
+	and then those constraints where current table is a
+	parent (referenced) table.
+	Thus we could check the parent (ref_table) table's
+	reference count (fk_max_recusive_level) to know how deep the
+	recursive call is. If the parent table (ref_table) is already
+	loaded, and its fk_max_recusive_level is larger than
+	DICT_FK_MAX_CHAIN_LEN, we will stop the recursive loading
+	by skipping loading the child table. It will not affect foreign
+	constraint check for DMLs since child table will be loaded
+	at that time for the constraint check. */
+	if (!ref_table
+	    || ref_table->fk_max_recusive_level < DICT_FK_MAX_RECURSIVE_LOAD) {
+
+		/* If the foreign table is not yet in the dictionary cache, we
+		have to load it so that we are able to make type comparisons
+		in the next function call. */
+
+		for_table = dict_table_get_low(foreign->foreign_table_name);
+
+		if (for_table && ref_table && check_recursive) {
+			/* This is to record the longest chain of ancesters
+			this table has, if the parent has more ancesters
+			than this table has, record it after add 1 (for this
+			parent */
+			if (ref_table->fk_max_recusive_level
+			    >= for_table->fk_max_recusive_level) {
+				for_table->fk_max_recusive_level =
+					 ref_table->fk_max_recusive_level + 1;
+			}
+		}
+	}
 
 	/* Note that there may already be a foreign constraint object in
 	the dictionary cache for this constraint: then the following
@@ -1223,6 +1283,8 @@ dict_load_foreigns(
 /*===============*/
 					/* out: DB_SUCCESS or error code */
 	const char*	table_name,	/* in: table name */
+	ibool		check_recursive,/* in: Whether to check recursive
+					load of tables chained by FK */
 	ibool		check_charsets)	/* in: TRUE=check charset
 					compatibility */
 {
@@ -1324,7 +1386,7 @@ loop:
 
 	/* Load the foreign constraint definition to the dictionary cache */
 
-	err = dict_load_foreign(id, check_charsets);
+	err = dict_load_foreign(id, check_charsets, check_recursive);
 
 	if (err != DB_SUCCESS) {
 		btr_pcur_close(&pcur);
@@ -1352,6 +1414,11 @@ load_next_index:
 
 		mtr_start(&mtr);
 
+		/* Switch to scan index on REF_NAME, fk_max_recusive_level
+		already been updated when scanning FOR_NAME index, no need to
+		update again */
+		check_recursive = FALSE;
+
 		goto start_load;
 	}
 

=== modified file 'storage/innobase/fil/fil0fil.c'
--- a/storage/innobase/fil/fil0fil.c	2009-12-15 13:23:54 +0000
+++ b/storage/innobase/fil/fil0fil.c	2010-08-20 07:49:43 +0000
@@ -966,6 +966,8 @@ try_again:
 	HASH_SEARCH(name_hash, system->name_hash, ut_fold_string(name), space,
 		    0 == strcmp(name, space->name));
 	if (space != NULL) {
+		ibool	success;
+
 		ut_print_timestamp(stderr);
 		fprintf(stderr,
 			"  InnoDB: Warning: trying to init to the"
@@ -1002,9 +1004,10 @@ try_again:
 
 		namesake_id = space->id;
 
-		mutex_exit(&(system->mutex));
+		success = fil_space_free(namesake_id, FALSE);
+		ut_a(success);
 
-		fil_space_free(namesake_id);
+		mutex_exit(&(system->mutex));
 
 		goto try_again;
 	}
@@ -1128,6 +1131,33 @@ fil_assign_new_space_id(void)
 }
 
 /***********************************************************************
+Check if the space id exists in the cache, complain to stderr if the
+space id cannot be found. */
+static
+fil_space_t*
+fil_space_search(
+/*=============*/
+			/* out: file space instance*/
+	ulint	id)	/* in: space id */
+{
+	fil_space_t*	space;
+
+	ut_ad(mutex_own(&fil_system->mutex));
+
+	HASH_SEARCH(hash, fil_system->spaces, id, space, space->id == id);
+
+	if (space == NULL) {
+		ut_print_timestamp(stderr);
+		fprintf(stderr,
+			"  InnoDB: Error: trying to remove tablespace %lu"
+			" from the cache but\n"
+			"InnoDB: it is not there.\n", (ulong) id);
+	}
+
+	return(space);
+}
+
+/***********************************************************************
 Frees a space object from the tablespace memory cache. Closes the files in
 the chain but does not delete them. There must not be any pending i/o's or
 flushes on the files. */
@@ -1135,27 +1165,21 @@ flushes on the files. */
 ibool
 fil_space_free(
 /*===========*/
-			/* out: TRUE if success */
-	ulint	id)	/* in: space id */
+				/* out: TRUE if success */
+	ulint	id,		/* in: space id */
+	ibool	x_latched)	/* in: TRUE if caller has space->latch
+				in X mode */
 {
 	fil_system_t*	system = fil_system;
 	fil_space_t*	space;
 	fil_space_t*	namespace;
 	fil_node_t*	fil_node;
 
-	mutex_enter(&(system->mutex));
-
-	HASH_SEARCH(hash, system->spaces, id, space, space->id == id);
-
-	if (!space) {
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			"  InnoDB: Error: trying to remove tablespace %lu"
-			" from the cache but\n"
-			"InnoDB: it is not there.\n", (ulong) id);
+	ut_ad(mutex_own(&fil_system->mutex));
 
-		mutex_exit(&(system->mutex));
+	space = fil_space_search(id);
 
+	if (space == NULL) {
 		return(FALSE);
 	}
 
@@ -1191,7 +1215,9 @@ fil_space_free(
 
 	ut_a(0 == UT_LIST_GET_LEN(space->chain));
 
-	mutex_exit(&(system->mutex));
+	if (x_latched) {
+		rw_lock_x_unlock(&space->latch);
+	}
 
 	rw_lock_free(&(space->latch));
 
@@ -2048,6 +2074,19 @@ try_again:
 	path = mem_strdup(space->name);
 
 	mutex_exit(&(system->mutex));
+
+	/* Important: We rely on the data dictionary mutex to ensure
+	that a race is not possible here. It should serialize the tablespace
+	drop/free. We acquire an X latch only to avoid a race condition
+	when accessing the tablespace instance via:
+
+	  fsp_get_available_space_in_free_extents().
+
+	There our main motivation is to reduce the contention on the
+	dictionary mutex and not correctness. */
+
+	rw_lock_x_lock(&space->latch);
+
 #ifndef UNIV_HOTBACKUP
 	/* Invalidate in the buffer pool all pages belonging to the
 	tablespace. Since we have set space->is_being_deleted = TRUE, readahead
@@ -2060,7 +2099,11 @@ try_again:
 #endif
 	/* printf("Deleting tablespace %s id %lu\n", space->name, id); */
 
-	success = fil_space_free(id);
+	mutex_enter(&system->mutex);
+
+	success = fil_space_free(id, TRUE);
+
+	mutex_exit(&system->mutex);
 
 	if (success) {
 		success = os_file_delete(path);
@@ -2068,6 +2111,8 @@ try_again:
 		if (!success) {
 			success = os_file_delete_if_exists(path);
 		}
+	} else {
+		rw_lock_x_unlock(&space->latch);
 	}
 
 	if (success) {
@@ -4569,3 +4614,28 @@ fil_page_get_type(
 
 	return(mach_read_from_2(page + FIL_PAGE_TYPE));
 }
+
+/***********************************************************************
+Returns TRUE if a single-table tablespace is being deleted. */
+
+ibool
+fil_tablespace_is_being_deleted(
+/*============================*/
+				/* out: TRUE if space is being deleted */
+	ulint		id)	/* in: space id */
+{
+	fil_space_t*	space;
+	ibool		is_being_deleted;
+
+	mutex_enter(&fil_system->mutex);
+
+	HASH_SEARCH(hash, fil_system->spaces, id, space, space->id == id);
+
+	ut_a(space != NULL);
+
+	is_being_deleted = space->is_being_deleted;
+
+	mutex_exit(&fil_system->mutex);
+
+	return(is_being_deleted);
+}

=== modified file 'storage/innobase/fsp/fsp0fsp.c'
--- a/storage/innobase/fsp/fsp0fsp.c	2010-05-04 13:13:58 +0000
+++ b/storage/innobase/fsp/fsp0fsp.c	2010-08-20 07:49:43 +0000
@@ -2842,12 +2842,61 @@ fsp_get_available_space_in_free_extents(
 
 	ut_ad(!mutex_own(&kernel_mutex));
 
+	/* The convoluted mutex acquire is to overcome latching order
+	issues: The problem is that the fil_mutex is at a lower level
+	than the tablespace latch and the buffer pool mutex. We have to
+	first prevent any operations on the file system by acquiring the
+	dictionary mutex. Then acquire the tablespace latch to obey the
+	latching order and then release the dictionary mutex. That way we
+	ensure that the tablespace instance can't be freed while we are
+	examining its contents (see fil_space_free()).
+
+	However, there is one further complication, we release the fil_mutex
+	when we need to invalidate the the pages in the buffer pool and we
+	reacquire the fil_mutex when deleting and freeing the tablespace
+	instance in fil0fil.c. Here we need to account for that situation
+	too. */
+
+	dict_mutex_enter_for_mysql();
+
+	/* At this stage there is no guarantee that the tablespace even
+	exists in the cache. */
+
+	if (fil_tablespace_deleted_or_being_deleted_in_mem(space, -1)) {
+
+		dict_mutex_exit_for_mysql();
+
+		return(ULLINT_UNDEFINED);
+	}
+
 	mtr_start(&mtr);
 
 	latch = fil_space_get_latch(space);
 
+	/* This should ensure that the tablespace instance can't be freed
+	by another thread. However, the tablespace pages can still be freed
+	from the buffer pool. We need to check for that again. */
+
 	mtr_x_lock(latch, &mtr);
 
+	dict_mutex_exit_for_mysql();
+
+	/* At this point it is possible for the tablespace to be deleted and
+	its pages removed from the buffer pool. We need to check for that
+	situation. However, the tablespace instance can't be deleted because
+	our latching above should ensure that. */
+
+	if (fil_tablespace_is_being_deleted(space)) {
+
+		mtr_commit(&mtr);
+
+		return(ULLINT_UNDEFINED);
+	}
+
+	/* From here on even if the user has dropped the tablespace, the
+	pages _must_ still exist in the buffer pool and the tablespace
+	instance _must be in the file system hash table. */
+
 	space_header = fsp_get_space_header(space, &mtr);
 
 	size = mtr_read_ulint(space_header + FSP_SIZE, MLOG_4BYTES, &mtr);

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2010-07-04 07:12:44 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2010-09-02 00:43:02 +0000
@@ -707,7 +707,9 @@ convert_error_code_to_mysql(
 
 		return(HA_ERR_ROW_IS_REFERENCED);
 
-	} else if (error == (int) DB_CANNOT_ADD_CONSTRAINT) {
+	} else if (error == (int) DB_CANNOT_ADD_CONSTRAINT
+		   || error == (int) DB_FOREIGN_NO_INDEX
+		   || error == (int) DB_REFERENCING_NO_INDEX) {
 
 		return(HA_ERR_CANNOT_ADD_FOREIGN);
 
@@ -763,6 +765,16 @@ convert_error_code_to_mysql(
 
 		my_error(ER_QUERY_INTERRUPTED, MYF(0));
 		return(-1);
+	} else if (error == DB_FOREIGN_EXCEED_MAX_CASCADE) {
+		push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+				    HA_ERR_ROW_IS_REFERENCED,
+				    "InnoDB: Cannot delete/update "
+				    "rows with cascading foreign key "
+				    "constraints that exceed max "
+				    "depth of %d. Please "
+				    "drop extra constraints and try "
+				    "again", DICT_FK_MAX_RECURSIVE_LOAD);
+		return(-1);
     	} else {
     		return(-1);			// Unknown error
     	}
@@ -2710,12 +2722,19 @@ ha_innobase::innobase_initialize_autoinc
 		err = row_search_max_autoinc(index, col_name, &read_auto_inc);
 
 		switch (err) {
-		case DB_SUCCESS:
+		case DB_SUCCESS: {
+			ulonglong	col_max_value;
+
+			col_max_value = innobase_get_int_col_max_value(field);
+
 			/* At the this stage we do not know the increment
-			or the offset, so use a default increment of 1. */
-			auto_inc = read_auto_inc + 1;
-			break;
+			nor the offset, so use a default increment of 1. */
 
+			auto_inc = innobase_next_autoinc(
+				read_auto_inc, 1, 1, col_max_value);
+
+			break;
+		}
 		case DB_RECORD_NOT_FOUND:
 			ut_print_timestamp(stderr);
 			fprintf(stderr, "  InnoDB: MySQL and InnoDB data "
@@ -2941,8 +2960,6 @@ retry:
 	/* Init table lock structure */
 	thr_lock_data_init(&share->lock,&lock,(void*) 0);
 
-	info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
-
 	/* Only if the table has an AUTOINC column. */
 	if (prebuilt->table != NULL && table->found_next_number_field != NULL) {
 		dict_table_autoinc_lock(prebuilt->table);
@@ -2959,6 +2976,8 @@ retry:
 		dict_table_autoinc_unlock(prebuilt->table);
 	}
 
+	info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
+
 	DBUG_RETURN(0);
 }
 
@@ -6099,6 +6118,8 @@ ha_innobase::rename_table(
 	innobase_commit_low(trx);
 	trx_free_for_mysql(trx);
 
+	switch (error) {
+	case DB_DUPLICATE_KEY:
 	/* Add a special case to handle the Duplicated Key error
 	and return DB_ERROR instead.
 	This is to avoid a possible SIGSEGV error from mysql error
@@ -6111,10 +6132,28 @@ ha_innobase::rename_table(
 	the dup key error here is due to an existing table whose name
 	is the one we are trying to rename to) and return the generic
 	error code. */
-	if (error == (int) DB_DUPLICATE_KEY) {
 		my_error(ER_TABLE_EXISTS_ERROR, MYF(0), to);
 
 		error = DB_ERROR;
+		break;
+	case DB_FOREIGN_NO_INDEX:
+		push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+				    HA_ERR_CANNOT_ADD_FOREIGN,
+				    "Alter or rename of table '%s' failed"
+				    " because the new table is a child table"
+				    " in a FK relationship and it does not"
+				    " have an index that contains foreign"
+				    " keys as its prefix columns.", norm_to);
+		break;
+	case DB_REFERENCING_NO_INDEX:
+		push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+				    HA_ERR_CANNOT_ADD_FOREIGN,
+				    "Alter or rename of table '%s' failed"
+				    " because the new table is a parent table"
+				    " in a FK relationship and it does not"
+				    " have an index that contains foreign"
+				    " keys as its prefix columns.", norm_to);
+		break;
 	}
 
 	error = convert_error_code_to_mysql(error, NULL);
@@ -6343,8 +6382,6 @@ ha_innobase::info(
 	dict_index_t*	index;
 	ha_rows		rec_per_key;
 	ib_longlong	n_rows;
-	ulong		j;
-	ulong		i;
 	char		path[FN_REFLEN];
 	os_file_stat_t	stat_info;
 
@@ -6354,16 +6391,6 @@ ha_innobase::info(
 	statistics calculation on tables, because that may crash the
 	server if an index is badly corrupted. */
 
-	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
-
-		/* We return success (0) instead of HA_ERR_CRASHED,
-		because we want MySQL to process this query and not
-		stop, like it would do if it received the error code
-		HA_ERR_CRASHED. */
-
-		DBUG_RETURN(0);
-	}
-
 	/* We do not know if MySQL can call this function before calling
 	external_lock(). To be safe, update the thd of the current table
 	handle. */
@@ -6458,25 +6485,24 @@ ha_innobase::info(
 		acquiring latches inside InnoDB, we do not call it if we
 		are asked by MySQL to avoid locking. Another reason to
 		avoid the call is that it uses quite a lot of CPU.
-		See Bug#38185.
-		We do not update delete_length if no locking is requested
-		so the "old" value can remain. delete_length is initialized
-		to 0 in the ha_statistics' constructor. */
-		if (!(flag & HA_STATUS_NO_LOCK)) {
-
-			/* lock the data dictionary to avoid races with
-			ibd_file_missing and tablespace_discarded */
-			row_mysql_lock_data_dictionary(prebuilt->trx);
-
-			/* ib_table->space must be an existent tablespace */
-			if (!ib_table->ibd_file_missing
-			    && !ib_table->tablespace_discarded) {
-
-				stats.delete_length =
-					fsp_get_available_space_in_free_extents(
-						ib_table->space) * 1024;
-			} else {
+		See Bug#38185. */
+		if (flag & HA_STATUS_NO_LOCK) {
+			/* We do not update delete_length if no
+			locking is requested so the "old" value can
+			remain. delete_length is initialized to 0 in
+			the ha_statistics' constructor. */
+		} else if (UNIV_UNLIKELY
+			   (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE)) {
+			/* Avoid accessing the tablespace if
+			innodb_crash_recovery is set to a high value. */
+			stats.delete_length = 0;
+		} else {
+			ullint	avail_space;
+
+			avail_space = fsp_get_available_space_in_free_extents(
+					ib_table->space);
 
+			if (avail_space == ULLINT_UNDEFINED) {
 				THD*	thd;
 
 				thd = ha_thd();
@@ -6493,9 +6519,9 @@ ha_innobase::info(
 					ib_table->name);
 
 				stats.delete_length = 0;
+			} else {
+				stats.delete_length = avail_space * 1024;
 			}
-
-			row_mysql_unlock_data_dictionary(prebuilt->trx);
 		}
 
 		stats.check_time = 0;
@@ -6508,6 +6534,7 @@ ha_innobase::info(
 	}
 
 	if (flag & HA_STATUS_CONST) {
+		ulong	i = 0;
 		index = dict_table_get_first_index_noninline(ib_table);
 
 		if (prebuilt->clust_index_was_generated) {
@@ -6515,6 +6542,8 @@ ha_innobase::info(
 		}
 
 		for (i = 0; i < table->s->keys; i++) {
+			ulong	j;
+
 			if (index == NULL) {
 				sql_print_error("Table %s contains fewer "
 						"indexes inside InnoDB than "
@@ -6571,6 +6600,11 @@ ha_innobase::info(
 		}
 	}
 
+	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
+
+		goto func_exit;
+	}
+
 	if (flag & HA_STATUS_ERRKEY) {
 		ut_a(prebuilt->trx);
 		ut_a(prebuilt->trx->magic_n == TRX_MAGIC_N);
@@ -6583,6 +6617,7 @@ ha_innobase::info(
  		stats.auto_increment_value = innobase_peek_autoinc();
 	}
 
+func_exit:
 	prebuilt->trx->op_info = (char*)"";
 
   	DBUG_RETURN(0);
@@ -7814,16 +7849,17 @@ ha_innobase::store_lock(
 		    && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
 		    && (sql_command == SQLCOM_INSERT_SELECT
 			|| sql_command == SQLCOM_UPDATE
-			|| sql_command == SQLCOM_CREATE_TABLE)) {
+			|| sql_command == SQLCOM_CREATE_TABLE
+			|| sql_command == SQLCOM_SET_OPTION)) {
 
 			/* If we either have innobase_locks_unsafe_for_binlog
 			option set or this session is using READ COMMITTED
 			isolation level and isolation level of the transaction
 			is not set to serializable and MySQL is doing
 			INSERT INTO...SELECT or UPDATE ... = (SELECT ...) or
-			CREATE  ... SELECT... without FOR UPDATE or
-			IN SHARE MODE in select, then we use consistent
-			read for select. */
+			CREATE  ... SELECT... or SET ... = (SELECT ...)
+			without FOR UPDATE or IN SHARE MODE in select,
+			then we use consistent read for select. */
 
 			prebuilt->select_lock_type = LOCK_NONE;
 			prebuilt->stored_select_lock_type = LOCK_NONE;

=== modified file 'storage/innobase/include/db0err.h'
--- a/storage/innobase/include/db0err.h	2010-06-02 10:26:37 +0000
+++ b/storage/innobase/include/db0err.h	2010-09-02 00:43:02 +0000
@@ -73,6 +73,15 @@ Created 5/24/1996 Heikki Tuuri
 					a later version of the engine. */
 #define DB_INTERRUPTED		49	/* the query has been interrupted with
 					"KILL QUERY N;" */
+#define DB_FOREIGN_EXCEED_MAX_CASCADE 50/* Foreign key constraint related
+					cascading delete/update exceeds
+					maximum allowed depth */
+#define DB_FOREIGN_NO_INDEX	51	/* the child (foreign) table does not
+					have an index that contains the
+					foreign keys as its prefix columns */
+#define DB_REFERENCING_NO_INDEX	52	/* the parent (referencing) table does
+					not have an index that contains the
+					foreign keys as its prefix columns */
 
 /* The following are partial failure codes */
 #define DB_FAIL			1000

=== modified file 'storage/innobase/include/dict0dict.h'
--- a/storage/innobase/include/dict0dict.h	2010-05-14 13:02:28 +0000
+++ b/storage/innobase/include/dict0dict.h	2010-08-25 03:42:33 +0000
@@ -588,6 +588,22 @@ dict_table_is_comp_noninline(
 					/* out: TRUE if table uses the
 					compact page format */
 	const dict_table_t*	table);	/* in: table */
+/*********************************************************************//**
+Obtain exclusive locks on all index trees of the table. This is to prevent
+accessing index trees while InnoDB is updating internal metadata for
+operations such as truncate tables. */
+UNIV_INLINE
+void
+dict_table_x_lock_indexes(
+/*======================*/
+	dict_table_t*	table);	/* in: table */
+/*********************************************************************//**
+Release the exclusive locks on all index tree. */
+UNIV_INLINE
+void
+dict_table_x_unlock_indexes(
+/*========================*/
+	dict_table_t*	table);	/* in: table */
 /************************************************************************
 Checks if a column is in the ordering columns of the clustered index of a
 table. Column prefixes are treated like whole columns. */

=== modified file 'storage/innobase/include/dict0dict.ic'
--- a/storage/innobase/include/dict0dict.ic	2007-06-01 06:01:15 +0000
+++ b/storage/innobase/include/dict0dict.ic	2010-08-25 03:42:33 +0000
@@ -298,6 +298,48 @@ dict_table_is_comp(
 	return(UNIV_LIKELY(table->flags & DICT_TF_COMPACT));
 }
 
+/*********************************************************************//**
+Obtain exclusive locks on all index trees of the table. This is to prevent
+accessing index trees while InnoDB is updating internal metadata for
+operations such as truncate tables. */
+UNIV_INLINE
+void
+dict_table_x_lock_indexes(
+/*======================*/
+	dict_table_t*	table)	/* in: table */
+{
+	dict_index_t*   index;
+
+	ut_a(table);
+	ut_ad(mutex_own(&(dict_sys->mutex)));
+
+	/* Loop through each index of the table and lock them */
+	for (index = dict_table_get_first_index(table);
+	     index != NULL;
+	     index = dict_table_get_next_index(index)) {
+		rw_lock_x_lock(dict_index_get_lock(index));
+	}
+}
+
+/*********************************************************************//**
+Release the exclusive locks on all index tree. */
+UNIV_INLINE
+void
+dict_table_x_unlock_indexes(
+/*========================*/
+	dict_table_t*	table)	/* in: table */
+{
+	dict_index_t*   index;
+
+	ut_a(table);
+	ut_ad(mutex_own(&(dict_sys->mutex)));
+
+	for (index = dict_table_get_first_index(table);
+	     index != NULL;
+	     index = dict_table_get_next_index(index)) {
+		rw_lock_x_unlock(dict_index_get_lock(index));
+	}
+}
 /************************************************************************
 Gets the number of fields in the internal representation of an index,
 including fields added by the dictionary system. */

=== modified file 'storage/innobase/include/dict0load.h'
--- a/storage/innobase/include/dict0load.h	2006-02-21 12:37:54 +0000
+++ b/storage/innobase/include/dict0load.h	2010-08-04 10:11:33 +0000
@@ -82,6 +82,8 @@ dict_load_foreigns(
 /*===============*/
 					/* out: DB_SUCCESS or error code */
 	const char*	table_name,	/* in: table name */
+	ibool		check_recursive,/* in: Whether to check recursive
+					load of tables chained by FK */
 	ibool		check_charsets);/* in: TRUE=check charsets
 					compatibility */
 /************************************************************************

=== modified file 'storage/innobase/include/dict0mem.h'
--- a/storage/innobase/include/dict0mem.h	2008-10-23 04:30:32 +0000
+++ b/storage/innobase/include/dict0mem.h	2010-08-04 10:11:33 +0000
@@ -283,6 +283,21 @@ a foreign key constraint is enforced, th
 #define DICT_FOREIGN_ON_DELETE_NO_ACTION 16
 #define DICT_FOREIGN_ON_UPDATE_NO_ACTION 32
 
+/** Tables could be chained together with Foreign key constraint. When
+first load the parent table, we would load all of its descedents.
+This could result in rescursive calls and out of stack error eventually.
+DICT_FK_MAX_RECURSIVE_LOAD defines the maximum number of recursive loads,
+when exceeded, the child table will not be loaded. It will be loaded when
+the foreign constraint check needs to be run. */
+#define DICT_FK_MAX_RECURSIVE_LOAD	250
+
+/** Similarly, when tables are chained together with foreign key constraints
+with on cascading delete/update clause, delete from parent table could
+result in recursive cascading calls. This defines the maximum number of
+such cascading deletes/updates allowed. When exceeded, the delete from
+parent table will fail, and user has to drop excessive foreign constraint
+before proceeds. */
+#define FK_MAX_CASCADE_DEL		300
 
 /* Data structure for a database table */
 struct dict_table_struct{
@@ -339,6 +354,12 @@ struct dict_table_struct{
 				NOT allowed until this count gets to zero;
 				MySQL does NOT itself check the number of
 				open handles at drop */
+	unsigned	fk_max_recusive_level:8;
+				/*!< maximum recursive level we support when
+				loading tables chained together with FK
+				constraints. If exceeds this level, we will
+				stop loading child table into memory along with
+				its parent table */
 	ulint		n_foreign_key_checks_running;
 				/* count of how many foreign key check
 				operations are currently being performed

=== modified file 'storage/innobase/include/fil0fil.h'
--- a/storage/innobase/include/fil0fil.h	2009-12-15 13:23:54 +0000
+++ b/storage/innobase/include/fil0fil.h	2010-08-20 07:49:43 +0000
@@ -202,8 +202,10 @@ the chain but does not delete them. */
 ibool
 fil_space_free(
 /*===========*/
-			/* out: TRUE if success */
-	ulint	id);	/* in: space id */
+				/* out: TRUE if success */
+	ulint	id,		/* in: space id */
+	ibool	x_latched);	/* in: TRUE if caller has space->latch
+				in X mode */
 /***********************************************************************
 Returns the size of the space in pages. The tablespace must be cached in the
 memory cache. */
@@ -710,6 +712,14 @@ fil_page_get_type(
 			written to page, the return value not defined */
 	byte*	page);	/* in: file page */
 
+/***********************************************************************
+Returns TRUE if a single-table tablespace is being deleted. */
+
+ibool
+fil_tablespace_is_being_deleted(
+/*============================*/
+				/* out: TRUE if space is being deleted */
+	ulint		id);	/* in: space id */
 
 typedef	struct fil_space_struct	fil_space_t;
 

=== modified file 'storage/innobase/include/que0que.h'
--- a/storage/innobase/include/que0que.h	2006-06-08 06:08:23 +0000
+++ b/storage/innobase/include/que0que.h	2010-08-04 10:11:33 +0000
@@ -367,6 +367,9 @@ struct que_thr_struct{
 					thus far */
 	ulint		lock_state;	/* lock state of thread (table or
 					row) */
+	ulint		fk_cascade_depth; /*!< maximum cascading call depth
+					supported for foreign key constraint
+					related delete/updates */
 };
 
 #define QUE_THR_MAGIC_N		8476583

=== modified file 'storage/innobase/include/univ.i'
--- a/storage/innobase/include/univ.i	2010-05-20 10:40:42 +0000
+++ b/storage/innobase/include/univ.i	2010-08-20 07:49:43 +0000
@@ -234,6 +234,12 @@ typedef unsigned long long int	ullint;
 /* Maximum value for a ulint */
 #define ULINT_MAX		((ulint)(-2))
 
+/* THe 'undefined' value for ullint */
+#define ULLINT_UNDEFINED        ((ullint)(-1))
+
+/* Maximum value for a ullint */
+#define ULLINT_MAX		((ullint)(-2))
+
 /* This 'ibool' type is used within Innobase. Remember that different included
 headers may define 'bool' differently. Do not assume that 'bool' is a ulint! */
 #define ibool			ulint

=== modified file 'storage/innobase/row/row0mysql.c'
--- a/storage/innobase/row/row0mysql.c	2010-06-02 10:26:37 +0000
+++ b/storage/innobase/row/row0mysql.c	2010-08-25 03:42:33 +0000
@@ -555,6 +555,12 @@ handle_new_error:
 		      "forcing-recovery.html"
 		      " for help.\n", stderr);
 
+	} else if (err == DB_FOREIGN_EXCEED_MAX_CASCADE) {
+		fprintf(stderr, "InnoDB: Cannot delete/update rows with"
+			" cascading foreign key constraints that exceed max"
+			" depth of %lu\n"
+			"Please drop excessive foreign constraints"
+			" and try again\n", (ulong) DICT_FK_MAX_RECURSIVE_LOAD);
 	} else {
 		fprintf(stderr, "InnoDB: unknown error code %lu\n",
 			(ulong) err);
@@ -1406,11 +1412,15 @@ row_update_for_mysql(
 run_again:
 	thr->run_node = node;
 	thr->prev_node = node;
+	thr->fk_cascade_depth = 0;
 
 	row_upd_step(thr);
 
 	err = trx->error_state;
 
+	/* Reset fk_cascade_depth back to 0 */
+	thr->fk_cascade_depth = 0;
+
 	if (err != DB_SUCCESS) {
 		que_thr_stop_for_mysql(thr);
 
@@ -1597,6 +1607,12 @@ row_update_cascade_for_mysql(
 	trx_t*	trx;
 
 	trx = thr_get_trx(thr);
+
+	thr->fk_cascade_depth++;
+
+	if (thr->fk_cascade_depth > FK_MAX_CASCADE_DEL) {
+		return (DB_FOREIGN_EXCEED_MAX_CASCADE);
+	}
 run_again:
 	thr->run_node = node;
 	thr->prev_node = node;
@@ -2129,7 +2145,7 @@ row_table_add_foreign_constraints(
 
 	if (err == DB_SUCCESS) {
 		/* Check that also referencing constraints are ok */
-		err = dict_load_foreigns(name, TRUE);
+		err = dict_load_foreigns(name, FALSE, TRUE);
 	}
 
 	if (err != DB_SUCCESS) {
@@ -2814,6 +2830,15 @@ row_truncate_table_for_mysql(
 
 	trx->table_id = table->id;
 
+	/* Lock all index trees for this table, as we will
+	truncate the table/index and possibly change their metadata.
+	All DML/DDL are blocked by table level lock, with
+	a few exceptions such as queries into information schema
+	about the table, MySQL could try to access index stats
+	for this kind of query, we need to use index locks to
+	sync up */
+	dict_table_x_lock_indexes(table);
+
 	/* scan SYS_INDEXES for all indexes of the table */
 	heap = mem_heap_create(800);
 
@@ -2886,6 +2911,10 @@ next_rec:
 
 	mem_heap_free(heap);
 
+	/* Done with index truncation, release index tree locks,
+	subsequent work relates to table level metadata change */
+	dict_table_x_unlock_indexes(table);
+
 	new_id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID);
 
 	info = pars_info_create();
@@ -3878,7 +3907,8 @@ end:
 		an ALTER, not in a RENAME. */
 
 		err = dict_load_foreigns(
-			new_name, old_is_tmp ? trx->check_foreigns : TRUE);
+			new_name, FALSE,
+			old_is_tmp ? trx->check_foreigns : TRUE);
 
 		if (err != DB_SUCCESS) {
 			ut_print_timestamp(stderr);

=== modified file 'storage/innodb_plugin/ChangeLog'
--- a/storage/innodb_plugin/ChangeLog	2010-07-28 10:20:44 +0000
+++ b/storage/innodb_plugin/ChangeLog	2010-09-02 00:43:02 +0000
@@ -1,3 +1,34 @@
+2010-08-24	The InnoDB Team
+
+	* handler/ha_innodb.c, dict/dict0dict.c:
+	Fix Bug #55832 selects crash too easily when innodb_force_recovery>3
+
+2010-08-03	The InnoDB Team
+
+	* include/dict0dict.h, include/dict0dict.ic, row/row0mysql.c:
+	Fix bug #54678, InnoDB, TRUNCATE, ALTER, I_S SELECT, crash or deadlock
+
+2010-08-03	The InnoDB Team
+
+	* dict/dict0load.c, handler/ha_innodb.cc, include/db0err.h,
+	include/dict0load.h, include/dict0mem.h, include/que0que.h,
+	row/row0merge.c, row/row0mysql.c:
+	Fix Bug#54582 stack overflow when opening many tables linked
+	with foreign keys at once
+
+2010-08-03	The InnoDB Team
+
+	* include/ut0mem.h, ut/ut0mem.c:
+	Fix Bug #55627 segv in ut_free pars_lexer_close innobase_shutdown
+	innodb-use-sys-malloc=0
+
+2010-08-01	The InnoDB Team
+
+	* handler/ha_innodb.cc
+	Fix Bug #55382 Assignment with SELECT expressions takes unexpected
+	S locks in READ COMMITTED
+>>>>>>> MERGE-SOURCE
+
 2010-07-27	The InnoDB Team
 
 	* include/mem0pool.h, mem/mem0mem.c, mem/mem0pool.c, srv/srv0start.c:

=== modified file 'storage/innodb_plugin/btr/btr0cur.c'
--- a/storage/innodb_plugin/btr/btr0cur.c	2010-06-30 09:31:49 +0000
+++ b/storage/innodb_plugin/btr/btr0cur.c	2010-08-05 09:18:17 +0000
@@ -3484,9 +3484,10 @@ btr_cur_set_ownership_of_extern_field(
 Marks not updated extern fields as not-owned by this record. The ownership
 is transferred to the updated record which is inserted elsewhere in the
 index tree. In purge only the owner of externally stored field is allowed
-to free the field. */
+to free the field.
+@return TRUE if BLOB ownership was transferred */
 UNIV_INTERN
-void
+ibool
 btr_cur_mark_extern_inherited_fields(
 /*=================================*/
 	page_zip_des_t*	page_zip,/*!< in/out: compressed page whose uncompressed
@@ -3500,13 +3501,14 @@ btr_cur_mark_extern_inherited_fields(
 	ulint	n;
 	ulint	j;
 	ulint	i;
+	ibool	change_ownership = FALSE;
 
 	ut_ad(rec_offs_validate(rec, NULL, offsets));
 	ut_ad(!rec_offs_comp(offsets) || !rec_get_node_ptr_flag(rec));
 
 	if (!rec_offs_any_extern(offsets)) {
 
-		return;
+		return(FALSE);
 	}
 
 	n = rec_offs_n_fields(offsets);
@@ -3529,10 +3531,14 @@ btr_cur_mark_extern_inherited_fields(
 
 			btr_cur_set_ownership_of_extern_field(
 				page_zip, rec, index, offsets, i, FALSE, mtr);
+
+			change_ownership = TRUE;
 updated:
 			;
 		}
 	}
+
+	return(change_ownership);
 }
 
 /*******************************************************************//**

=== modified file 'storage/innodb_plugin/btr/btr0sea.c'
--- a/storage/innodb_plugin/btr/btr0sea.c	2010-07-01 05:06:01 +0000
+++ b/storage/innodb_plugin/btr/btr0sea.c	2010-08-05 15:34:44 +0000
@@ -1734,6 +1734,7 @@ function_exit:
 	}
 }
 
+#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
 /********************************************************************//**
 Validates the search system.
 @return	TRUE if ok */
@@ -1897,3 +1898,4 @@ btr_search_validate(void)
 
 	return(ok);
 }
+#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */

=== modified file 'storage/innodb_plugin/dict/dict0dict.c'
--- a/storage/innodb_plugin/dict/dict0dict.c	2010-06-25 08:18:41 +0000
+++ b/storage/innodb_plugin/dict/dict0dict.c	2010-08-24 08:10:03 +0000
@@ -568,8 +568,7 @@ dict_table_get_on_id(
 {
 	dict_table_t*	table;
 
-	if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0
-	    || trx->dict_operation_lock_mode == RW_X_LATCH) {
+	if (trx->dict_operation_lock_mode == RW_X_LATCH) {
 
 		/* Note: An X latch implies that the transaction
 		already owns the dictionary mutex. */
@@ -4192,7 +4191,6 @@ dict_update_statistics_low(
 					dictionary mutex */
 {
 	dict_index_t*	index;
-	ulint		size;
 	ulint		sum_of_index_sizes	= 0;
 
 	if (table->ibd_file_missing) {
@@ -4207,14 +4205,6 @@ dict_update_statistics_low(
 		return;
 	}
 
-	/* If we have set a high innodb_force_recovery level, do not calculate
-	statistics, as a badly corrupted index can cause a crash in it. */
-
-	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
-
-		return;
-	}
-
 	/* Find out the sizes of the indexes and how many different values
 	for the key they approximately have */
 
@@ -4226,26 +4216,48 @@ dict_update_statistics_low(
 		return;
 	}
 
-	while (index) {
-		size = btr_get_size(index, BTR_TOTAL_SIZE);
 
-		index->stat_index_size = size;
+	do {
+		if (UNIV_LIKELY
+		    (srv_force_recovery < SRV_FORCE_NO_IBUF_MERGE
+		     || (srv_force_recovery < SRV_FORCE_NO_LOG_REDO
+			 && dict_index_is_clust(index)))) {
+			ulint	size;
+			size = btr_get_size(index, BTR_TOTAL_SIZE);
 
-		sum_of_index_sizes += size;
+			index->stat_index_size = size;
 
-		size = btr_get_size(index, BTR_N_LEAF_PAGES);
+			sum_of_index_sizes += size;
 
-		if (size == 0) {
-			/* The root node of the tree is a leaf */
-			size = 1;
-		}
+			size = btr_get_size(index, BTR_N_LEAF_PAGES);
+
+			if (size == 0) {
+				/* The root node of the tree is a leaf */
+				size = 1;
+			}
+
+			index->stat_n_leaf_pages = size;
+
+			btr_estimate_number_of_different_key_vals(index);
+		} else {
+			/* If we have set a high innodb_force_recovery
+			level, do not calculate statistics, as a badly
+			corrupted index can cause a crash in it.
+			Initialize some bogus index cardinality
+			statistics, so that the data can be queried in
+			various means, also via secondary indexes. */
+			ulint	i;
 
-		index->stat_n_leaf_pages = size;
+			sum_of_index_sizes++;
+			index->stat_index_size = index->stat_n_leaf_pages = 1;
 
-		btr_estimate_number_of_different_key_vals(index);
+			for (i = dict_index_get_n_unique(index); i; ) {
+				index->stat_n_diff_key_vals[i--] = 1;
+			}
+		}
 
 		index = dict_table_get_next_index(index);
-	}
+	} while (index);
 
 	index = dict_table_get_first_index(table);
 

=== modified file 'storage/innodb_plugin/dict/dict0load.c'
--- a/storage/innodb_plugin/dict/dict0load.c	2010-06-21 09:40:08 +0000
+++ b/storage/innodb_plugin/dict/dict0load.c	2010-08-04 10:11:33 +0000
@@ -1009,16 +1009,27 @@ err_exit:
 
 	err = dict_load_indexes(table, heap);
 
+	/* Initialize table foreign_child value. Its value could be
+	changed when dict_load_foreigns() is called below */
+	table->fk_max_recusive_level = 0;
+
 	/* If the force recovery flag is set, we open the table irrespective
 	of the error condition, since the user may want to dump data from the
 	clustered index. However we load the foreign key information only if
 	all indexes were loaded. */
 	if (err == DB_SUCCESS) {
-		err = dict_load_foreigns(table->name, TRUE);
+		err = dict_load_foreigns(table->name, TRUE, TRUE);
+
+		if (err != DB_SUCCESS) {
+			dict_table_remove_from_cache(table);
+			table = NULL;
+		}
 	} else if (!srv_force_recovery) {
 		dict_table_remove_from_cache(table);
 		table = NULL;
 	}
+
+	table->fk_max_recusive_level = 0;
 #if 0
 	if (err != DB_SUCCESS && table != NULL) {
 
@@ -1241,8 +1252,12 @@ dict_load_foreign(
 /*==============*/
 	const char*	id,	/*!< in: foreign constraint id as a
 				null-terminated string */
-	ibool		check_charsets)
+	ibool		check_charsets,
 				/*!< in: TRUE=check charset compatibility */
+	ibool		check_recursive)
+				/*!< in: Whether to record the foreign table
+				parent count to avoid unlimited recursive
+				load of chained foreign tables */
 {
 	dict_foreign_t*	foreign;
 	dict_table_t*	sys_foreign;
@@ -1256,6 +1271,8 @@ dict_load_foreign(
 	ulint		len;
 	ulint		n_fields_and_type;
 	mtr_t		mtr;
+	dict_table_t*	for_table;
+	dict_table_t*	ref_table;
 
 	ut_ad(mutex_own(&(dict_sys->mutex)));
 
@@ -1340,11 +1357,54 @@ dict_load_foreign(
 
 	dict_load_foreign_cols(id, foreign);
 
-	/* If the foreign table is not yet in the dictionary cache, we
-	have to load it so that we are able to make type comparisons
-	in the next function call. */
+	ref_table = dict_table_check_if_in_cache_low(
+			foreign->referenced_table_name);
 
-	dict_table_get_low(foreign->foreign_table_name);
+	/* We could possibly wind up in a deep recursive calls if
+	we call dict_table_get_low() again here if there
+	is a chain of tables concatenated together with
+	foreign constraints. In such case, each table is
+	both a parent and child of the other tables, and
+	act as a "link" in such table chains.
+	To avoid such scenario, we would need to check the
+	number of ancesters the current table has. If that
+	exceeds DICT_FK_MAX_CHAIN_LEN, we will stop loading
+	the child table.
+	Foreign constraints are loaded in a Breath First fashion,
+	that is, the index on FOR_NAME is scanned first, and then
+	index on REF_NAME. So foreign constrains in which
+	current table is a child (foreign table) are loaded first,
+	and then those constraints where current table is a
+	parent (referenced) table.
+	Thus we could check the parent (ref_table) table's
+	reference count (fk_max_recusive_level) to know how deep the
+	recursive call is. If the parent table (ref_table) is already
+	loaded, and its fk_max_recusive_level is larger than
+	DICT_FK_MAX_CHAIN_LEN, we will stop the recursive loading
+	by skipping loading the child table. It will not affect foreign
+	constraint check for DMLs since child table will be loaded
+	at that time for the constraint check. */
+	if (!ref_table
+	    || ref_table->fk_max_recusive_level < DICT_FK_MAX_RECURSIVE_LOAD) {
+
+		/* If the foreign table is not yet in the dictionary cache, we
+		have to load it so that we are able to make type comparisons
+		in the next function call. */
+
+		for_table = dict_table_get_low(foreign->foreign_table_name);
+
+		if (for_table && ref_table && check_recursive) {
+			/* This is to record the longest chain of ancesters
+			this table has, if the parent has more ancesters
+			than this table has, record it after add 1 (for this
+			parent */
+			if (ref_table->fk_max_recusive_level
+			    >= for_table->fk_max_recusive_level) {
+				for_table->fk_max_recusive_level =
+					 ref_table->fk_max_recusive_level + 1;
+			}
+		}
+	}
 
 	/* Note that there may already be a foreign constraint object in
 	the dictionary cache for this constraint: then the following
@@ -1369,6 +1429,8 @@ ulint
 dict_load_foreigns(
 /*===============*/
 	const char*	table_name,	/*!< in: table name */
+	ibool		check_recursive,/*!< in: Whether to check recursive
+					load of tables chained by FK */
 	ibool		check_charsets)	/*!< in: TRUE=check charset
 					compatibility */
 {
@@ -1470,7 +1532,7 @@ loop:
 
 	/* Load the foreign constraint definition to the dictionary cache */
 
-	err = dict_load_foreign(id, check_charsets);
+	err = dict_load_foreign(id, check_charsets, check_recursive);
 
 	if (err != DB_SUCCESS) {
 		btr_pcur_close(&pcur);
@@ -1498,6 +1560,11 @@ load_next_index:
 
 		mtr_start(&mtr);
 
+		/* Switch to scan index on REF_NAME, fk_max_recusive_level
+		already been updated when scanning FOR_NAME index, no need to
+		update again */
+		check_recursive = FALSE;
+
 		goto start_load;
 	}
 

=== modified file 'storage/innodb_plugin/ha/ha0ha.c'
--- a/storage/innodb_plugin/ha/ha0ha.c	2010-07-01 05:06:01 +0000
+++ b/storage/innodb_plugin/ha/ha0ha.c	2010-08-05 15:34:44 +0000
@@ -354,6 +354,7 @@ ha_remove_all_nodes_to_page(
 #endif
 }
 
+#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
 /*************************************************************//**
 Validates a given range of the cells in hash table.
 @return	TRUE if ok */
@@ -400,6 +401,7 @@ ha_validate(
 
 	return(ok);
 }
+#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
 
 /*************************************************************//**
 Prints info of a hash table. */

=== modified file 'storage/innodb_plugin/handler/ha_innodb.cc'
--- a/storage/innodb_plugin/handler/ha_innodb.cc	2010-07-23 09:51:14 +0000
+++ b/storage/innodb_plugin/handler/ha_innodb.cc	2010-09-02 00:43:02 +0000
@@ -767,6 +767,19 @@ convert_error_code_to_mysql(
 	case DB_INTERRUPTED:
 		my_error(ER_QUERY_INTERRUPTED, MYF(0));
 		/* fall through */
+
+	case DB_FOREIGN_EXCEED_MAX_CASCADE:
+		push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+				    HA_ERR_ROW_IS_REFERENCED,
+				    "InnoDB: Cannot delete/update "
+				    "rows with cascading foreign key "
+				    "constraints that exceed max "
+				    "depth of %d. Please "
+				    "drop extra constraints and try "
+				    "again", DICT_FK_MAX_RECURSIVE_LOAD);
+
+		/* fall through */
+
 	case DB_ERROR:
 	default:
 		return(-1); /* unspecified error */
@@ -3348,12 +3361,19 @@ ha_innobase::innobase_initialize_autoinc
 		err = row_search_max_autoinc(index, col_name, &read_auto_inc);
 
 		switch (err) {
-		case DB_SUCCESS:
+		case DB_SUCCESS: {
+			ulonglong	col_max_value;
+
+			col_max_value = innobase_get_int_col_max_value(field);
+
 			/* At the this stage we do not know the increment
-			or the offset, so use a default increment of 1. */
-			auto_inc = read_auto_inc + 1;
-			break;
+			nor the offset, so use a default increment of 1. */
 
+			auto_inc = innobase_next_autoinc(
+				read_auto_inc, 1, 1, col_max_value);
+
+			break;
+		}
 		case DB_RECORD_NOT_FOUND:
 			ut_print_timestamp(stderr);
 			fprintf(stderr, "  InnoDB: MySQL and InnoDB data "
@@ -3648,8 +3668,6 @@ retry:
 			dict_table_get_format(prebuilt->table));
 	}
 
-	info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
-
 	/* Only if the table has an AUTOINC column. */
 	if (prebuilt->table != NULL && table->found_next_number_field != NULL) {
 		dict_table_autoinc_lock(prebuilt->table);
@@ -3666,6 +3684,8 @@ retry:
 		dict_table_autoinc_unlock(prebuilt->table);
 	}
 
+	info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
+
 	DBUG_RETURN(0);
 }
 
@@ -7511,28 +7531,15 @@ ha_innobase::info(
 	dict_index_t*	index;
 	ha_rows		rec_per_key;
 	ib_int64_t	n_rows;
-	ulong		j;
-	ulong		i;
 	char		path[FN_REFLEN];
 	os_file_stat_t	stat_info;
 
-
 	DBUG_ENTER("info");
 
 	/* If we are forcing recovery at a high level, we will suppress
 	statistics calculation on tables, because that may crash the
 	server if an index is badly corrupted. */
 
-	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
-
-		/* We return success (0) instead of HA_ERR_CRASHED,
-		because we want MySQL to process this query and not
-		stop, like it would do if it received the error code
-		HA_ERR_CRASHED. */
-
-		DBUG_RETURN(0);
-	}
-
 	/* We do not know if MySQL can call this function before calling
 	external_lock(). To be safe, update the thd of the current table
 	handle. */
@@ -7627,12 +7634,18 @@ ha_innobase::info(
 		acquiring latches inside InnoDB, we do not call it if we
 		are asked by MySQL to avoid locking. Another reason to
 		avoid the call is that it uses quite a lot of CPU.
-		See Bug#38185.
-		We do not update delete_length if no locking is requested
-		so the "old" value can remain. delete_length is initialized
-		to 0 in the ha_statistics' constructor. */
-		if (!(flag & HA_STATUS_NO_LOCK)) {
-
+		See Bug#38185. */
+		if (flag & HA_STATUS_NO_LOCK) {
+			/* We do not update delete_length if no
+			locking is requested so the "old" value can
+			remain. delete_length is initialized to 0 in
+			the ha_statistics' constructor. */
+		} else if (UNIV_UNLIKELY
+			   (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE)) {
+			/* Avoid accessing the tablespace if
+			innodb_crash_recovery is set to a high value. */
+			stats.delete_length = 0;
+		} else {
 			/* lock the data dictionary to avoid races with
 			ibd_file_missing and tablespace_discarded */
 			row_mysql_lock_data_dictionary(prebuilt->trx);
@@ -7677,6 +7690,7 @@ ha_innobase::info(
 	}
 
 	if (flag & HA_STATUS_CONST) {
+		ulong	i;
 		/* Verify the number of index in InnoDB and MySQL
 		matches up. If prebuilt->clust_index_was_generated
 		holds, InnoDB defines GEN_CLUST_INDEX internally */
@@ -7693,6 +7707,7 @@ ha_innobase::info(
 		}
 
 		for (i = 0; i < table->s->keys; i++) {
+			ulong	j;
 			/* We could get index quickly through internal
 			index mapping with the index translation table.
 			The identity of index (match up index name with
@@ -7758,6 +7773,11 @@ ha_innobase::info(
 		}
 	}
 
+	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) {
+
+		goto func_exit;
+	}
+
 	if (flag & HA_STATUS_ERRKEY) {
 		const dict_index_t*	err_index;
 
@@ -7778,6 +7798,7 @@ ha_innobase::info(
 		stats.auto_increment_value = innobase_peek_autoinc();
 	}
 
+func_exit:
 	prebuilt->trx->op_info = (char*)"";
 
 	DBUG_RETURN(0);
@@ -9235,7 +9256,8 @@ ha_innobase::store_lock(
 		    && (sql_command == SQLCOM_INSERT_SELECT
 			|| sql_command == SQLCOM_REPLACE_SELECT
 			|| sql_command == SQLCOM_UPDATE
-			|| sql_command == SQLCOM_CREATE_TABLE)) {
+			|| sql_command == SQLCOM_CREATE_TABLE
+			|| sql_command == SQLCOM_SET_OPTION)) {
 
 			/* If we either have innobase_locks_unsafe_for_binlog
 			option set or this session is using READ COMMITTED
@@ -9243,9 +9265,9 @@ ha_innobase::store_lock(
 			is not set to serializable and MySQL is doing
 			INSERT INTO...SELECT or REPLACE INTO...SELECT
 			or UPDATE ... = (SELECT ...) or CREATE  ...
-			SELECT... without FOR UPDATE or IN SHARE
-			MODE in select, then we use consistent read
-			for select. */
+			SELECT... or SET ... = (SELECT ...) without
+			FOR UPDATE or IN SHARE MODE in select,
+			then we use consistent read for select. */
 
 			prebuilt->select_lock_type = LOCK_NONE;
 			prebuilt->stored_select_lock_type = LOCK_NONE;

=== modified file 'storage/innodb_plugin/include/btr0cur.h'
--- a/storage/innodb_plugin/include/btr0cur.h	2010-06-29 12:55:18 +0000
+++ b/storage/innodb_plugin/include/btr0cur.h	2010-08-05 09:18:17 +0000
@@ -468,9 +468,10 @@ btr_estimate_number_of_different_key_val
 Marks not updated extern fields as not-owned by this record. The ownership
 is transferred to the updated record which is inserted elsewhere in the
 index tree. In purge only the owner of externally stored field is allowed
-to free the field. */
+to free the field.
+@return TRUE if BLOB ownership was transferred */
 UNIV_INTERN
-void
+ibool
 btr_cur_mark_extern_inherited_fields(
 /*=================================*/
 	page_zip_des_t*	page_zip,/*!< in/out: compressed page whose uncompressed

=== modified file 'storage/innodb_plugin/include/btr0sea.h'
--- a/storage/innodb_plugin/include/btr0sea.h	2010-07-01 05:06:01 +0000
+++ b/storage/innodb_plugin/include/btr0sea.h	2010-08-05 15:34:44 +0000
@@ -180,6 +180,7 @@ btr_search_update_hash_on_delete(
 	btr_cur_t*	cursor);/*!< in: cursor which was positioned on the
 				record to delete using btr_cur_search_...,
 				the record is not yet deleted */
+#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
 /********************************************************************//**
 Validates the search system.
 @return	TRUE if ok */
@@ -187,6 +188,9 @@ UNIV_INTERN
 ibool
 btr_search_validate(void);
 /*======================*/
+#else
+# define btr_search_validate()	TRUE
+#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
 
 /** Flag: has the search system been enabled?
 Protected by btr_search_latch and btr_search_enabled_mutex. */

=== modified file 'storage/innodb_plugin/include/db0err.h'
--- a/storage/innodb_plugin/include/db0err.h	2010-06-02 10:37:14 +0000
+++ b/storage/innodb_plugin/include/db0err.h	2010-08-04 10:11:33 +0000
@@ -94,6 +94,9 @@ enum db_err {
 
 	DB_PRIMARY_KEY_IS_NULL,		/* a column in the PRIMARY KEY
 					was found to be NULL */
+	DB_FOREIGN_EXCEED_MAX_CASCADE,	/* Foreign key constraint related
+					cascading delete/update exceeds
+					maximum allowed depth */
 
 	/* The following are partial failure codes */
 	DB_FAIL = 1000,

=== modified file 'storage/innodb_plugin/include/dict0dict.h'
--- a/storage/innodb_plugin/include/dict0dict.h	2010-05-14 13:08:15 +0000
+++ b/storage/innodb_plugin/include/dict0dict.h	2010-08-04 10:37:44 +0000
@@ -680,6 +680,22 @@ ulint
 dict_table_zip_size(
 /*================*/
 	const dict_table_t*	table);	/*!< in: table */
+/*********************************************************************//**
+Obtain exclusive locks on all index trees of the table. This is to prevent
+accessing index trees while InnoDB is updating internal metadata for
+operations such as truncate tables. */
+UNIV_INLINE
+void
+dict_table_x_lock_indexes(
+/*======================*/
+	dict_table_t*	table);	/*!< in: table */
+/*********************************************************************//**
+Release the exclusive locks on all index tree. */
+UNIV_INLINE
+void
+dict_table_x_unlock_indexes(
+/*========================*/
+	dict_table_t*	table);	/*!< in: table */
 /********************************************************************//**
 Checks if a column is in the ordering columns of the clustered index of a
 table. Column prefixes are treated like whole columns.

=== modified file 'storage/innodb_plugin/include/dict0dict.ic'
--- a/storage/innodb_plugin/include/dict0dict.ic	2009-05-25 09:52:29 +0000
+++ b/storage/innodb_plugin/include/dict0dict.ic	2010-08-04 10:37:44 +0000
@@ -452,6 +452,48 @@ dict_table_zip_size(
 	return(dict_table_flags_to_zip_size(table->flags));
 }
 
+/*********************************************************************//**
+Obtain exclusive locks on all index trees of the table. This is to prevent
+accessing index trees while InnoDB is updating internal metadata for
+operations such as truncate tables. */
+UNIV_INLINE
+void
+dict_table_x_lock_indexes(
+/*======================*/
+	dict_table_t*	table)	/*!< in: table */
+{
+	dict_index_t*   index;
+
+	ut_a(table);
+	ut_ad(mutex_own(&(dict_sys->mutex)));
+
+	/* Loop through each index of the table and lock them */
+	for (index = dict_table_get_first_index(table);
+	     index != NULL;
+	     index = dict_table_get_next_index(index)) {
+		rw_lock_x_lock(dict_index_get_lock(index));
+	}
+}
+
+/*********************************************************************//**
+Release the exclusive locks on all index tree. */
+UNIV_INLINE
+void
+dict_table_x_unlock_indexes(
+/*========================*/
+	dict_table_t*	table)	/*!< in: table */
+{
+	dict_index_t*   index;
+
+	ut_a(table);
+	ut_ad(mutex_own(&(dict_sys->mutex)));
+
+	for (index = dict_table_get_first_index(table);
+	     index != NULL;
+	     index = dict_table_get_next_index(index)) {
+		rw_lock_x_unlock(dict_index_get_lock(index));
+	}
+}
 /********************************************************************//**
 Gets the number of fields in the internal representation of an index,
 including fields added by the dictionary system.

=== modified file 'storage/innodb_plugin/include/dict0load.h'
--- a/storage/innodb_plugin/include/dict0load.h	2009-05-25 09:52:29 +0000
+++ b/storage/innodb_plugin/include/dict0load.h	2010-08-04 10:11:33 +0000
@@ -97,6 +97,8 @@ ulint
 dict_load_foreigns(
 /*===============*/
 	const char*	table_name,	/*!< in: table name */
+	ibool		check_recursive,/*!< in: Whether to check recursive
+					load of tables chained by FK */
 	ibool		check_charsets);/*!< in: TRUE=check charsets
 					compatibility */
 /********************************************************************//**

=== modified file 'storage/innodb_plugin/include/dict0mem.h'
--- a/storage/innodb_plugin/include/dict0mem.h	2010-06-22 16:30:43 +0000
+++ b/storage/innodb_plugin/include/dict0mem.h	2010-08-04 10:11:33 +0000
@@ -112,6 +112,21 @@ ROW_FORMAT=REDUNDANT. */
 						in table->flags. */
 /* @} */
 
+/** Tables could be chained together with Foreign key constraint. When
+first load the parent table, we would load all of its descedents.
+This could result in rescursive calls and out of stack error eventually.
+DICT_FK_MAX_RECURSIVE_LOAD defines the maximum number of recursive loads,
+when exceeded, the child table will not be loaded. It will be loaded when
+the foreign constraint check needs to be run. */
+#define DICT_FK_MAX_RECURSIVE_LOAD	250
+
+/** Similarly, when tables are chained together with foreign key constraints
+with on cascading delete/update clause, delete from parent table could
+result in recursive cascading calls. This defines the maximum number of
+such cascading deletes/updates allowed. When exceeded, the delete from
+parent table will fail, and user has to drop excessive foreign constraint
+before proceeds. */
+#define FK_MAX_CASCADE_DEL		300
 
 /**********************************************************************//**
 Creates a table memory object.
@@ -434,6 +449,12 @@ struct dict_table_struct{
 				NOT allowed until this count gets to zero;
 				MySQL does NOT itself check the number of
 				open handles at drop */
+	unsigned	fk_max_recusive_level:8;
+				/*!< maximum recursive level we support when
+				loading tables chained together with FK
+				constraints. If exceeds this level, we will
+				stop loading child table into memory along with
+				its parent table */
 	ulint		n_foreign_key_checks_running;
 				/*!< count of how many foreign key check
 				operations are currently being performed

=== modified file 'storage/innodb_plugin/include/ha0ha.h'
--- a/storage/innodb_plugin/include/ha0ha.h	2009-06-30 09:30:14 +0000
+++ b/storage/innodb_plugin/include/ha0ha.h	2010-08-05 15:34:44 +0000
@@ -186,6 +186,7 @@ ha_remove_all_nodes_to_page(
 	hash_table_t*	table,	/*!< in: hash table */
 	ulint		fold,	/*!< in: fold value */
 	const page_t*	page);	/*!< in: buffer page */
+#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
 /*************************************************************//**
 Validates a given range of the cells in hash table.
 @return	TRUE if ok */
@@ -196,6 +197,7 @@ ha_validate(
 	hash_table_t*	table,		/*!< in: hash table */
 	ulint		start_index,	/*!< in: start index */
 	ulint		end_index);	/*!< in: end index */
+#endif /* defined UNIV_AHI_DEBUG || defined UNIV_DEBUG */
 /*************************************************************//**
 Prints info of a hash table. */
 UNIV_INTERN

=== modified file 'storage/innodb_plugin/include/que0que.h'
--- a/storage/innodb_plugin/include/que0que.h	2010-02-20 16:45:41 +0000
+++ b/storage/innodb_plugin/include/que0que.h	2010-08-04 10:11:33 +0000
@@ -381,6 +381,9 @@ struct que_thr_struct{
 					thus far */
 	ulint		lock_state;	/*!< lock state of thread (table or
 					row) */
+	ulint		fk_cascade_depth; /*!< maximum cascading call depth
+					supported for foreign key constraint
+					related delete/updates */
 };
 
 #define QUE_THR_MAGIC_N		8476583

=== modified file 'storage/innodb_plugin/include/univ.i'
--- a/storage/innodb_plugin/include/univ.i	2010-07-23 16:32:38 +0000
+++ b/storage/innodb_plugin/include/univ.i	2010-08-26 15:06:07 +0000
@@ -46,7 +46,7 @@ Created 1/20/1994 Heikki Tuuri
 
 #define INNODB_VERSION_MAJOR	1
 #define INNODB_VERSION_MINOR	0
-#define INNODB_VERSION_BUGFIX	11
+#define INNODB_VERSION_BUGFIX	12
 
 /* The following is the InnoDB version as shown in
 SELECT plugin_version FROM information_schema.plugins;

=== modified file 'storage/innodb_plugin/include/ut0mem.h'
--- a/storage/innodb_plugin/include/ut0mem.h	2009-05-25 12:09:24 +0000
+++ b/storage/innodb_plugin/include/ut0mem.h	2010-08-04 03:20:55 +0000
@@ -113,7 +113,8 @@ ut_test_malloc(
 	ulint	n);	/*!< in: try to allocate this many bytes */
 #endif /* !UNIV_HOTBACKUP */
 /**********************************************************************//**
-Frees a memory block allocated with ut_malloc. */
+Frees a memory block allocated with ut_malloc. Freeing a NULL pointer is
+a nop. */
 UNIV_INTERN
 void
 ut_free(

=== modified file 'storage/innodb_plugin/row/row0merge.c'
--- a/storage/innodb_plugin/row/row0merge.c	2010-06-29 12:55:18 +0000
+++ b/storage/innodb_plugin/row/row0merge.c	2010-08-04 10:11:33 +0000
@@ -2395,7 +2395,7 @@ row_merge_rename_tables(
 		goto err_exit;
 	}
 
-	err = dict_load_foreigns(old_name, TRUE);
+	err = dict_load_foreigns(old_name, FALSE, TRUE);
 
 	if (err != DB_SUCCESS) {
 err_exit:

=== modified file 'storage/innodb_plugin/row/row0mysql.c'
--- a/storage/innodb_plugin/row/row0mysql.c	2010-06-02 10:37:14 +0000
+++ b/storage/innodb_plugin/row/row0mysql.c	2010-08-04 10:37:44 +0000
@@ -576,6 +576,13 @@ handle_new_error:
 		      "InnoDB: " REFMAN "forcing-recovery.html"
 		      " for help.\n", stderr);
 		break;
+	case DB_FOREIGN_EXCEED_MAX_CASCADE:
+		fprintf(stderr, "InnoDB: Cannot delete/update rows with"
+			" cascading foreign key constraints that exceed max"
+			" depth of %lu\n"
+			"Please drop excessive foreign constraints"
+			" and try again\n", (ulong) DICT_FK_MAX_RECURSIVE_LOAD);
+		break;
 	default:
 		fprintf(stderr, "InnoDB: unknown error code %lu\n",
 			(ulong) err);
@@ -1381,11 +1388,15 @@ row_update_for_mysql(
 run_again:
 	thr->run_node = node;
 	thr->prev_node = node;
+	thr->fk_cascade_depth = 0;
 
 	row_upd_step(thr);
 
 	err = trx->error_state;
 
+	/* Reset fk_cascade_depth back to 0 */
+	thr->fk_cascade_depth = 0;
+
 	if (err != DB_SUCCESS) {
 		que_thr_stop_for_mysql(thr);
 
@@ -1576,6 +1587,12 @@ row_update_cascade_for_mysql(
 	trx_t*	trx;
 
 	trx = thr_get_trx(thr);
+
+	thr->fk_cascade_depth++;
+
+	if (thr->fk_cascade_depth > FK_MAX_CASCADE_DEL) {
+		return (DB_FOREIGN_EXCEED_MAX_CASCADE);
+	}
 run_again:
 	thr->run_node = node;
 	thr->prev_node = node;
@@ -2056,7 +2073,7 @@ row_table_add_foreign_constraints(
 					      name, reject_fks);
 	if (err == DB_SUCCESS) {
 		/* Check that also referencing constraints are ok */
-		err = dict_load_foreigns(name, TRUE);
+		err = dict_load_foreigns(name, FALSE, TRUE);
 	}
 
 	if (err != DB_SUCCESS) {
@@ -2749,6 +2766,15 @@ row_truncate_table_for_mysql(
 
 	trx->table_id = table->id;
 
+	/* Lock all index trees for this table, as we will
+	truncate the table/index and possibly change their metadata.
+	All DML/DDL are blocked by table level lock, with
+	a few exceptions such as queries into information schema
+	about the table, MySQL could try to access index stats
+	for this kind of query, we need to use index locks to
+	sync up */
+	dict_table_x_lock_indexes(table);
+
 	if (table->space && !table->dir_path_of_temp_table) {
 		/* Discard and create the single-table tablespace. */
 		ulint	space	= table->space;
@@ -2765,6 +2791,7 @@ row_truncate_table_for_mysql(
 			    || fil_create_new_single_table_tablespace(
 				    space, table->name, FALSE, flags,
 				    FIL_IBD_FILE_INITIAL_SIZE) != DB_SUCCESS) {
+				dict_table_x_unlock_indexes(table);
 				ut_print_timestamp(stderr);
 				fprintf(stderr,
 					"  InnoDB: TRUNCATE TABLE %s failed to"
@@ -2868,6 +2895,10 @@ next_rec:
 
 	mem_heap_free(heap);
 
+	/* Done with index truncation, release index tree locks,
+	subsequent work relates to table level metadata change */
+	dict_table_x_unlock_indexes(table);
+
 	dict_hdr_get_new_id(&new_id, NULL, NULL);
 
 	info = pars_info_create();
@@ -3915,7 +3946,7 @@ end:
 		an ALTER, not in a RENAME. */
 
 		err = dict_load_foreigns(
-			new_name, !old_is_tmp || trx->check_foreigns);
+			new_name, FALSE, !old_is_tmp || trx->check_foreigns);
 
 		if (err != DB_SUCCESS) {
 			ut_print_timestamp(stderr);

=== modified file 'storage/innodb_plugin/row/row0sel.c'
--- a/storage/innodb_plugin/row/row0sel.c	2010-06-30 09:38:47 +0000
+++ b/storage/innodb_plugin/row/row0sel.c	2010-08-18 11:01:10 +0000
@@ -2690,7 +2690,6 @@ row_sel_store_mysql_rec(
 	ut_ad(prebuilt->mysql_template);
 	ut_ad(prebuilt->default_rec);
 	ut_ad(rec_offs_validate(rec, NULL, offsets));
-	ut_ad(!rec_get_deleted_flag(rec, rec_offs_comp(offsets)));
 
 	if (UNIV_LIKELY_NULL(prebuilt->blob_heap)) {
 		mem_heap_free(prebuilt->blob_heap);
@@ -3611,6 +3610,7 @@ row_search_for_mysql(
 				row_sel_try_search_shortcut_for_mysql().
 				The latch will not be released until
 				mtr_commit(&mtr). */
+				ut_ad(!rec_get_deleted_flag(rec, comp));
 
 				if (!row_sel_store_mysql_rec(buf, prebuilt,
 							     rec, offsets)) {
@@ -4238,7 +4238,7 @@ no_gap_lock:
 
 				rec = old_vers;
 			}
-		} else if (!lock_sec_rec_cons_read_sees(rec, trx->read_view)) {
+		} else {
 			/* We are looking into a non-clustered index,
 			and to get the right version of the record we
 			have to look also into the clustered index: this
@@ -4246,8 +4246,12 @@ no_gap_lock:
 			information via the clustered index record. */
 
 			ut_ad(index != clust_index);
+			ut_ad(!dict_index_is_clust(index));
 
-			goto requires_clust_rec;
+			if (!lock_sec_rec_cons_read_sees(
+				    rec, trx->read_view)) {
+				goto requires_clust_rec;
+			}
 		}
 	}
 
@@ -4370,8 +4374,13 @@ requires_clust_rec:
 						  ULINT_UNDEFINED, &heap);
 			result_rec = rec;
 		}
+
+		/* result_rec can legitimately be delete-marked
+		now that it has been established that it points to a
+		clustered index record that exists in the read view. */
 	} else {
 		result_rec = rec;
+		ut_ad(!rec_get_deleted_flag(rec, comp));
 	}
 
 	/* We found a qualifying record 'result_rec'. At this point,

=== modified file 'storage/innodb_plugin/row/row0upd.c'
--- a/storage/innodb_plugin/row/row0upd.c	2010-06-29 13:00:58 +0000
+++ b/storage/innodb_plugin/row/row0upd.c	2010-08-05 09:18:17 +0000
@@ -1598,6 +1598,7 @@ row_upd_clust_rec_by_insert(
 	dict_table_t*	table;
 	dtuple_t*	entry;
 	ulint		err;
+	ibool		change_ownership = FALSE;
 
 	ut_ad(node);
 	ut_ad(dict_index_is_clust(index));
@@ -1630,9 +1631,9 @@ row_upd_clust_rec_by_insert(
 		index = dict_table_get_first_index(table);
 		offsets = rec_get_offsets(rec, index, offsets_,
 					  ULINT_UNDEFINED, &heap);
-		btr_cur_mark_extern_inherited_fields(
-			btr_cur_get_page_zip(btr_cur),
-			rec, index, offsets, node->update, mtr);
+		change_ownership = btr_cur_mark_extern_inherited_fields(
+			btr_cur_get_page_zip(btr_cur), rec, index, offsets,
+			node->update, mtr);
 		if (check_ref) {
 			/* NOTE that the following call loses
 			the position of pcur ! */
@@ -1661,10 +1662,11 @@ row_upd_clust_rec_by_insert(
 
 	row_upd_index_entry_sys_field(entry, index, DATA_TRX_ID, trx->id);
 
-	if (node->upd_ext) {
+	if (change_ownership) {
 		/* If we return from a lock wait, for example, we may have
 		extern fields marked as not-owned in entry (marked in the
-		if-branch above). We must unmark them. */
+		if-branch above). We must unmark them, take the ownership
+		back. */
 
 		btr_cur_unmark_dtuple_extern_fields(entry);
 

=== modified file 'storage/innodb_plugin/trx/trx0undo.c'
--- a/storage/innodb_plugin/trx/trx0undo.c	2009-11-02 09:42:56 +0000
+++ b/storage/innodb_plugin/trx/trx0undo.c	2010-08-20 02:55:52 +0000
@@ -1938,7 +1938,8 @@ trx_undo_update_cleanup(
 
 		UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_cached, undo);
 	} else {
-		ut_ad(undo->state == TRX_UNDO_TO_PURGE);
+		ut_ad(undo->state == TRX_UNDO_TO_PURGE
+		      || undo->state == TRX_UNDO_TO_FREE);
 
 		trx_undo_mem_free(undo);
 	}

=== modified file 'storage/innodb_plugin/ut/ut0mem.c'
--- a/storage/innodb_plugin/ut/ut0mem.c	2009-11-02 09:42:56 +0000
+++ b/storage/innodb_plugin/ut/ut0mem.c	2010-08-04 03:20:55 +0000
@@ -290,7 +290,8 @@ ut_test_malloc(
 #endif /* !UNIV_HOTBACKUP */
 
 /**********************************************************************//**
-Frees a memory block allocated with ut_malloc. */
+Frees a memory block allocated with ut_malloc. Freeing a NULL pointer is
+a nop. */
 UNIV_INTERN
 void
 ut_free(
@@ -300,7 +301,9 @@ ut_free(
 #ifndef UNIV_HOTBACKUP
 	ut_mem_block_t* block;
 
-	if (UNIV_LIKELY(srv_use_sys_malloc)) {
+	if (ptr == NULL) {
+		return;
+	} else if (UNIV_LIKELY(srv_use_sys_malloc)) {
 		free(ptr);
 		return;
 	}

=== modified file 'support-files/my-innodb-heavy-4G.cnf.sh'
--- a/support-files/my-innodb-heavy-4G.cnf.sh	2009-03-31 14:04:01 +0000
+++ b/support-files/my-innodb-heavy-4G.cnf.sh	2010-08-06 12:56:23 +0000
@@ -109,6 +109,16 @@ binlog_cache_size = 1M
 # table which could otherwise use up all memory resources.
 max_heap_table_size = 64M
 
+# Size of the buffer used for doing full table scans.
+# Allocated per thread, if a full scan is needed.
+read_buffer_size = 2M
+
+# When reading rows in sorted order after a sort, the rows are read
+# through this buffer to avoid disk seeks. You can improve ORDER BY
+# performance a lot, if set this to a high value.
+# Allocated per thread, when needed.
+read_rnd_buffer_size = 16M
+
 # Sort buffer is used to perform sorts for some ORDER BY and GROUP BY
 # queries. If sorted data does not fit into the sort buffer, a disk
 # based merge sort is used instead - See the "Sort_merge_passes"
@@ -310,16 +320,6 @@ server-id = 1
 # used for internal temporary disk tables.
 key_buffer_size = 32M
 
-# Size of the buffer used for doing full table scans of MyISAM tables.
-# Allocated per thread, if a full scan is needed.
-read_buffer_size = 2M
-
-# When reading rows in sorted order after a sort, the rows are read
-# through this buffer to avoid disk seeks. You can improve ORDER BY
-# performance a lot, if set this to a high value.
-# Allocated per thread, when needed.
-read_rnd_buffer_size = 16M
-
 # MyISAM uses special tree-like cache to make bulk inserts (that is,
 # INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA
 # INFILE) faster. This variable limits the size of the cache tree in


Attachment: [text/bzr-bundle] bzr/sunanda.menon@sun.com-20100928083322-wangbv97uobu7g66.bundle
Thread
bzr push into mysql-5.1 branch (sunanda.menon:3469 to 3470) smenon28 Sep