List:Commits« Previous MessageNext Message »
From:Joerg Bruehe Date:May 29 2009 3:10pm
Subject:bzr push into mysql-5.1 branch (joerg:2860 to 2862)
View as plain text  
 2862 Joerg Bruehe	2009-05-29 [merge]
      Merge up 5.0-build into 5.1-build:
      mostly just the merge changesets,
      but also a change of Perl scripts to use "/usr/bin/perl" fixed.

    modified:
      scripts/mysql_find_rows.sh
      scripts/mysql_fix_extensions.sh
      scripts/mysql_setpermission.sh
      scripts/mysql_zap.sh
      scripts/mysqlaccess.sh
      sql-bench/as3ap.sh
      sql-bench/bench-count-distinct.sh
      sql-bench/bench-init.pl.sh
      sql-bench/compare-results.sh
      sql-bench/copy-db.sh
      sql-bench/crash-me.sh
      sql-bench/innotest1.sh
      sql-bench/innotest1a.sh
      sql-bench/innotest1b.sh
      sql-bench/innotest2.sh
      sql-bench/innotest2a.sh
      sql-bench/innotest2b.sh
      sql-bench/run-all-tests.sh
      sql-bench/server-cfg.sh
      sql-bench/test-ATIS.sh
      sql-bench/test-alter-table.sh
      sql-bench/test-big-tables.sh
      sql-bench/test-connect.sh
      sql-bench/test-create.sh
      sql-bench/test-insert.sh
      sql-bench/test-select.sh
      sql-bench/test-transactions.sh
      sql-bench/test-wisconsin.sh
 2861 Joerg Bruehe	2009-05-29 [merge]
      Merge main 5.1 into 5.1-build

    removed:
      mysql-test/include/diff_tables.inc
    added:
      mysql-test/include/diff_tables.inc
      mysql-test/include/mysqldump.inc
      mysql-test/r/innodb_bug42101-nonzero.result
      mysql-test/r/innodb_bug42101.result
      mysql-test/r/mysqldump_restore.result
      mysql-test/suite/binlog/r/binlog_incident.result
      mysql-test/suite/binlog/r/binlog_tbl_metadata.result
      mysql-test/suite/binlog/t/binlog_incident-master.opt
      mysql-test/suite/binlog/t/binlog_incident.test
      mysql-test/suite/binlog/t/binlog_tbl_metadata.test
      mysql-test/suite/ibmdb2i/include/have_i54.inc
      mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44232.result
      mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44610.result
      mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44232.test
      mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44610.test
      mysql-test/t/innodb_bug42101-nonzero-master.opt
      mysql-test/t/innodb_bug42101-nonzero.test
      mysql-test/t/innodb_bug42101.test
      mysql-test/t/mysqldump_restore.test
    modified:
      CMakeLists.txt
      client/mysql.cc
      client/mysql_upgrade.c
      client/mysqladmin.cc
      client/mysqlbinlog.cc
      client/mysqlcheck.c
      client/mysqldump.c
      client/mysqlimport.c
      client/mysqlshow.c
      client/mysqlslap.c
      client/mysqltest.cc
      extra/innochecksum.c
      extra/perror.c
      include/myisam.h
      mysql-test/include/concurrent.inc
      mysql-test/include/grant_cache.inc
      mysql-test/include/handler.inc
      mysql-test/include/mix1.inc
      mysql-test/include/mtr_check.sql
      mysql-test/include/query_cache.inc
      mysql-test/lib/My/CoreDump.pm
      mysql-test/lib/My/File/Path.pm
      mysql-test/lib/My/SafeProcess.pm
      mysql-test/lib/My/SafeProcess/Base.pm
      mysql-test/lib/My/SafeProcess/safe_process_win.cc
      mysql-test/lib/mtr_cases.pm
      mysql-test/lib/mtr_process.pl
      mysql-test/lib/mtr_report.pm
      mysql-test/lib/mtr_unique.pm
      mysql-test/mysql-test-run.pl
      mysql-test/r/cast.result
      mysql-test/r/concurrent_innodb_safelog.result
      mysql-test/r/concurrent_innodb_unsafelog.result
      mysql-test/r/consistent_snapshot.result
      mysql-test/r/ctype_cp932_binlog_stm.result
      mysql-test/r/ctype_sjis.result
      mysql-test/r/ddl_i18n_koi8r.result
      mysql-test/r/ddl_i18n_utf8.result
      mysql-test/r/distinct.result
      mysql-test/r/events_stress.result
      mysql-test/r/func_compress.result
      mysql-test/r/func_concat.result
      mysql-test/r/func_in.result
      mysql-test/r/func_math.result
      mysql-test/r/func_str.result
      mysql-test/r/grant_cache_no_prot.result
      mysql-test/r/grant_cache_ps_prot.result
      mysql-test/r/heap_btree.result
      mysql-test/r/information_schema_db.result
      mysql-test/r/init_file.result
      mysql-test/r/innodb_mysql.result
      mysql-test/r/insert_select.result
      mysql-test/r/mysql.result
      mysql-test/r/mysqlbinlog.result
      mysql-test/r/openssl_1.result
      mysql-test/r/subselect3.result
      mysql-test/r/type_time.result
      mysql-test/r/union.result
      mysql-test/r/user_var.result
      mysql-test/r/variables.result
      mysql-test/r/view.result
      mysql-test/suite/binlog/r/binlog_stm_ps.result
      mysql-test/suite/binlog/r/binlog_unsafe.result
      mysql-test/suite/binlog/t/binlog_unsafe.test
      mysql-test/suite/funcs_1/datadict/is_routines.inc
      mysql-test/suite/funcs_1/r/is_routines.result
      mysql-test/suite/rpl/r/rpl_slave_load_tmpdir_not_exist.result
      mysql-test/suite/rpl/r/rpl_slave_skip.result
      mysql-test/suite/rpl/r/rpl_stm_loadfile.result
      mysql-test/suite/rpl/r/rpl_temporary.result
      mysql-test/suite/rpl/r/rpl_udf.result
      mysql-test/suite/rpl/t/disabled.def
      mysql-test/suite/rpl/t/rpl_incident.test
      mysql-test/suite/rpl/t/rpl_slave_load_tmpdir_not_exist.test
      mysql-test/suite/rpl/t/rpl_temporary.test
      mysql-test/suite/rpl_ndb/t/rpl_ndb_2other-slave.opt
      mysql-test/suite/sys_vars/r/innodb_data_home_dir_basic.result
      mysql-test/suite/sys_vars/r/innodb_flush_method_basic.result
      mysql-test/suite/sys_vars/r/rpl_init_slave_func.result
      mysql-test/suite/sys_vars/r/ssl_capath_basic.result
      mysql-test/suite/sys_vars/r/ssl_cipher_basic.result
      mysql-test/suite/sys_vars/t/innodb_data_home_dir_basic.test
      mysql-test/suite/sys_vars/t/innodb_flush_method_basic.test
      mysql-test/suite/sys_vars/t/ssl_capath_basic.test
      mysql-test/suite/sys_vars/t/ssl_cipher_basic.test
      mysql-test/t/archive_bitfield.test
      mysql-test/t/cast.test
      mysql-test/t/client_xml.test
      mysql-test/t/consistent_snapshot.test
      mysql-test/t/csv.test
      mysql-test/t/ctype_cp932_binlog_stm.test
      mysql-test/t/ctype_sjis.test
      mysql-test/t/ddl_i18n_koi8r.test
      mysql-test/t/ddl_i18n_utf8.test
      mysql-test/t/derived.test
      mysql-test/t/disabled.def
      mysql-test/t/drop.test
      mysql-test/t/events_grant.test
      mysql-test/t/events_stress.test
      mysql-test/t/events_trans_notembedded.test
      mysql-test/t/fix_priv_tables.test
      mysql-test/t/flush.test
      mysql-test/t/func_compress.test
      mysql-test/t/func_concat.test
      mysql-test/t/func_in.test
      mysql-test/t/func_math.test
      mysql-test/t/func_str.test
      mysql-test/t/heap_btree.test
      mysql-test/t/information_schema_db.test
      mysql-test/t/init_file.test
      mysql-test/t/innodb_mysql.test
      mysql-test/t/insert_select.test
      mysql-test/t/lowercase_fs_off.test
      mysql-test/t/mysql.test
      mysql-test/t/mysqlbinlog.test
      mysql-test/t/mysqldump.test
      mysql-test/t/openssl_1.test
      mysql-test/t/subselect3.test
      mysql-test/t/type_time.test
      mysql-test/t/union.test
      mysql-test/t/user_var.test
      mysql-test/t/variables.test
      mysql-test/t/view.test
      mysys/mf_format.c
      mysys/mf_getdate.c
      mysys/my_getopt.c
      scripts/mysql_convert_table_format.sh
      scripts/mysql_zap.sh
      scripts/mysqld_multi.sh
      scripts/mysqld_safe.sh
      scripts/mysqldumpslow.sh
      sql-common/client.c
      sql/field.cc
      sql/handler.h
      sql/item.cc
      sql/item.h
      sql/item_cmpfunc.cc
      sql/item_func.cc
      sql/item_func.h
      sql/item_strfunc.cc
      sql/log_event.cc
      sql/rpl_rli.cc
      sql/share/errmsg.txt
      sql/slave.cc
      sql/sql_acl.cc
      sql/sql_base.cc
      sql/sql_class.cc
      sql/sql_delete.cc
      sql/sql_parse.cc
      sql/sql_plugin.cc
      sql/sql_plugin.h
      sql/sql_prepare.cc
      sql/sql_rename.cc
      sql/sql_select.cc
      sql/sql_string.cc
      sql/sql_table.cc
      sql/sql_union.cc
      sql/sql_update.cc
      sql/table.cc
      sql/unireg.cc
      storage/archive/ha_archive.cc
      storage/federated/ha_federated.cc
      storage/ibmdb2i/db2i_charsetSupport.cc
      storage/ibmdb2i/db2i_conversion.cc
      storage/ibmdb2i/db2i_errors.cc
      storage/ibmdb2i/db2i_errors.h
      storage/ibmdb2i/ha_ibmdb2i.cc
      storage/ibmdb2i/ha_ibmdb2i.h
      storage/innobase/dict/dict0dict.c
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/include/srv0srv.h
      storage/innobase/page/page0cur.c
      storage/innobase/srv/srv0srv.c
      storage/myisam/ha_myisam.cc
      storage/myisam/myisamchk.c
      storage/myisammrg/ha_myisammrg.cc
      storage/ndb/src/kernel/blocks/backup/read.cpp
      strings/ctype-cp932.c
      strings/ctype-sjis.c
      tests/mysql_client_test.c
 2860 Joerg Bruehe	2009-05-15
      Fix a bad merge:
      Remove a cast (which shouldn't have got here anyway)
      which might lose significant bits beyond 4 GB RAM.
     @ mysys/safemalloc.c
        Vlad's comment to the cast:
          pointless cast from size_t to uint that loses
          significant bits, when safe_malloc allocates more than 4GB Ram.
          safemalloc is not used in release binaries,
          so it is not absolutely critical.
        
        It got into the sources by a wrong merge resolution.

    modified:
      mysys/safemalloc.c
=== modified file 'CMakeLists.txt'
--- a/CMakeLists.txt	2009-02-25 16:02:34 +0000
+++ b/CMakeLists.txt	2009-05-27 15:14:09 +0000
@@ -47,6 +47,10 @@ SET(WITH_MYISAMMRG_STORAGE_ENGINE TRUE)
 ADD_DEFINITIONS(-DWITH_MYISAMMRG_STORAGE_ENGINE)
 SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_myisammrg_plugin")
 
+IF(WITH_COMMUNITY_FEATURES)
+  ADD_DEFINITIONS(-DENABLED_PROFILING -DCOMMUNITY_SERVER)
+ENDIF(WITH_COMMUNITY_FEATURES)
+
 IF(WITH_ARCHIVE_STORAGE_ENGINE)
   ADD_DEFINITIONS(-DWITH_ARCHIVE_STORAGE_ENGINE)
   SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_archive_plugin")

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2009-05-08 19:04:07 +0000
+++ b/client/mysql.cc	2009-05-15 13:25:29 +0000
@@ -143,7 +143,8 @@ static my_bool ignore_errors=0,wait_flag
 	       tty_password= 0, opt_nobeep=0, opt_reconnect=1,
 	       default_charset_used= 0, opt_secure_auth= 0,
                default_pager_set= 0, opt_sigint_ignore= 0,
-               show_warnings= 0, executing_query= 0, interrupted_query= 0;
+               show_warnings= 0, executing_query= 0, interrupted_query= 0,
+               ignore_spaces= 0;
 static my_bool debug_info_flag, debug_check_flag;
 static my_bool column_types_flag;
 static my_bool preserve_comments= 0;
@@ -1183,7 +1184,12 @@ int main(int argc,char *argv[])
         histfile= 0;
       }
     }
-    if (histfile)
+
+    /* We used to suggest setting MYSQL_HISTFILE=/dev/null. */
+    if (histfile && strncmp(histfile, "/dev/null", 10) == 0)
+      histfile= NULL;
+
+    if (histfile && histfile[0])
     {
       if (verbose)
 	tee_fprintf(stdout, "Reading history-file %s\n",histfile);
@@ -1218,7 +1224,8 @@ sig_handler mysql_end(int sig)
 {
   mysql_close(&mysql);
 #ifdef HAVE_READLINE
-  if (!status.batch && !quick && !opt_html && !opt_xml && histfile)
+  if (!status.batch && !quick && !opt_html && !opt_xml &&
+      histfile && histfile[0])
   {
     /* write-history */
     if (verbose)
@@ -1345,7 +1352,7 @@ static struct my_option my_long_options[
   {"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
    (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 #endif
-  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
+  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
    (uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"debug-info", 'T', "Print some debug info at exit.", (uchar**) &debug_info_flag,
@@ -1372,8 +1379,9 @@ static struct my_option my_long_options[
   {"no-named-commands", 'g',
    "Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead.",
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"ignore-spaces", 'i', "Ignore space after function names.", 0, 0, 0,
-   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"ignore-spaces", 'i', "Ignore space after function names.",
+   (uchar**) &ignore_spaces, (uchar**) &ignore_spaces, 0, GET_BOOL, NO_ARG, 0, 0,
+   0, 0, 0, 0},
   {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
    (uchar**) &opt_local_infile,
    (uchar**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
@@ -1794,6 +1802,10 @@ static int get_options(int argc, char **
     my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
   if (debug_check_flag)
     my_end_arg= MY_CHECK_ERROR;
+
+  if (ignore_spaces)
+    connect_flag|= CLIENT_IGNORE_SPACE;
+
   return(0);
 }
 
@@ -3381,9 +3393,12 @@ print_table_data_html(MYSQL_RES *result)
   {
     while((field = mysql_fetch_field(result)))
     {
-      tee_fprintf(PAGER, "<TH>%s</TH>", (field->name ? 
-					 (field->name[0] ? field->name : 
-					  " &nbsp; ") : "NULL"));
+      tee_fputs("<TH>", PAGER);
+      if (field->name && field->name[0])
+        xmlencode_print(field->name, field->name_length);
+      else
+        tee_fputs(field->name ? " &nbsp; " : "NULL", PAGER);
+      tee_fputs("</TH>", PAGER);
     }
     (void) tee_fputs("</TR>", PAGER);
   }
@@ -3396,7 +3411,7 @@ print_table_data_html(MYSQL_RES *result)
     for (uint i=0; i < mysql_num_fields(result); i++)
     {
       (void) tee_fputs("<TD>", PAGER);
-      safe_put_field(cur[i],lengths[i]);
+      xmlencode_print(cur[i], lengths[i]);
       (void) tee_fputs("</TD>", PAGER);
     }
     (void) tee_fputs("</TR>", PAGER);

=== modified file 'client/mysql_upgrade.c'
--- a/client/mysql_upgrade.c	2009-03-20 14:27:53 +0000
+++ b/client/mysql_upgrade.c	2009-05-07 17:51:55 +0000
@@ -115,11 +115,11 @@ static struct my_option my_long_options[
 #endif
   {"socket", 'S', "Socket file to use for connection.",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#include <sslopt-longopts.h>
   {"tmpdir", 't', "Directory for temporary files",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"user", 'u', "User for login if not current user.", (uchar**) &opt_user,
    (uchar**) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#include <sslopt-longopts.h>
   {"verbose", 'v', "Display more output about the process",
    (uchar**) &opt_verbose, (uchar**) &opt_verbose, 0,
    GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
@@ -231,6 +231,8 @@ get_one_option(int optid, const struct m
     break;
 
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";			// Don't require password
     tty_password= 1;
     add_option= FALSE;
     if (argument)

=== modified file 'client/mysqladmin.cc'
--- a/client/mysqladmin.cc	2009-02-13 16:41:47 +0000
+++ b/client/mysqladmin.cc	2009-05-07 20:09:53 +0000
@@ -232,6 +232,8 @@ get_one_option(int optid, const struct m
     opt_count_iterations= 1;
     break;
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";			// Don't require password
     if (argument)
     {
       char *start=argument;
@@ -677,10 +679,16 @@ static int execute_commands(MYSQL *mysql
 	pos=argv[1];
 	for (;;)
 	{
-	  if (mysql_kill(mysql,(ulong) atol(pos)))
+          /* We don't use mysql_kill(), since it only handles 32-bit IDs. */
+          char buff[26], *out; /* "KILL " + max 20 digs + NUL */
+          out= strxmov(buff, "KILL ", NullS);
+          ullstr(strtoull(pos, NULL, 0), out);
+
+          if (mysql_query(mysql, buff))
 	  {
-	    my_printf_error(0, "kill failed on %ld; error: '%s'", error_flags,
-			    atol(pos), mysql_error(mysql));
+            /* out still points to just the number */
+	    my_printf_error(0, "kill failed on %s; error: '%s'", error_flags,
+			    out, mysql_error(mysql));
 	    error=1;
 	  }
 	  if (!(pos=strchr(pos,',')))

=== modified file 'client/mysqlbinlog.cc'
--- a/client/mysqlbinlog.cc	2009-02-13 16:41:47 +0000
+++ b/client/mysqlbinlog.cc	2009-05-12 21:27:19 +0000
@@ -1226,6 +1226,8 @@ get_one_option(int optid, const struct m
     one_database = 1;
     break;
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";                     // Don't require password
     if (argument)
     {
       my_free(pass,MYF(MY_ALLOW_ZERO_PTR));
@@ -1529,8 +1531,7 @@ static Exit_status dump_remote_log_entri
       If reading from a remote host, ensure the temp_buf for the
       Log_event class is pointing to the incoming stream.
     */
-    if (remote_opt)
-      ev->register_temp_buf((char*) net->read_pos + 1); 
+    ev->register_temp_buf((char *) net->read_pos + 1);
 
     Log_event_type type= ev->get_type_code();
     if (glob_description_event->binlog_version >= 3 ||

=== modified file 'client/mysqlcheck.c'
--- a/client/mysqlcheck.c	2009-02-13 16:41:47 +0000
+++ b/client/mysqlcheck.c	2009-05-15 13:03:22 +0000
@@ -286,6 +286,8 @@ get_one_option(int optid, const struct m
     what_to_do= DO_UPGRADE;
     break;
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";			// Don't require password
     if (argument)
     {
       char *start = argument;

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2009-03-24 13:58:52 +0000
+++ b/client/mysqldump.c	2009-05-07 17:51:55 +0000
@@ -221,7 +221,7 @@ static struct my_option my_long_options[
    (uchar**) &opt_compatible_mode_str, (uchar**) &opt_compatible_mode_str, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"compact", OPT_COMPACT,
-   "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --no-set-names --skip-disable-keys --skip-add-locks",
+   "Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs.  Enables options --skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys --skip-set-charset",
    (uchar**) &opt_compact, (uchar**) &opt_compact, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"complete-insert", 'c', "Use complete insert statements.",
@@ -702,6 +702,8 @@ get_one_option(int optid, const struct m
     break;
 #endif
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";                     // Don't require password
     if (argument)
     {
       char *start=argument;

=== modified file 'client/mysqlimport.c'
--- a/client/mysqlimport.c	2008-11-14 16:29:38 +0000
+++ b/client/mysqlimport.c	2009-05-07 17:51:55 +0000
@@ -221,6 +221,8 @@ get_one_option(int optid, const struct m
     break;
 #endif
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";			// Don't require password
     if (argument)
     {
       char *start=argument;

=== modified file 'client/mysqlshow.c'
--- a/client/mysqlshow.c	2008-11-14 16:29:38 +0000
+++ b/client/mysqlshow.c	2009-05-07 17:51:55 +0000
@@ -281,6 +281,8 @@ get_one_option(int optid, const struct m
     opt_verbose++;
     break;
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";			// Don't require password
     if (argument)
     {
       char *start=argument;

=== modified file 'client/mysqlslap.c'
--- a/client/mysqlslap.c	2009-02-13 16:41:47 +0000
+++ b/client/mysqlslap.c	2009-05-07 17:51:55 +0000
@@ -712,6 +712,8 @@ get_one_option(int optid, const struct m
     verbose++;
     break;
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";			// Don't require password
     if (argument)
     {
       char *start= argument;

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2009-04-09 09:24:36 +0000
+++ b/client/mysqltest.cc	2009-05-07 17:51:55 +0000
@@ -5665,11 +5665,11 @@ static struct my_option my_long_options[
   {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select",
    (uchar**) &sp_protocol, (uchar**) &sp_protocol, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+#include "sslopt-longopts.h"
   {"tail-lines", OPT_TAIL_LINES,
    "Number of lines of the resul to include in a failure report",
    (uchar**) &opt_tail_lines, (uchar**) &opt_tail_lines, 0,
    GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0},
-#include "sslopt-longopts.h"
   {"test-file", 'x', "Read test from/in this file (default stdin).",
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"timer-file", 'm', "File where the timing in micro seconds is stored.",
@@ -5803,6 +5803,8 @@ get_one_option(int optid, const struct m
     break;
   }
   case 'p':
+    if (argument == disabled_my_option)
+      argument= (char*) "";			// Don't require password
     if (argument)
     {
       my_free(opt_pass, MYF(MY_ALLOW_ZERO_PTR));

=== modified file 'extra/innochecksum.c'
--- a/extra/innochecksum.c	2007-05-10 09:59:39 +0000
+++ b/extra/innochecksum.c	2009-05-05 18:07:26 +0000
@@ -224,7 +224,7 @@ int main(int argc, char **argv)
   }
   else if (verbose)
   {
-    printf("file %s= %llu bytes (%lu pages)...\n", argv[1], size, pages);
+    printf("file %s = %llu bytes (%lu pages)...\n", argv[optind], size, pages);
     printf("checking pages in range %lu to %lu\n", start_page, use_end_page ? end_page : (pages - 1));
   }
 

=== modified file 'extra/perror.c'
--- a/extra/perror.c	2009-02-24 10:33:51 +0000
+++ b/extra/perror.c	2009-04-28 18:16:44 +0000
@@ -115,7 +115,7 @@ static void usage(void)
 {
   print_version();
   puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
-  printf("Print a description for a system error code or an error code from\na MyISAM/ISAM/BDB table handler.\n");
+  printf("Print a description for a system error code or a MySQL error code.\n");
   printf("If you want to get the error for a negative error code, you should use\n-- before the first error code to tell perror that there was no more options.\n\n");
   printf("Usage: %s [OPTIONS] [ERRORCODE [ERRORCODE...]]\n",my_progname);
   my_print_help(my_long_options);

=== modified file 'include/myisam.h'
--- a/include/myisam.h	2009-01-26 06:35:15 +0000
+++ b/include/myisam.h	2009-05-27 08:11:28 +0000
@@ -404,7 +404,8 @@ typedef struct st_mi_check_param
   my_off_t keydata,totaldata,key_blocks,start_check_pos;
   ha_rows total_records,total_deleted;
   ha_checksum record_checksum,glob_crc;
-  ulong	use_buffers,read_buffer_length,write_buffer_length,
+  ulonglong use_buffers;
+  ulong read_buffer_length,write_buffer_length,
 	sort_buffer_length,sort_key_blocks;
   uint out_flag,warning_printed,error_printed,verbose;
   uint opt_sort_key,total_files,max_level;

=== modified file 'mysql-test/include/concurrent.inc'
--- a/mysql-test/include/concurrent.inc	2009-03-18 16:23:39 +0000
+++ b/mysql-test/include/concurrent.inc	2009-05-15 10:15:56 +0000
@@ -659,11 +659,16 @@ drop table t1;
   connection thread1;
   select * from t1;
 
+--echo ** Cleanup
+connection thread1;
+disconnect thread1;
+--source include/wait_until_disconnected.inc
+--echo ** connection thread2
+connection thread2;
+disconnect thread2;
+--source include/wait_until_disconnected.inc
 --echo ** connection default
 connection default;
 drop table t1;
 drop user mysqltest@localhost;
 
-disconnect thread1;
-disconnect thread2;
-

=== added file 'mysql-test/include/diff_tables.inc'
--- a/mysql-test/include/diff_tables.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/diff_tables.inc	2009-05-21 20:03:53 +0000
@@ -0,0 +1,122 @@
+# ==== Purpose ====
+#
+# Check if the two given tables (possibly residing on different
+# master/slave servers) are equal.
+#
+# ==== Usage ====
+#
+# The tables to check are given by the test language variables
+# $diff_table_1 and $diff_table_2.  They must be of the
+# following form:
+#
+#  [master:|slave:]database.table
+#
+# I.e., both database and table must be speicified.  Optionally, you
+# can prefix the name with 'master:' (to read the table on master) or
+# with 'slave:' (to read the table on slave).  If no prefix is given,
+# reads the table from the current connection.  If one of these
+# variables has a prefix, both should have a prefix.
+#
+# ==== Side effects ====
+#
+# - Prints "Comparing tables $diff_table_1 and $diff_tables_2".
+#
+# - If the tables are different, prints the difference in a
+#   system-specific format (unified diff if supported) and generates
+#   an error.
+#
+# - If $diff_table_1 or $diff_table_2 begins with 'master:' or
+#   'slave:', it will stay connected to one of those hosts after
+#   execution.  The host is only guaranteed to remain unchanged if
+#   none of $diff_table_1 or $diff_table_2 begins with 'master:' or
+#   'slave:'.
+#
+# ==== Bugs ====
+#
+# - It is currently not possible to use this for tables that are
+#   supposed to be different, because if the files are different:
+#    - 'diff' produces system-dependent output,
+#    - the output includes the absolute path of the compared files,
+#    - the output includes a timestamp.
+#   To fix that, we'd probably have to use SQL to compute the
+#   symmetric difference between the tables.  I'm not sure how to do
+#   that efficiently.  If we implement this, it would be nice to
+#   compare the table definitions too.
+#
+# - It actually compares the result of "SELECT * FROM table ORDER BY
+#   col1, col2, ..., colN INTO OUTFILE 'file'".  Hence, it is assumed
+#   that the comparison orders for both tables are equal and that two
+#   rows that are equal in the comparison order cannot differ, e.g.,
+#   by character case.
+
+
+# ==== Save both tables to file ====
+
+--echo Comparing tables $diff_table_1 and $diff_table_2
+disable_query_log;
+
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
+
+let $_diff_table=$diff_table_2;
+let $_diff_i=2;
+while ($_diff_i) {
+
+  # Parse out any leading "master:" or "slave:" from the table
+  # specification and connect the appropriate server.
+  let $_diff_conn_master=`SELECT SUBSTR('$_diff_table', 1, 7) = 'master:'`;
+  if ($_diff_conn_master) {
+    let $_diff_table=`SELECT SUBSTR('$_diff_table', 8)`;
+    connection master;
+  }
+  let $_diff_conn_slave=`SELECT SUBSTR('$_diff_table', 1, 6) = 'slave:'`;
+  if ($_diff_conn_slave) {
+    let $_diff_table=`SELECT SUBSTR('$_diff_table', 7)`;
+    connection slave;
+  }
+
+  # Sanity-check the input.
+  let $_diff_error= `SELECT '$_diff_table' NOT LIKE '_%._%'`;
+  if ($_diff_error) {
+    --echo !!!ERROR IN TEST: \$diff_table_$_diff_i='$_diff_table' is not in the form database.table
+    exit;
+  }
+
+  # We need the output files to be sorted (so that diff_files does not
+  # think the files are different just because they are differently
+  # ordered).  To this end, we first generate a query that sorts the
+  # table by all columns.  Since ORDER BY accept column indices, we
+  # just generate a comma-separated list of all numbers from 1 to the
+  # number of columns in the table.
+  let $_diff_column_index=`SELECT MAX(ordinal_position)
+                           FROM information_schema.columns
+                           WHERE CONCAT(table_schema, '.', table_name) =
+                                 '$_diff_table'`;
+  let $_diff_column_list=$_diff_column_index;
+  dec $_diff_column_index;
+  while ($_diff_column_index) {
+    let $_diff_column_list=$_diff_column_index, $_diff_column_list;
+    dec $_diff_column_index;
+  }
+
+  # Now that we have the comma-separated list of columns, we can write
+  # the table to a file.
+  eval SELECT * FROM $_diff_table ORDER BY $_diff_column_list
+              INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/diff_table_$_diff_i';
+
+  # Do the same for $diff_table_1.
+  dec $_diff_i;
+  let $_diff_table=$diff_table_1;
+}
+
+
+# ==== Compare the generated files ====
+
+diff_files $MYSQLTEST_VARDIR/tmp/diff_table_1 $MYSQLTEST_VARDIR/tmp/diff_table_2;
+
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
+--remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
+
+enable_query_log;

=== removed file 'mysql-test/include/diff_tables.inc'
--- a/mysql-test/include/diff_tables.inc	2008-03-07 12:59:36 +0000
+++ b/mysql-test/include/diff_tables.inc	1970-01-01 00:00:00 +0000
@@ -1,122 +0,0 @@
-# ==== Purpose ====
-#
-# Check if the two given tables (possibly residing on different
-# master/slave servers) are equal.
-#
-# ==== Usage ====
-#
-# The tables to check are given by the test language variables
-# $diff_table_1 and $diff_table_2.  They must be of the
-# following form:
-#
-#  [master:|slave:]database.table
-#
-# I.e., both database and table must be speicified.  Optionally, you
-# can prefix the name with 'master:' (to read the table on master) or
-# with 'slave:' (to read the table on slave).  If no prefix is given,
-# reads the table from the current connection.  If one of these
-# variables has a prefix, both should have a prefix.
-#
-# ==== Side effects ====
-#
-# - Prints "Comparing tables $diff_table_1 and $diff_tables_2".
-#
-# - If the tables are different, prints the difference in a
-#   system-specific format (unified diff if supported) and generates
-#   an error.
-#
-# - If $diff_table_1 or $diff_table_2 begins with 'master:' or
-#   'slave:', it will stay connected to one of those hosts after
-#   execution.  The host is only guaranteed to remain unchanged if
-#   none of $diff_table_1 or $diff_table_2 begins with 'master:' or
-#   'slave:'.
-#
-# ==== Bugs ====
-#
-# - It is currently not possible to use this for tables that are
-#   supposed to be different, because if the files are different:
-#    - 'diff' produces system-dependent output,
-#    - the output includes the absolute path of the compared files,
-#    - the output includes a timestamp.
-#   To fix that, we'd probably have to use SQL to compute the
-#   symmetric difference between the tables.  I'm not sure how to do
-#   that efficiently.  If we implement this, it would be nice to
-#   compare the table definitions too.
-#
-# - It actually compares the result of "SELECT * FROM table ORDER BY
-#   col1, col2, ..., colN INTO OUTFILE 'file'".  Hence, it is assumed
-#   that the comparison orders for both tables are equal and that two
-#   rows that are equal in the comparison order cannot differ, e.g.,
-#   by character case.
-
-
-# ==== Save both tables to file ====
-
---echo Comparing tables $diff_table_1 and $diff_table_2
-disable_query_log;
-
---error 0,1
---remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
---error 0,1
---remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
-
-let $_diff_table=$diff_table_2;
-let $_diff_i=2;
-while ($_diff_i) {
-
-  # Parse out any leading "master:" or "slave:" from the table
-  # specification and connect the appropriate server.
-  let $_diff_conn_master=`SELECT SUBSTR('$_diff_table', 1, 7) = 'master:'`;
-  if ($_diff_conn_master) {
-    let $_diff_table=`SELECT SUBSTR('$_diff_table', 8)`;
-    connection master;
-  }
-  let $_diff_conn_slave=`SELECT SUBSTR('$_diff_table', 1, 6) = 'slave:'`;
-  if ($_diff_conn_slave) {
-    let $_diff_table=`SELECT SUBSTR('$_diff_table', 7)`;
-    connection slave;
-  }
-
-  # Sanity-check the input.
-  let $_diff_error= `SELECT '$_diff_table' NOT LIKE '_%._%'`;
-  if ($_diff_error) {
-    --echo !!!ERROR IN TEST: \$diff_table_$_diff_i='$_diff_table' is not in the form database.table
-    exit;
-  }
-
-  # We need the output files to be sorted (so that diff_files does not
-  # think the files are different just because they are differently
-  # ordered).  To this end, we first generate a query that sorts the
-  # table by all columns.  Since ORDER BY accept column indices, we
-  # just generate a comma-separated list of all numbers from 1 to the
-  # number of columns in the table.
-  let $_diff_column_index=`SELECT MAX(ordinal_position)
-                           FROM information_schema.columns
-                           WHERE CONCAT(table_schema, '.', table_name) =
-                                 '$_diff_table'`;
-  let $_diff_column_list=$_diff_column_index;
-  dec $_diff_column_index;
-  while ($_diff_column_index) {
-    let $_diff_column_list=$_diff_column_index, $_diff_column_list;
-    dec $_diff_column_index;
-  }
-
-  # Now that we have the comma-separated list of columns, we can write
-  # the table to a file.
-  eval SELECT * FROM $_diff_table ORDER BY $_diff_column_list
-              INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/diff_table_$_diff_i';
-
-  # Do the same for $diff_table_1.
-  dec $_diff_i;
-  let $_diff_table=$diff_table_1;
-}
-
-
-# ==== Compare the generated files ====
-
-diff_files $MYSQLTEST_VARDIR/tmp/diff_table_1 $MYSQLTEST_VARDIR/tmp/diff_table_2;
-
---remove_file $MYSQLTEST_VARDIR/tmp/diff_table_1
---remove_file $MYSQLTEST_VARDIR/tmp/diff_table_2
-
-enable_query_log;

=== modified file 'mysql-test/include/grant_cache.inc'
--- a/mysql-test/include/grant_cache.inc	2008-09-03 14:45:40 +0000
+++ b/mysql-test/include/grant_cache.inc	2009-05-20 13:27:44 +0000
@@ -171,15 +171,30 @@ show status like "Qcache_not_cached";
 
 # Cleanup
 
---echo ----- switch to connection default and close connections -----
-connection default;
+--echo ----- close connections -----
+connection root;
 disconnect root;
+--source include/wait_until_disconnected.inc
+connection root2;
 disconnect root2;
+--source include/wait_until_disconnected.inc
+connection user1;
 disconnect user1;
+--source include/wait_until_disconnected.inc
+connection user2;
 disconnect user2;
+--source include/wait_until_disconnected.inc
+connection user3;
 disconnect user3;
+--source include/wait_until_disconnected.inc
+connection user4;
 disconnect user4;
+--source include/wait_until_disconnected.inc
+connection unkuser;
 disconnect unkuser;
+--source include/wait_until_disconnected.inc
+--echo ----- switch to connection default -----
+connection default;
 
 #
 # A temporary 4.1 workaround to make this test pass if

=== modified file 'mysql-test/include/handler.inc'
--- a/mysql-test/include/handler.inc	2009-04-17 08:46:27 +0000
+++ b/mysql-test/include/handler.inc	2009-05-15 10:15:56 +0000
@@ -719,6 +719,7 @@ connection con1;
 --reap
 drop table t1;
 disconnect con1;
+--source include/wait_until_disconnected.inc
 connection default;
 
 #

=== modified file 'mysql-test/include/mix1.inc'
--- a/mysql-test/include/mix1.inc	2009-05-13 07:51:39 +0000
+++ b/mysql-test/include/mix1.inc	2009-05-25 08:00:40 +0000
@@ -1162,6 +1162,15 @@ ROLLBACK;
 --error 1305
 ROLLBACK TO SAVEPOINT s4;
 
+#
+# Bug#39793 Foreign keys not constructed when column has a '#' in a comment or default value
+#
+
+#This statement should be written on a single line for proper testing
+CREATE TABLE t1 (f1 INTEGER PRIMARY KEY COMMENT 'My ID#', f2 INTEGER DEFAULT NULL, f3 CHAR(10) DEFAULT 'My ID#', CONSTRAINT f2_ref FOREIGN KEY (f2) REFERENCES t1 (f1)) ENGINE=INNODB;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
 --echo End of 5.0 tests
 
 # Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY
@@ -1535,4 +1544,31 @@ SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
 
 DROP TABLE t1;
 
+eval
+CREATE TABLE t1 (c1 REAL, c2 REAL, c3 REAL, KEY (c3), KEY (c2, c3))
+  ENGINE=$engine_type;
+INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
+
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+                 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+EXPLAIN 
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+                 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+
+DROP TABLE t1;
+
+eval
+CREATE TABLE t1 (c1 DECIMAL(12,2), c2 DECIMAL(12,2), c3 DECIMAL(12,2), 
+  KEY (c3), KEY (c2, c3))
+  ENGINE=$engine_type;
+INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
+
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+                 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+EXPLAIN 
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+                 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/include/mtr_check.sql'
--- a/mysql-test/include/mtr_check.sql	2009-02-01 09:18:09 +0000
+++ b/mysql-test/include/mtr_check.sql	2009-03-31 13:39:40 +0000
@@ -57,3 +57,13 @@ BEGIN
     mysql.user;
 
 END||
+
+--
+-- Procedure used by test case used to force all
+-- servers to restart after testcase and thus skipping
+-- check test case after test
+--
+CREATE DEFINER=root@localhost PROCEDURE force_restart()
+BEGIN
+  SELECT 1 INTO OUTFILE 'force_restart';
+END||

=== added file 'mysql-test/include/mysqldump.inc'
--- a/mysql-test/include/mysqldump.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/mysqldump.inc	2009-05-22 14:38:17 +0000
@@ -0,0 +1,50 @@
+################################################################################
+# mysqldump.inc
+#
+# SUMMARY: include file to facilitate testing the quality of mysqldump output
+#
+# INPUTS:  Two variables:
+#          $table_name - the name of the table that was dumped
+#          $mysqldumpfile - the name of the file that captured mysqldump output
+#
+# OUTPUTS: minor echo data:
+#          We 'echo' some stage information to the .result file:
+#          'altering original table', 'restoring from dumpfile', 'comparing'
+#
+# OTHER FILES:  We use include/diff_tables.inc to compare the original, renamed
+#               table with the 'restored' one. 
+#
+# DESCRIPTION: This file works by being fed the name of the original table
+#              and a mysqldump output file.  The original table is then renamed
+#              to <table_name>_orig, the mysqldump file is used to recreate the
+#              table, then diff_tables.inc is called to compare them.
+#
+# LIMITATIONS:  Does *NOT* work with xml output!
+#
+# AUTHOR: pcrews 2009-05-21
+#                Bug#40465 mysqldump.test does no checking of dump or restore
+#
+# LAST CHANGE: 2009-05-21 
+#
+################################################################################
+
+--echo # Begin testing mysqldump output + restore
+--echo # Create 'original table name - <table>_orig
+# NOTE: We use SET then let as query_get_value has issues with the extra commas
+#       used in the CONCAT statement.
+eval SET @orig_table_name = CONCAT('$table_name', '_orig');
+let $orig_table_name = query_get_value(SELECT @orig_table_name,@orig_table_name,1);
+--echo # Rename original table
+eval ALTER TABLE $table_name RENAME to $orig_table_name;
+--echo # Recreate table from mysqldump output
+--exec $MYSQL test < $mysqldumpfile
+--echo # Compare original and recreated tables
+--echo # Recreated table: $table_name
+--echo # Original table: $orig_table_name
+let $diff_table_1 = $table_name;
+let $diff_table_2 = $orig_table_name;
+--source include/diff_tables.inc
+--echo # Cleanup
+--remove_file $mysqldumpfile
+eval DROP TABLE $table_name, $orig_table_name;
+

=== modified file 'mysql-test/include/query_cache.inc'
--- a/mysql-test/include/query_cache.inc	2008-11-13 19:19:00 +0000
+++ b/mysql-test/include/query_cache.inc	2009-05-15 10:15:56 +0000
@@ -177,6 +177,7 @@ show status like "Qcache_hits";
 
 # Final cleanup
 eval set GLOBAL query_cache_size=$save_query_cache_size;
+disconnect connection1;
+--source include/wait_until_disconnected.inc
 connection default;
 drop table t2;
-disconnect connection1;

=== modified file 'mysql-test/lib/My/CoreDump.pm'
--- a/mysql-test/lib/My/CoreDump.pm	2009-02-12 16:13:56 +0000
+++ b/mysql-test/lib/My/CoreDump.pm	2009-03-24 13:44:21 +0000
@@ -22,6 +22,33 @@ use My::Platform;
 
 use File::Temp qw/ tempfile tempdir /;
 
+my $hint_mysqld;		# Last resort guess for executable path
+
+# If path in core file is 79 chars we assume it's been truncated
+# Looks like we can still find the full path using 'strings'
+# If that doesn't work, use the hint (mysqld path) as last resort.
+
+sub _verify_binpath {
+  my ($binary, $core_name)= @_;
+  my $binpath;
+
+  if (length $binary != 79) {
+    $binpath= $binary;
+    print "Core generated by '$binpath'\n";
+  } else {
+    # Last occurrence of path ending in /mysql*, cut from first /
+    if (`strings '$core_name' | grep "/mysql[^/. ]*\$" | tail -1` =~ /(\/.*)/) {
+      $binpath= $1;
+      print "Guessing that core was generated by '$binpath'\n";
+    } else {
+      return unless $hint_mysqld;
+      $binpath= $hint_mysqld;
+      print "Wild guess that core was generated by '$binpath'\n";
+    }
+  }
+  return $binpath;
+}
+
 sub _gdb {
   my ($core_name)= @_;
 
@@ -33,7 +60,8 @@ sub _gdb {
   `gdb -c '$core_name' --batch 2>&1` =~
     /Core was generated by `([^\s\'\`]+)/;
   my $binary= $1 or return;
-  print "Core generated by '$binary'\n";
+
+  $binary= _verify_binpath ($binary, $core_name) or return;
 
   # Create tempfile containing gdb commands
   my ($tmp, $tmp_name) = tempfile();
@@ -73,7 +101,8 @@ sub _dbx {
   `echo | dbx - '$core_name' 2>&1` =~
     /Corefile specified executable: "([^"]+)"/;
   my $binary= $1 or return;
-  print "Core generated by '$binary'\n";
+
+  $binary= _verify_binpath ($binary, $core_name) or return;
 
   # Find all threads
   my @thr_ids = `echo threads | dbx '$binary' '$core_name' 2>&1` =~ /t@\d+/g;
@@ -203,7 +232,7 @@ sub _cdb {
 
   my $cdb_cmd = "!sym prompts off; !analyze -v; .ecxr; !for_each_frame dv /t;!uniqstack -p;q";
   my $cdb_output=
-    `cdb -z $core_name -i "$image_path" -y "$symbol_path" -t 0 -lines -c "$cdb_cmd" 2>&1`;
+    `cdb -c "$cdb_cmd" -z $core_name -i "$image_path" -y "$symbol_path" -t 0 -lines 2>&1`;
   return if $? >> 8;
   return unless $cdb_output;
   
@@ -225,7 +254,8 @@ EOF
 
 
 sub show {
-  my ($class, $core_name)= @_;
+  my ($class, $core_name, $exe_mysqld)= @_;
+  $hint_mysqld= $exe_mysqld;
 
   # On Windows, rely on cdb to be there...
   if (IS_WINDOWS)

=== modified file 'mysql-test/lib/My/File/Path.pm'
--- a/mysql-test/lib/My/File/Path.pm	2009-01-24 14:07:57 +0000
+++ b/mysql-test/lib/My/File/Path.pm	2009-04-01 14:23:10 +0000
@@ -164,6 +164,9 @@ sub copytree {
       copytree("$from_dir/$_", "$to_dir/$_");
       next;
     }
+
+    # Only copy plain files
+    next unless -f "$from_dir/$_";
     copy("$from_dir/$_", "$to_dir/$_");
   }
   closedir(DIR);

=== modified file 'mysql-test/lib/My/SafeProcess.pm'
--- a/mysql-test/lib/My/SafeProcess.pm	2009-03-09 13:31:39 +0000
+++ b/mysql-test/lib/My/SafeProcess.pm	2009-04-29 14:13:38 +0000
@@ -536,7 +536,37 @@ sub wait_any {
   return $proc;
 }
 
+
+#
+# Wait for all processes to exit
+#
+sub wait_all {
+  while(keys %running)
+  {
+    wait_any();
+  }
+}
+
+
 #
+# Check if any process has exited, but don't wait.
+#
+# Returns a reference to the SafeProcess that
+# exited or undefined
+#
+sub check_any {
+  for my $proc (values %running){
+    if ( $proc->is_child($$) ) {
+      if (not $proc->wait_one(0)) {
+	_verbose ("Found exited $proc");
+	return $proc;
+      }
+    }
+  }
+  return undef;
+}
+
+
 # Overload string operator
 # and fallback to default functions if no
 # overloaded function is found

=== modified file 'mysql-test/lib/My/SafeProcess/Base.pm'
--- a/mysql-test/lib/My/SafeProcess/Base.pm	2008-10-08 20:06:10 +0000
+++ b/mysql-test/lib/My/SafeProcess/Base.pm	2009-04-23 11:35:02 +0000
@@ -83,6 +83,13 @@ sub exit_status {
   };
 }
 
+# threads.pm may not exist everywhere, so use only on Windows.
+
+use if $^O eq "MSWin32", "threads";
+use if $^O eq "MSWin32", "threads::shared";
+
+my $win32_spawn_lock :shared;
+
 
 #
 # Create a new process
@@ -104,6 +111,8 @@ sub create_process {
 
   if ($^O eq "MSWin32"){
 
+    lock($win32_spawn_lock);
+
     #printf STDERR "stdin %d, stdout %d, stderr %d\n",
     #    fileno STDIN, fileno STDOUT, fileno STDERR;
 

=== modified file 'mysql-test/lib/My/SafeProcess/safe_process_win.cc'
--- a/mysql-test/lib/My/SafeProcess/safe_process_win.cc	2009-02-09 18:24:48 +0000
+++ b/mysql-test/lib/My/SafeProcess/safe_process_win.cc	2009-05-14 19:56:53 +0000
@@ -259,22 +259,37 @@ int main(int argc, const char** argv )
     the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag, making sure it will be
     terminated when the last handle to it is closed(which is owned by
     this process).
+
+    If breakaway from job fails on some reason, fallback is to create a
+    new process group. Process groups also allow to kill process and its 
+    descedants, subject to some restrictions (processes have to run within
+    the same console,and must not ignore CTRL_BREAK)
   */
-  if (CreateProcess(NULL, (LPSTR)child_args,
+  DWORD create_flags[]= {CREATE_BREAKAWAY_FROM_JOB, CREATE_NEW_PROCESS_GROUP, 0};
+  BOOL process_created= FALSE;
+  BOOL jobobject_assigned= FALSE;
+
+  for (int i=0; i < sizeof(create_flags)/sizeof(create_flags[0]); i++)
+  { 
+    process_created= CreateProcess(NULL, (LPSTR)child_args,
                     NULL,
                     NULL,
                     TRUE, /* inherit handles */
-                    CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB,
+                    CREATE_SUSPENDED | create_flags[i],
                     NULL,
                     NULL,
                     &si,
-                    &process_info) == 0)
-    die("CreateProcess failed");
+                    &process_info);
+    if (process_created)
+    {
+     jobobject_assigned= AssignProcessToJobObject(job_handle, process_info.hProcess);
+     break;
+    }
+  }
 
-  if (AssignProcessToJobObject(job_handle, process_info.hProcess) == 0)
+  if (!process_created)
   {
-    TerminateProcess(process_info.hProcess, 200);
-    die("AssignProcessToJobObject failed");
+    die("CreateProcess failed");
   }
   ResumeThread(process_info.hThread);
   CloseHandle(process_info.hThread);
@@ -312,6 +327,13 @@ int main(int argc, const char** argv )
     message("TerminateJobObject failed");
   CloseHandle(job_handle);
   message("Job terminated and closed");
+
+  if (!jobobject_assigned)
+  {
+    GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, process_info.dwProcessId);
+    TerminateProcess(process_info.hProcess, 202);
+  }
+
   if (wait_res != WAIT_OBJECT_0 + CHILD)
   {
     /* The child has not yet returned, wait for it */

=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	2009-01-21 10:17:16 +0000
+++ b/mysql-test/lib/mtr_cases.pm	2009-05-25 20:58:31 +0000
@@ -33,7 +33,7 @@ our $print_testcases;
 our $skip_rpl;
 our $do_test;
 our $skip_test;
-our $opt_skip_combination;
+our $skip_combinations;
 our $binlog_format;
 our $enable_disabled;
 our $default_storage_engine;
@@ -119,11 +119,22 @@ sub collect_test_cases ($$) {
 	if ( $test->{name} =~ /.*\.$tname/ )
 	{
 	  $found= 1;
+	  last;
 	}
       }
       if ( not $found )
       {
-	mtr_error("Could not find '$tname' in '$suites' suite(s)");
+	mtr_error("Could not find '$tname' in '$suites' suite(s)") unless $sname;
+	# If suite was part of name, find it there
+	my ($this_case) = collect_one_suite($sname, [ $tname ]);
+	if ($this_case)
+        {
+	  push (@$cases, $this_case);
+	}
+	else
+	{
+	  mtr_error("Could not find '$tname' in '$sname' suite");
+        }
       }
     }
   }
@@ -375,7 +386,7 @@ sub collect_one_suite($)
   # Read combinations for this suite and build testcases x combinations
   # if any combinations exists
   # ----------------------------------------------------------------------
-  if ( ! $opt_skip_combination )
+  if ( ! $skip_combinations )
   {
     my @combinations;
     my $combination_file= "$suitedir/combinations";
@@ -887,7 +898,8 @@ sub collect_one_test_case {
   if ( $tinfo->{'innodb_test'} )
   {
     # This is a test that need innodb
-    if ( $::mysqld_variables{'innodb'} ne "TRUE" )
+    if ( $::mysqld_variables{'innodb'} eq "OFF" ||
+         ! exists $::mysqld_variables{'innodb'} )
     {
       # innodb is not supported, skip it
       $tinfo->{'skip'}= 1;

=== modified file 'mysql-test/lib/mtr_process.pl'
--- a/mysql-test/lib/mtr_process.pl	2007-12-12 17:19:24 +0000
+++ b/mysql-test/lib/mtr_process.pl	2009-05-07 23:10:53 +0000
@@ -21,7 +21,25 @@
 use strict;
 use Socket;
 use Errno;
+use My::Platform;
+use if IS_WINDOWS, "Net::Ping";
 
+# Ancient perl might not have port_number method for Net::Ping.
+# Check it and use fallback to connect() if it is not present.
+BEGIN 
+{
+  my $use_netping= 0;
+  if (IS_WINDOWS)
+  {
+    my $ping = Net::Ping->new();
+    if ($ping->can("port_number"))
+    {
+      $use_netping= 1;
+    }
+  }
+  eval 'sub USE_NETPING { $use_netping }';
+}
+  
 sub sleep_until_file_created ($$$);
 sub mtr_ping_port ($);
 
@@ -30,6 +48,24 @@ sub mtr_ping_port ($) {
 
   mtr_verbose("mtr_ping_port: $port");
 
+  if (IS_WINDOWS && USE_NETPING)
+  {
+    # Under Windows, connect to a port that is not open is slow
+    # It takes ~1sec. Net::Ping with small timeout is much faster.
+    my $ping = Net::Ping->new();
+    $ping->port_number($port);
+    if ($ping->ping("localhost",0.1))
+    {
+      mtr_verbose("USED");
+      return 1;
+    }
+    else
+    {
+      mtr_verbose("FREE");
+      return 0;
+    }
+  }
+  
   my $remote= "localhost";
   my $iaddr=  inet_aton($remote);
   if ( ! $iaddr )

=== modified file 'mysql-test/lib/mtr_report.pm'
--- a/mysql-test/lib/mtr_report.pm	2009-03-09 11:59:34 +0000
+++ b/mysql-test/lib/mtr_report.pm	2009-04-23 11:35:02 +0000
@@ -30,6 +30,8 @@ our @EXPORT= qw(report_option mtr_print_
 		mtr_report_test);
 
 use mtr_match;
+use My::Platform;
+use POSIX qw[ _exit ];
 require "mtr_io.pl";
 
 my $tot_real_time= 0;
@@ -257,6 +259,17 @@ sub mtr_report_stats ($) {
       $tot_restarts++;
     }
 
+    # Add counts for repeated runs, if any.
+    # Note that the last run has already been counted above.
+    my $num_repeat = $tinfo->{'repeat'} - 1;
+    if ( $num_repeat > 0 )
+    {
+      $tot_tests += $num_repeat;
+      my $rep_failed = $tinfo->{'rep_failures'} || 0;
+      $tot_failed += $rep_failed;
+      $tot_passed += $num_repeat - $rep_failed;
+    }
+
     # Look for warnings produced by mysqltest
     my $base_file= mtr_match_extension($tinfo->{'result_file'},
 				       "result"); # Trim extension
@@ -336,7 +349,7 @@ sub mtr_report_stats ($) {
     foreach my $tinfo (@$tests)
     {
       my $tname= $tinfo->{'name'};
-      if ( $tinfo->{failures} and ! $seen{$tname})
+      if ( ($tinfo->{failures} || $tinfo->{rep_failures}) and ! $seen{$tname})
       {
         print " $tname";
 	$seen{$tname}= 1;
@@ -459,7 +472,14 @@ sub mtr_warning (@) {
 sub mtr_error (@) {
   print STDERR _name(), _timestamp(),
     "mysql-test-run: *** ERROR: ", join(" ", @_), "\n";
-  exit(1);
+  if (IS_WINDOWS)
+  {
+    POSIX::_exit(1);
+  }
+  else
+  {
+    exit(1);
+  }
 }
 
 

=== modified file 'mysql-test/lib/mtr_unique.pm'
--- a/mysql-test/lib/mtr_unique.pm	2009-03-04 10:34:47 +0000
+++ b/mysql-test/lib/mtr_unique.pm	2009-04-23 11:35:02 +0000
@@ -28,32 +28,36 @@ sub msg {
  # print "### unique($$) - ", join(" ", @_), "\n";
 }
 
-my $file;
+my $dir;
 
 if(!IS_WINDOWS)
 {
-  $file= "/tmp/mysql-test-ports";
+  $dir= "/tmp/mysql-unique-ids";
 }
 else
 {
-  $file= $ENV{'TEMP'}."/mysql-test-ports";
+  # Try to use machine-wide directory location for unique IDs,
+  # $ALLUSERSPROFILE . IF it is not available, fallback to $TEMP
+  # which is typically a per-user temporary directory
+  if (exists $ENV{'ALLUSERSPROFILE'} && -w $ENV{'ALLUSERSPROFILE'})
+  {
+    $dir= $ENV{'ALLUSERSPROFILE'}."/mysql-unique-ids";
+  }
+  else
+  {
+    $dir= $ENV{'TEMP'}."/mysql-unique-ids";
+  }
 }
-  
 
-my %mtr_unique_ids;
+my $mtr_unique_fh = undef;
 
-END {
-  my $allocated_id= $mtr_unique_ids{$$};
-  if (defined $allocated_id)
-  {
-    mtr_release_unique_id($allocated_id);
-  }
-  delete $mtr_unique_ids{$$};
+END
+{
+  mtr_release_unique_id();
 }
 
 #
-# Get a unique, numerical ID, given a file name (where all
-# requested IDs are stored), a minimum and a maximum value.
+# Get a unique, numerical ID in a specified range.
 #
 # If no unique ID within the specified parameters can be
 # obtained, return undef.
@@ -61,135 +65,63 @@ END {
 sub mtr_get_unique_id($$) {
   my ($min, $max)= @_;;
 
-  msg("get, '$file', $min-$max");
-
-  die "Can only get one unique id per process!" if $mtr_unique_ids{$$};
+  msg("get $min-$max, $$");
 
-  my $ret = undef;
-  my $changed = 0;
-
-  if(eval("readlink '$file'") || eval("readlink '$file.sem'")) {
-    die 'lock file is a symbolic link';
-  }
+  die "Can only get one unique id per process!" if defined $mtr_unique_fh;
 
-  chmod 0777, "$file.sem";
-  open SEM, ">", "$file.sem" or die "can't write to $file.sem";
-  flock SEM, LOCK_EX or die "can't lock $file.sem";
-  if(! -e $file) {
-    open FILE, ">", $file or die "can't create $file";
-    close FILE;
-  }
 
-  msg("HAVE THE LOCK");
+  # Make sure our ID directory exists
+  if (! -d $dir)
+  {
+    # If there is a file with the reserved
+    # directory name, just delete the file.
+    if (-e $dir)
+    {
+      unlink($dir);

+    }
 
-  if(eval("readlink '$file'") || eval("readlink '$file.sem'")) {
-    die 'lock file is a symbolic link';
-  }
+    mkdir $dir;
+    chmod 0777, $dir;
 
-  chmod 0777, $file;
-  open FILE, "+<", $file or die "can't open $file";
-  #select undef,undef,undef,0.2;
-  seek FILE, 0, 0;
-  my %taken = ();
-  while(<FILE>) {
-    chomp;
-    my ($id, $pid) = split / /;
-    $taken{$id} = $pid;
-    msg("taken: $id, $pid");
-    # Check if process with given pid is alive
-    if(!process_alive($pid)) {
-      print "Removing slot $id used by missing process $pid\n";
-      msg("Removing slot $id used by missing process $pid");
-      delete $taken{$id};
-      $changed++;
+    if(! -d $dir)
+    {
+      die "can't make directory $dir";
     }
   }
-  for(my $i=$min; $i<=$max; ++$i) {
-    if(! exists $taken{$i}) {
-      $ret = $i;
-      $taken{$i} = $$;
-      $changed++;
-      # Remember the id this process got
-      $mtr_unique_ids{$$}= $i;
-      msg(" got $i"); 
-      last;
+
+
+  my $fh;
+  for(my $id = $min; $id <= $max; $id++)
+  {
+    open( $fh, ">$dir/$id");
+    chmod 0666, "$dir/$id";
+    # Try to lock the file exclusively. If lock succeeds, we're done.
+    if (flock($fh, LOCK_EX|LOCK_NB))
+    {
+      # Store file handle - we would need it to release the ID (==unlock the file)
+      $mtr_unique_fh = $fh;
+      return $id;
     }
-  }
-  if($changed) {
-    seek FILE, 0, 0;
-    truncate FILE, 0 or die "can't truncate $file";
-    for my $k (keys %taken) {
-      print FILE $k . ' ' . $taken{$k} . "\n";
+    else
+    {
+      close $fh;
     }
   }
-  close FILE;

-
-  msg("RELEASING THE LOCK");
-  flock SEM, LOCK_UN or warn "can't unlock $file.sem";
-  close SEM;
-
-  return $ret;
+  return undef;
 }
 
 
 #
 # Release a unique ID.
 #
-sub mtr_release_unique_id($) {
-  my ($myid)= @_;
-
-  msg("release, $myid");
-
-
-  if(eval("readlink '$file'") || eval("readlink '$file.sem'")) {
-    die 'lock file is a symbolic link';
-  }
-
-  open SEM, ">", "$file.sem" or die "can't write to $file.sem";
-  flock SEM, LOCK_EX or die "can't lock $file.sem";
-
-  msg("HAVE THE LOCK");
-
-  if(eval("readlink '$file'") || eval("readlink '$file.sem'")) {
-    die 'lock file is a symbolic link';
-  }
-
-  if(! -e $file) {
-    open FILE, ">", $file or die "can't create $file";
-    close FILE;
-  }
-  open FILE, "+<", $file or die "can't open $file";
-  #select undef,undef,undef,0.2;
-  seek FILE, 0, 0;
-  my %taken = ();
-  while(<FILE>) {
-    chomp;
-    my ($id, $pid) = split / /;
-    msg(" taken, $id $pid");
-    $taken{$id} = $pid;
-  }
-
-  if ($taken{$myid} != $$)
+sub mtr_release_unique_id()
+{
+  msg("release $$");
+  if (defined $mtr_unique_fh)
   {
-    msg(" The unique id for this process does not match pid");
+    close $mtr_unique_fh;
+    $mtr_unique_fh = undef;
   }
-
-
-  msg(" removing $myid");
-  delete $taken{$myid};
-  seek FILE, 0, 0;
-  truncate FILE, 0 or die "can't truncate $file";
-  for my $k (keys %taken) {
-    print FILE $k . ' ' . $taken{$k} . "\n";
-  }
-  close FILE;
-
-  msg("RELEASE THE LOCK");
-
-  flock SEM, LOCK_UN or warn "can't unlock $file.sem";
-  close SEM;
-
-  delete $mtr_unique_ids{$$};
 }
 
 

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2009-04-08 23:42:51 +0000
+++ b/mysql-test/mysql-test-run.pl	2009-05-25 20:58:31 +0000
@@ -209,6 +209,7 @@ sub check_timeout { return $opt_testcase
 
 my $opt_start;
 my $opt_start_dirty;
+my $opt_wait_all;
 my $opt_repeat= 1;
 my $opt_retry= 3;
 my $opt_retry_failure= 2;
@@ -429,6 +430,7 @@ sub run_test_server ($$$) {
   my $completed= [];
   my %running;
   my $result;
+  my $exe_mysqld= find_mysqld($basedir) || ""; # Used as hint to CoreDump
 
   my $suite_timeout_proc= My::SafeProcess->timer(suite_timeout());
 
@@ -500,7 +502,7 @@ sub run_test_server ($$$) {
 			   mtr_report(" - found '$core_name'",
 				      "($num_saved_cores/$opt_max_save_core)");
 
-			   My::CoreDump->show($core_file);
+			   My::CoreDump->show($core_file, $exe_mysqld);
 
 			   if ($num_saved_cores >= $opt_max_save_core) {
 			     mtr_report(" - deleting it, already saved",
@@ -515,6 +517,7 @@ sub run_test_server ($$$) {
 	      }
 	    }
 	    $num_saved_datadir++;
+	    $num_failed_test++ unless $result->{retries};
 
 	    if ( !$opt_force ) {
 	      # Test has failed, force is off
@@ -529,7 +532,6 @@ sub run_test_server ($$$) {
 			 "Terminating...");
 	      return undef;
 	    }
-	    $num_failed_test++;
 	  }
 
 	  # Retry test run after test failure
@@ -554,9 +556,11 @@ sub run_test_server ($$$) {
 
 	  # Repeat test $opt_repeat number of times
 	  my $repeat= $result->{repeat} || 1;
-	  if ($repeat < $opt_repeat)
+	  # Don't repeat if test was skipped
+	  if ($repeat < $opt_repeat && $result->{'result'} ne 'MTR_RES_SKIPPED')
 	  {
 	    $result->{retries}= 0;
+	    $result->{rep_failures}++ if $result->{failures};
 	    $result->{failures}= 0;
 	    delete($result->{result});
 	    $result->{repeat}= $repeat+1;
@@ -876,6 +880,7 @@ sub command_line_setup {
              'sleep=i'                  => \$opt_sleep,
              'start-dirty'              => \$opt_start_dirty,
              'start'                    => \$opt_start,
+             'wait-all'                 => \$opt_wait_all,
 	     'print-testcases'          => \&collect_option,
 	     'repeat=i'                 => \$opt_repeat,
 	     'retry=i'                  => \$opt_retry,
@@ -1234,6 +1239,15 @@ sub command_line_setup {
   }
 
   # --------------------------------------------------------------------------
+  # Check use of wait-all
+  # --------------------------------------------------------------------------
+
+  if ($opt_wait_all && ! ($opt_start_dirty || $opt_start))
+  {
+    mtr_error("--wait-all can only be used with --start or --start-dirty");
+  }
+
+  # --------------------------------------------------------------------------
   # Check timeout arguments
   # --------------------------------------------------------------------------
 
@@ -1323,29 +1337,31 @@ sub set_build_thread_ports($) {
 
   if ( lc($opt_build_thread) eq 'auto' ) {
     my $found_free = 0;
-    $build_thread = 250;	# Start attempts from here
+    $build_thread = 300;	# Start attempts from here
     while (! $found_free)
     {
-      $build_thread= mtr_get_unique_id($build_thread, 299);
+      $build_thread= mtr_get_unique_id($build_thread, 349);
       if ( !defined $build_thread ) {
-	mtr_error("Could not get a unique build thread id");
+        mtr_error("Could not get a unique build thread id");
       }
       $found_free= check_ports_free($build_thread);
       # If not free, release and try from next number
-      mtr_release_unique_id($build_thread++) unless $found_free;
+      if (! $found_free) {
+        mtr_release_unique_id();
+        $build_thread++;
+      }
     }
   }
   else
   {
     $build_thread = $opt_build_thread + $thread - 1;
+    if (! check_ports_free($build_thread)) {
+      # Some port was not free(which one has already been printed)
+      mtr_error("Some port(s) was not free")
+    }
   }
   $ENV{MTR_BUILD_THREAD}= $build_thread;
 
-  if (! check_ports_free($build_thread)) {
-    # Some port was not free(which one has already been printed)
-    mtr_error("Some port(s) was not free")
-  }
-
   # Calculate baseport
   $baseport= $build_thread * 10 + 10000;
   if ( $baseport < 5001 or $baseport + 9 >= 32767 )
@@ -3134,6 +3150,26 @@ sub find_analyze_request
 }
 
 
+# The test can leave a file in var/tmp/ to signal
+# that all servers should be restarted
+sub restart_forced_by_test
+{
+  my $restart = 0;
+  foreach my $mysqld ( mysqlds() )
+  {
+    my $datadir = $mysqld->value('datadir');
+    my $force_restart_file = "$datadir/mtr/force_restart";
+    if ( -f $force_restart_file )
+    {
+      mtr_verbose("Restart of servers forced by test");
+      $restart = 1;
+      last;
+    }
+  }
+  return $restart;
+}
+
+
 # Return timezone value of tinfo or default value
 sub timezone {
   my ($tinfo)= @_;
@@ -3175,7 +3211,7 @@ sub run_testcase ($) {
     {
 
       # Remove old datadirs
-      clean_datadir();
+      clean_datadir() unless $opt_start_dirty;

 
       # Restore old ENV
       while (my ($option, $value)= each( %old_env )) {
@@ -3242,19 +3278,29 @@ sub run_testcase ($) {
   # --------------------------------------------------------------------
   # If --start or --start-dirty given, stop here to let user manually
   # run tests
+  # If --wait-all is also given, do the same, but don't die if one
+  # server exits
   # ----------------------------------------------------------------------
+
   if ( $opt_start or $opt_start_dirty )
   {
     mtr_print("\nStarted", started(all_servers()));
     mtr_print("Waiting for server(s) to exit...");
-    my $proc= My::SafeProcess->wait_any();
-    if ( grep($proc eq $_, started(all_servers())) )
-    {
-      mtr_print("Server $proc died");
+    if ( $opt_wait_all ) {
+      My::SafeProcess->wait_all();
+      mtr_print( "All servers exited" );
+      exit(1);
+    }
+    else {
+      my $proc= My::SafeProcess->wait_any();
+      if ( grep($proc eq $_, started(all_servers())) )
+      {
+        mtr_print("Server $proc died");
+        exit(1);
+      }
+      mtr_print("Unknown process $proc died");
       exit(1);
     }
-    mtr_print("Unknown process $proc died");
-    exit(1);
   }
 
   my $test_timeout_proc= My::SafeProcess->timer(testcase_timeout());
@@ -3272,10 +3318,38 @@ sub run_testcase ($) {
   }
 
   my $test= start_mysqltest($tinfo);
+  # Set only when we have to keep waiting after expectedly died server
+  my $keep_waiting_proc = 0;
 
   while (1)
   {
-    my $proc= My::SafeProcess->wait_any();
+    my $proc;
+    if ($keep_waiting_proc)
+    {
+      # Any other process exited?
+      $proc = My::SafeProcess->check_any();
+      if ($proc)
+      {
+	mtr_verbose ("Found exited process $proc");
+	# If that was the timeout, cancel waiting
+	if ( $proc eq $test_timeout_proc )
+	{
+	  $keep_waiting_proc = 0;
+	}
+      }
+      else
+      {
+	$proc = $keep_waiting_proc;
+      }
+    }
+    else
+    {
+      $proc= My::SafeProcess->wait_any();
+    }
+
+    # Will be restored if we need to keep waiting
+    $keep_waiting_proc = 0;
+
     unless ( defined $proc )
     {
       mtr_error("wait_any failed");
@@ -3302,7 +3376,11 @@ sub run_testcase ($) {
       if ( $res == 0 )
       {
 	my $check_res;
-	if ( $opt_check_testcases and
+	if ( restart_forced_by_test() )
+	{
+	  stop_all_servers();
+	}
+	elsif ( $opt_check_testcases and
 	     $check_res= check_testcase($tinfo, "after"))
 	{
 	  if ($check_res == 1) {
@@ -3367,8 +3445,12 @@ sub run_testcase ($) {
     # ----------------------------------------------------
     # Check if it was an expected crash
     # ----------------------------------------------------
-    if ( check_expected_crash_and_restart($proc) )
+    my $check_crash = check_expected_crash_and_restart($proc);
+    if ($check_crash)
     {
+      # Keep waiting if it returned 2, if 1 don't wait or stop waiting.
+      $keep_waiting_proc = 0 if $check_crash == 1;
+      $keep_waiting_proc = $proc if $check_crash == 2;
       next;
     }
 
@@ -3709,16 +3791,16 @@ sub check_expected_crash_and_restart {
     {
       mtr_verbose("Crash was expected, file '$expect_file' exists");
 
-      while (1){
-
+      for (my $waits = 0;  $waits < 50;  $waits++)
+      {
 	# If last line in expect file starts with "wait"
 	# sleep a little and try again, thus allowing the
 	# test script to control when the server should start
-	# up again
+	# up again. Keep trying for up to 5s at a time.
 	my $last_line= mtr_lastlinesfromfile($expect_file, 1);
 	if ($last_line =~ /^wait/ )
 	{
-	  mtr_verbose("Test says wait before restart");
+	  mtr_verbose("Test says wait before restart") if $waits == 0;
 	  mtr_milli_sleep(100);
 	  next;
 	}
@@ -3728,11 +3810,11 @@ sub check_expected_crash_and_restart {
 	# Start server with same settings as last time
 	mysqld_start($mysqld, $mysqld->{'started_opts'});
 
-	last;
+	return 1;
       }
+      # Loop ran through: we should keep waiting after a re-check
+      return 2;
     }
-
-    return 1;
   }
 
   # Not an expected crash
@@ -4431,14 +4513,17 @@ sub start_servers($) {
     my $mysqld_basedir= $mysqld->value('basedir');
     if ( $basedir eq $mysqld_basedir )
     {
-      # Copy datadir from installed system db
-      for my $path ( "$opt_vardir", "$opt_vardir/..") {
-	my $install_db= "$path/install.db";
-	copytree($install_db, $datadir)
-	  if -d $install_db;
+      if (! $opt_start_dirty)	# If dirty, keep possibly grown system db
+      {
+	# Copy datadir from installed system db
+	for my $path ( "$opt_vardir", "$opt_vardir/..") {
+	  my $install_db= "$path/install.db";
+	  copytree($install_db, $datadir)
+	    if -d $install_db;
+	}
+	mtr_error("Failed to copy system db to '$datadir'")
+	  unless -d $datadir;
       }
-      mtr_error("Failed to copy system db to '$datadir'")
-	unless -d $datadir;
     }
     else
     {
@@ -4978,10 +5063,13 @@ Options to control what engine/variation
   vs-config             Visual Studio configuration used to create executables
                         (default: MTR_VS_CONFIG environment variable)
 
-  config|defaults-file=<config template> Use fixed config template for all
+  defaults-file=<config template> Use fixed config template for all
                         tests
   defaults_extra_file=<config template> Extra config template to add to
                         all generated configs
+  combination=<opt>     Use at least twice to run tests with specified 
+                        options to mysqld
+  skip-combinations     Ignore combination file (or options)
 
 Options to control directories to use
   tmpdir=DIR            The directory where temporary files are stored
@@ -5004,7 +5092,6 @@ Options to control what test suites or c
   force                 Continue to run the suite after failure
   with-ndbcluster-only  Run only tests that include "ndb" in the filename
   skip-ndb[cluster]     Skip all tests that need cluster
-  skip-ndb[cluster]-slave Skip all tests that need a slave cluster

   do-test=PREFIX or REGEX
                         Run test cases which name are prefixed with PREFIX
                         or fulfills REGEX
@@ -5019,6 +5106,9 @@ Options to control what test suites or c
                         The default is: "$DEFAULT_SUITES"
   skip-rpl              Skip the replication test cases.
   big-test              Also run tests marked as "big"
+  enable-disabled       Run also tests marked as disabled
+  print_testcases       Don't run the tests but print details about all the
+                        selected tests, in the order they would be run.
 
 Options that specify ports
 
@@ -5087,7 +5177,7 @@ Options for valgrind
   valgrind-options=ARGS Deprecated, use --valgrind-option
   valgrind-option=ARGS  Option to give valgrind, replaces default option(s),
                         can be specified more then once
-  valgrind-path=[EXE]   Path to the valgrind executable
+  valgrind-path=<EXE>   Path to the valgrind executable
   callgrind             Instruct valgrind to use callgrind
 
 Misc options
@@ -5095,14 +5185,18 @@ Misc options
   comment=STR           Write STR to the output
   notimer               Don't show test case execution time
   verbose               More verbose output(use multiple times for even more)
+  verbose-restart       Write when and why servers are restarted
   start                 Only initialize and start the servers, using the
                         startup settings for the first specified test case
                         Example:
                          $0 --start alias &
   start-dirty           Only start the servers (without initialization) for
                         the first specified test case
+  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
                         to shutdown etc.
+  parallel=N            Run tests in N parallel threads (default=1)
   repeat=N              Run each test N number of times
   retry=N               Retry tests that fail N times, limit number of failures
                         to $opt_retry_failure
@@ -5120,6 +5214,12 @@ Misc options
   sleep=SECONDS         Passed to mysqltest, will be used as fixed sleep time
   gcov                  Collect coverage information after the test.
                         The result is a gcov file per source and header file.
+  experimental=<file>   Refer to list of tests considered experimental;
+                        failures will be marked exp-fail instead of fail.
+  report-features       First run a "test" that reports mysql features
+  timestamp             Print timestamp before each test report line
+  timediff              With --timestamp, also print time passed since
+                        *previous* test started
 
 HERE
   exit(1);

=== modified file 'mysql-test/r/cast.result'
--- a/mysql-test/r/cast.result	2008-01-10 10:37:54 +0000
+++ b/mysql-test/r/cast.result	2009-05-21 08:06:43 +0000
@@ -439,3 +439,16 @@ HOUR(NULL)	MINUTE(NULL)	SECOND(NULL)
 NULL	NULL	NULL
 DROP TABLE t1;
 End of 5.0 tests
+#
+#  Bug #44766: valgrind error when using convert() in a subquery
+#
+CREATE TABLE t1(a tinyint);
+INSERT INTO t1 VALUES (127);
+SELECT 1 FROM
+(
+SELECT CONVERT(t2.a USING UTF8) FROM t1, t1 t2 LIMIT 1
+) AS s LIMIT 1;
+1
+1
+DROP TABLE t1;
+End of 5.1 tests

=== modified file 'mysql-test/r/concurrent_innodb_safelog.result'
--- a/mysql-test/r/concurrent_innodb_safelog.result	2009-03-17 13:43:43 +0000
+++ b/mysql-test/r/concurrent_innodb_safelog.result	2009-05-15 10:15:56 +0000
@@ -785,6 +785,8 @@ eta	tipo	c
 70	1	iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
 80	22	jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
 90	11	kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
+** Cleanup
+** connection thread2
 ** connection default
 drop table t1;
 drop user mysqltest@localhost;

=== modified file 'mysql-test/r/concurrent_innodb_unsafelog.result'
--- a/mysql-test/r/concurrent_innodb_unsafelog.result	2009-03-17 13:43:43 +0000
+++ b/mysql-test/r/concurrent_innodb_unsafelog.result	2009-05-15 10:15:56 +0000
@@ -781,6 +781,8 @@ eta	tipo	c
 70	1	iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
 80	1	jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
 90	11	kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
+** Cleanup
+** connection thread2
 ** connection default
 drop table t1;
 drop user mysqltest@localhost;

=== modified file 'mysql-test/r/consistent_snapshot.result'
--- a/mysql-test/r/consistent_snapshot.result	2009-03-03 20:34:18 +0000
+++ b/mysql-test/r/consistent_snapshot.result	2009-05-11 23:54:00 +0000
@@ -1,6 +1,9 @@
 DROP TABLE IF EXISTS t1;
 # Establish connection con1 (user=root)
 # Establish connection con2 (user=root)
+### Test 1:
+### - While a consistent snapshot transaction is executed,
+###   no external inserts should be visible to the transaction.
 # Switch to connection con1
 CREATE TABLE t1 (a INT) ENGINE=innodb;
 START TRANSACTION WITH CONSISTENT SNAPSHOT;
@@ -10,6 +13,9 @@ INSERT INTO t1 VALUES(1);
 SELECT * FROM t1;
 a
 COMMIT;
+### Test 2:
+### - For any non-consistent snapshot transaction, external
+###   committed inserts should be visible to the transaction.
 DELETE FROM t1;
 START TRANSACTION;
 # Switch to connection con2
@@ -19,5 +25,18 @@ SELECT * FROM t1;
 a
 1
 COMMIT;
+### Test 3:
+### - Bug#44664: valgrind warning for COMMIT_AND_CHAIN and ROLLBACK_AND_CHAIN
+###   Chaining a transaction does not retain consistency level.
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+DELETE FROM t1;
+COMMIT WORK AND CHAIN;
+# Switch to connection con2
+INSERT INTO t1 VALUES(1);
+# Switch to connection con1
+SELECT * FROM t1;
+a
+1
+COMMIT;
 # Switch to connection default + close connections con1 and con2
 DROP TABLE t1;

=== modified file 'mysql-test/r/ctype_cp932_binlog_stm.result'
--- a/mysql-test/r/ctype_cp932_binlog_stm.result	2008-10-02 05:56:07 +0000
+++ b/mysql-test/r/ctype_cp932_binlog_stm.result	2009-05-05 06:55:22 +0000
@@ -46,4 +46,12 @@ master-bin.000001	1137	Query	1	1216	use 
 End of 5.0 tests
 SHOW BINLOG EVENTS FROM 364;
 ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
+Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment.
+CREATE TABLE t1 (a varchar(16)) character set cp932;
+INSERT INTO t1 VALUES (0x8372835E),(0x8352835E);
+SELECT hex(a), hex(lower(a)), hex(upper(a)) FROM t1 ORDER BY binary(a);
+hex(a)	hex(lower(a))	hex(upper(a))
+8352835E	8352835E	8352835E
+8372835E	8372835E	8372835E
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/ctype_sjis.result'
--- a/mysql-test/r/ctype_sjis.result	2008-02-20 18:49:26 +0000
+++ b/mysql-test/r/ctype_sjis.result	2009-05-05 06:55:22 +0000
@@ -209,3 +209,13 @@ SET NAMES sjis;
 SELECT HEX('�����@�\') FROM DUAL;
 HEX('�����@�\')
 8DB2939181408C5C
+# Start of 5.1 tests
+Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment.
+CREATE TABLE t1 (a varchar(16)) character set sjis;
+INSERT INTO t1 VALUES (0x8372835E),(0x8352835E);
+SELECT hex(a), hex(lower(a)), hex(upper(a)) FROM t1 ORDER BY binary(a);
+hex(a)	hex(lower(a))	hex(upper(a))
+8352835E	8352835E	8352835E
+8372835E	8372835E	8372835E
+DROP TABLE t1;
+# End of 5.1 tests

=== modified file 'mysql-test/r/ddl_i18n_koi8r.result'
--- a/mysql-test/r/ddl_i18n_koi8r.result	2009-02-19 17:22:28 +0000
+++ b/mysql-test/r/ddl_i18n_koi8r.result	2009-05-15 10:15:56 +0000
@@ -2829,7 +2829,11 @@ t2	CREATE TABLE `t2` (
   `col1` varchar(10) COLLATE cp1251_general_cs DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_general_cs
 
+---> connection: con2
+
+---> connection: con3
+
 ---> connection: default
-use test|
-DROP DATABASE mysqltest1|
-DROP DATABASE mysqltest2|
+USE test;
+DROP DATABASE mysqltest1;
+DROP DATABASE mysqltest2;

=== modified file 'mysql-test/r/ddl_i18n_utf8.result'
--- a/mysql-test/r/ddl_i18n_utf8.result	2009-02-19 17:22:28 +0000
+++ b/mysql-test/r/ddl_i18n_utf8.result	2009-05-15 10:15:56 +0000
@@ -2829,7 +2829,11 @@ t2	CREATE TABLE `t2` (
   `col1` varchar(10) COLLATE cp1251_general_cs DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_general_cs
 
+---> connection: con2
+
+---> connection: con3
+
 ---> connection: default
-use test|
-DROP DATABASE mysqltest1|
-DROP DATABASE mysqltest2|
+USE test;
+DROP DATABASE mysqltest1;
+DROP DATABASE mysqltest2;

=== modified file 'mysql-test/r/distinct.result'
--- a/mysql-test/r/distinct.result	2008-10-29 17:38:18 +0000
+++ b/mysql-test/r/distinct.result	2009-05-10 16:20:35 +0000
@@ -629,21 +629,21 @@ SELECT DISTINCT @v5:= fruit_id, @v6:= fr
 fruit_name = 'APPLE';
 SELECT @v5, @v6, @v7, @v8;
 @v5	@v6	@v7	@v8
-3	PEAR	3	PEAR
+2	APPLE	2	APPLE
 SELECT DISTINCT @v5 + fruit_id, CONCAT(@v6, fruit_name) INTO @v9, @v10 FROM t1 
 WHERE fruit_name = 'APPLE';
 SELECT @v5, @v6, @v7, @v8, @v9, @v10;
 @v5	@v6	@v7	@v8	@v9	@v10
-3	PEAR	3	PEAR	5	PEARAPPLE
+2	APPLE	2	APPLE	4	APPLEAPPLE
 SELECT DISTINCT @v11:= @v5 + fruit_id, @v12:= CONCAT(@v6, fruit_name) INTO 
 @v13, @v14 FROM t1 WHERE fruit_name = 'APPLE';
 SELECT @v11, @v12, @v13, @v14;
 @v11	@v12	@v13	@v14
-6	PEARPEAR	6	PEARPEAR
+4	APPLEAPPLE	4	APPLEAPPLE
 SELECT DISTINCT @v13, @v14 INTO @v15, @v16 FROM t1 WHERE fruit_name = 'APPLE';
 SELECT @v15, @v16;
 @v15	@v16
-6	PEARPEAR
+4	APPLEAPPLE
 SELECT DISTINCT 2 + 2, 'Bob' INTO @v17, @v18 FROM t1 WHERE fruit_name = 
 'APPLE';
 SELECT @v17, @v18;

=== modified file 'mysql-test/r/events_stress.result'
--- a/mysql-test/r/events_stress.result	2006-09-01 11:08:44 +0000
+++ b/mysql-test/r/events_stress.result	2009-05-15 10:15:56 +0000
@@ -63,3 +63,4 @@ DROP TABLE fill_it1;
 DROP TABLE fill_it2;
 DROP TABLE fill_it3;
 DROP DATABASE events_test;
+SET GLOBAL event_scheduler=off;

=== modified file 'mysql-test/r/func_compress.result'
--- a/mysql-test/r/func_compress.result	2009-01-31 16:10:43 +0000
+++ b/mysql-test/r/func_compress.result	2009-05-21 17:51:48 +0000
@@ -117,4 +117,13 @@ Warnings:
 Error	1259	ZLIB: Input data corrupted
 Error	1259	ZLIB: Input data corrupted
 drop table t1;
+CREATE TABLE t1 (c1 INT);
+INSERT INTO t1 VALUES (1), (1111), (11111);
+SELECT UNCOMPRESS(c1), UNCOMPRESSED_LENGTH(c1) FROM t1;
+UNCOMPRESS(c1)	UNCOMPRESSED_LENGTH(c1)
+NULL	NULL
+NULL	NULL
+NULL	825307441
+EXPLAIN EXTENDED SELECT * FROM (SELECT UNCOMPRESSED_LENGTH(c1) FROM t1) AS s;
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/func_concat.result'
--- a/mysql-test/r/func_concat.result	2008-05-13 15:27:46 +0000
+++ b/mysql-test/r/func_concat.result	2009-05-21 08:06:43 +0000
@@ -89,3 +89,34 @@ c1	c2
 	First
 DROP TABLE t1;
 # End of 5.0 tests
+#
+# Bug #44743: Join in combination with concat does not always work
+#
+CREATE TABLE t1 (
+a VARCHAR(100) NOT NULL DEFAULT '0',
+b VARCHAR(2) NOT NULL DEFAULT '',
+c VARCHAR(2) NOT NULL DEFAULT '',
+d TEXT NOT NULL,
+PRIMARY KEY (a, b, c),
+KEY (a)
+) DEFAULT CHARSET=utf8;
+INSERT INTO t1 VALUES ('gui_A', 'a', 'b', 'str1'),
+('gui_AB', 'a', 'b', 'str2'), ('gui_ABC', 'a', 'b', 'str3');
+CREATE TABLE t2 (
+a VARCHAR(100) NOT NULL DEFAULT '',
+PRIMARY KEY (a)
+) DEFAULT CHARSET=latin1;
+INSERT INTO t2 VALUES ('A'), ('AB'), ('ABC');
+SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+CONCAT('gui_', t2.a)	d
+gui_A	str1
+gui_AB	str2
+gui_ABC	str3
+EXPLAIN SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index	NULL	PRIMARY	102	NULL	3	Using index
+1	SIMPLE	t1	eq_ref	PRIMARY,a	PRIMARY	318	func,const,const	1	
+DROP TABLE t1, t2;
+# End of 5.1 tests

=== modified file 'mysql-test/r/func_in.result'
--- a/mysql-test/r/func_in.result	2008-12-31 11:55:04 +0000
+++ b/mysql-test/r/func_in.result	2009-05-25 08:00:40 +0000
@@ -587,4 +587,25 @@ SELECT CASE c1 WHEN c1 + 1 THEN 1 END, A
 CASE c1 WHEN c1 + 1 THEN 1 END	ABS(AVG(c0))
 NULL	1.0000
 DROP TABLE t1;
+CREATE TABLE t1(a TEXT, b INT, c INT UNSIGNED, d DECIMAL(12,2), e REAL);
+INSERT INTO t1 VALUES('iynfj', 1, 1, 1, 1);
+INSERT INTO t1 VALUES('innfj', 2, 2, 2, 2);
+SELECT SUM( DISTINCT a ) FROM t1 GROUP BY a HAVING a IN ( AVG( 1 ), 1 + a);
+SUM( DISTINCT a )
+SELECT SUM( DISTINCT b ) FROM t1 GROUP BY b HAVING b IN ( AVG( 1 ), 1 + b);
+SUM( DISTINCT b )
+1
+SELECT SUM( DISTINCT c ) FROM t1 GROUP BY c HAVING c IN ( AVG( 1 ), 1 + c);
+SUM( DISTINCT c )
+1
+SELECT SUM( DISTINCT d ) FROM t1 GROUP BY d HAVING d IN ( AVG( 1 ), 1 + d);
+SUM( DISTINCT d )
+1.00
+SELECT SUM( DISTINCT e ) FROM t1 GROUP BY e HAVING e IN ( AVG( 1 ), 1 + e);
+SUM( DISTINCT e )
+1
+SELECT SUM( DISTINCT e ) FROM t1 GROUP BY b,c,d HAVING (b,c,d) IN 
+((AVG( 1 ), 1 + c, 1 + d), (AVG( 1 ), 2 + c, 2 + d));
+SUM( DISTINCT e )
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/func_math.result'
--- a/mysql-test/r/func_math.result	2009-02-23 12:42:31 +0000
+++ b/mysql-test/r/func_math.result	2009-05-18 04:21:25 +0000
@@ -456,4 +456,23 @@ NULL
 SELECT POW(10, 309);
 POW(10, 309)
 NULL
+#
+# Bug #44768: SIGFPE crash when selecting rand from a view
+#             containing null
+#
+CREATE OR REPLACE VIEW v1 AS SELECT NULL AS a;
+SELECT RAND(a) FROM v1;
+RAND(a)
+0.155220427694936
+DROP VIEW v1;
+SELECT RAND(a) FROM (SELECT NULL AS a) b;
+RAND(a)
+0.155220427694936
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (NULL);
+SELECT RAND(i) FROM t1;
+RAND(i)
+0.155220427694936
+DROP TABLE t1;
+#
 End of 5.1 tests

=== modified file 'mysql-test/r/func_str.result'
--- a/mysql-test/r/func_str.result	2009-04-23 07:43:42 +0000
+++ b/mysql-test/r/func_str.result	2009-05-13 18:39:35 +0000
@@ -2525,6 +2525,15 @@ SELECT DATE_FORMAT(c, GET_FORMAT(DATE, '
 h	i
 31.12.2008	AAAAAA, aaaaaa
 DROP TABLE t1;
+#
+# BUG#44774: load_file function produces valgrind warnings
+#
+CREATE TABLE t1 (a TINYBLOB);
+INSERT INTO t1 VALUES ('aaaaaaaa');
+SELECT LOAD_FILE(a) FROM t1;
+LOAD_FILE(a)
+NULL
+DROP TABLE t1;
 End of 5.0 tests
 drop table if exists t1;
 create table t1(f1 tinyint default null)engine=myisam;

=== modified file 'mysql-test/r/grant_cache_no_prot.result'
--- a/mysql-test/r/grant_cache_no_prot.result	2008-09-03 14:45:40 +0000
+++ b/mysql-test/r/grant_cache_no_prot.result	2009-05-20 13:27:44 +0000
@@ -206,7 +206,8 @@ Qcache_hits	8
 show status like "Qcache_not_cached";
 Variable_name	Value
 Qcache_not_cached	8
------ switch to connection default and close connections -----
+----- close connections -----
+----- switch to connection default -----
 set names binary;
 delete from mysql.user where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
 delete from mysql.db where user in ("mysqltest_1","mysqltest_2","mysqltest_3");

=== modified file 'mysql-test/r/grant_cache_ps_prot.result'
--- a/mysql-test/r/grant_cache_ps_prot.result	2008-09-03 14:45:40 +0000
+++ b/mysql-test/r/grant_cache_ps_prot.result	2009-05-15 10:15:56 +0000
@@ -206,7 +206,8 @@ Qcache_hits	8
 show status like "Qcache_not_cached";
 Variable_name	Value
 Qcache_not_cached	5
------ switch to connection default and close connections -----
+----- close connections -----
+----- switch to connection default -----
 set names binary;
 delete from mysql.user where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
 delete from mysql.db where user in ("mysqltest_1","mysqltest_2","mysqltest_3");

=== modified file 'mysql-test/r/heap_btree.result'
--- a/mysql-test/r/heap_btree.result	2007-10-19 20:12:14 +0000
+++ b/mysql-test/r/heap_btree.result	2009-05-06 09:30:14 +0000
@@ -336,4 +336,11 @@ a	b
 NULL	NULL
 NULL	1
 drop table t1;
+#
+# bug#39918 - memory (heap) engine crashing while executing self join with delete
+#
+CREATE TABLE t1(a INT, KEY USING BTREE (a)) ENGINE=MEMORY;
+INSERT INTO t1 VALUES(1),(1);
+DELETE a1 FROM t1 AS a1, t1 AS a2 WHERE a1.a=a2.a;
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/information_schema_db.result'
--- a/mysql-test/r/information_schema_db.result	2009-02-25 12:18:24 +0000
+++ b/mysql-test/r/information_schema_db.result	2009-05-15 15:47:50 +0000
@@ -61,7 +61,7 @@ begin
 select table_name from information_schema.key_column_usage
 order by table_name;
 end|
-create table t1 
+create table t1
 (f1 int(10) unsigned not null,
 f2 varchar(100) not null,
 primary key (f1), unique key (f2));
@@ -203,15 +203,15 @@ View	Create View	character_set_client	co
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`testdb_2`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `v1`.`f1` AS `f1` from `testdb_1`.`v1`	latin1	latin1_swedish_ci
 show create view testdb_1.v1;
 ERROR 42000: SHOW VIEW command denied to user 'testdb_2'@'localhost' for table 'v1'
-select table_name from information_schema.columns a 
+select table_name from information_schema.columns a
 where a.table_name = 'v2';
 table_name
 v2
-select view_definition from information_schema.views a 
+select view_definition from information_schema.views a
 where a.table_name = 'v2';
 view_definition
 select `v1`.`f1` AS `f1` from `testdb_1`.`v1`
-select view_definition from information_schema.views a 
+select view_definition from information_schema.views a
 where a.table_name = 'testdb_1.v1';
 view_definition
 select * from v2;

=== modified file 'mysql-test/r/init_file.result'
--- a/mysql-test/r/init_file.result	2009-02-01 09:18:09 +0000
+++ b/mysql-test/r/init_file.result	2009-04-02 11:00:44 +0000
@@ -4,6 +4,7 @@ SELECT * INTO @Y FROM init_file.startup 
 SELECT YEAR(@X)-YEAR(@Y);
 YEAR(@X)-YEAR(@Y)
 0
+DROP DATABASE init_file;
 ok
 end of 4.1 tests
 select * from t1;
@@ -19,3 +20,5 @@ y
 3
 11
 13
+drop table t1, t2;
+call mtr.force_restart();

=== added file 'mysql-test/r/innodb_bug42101-nonzero.result'
--- a/mysql-test/r/innodb_bug42101-nonzero.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_bug42101-nonzero.result	2009-05-19 08:20:28 +0000
@@ -0,0 +1,22 @@
+set global innodb_commit_concurrency=0;
+ERROR HY000: Incorrect arguments to SET
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+1
+set global innodb_commit_concurrency=1;
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+1
+set global innodb_commit_concurrency=42;
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+42
+set global innodb_commit_concurrency=0;
+ERROR HY000: Incorrect arguments to SET
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+42
+set global innodb_commit_concurrency=1;
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+1

=== added file 'mysql-test/r/innodb_bug42101.result'
--- a/mysql-test/r/innodb_bug42101.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_bug42101.result	2009-05-19 08:20:28 +0000
@@ -0,0 +1,18 @@
+set global innodb_commit_concurrency=0;
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+0
+set global innodb_commit_concurrency=1;
+ERROR HY000: Incorrect arguments to SET
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+0
+set global innodb_commit_concurrency=42;
+ERROR HY000: Incorrect arguments to SET
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+0
+set global innodb_commit_concurrency=0;
+select @@innodb_commit_concurrency;
+@@innodb_commit_concurrency
+0

=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result	2009-05-13 07:51:39 +0000
+++ b/mysql-test/r/innodb_mysql.result	2009-05-25 08:00:40 +0000
@@ -1408,6 +1408,18 @@ SAVEPOINT s4;
 ROLLBACK;
 ROLLBACK TO SAVEPOINT s4;
 ERROR 42000: SAVEPOINT s4 does not exist
+CREATE TABLE t1 (f1 INTEGER PRIMARY KEY COMMENT 'My ID#', f2 INTEGER DEFAULT NULL, f3 CHAR(10) DEFAULT 'My ID#', CONSTRAINT f2_ref FOREIGN KEY (f2) REFERENCES t1 (f1)) ENGINE=INNODB;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `f1` int(11) NOT NULL COMMENT 'My ID#',
+  `f2` int(11) DEFAULT NULL,
+  `f3` char(10) DEFAULT 'My ID#',
+  PRIMARY KEY (`f1`),
+  KEY `f2_ref` (`f2`),
+  CONSTRAINT `f2_ref` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
 End of 5.0 tests
 CREATE TABLE `t2` (
 `k` int(11) NOT NULL auto_increment,
@@ -1706,6 +1718,35 @@ id	select_type	table	type	possible_keys	
 1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
 2	DERIVED	t1	index	c3,c2	c2	10	NULL	5	
 DROP TABLE t1;
+CREATE TABLE t1 (c1 REAL, c2 REAL, c3 REAL, KEY (c3), KEY (c2, c3))
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+1
+1
+EXPLAIN 
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
+2	DERIVED	t1	index	c3,c2	c2	18	NULL	5	
+DROP TABLE t1;
+CREATE TABLE t1 (c1 DECIMAL(12,2), c2 DECIMAL(12,2), c3 DECIMAL(12,2), 
+KEY (c3), KEY (c2, c3))
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+1
+1
+EXPLAIN 
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
+2	DERIVED	t1	index	c3,c2	c2	14	NULL	5	
+DROP TABLE t1;
 End of 5.1 tests
 drop table if exists t1, t2, t3;
 create table t1(a int);
@@ -2040,4 +2081,31 @@ DROP TABLE t4;
 DROP TABLE t1;
 DROP TABLE t2;
 DROP TABLE t3;
+CREATE TABLE t1 (a INT, b INT, KEY (a)) ENGINE = INNODB;
+CREATE TABLE t2 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
+CREATE TABLE t3 (a INT, b INT KEY, KEY (a)) ENGINE = INNODB;
+CREATE TABLE t4 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6);
+INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+INSERT INTO t3 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105), (6, 106);
+INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+UPDATE t1, t2 SET t1.a = t1.a + 100, t2.b = t1.a + 10 
+WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b;
+SELECT * FROM t2;
+a	b
+1	1
+2	12
+3	13
+4	14
+5	5
+UPDATE t3, t4 SET t3.a = t3.a + 100, t4.b = t3.a + 10 
+WHERE t3.a BETWEEN 2 AND 4 AND t4.a = t3.b - 100;
+SELECT * FROM t4;
+a	b
+1	1
+2	12
+3	13
+4	14
+5	5
+DROP TABLE t1, t2, t3, t4;
 End of 5.1 tests

=== modified file 'mysql-test/r/insert_select.result'
--- a/mysql-test/r/insert_select.result	2007-09-24 13:23:40 +0000
+++ b/mysql-test/r/insert_select.result	2009-05-04 12:45:36 +0000
@@ -765,6 +765,11 @@ f1	f2
 2	2
 10	10
 DROP TABLE t1, t2;
+CREATE TABLE t1 ( a INT KEY, b INT );
+INSERT INTO t1 VALUES ( 0, 1 );
+INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+DROP TABLE t1;
 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 CREATE TABLE t1 (c VARCHAR(30), INDEX ix_c (c(10)));
 CREATE TABLE t2 (d VARCHAR(10));

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	2009-03-24 20:48:31 +0000
+++ b/mysql-test/r/mysql.result	2009-05-15 13:25:29 +0000
@@ -192,6 +192,12 @@ delimiter
 1
 1
 1
+COUNT (*)
+1
+COUNT (*)
+1
+COUNT (*)
+1
 End of 5.0 tests
 WARNING: --server-arg option not supported in this configuration.
 Warning (Code 1286): Unknown table engine 'nonexistent'
@@ -200,4 +206,5 @@ Warning (Code 1286): Unknown table engin
 Warning (Code 1266): Using storage engine MyISAM for table 't2'
 Error (Code 1050): Table 't2' already exists
 drop tables t1, t2;
+<TABLE BORDER=1><TR><TH>&lt;</TH></TR><TR><TD>&lt; &amp; &gt;</TD></TR></TABLE>
 End of tests

=== modified file 'mysql-test/r/mysqlbinlog.result'
--- a/mysql-test/r/mysqlbinlog.result	2009-03-20 14:49:43 +0000
+++ b/mysql-test/r/mysqlbinlog.result	2009-05-08 17:24:15 +0000
@@ -471,4 +471,7 @@ IS NOT NULL
 1
 *** Unsigned server_id 4294967295 is found: 1 ***
 SET @@global.server_id= 1;
+RESET MASTER;
+FLUSH LOGS;
+End of 5.0 tests
 End of 5.1 tests

=== added file 'mysql-test/r/mysqldump_restore.result'
--- a/mysql-test/r/mysqldump_restore.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/mysqldump_restore.result	2009-05-22 14:38:17 +0000
@@ -0,0 +1,110 @@
+# Set concurrent_insert = 0 to prevent random errors
+# will reset to original value at the end of the test
+SET @old_concurrent_insert = @@global.concurrent_insert;
+SET @@global.concurrent_insert = 0;
+# Pre-test cleanup
+DROP TABLE IF EXISTS t1;
+# Begin tests
+#
+# Bug#2005 Long decimal comparison bug.
+#
+CREATE TABLE t1 (a DECIMAL(64, 20));
+INSERT INTO t1 VALUES ("1234567890123456789012345678901234567890"),
+("0987654321098765432109876543210987654321");
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+#
+# Bug#3361 mysqldump quotes DECIMAL values inconsistently
+#
+CREATE TABLE t1 (a DECIMAL(10,5), b FLOAT);
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ANSI_QUOTES';
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+ERROR 42S22: Unknown column '1.2345' in 'field list'
+SET SQL_MODE=@OLD_SQL_MODE;
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+#
+# Bug#1994 mysqldump does not correctly dump UCS2 data
+# Bug#4261 mysqldump 10.7 (mysql 4.1.2) --skip-extended-insert drops NULL from inserts
+#
+CREATE TABLE t1 (a  VARCHAR(255)) DEFAULT CHARSET koi8r;
+INSERT INTO t1  VALUES (_koi8r x'C1C2C3C4C5'), (NULL);
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+#
+# WL#2319 Exclude Tables from dump
+#
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+INSERT INTO t2 VALUES (4),(5),(6);
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t2', '_orig');
+# Rename original table
+ALTER TABLE test.t2 RENAME to test.t2_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t2
+# Original table: test.t2_orig
+Comparing tables test.t2 and test.t2_orig
+# Cleanup
+DROP TABLE test.t2, test.t2_orig;
+DROP TABLE t1;
+#
+# Bug#8830 mysqldump --skip-extended-insert causes --hex-blob to dump wrong values
+#
+CREATE TABLE t1 (`b` blob);
+INSERT INTO `t1` VALUES (0x602010000280100005E71A);
+# Begin testing mysqldump output + restore
+# Create 'original table name - <table>_orig
+SET @orig_table_name = CONCAT('test.t1', '_orig');
+# Rename original table
+ALTER TABLE test.t1 RENAME to test.t1_orig;
+# Recreate table from mysqldump output
+# Compare original and recreated tables
+# Recreated table: test.t1
+# Original table: test.t1_orig
+Comparing tables test.t1 and test.t1_orig
+# Cleanup
+DROP TABLE test.t1, test.t1_orig;
+# End tests
+# Cleanup
+# Reset concurrent_insert to its original value
+SET @@global.concurrent_insert = @old_concurrent_insert;
+# remove mysqldumpfile

=== modified file 'mysql-test/r/openssl_1.result'
--- a/mysql-test/r/openssl_1.result	2009-04-11 09:46:14 +0000
+++ b/mysql-test/r/openssl_1.result	2009-05-25 13:00:18 +0000
@@ -202,4 +202,10 @@ Ssl_cipher	RC4-SHA
 select 'is still running; no cipher request crashed the server' as result from dual;
 result
 is still running; no cipher request crashed the server
+GRANT SELECT ON test.* TO bug42158@localhost REQUIRE X509;
+FLUSH PRIVILEGES;
+SHOW STATUS LIKE 'Ssl_cipher';
+Variable_name	Value
+Ssl_cipher	DHE-RSA-AES256-SHA
+DROP USER bug42158@localhost;
 End of 5.1 tests

=== modified file 'mysql-test/r/subselect3.result'
--- a/mysql-test/r/subselect3.result	2009-01-28 18:48:41 +0000
+++ b/mysql-test/r/subselect3.result	2009-04-30 19:27:10 +0000
@@ -849,6 +849,25 @@ ROW(1,2) = (SELECT    1,    1)	ROW(1,2) 
 SELECT ROW(1,2) = (SELECT    1,    2), ROW(1,2) IN (SELECT    1,    2);
 ROW(1,2) = (SELECT    1,    2)	ROW(1,2) IN (SELECT    1,    2)
 1	1
+CREATE TABLE t1 (a INT, b INT, c INT);
+INSERT INTO t1 VALUES (1,1,1), (1,1,1);
+EXPLAIN EXTENDED 
+SELECT c FROM 
+( SELECT 
+(SELECT COUNT(a) FROM 
+(SELECT COUNT(b) FROM t1) AS x GROUP BY c
+) FROM t1 GROUP BY b
+) AS y;
+ERROR 42S22: Unknown column 'c' in 'field list'
+SHOW WARNINGS;
+Level	Code	Message
+Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #2
+Note	1276	Field or reference 'test.t1.c' of SELECT #3 was resolved in SELECT #2
+Error	1054	Unknown column 'c' in 'field list'
+Note	1003	select `c` AS `c` from (select (select count(`test`.`t1`.`a`) AS `COUNT(a)` from (select count(`test`.`t1`.`b`) AS `COUNT(b)` from `test`.`t1`) `x` group by `c`) AS `(SELECT COUNT(a) FROM 
+(SELECT COUNT(b) FROM t1) AS x GROUP BY c
+)` from `test`.`t1` group by `test`.`t1`.`b`) `y`
+DROP TABLE t1;
 End of 5.0 tests
 create table t0 (a int);
 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

=== modified file 'mysql-test/r/type_time.result'
--- a/mysql-test/r/type_time.result	2007-07-18 12:56:29 +0000
+++ b/mysql-test/r/type_time.result	2009-05-15 08:42:57 +0000
@@ -128,3 +128,13 @@ SELECT sum(f3) FROM t1 where f2='2007-07
 sum(f3)
 3
 drop table t1;
+#
+# Bug #44792: valgrind warning when casting from time to time
+#
+CREATE TABLE t1 (c TIME);
+INSERT INTO t1 VALUES ('0:00:00');
+SELECT CAST(c AS TIME) FROM t1;
+CAST(c AS TIME)
+00:00:00
+DROP TABLE t1;
+End of 5.0 tests

=== modified file 'mysql-test/r/union.result'
--- a/mysql-test/r/union.result	2009-03-27 13:00:20 +0000
+++ b/mysql-test/r/union.result	2009-05-15 07:11:07 +0000
@@ -1574,4 +1574,17 @@ SHOW FIELDS FROM t2;
 Field	Type	Null	Key	Default	Extra
 d	double(9,6)	YES		NULL	
 DROP TABLE t1, t2;
+CREATE TABLE t1(a INT);
+EXPLAIN EXTENDED
+SELECT a FROM t1
+UNION
+SELECT a FROM t1
+ORDER BY a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+2	UNION	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	Using filesort
+Warnings:
+Note	1003	select '0' AS `a` from `test`.`t1` union select '0' AS `a` from `test`.`t1` order by `a`
+DROP TABLE t1;
 End of 5.0 tests

=== modified file 'mysql-test/r/user_var.result'
--- a/mysql-test/r/user_var.result	2009-04-11 09:46:14 +0000
+++ b/mysql-test/r/user_var.result	2009-05-15 13:03:22 +0000
@@ -399,6 +399,17 @@ select @lastid != id, @lastid, @lastid :
 0	3	3
 1	3	4
 drop table t1;
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 VALUES (0, 0), (2, 1), (2, 3), (1, 1), (30, 20);
+SELECT a, b INTO @a, @b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
+SELECT @a, @b;
+@a	@b
+2	3
+SELECT a, b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
+a	b
+2	3
+DROP TABLE t1;
+End of 5.0 tests
 CREATE TABLE t1 (i INT);
 CREATE TRIGGER t_after_insert AFTER INSERT ON t1 FOR EACH ROW SET @bug42188 = 10;
 INSERT INTO t1 VALUES (1);

=== modified file 'mysql-test/r/variables.result'
--- a/mysql-test/r/variables.result	2009-03-16 15:11:45 +0000
+++ b/mysql-test/r/variables.result	2009-05-22 06:44:11 +0000
@@ -1436,7 +1436,7 @@ Warnings:
 Warning	1292	Truncated incorrect auto_increment_offset value: '0'
 select @@storage_engine;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					@@storage_engine	253	6	6	N	1	31	8
+def					@@storage_engine	253	6	6	Y	0	31	8
 @@storage_engine
 MyISAM
 SET @old_server_id = @@GLOBAL.server_id;
@@ -1467,4 +1467,14 @@ SELECT @@GLOBAL.server_id;
 @@GLOBAL.server_id
 0
 SET GLOBAL server_id = @old_server_id;
+SELECT @@GLOBAL.INIT_FILE, @@GLOBAL.INIT_FILE IS NULL;
+@@GLOBAL.INIT_FILE	@@GLOBAL.INIT_FILE IS NULL
+NULL	1
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES ();
+SET @bug42778= @@sql_safe_updates;
+SET @@sql_safe_updates= 0;
+DELETE FROM t1 ORDER BY (@@GLOBAL.INIT_FILE) ASC LIMIT 10;
+SET @@sql_safe_updates= @bug42778;
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2009-03-06 14:56:17 +0000
+++ b/mysql-test/r/view.result	2009-05-19 04:25:36 +0000
@@ -3700,6 +3700,25 @@ ERROR 42000: Key 'c2' doesn't exist in t
 DROP VIEW v1;
 DROP TABLE t1;
 # -----------------------------------------------------------------
+# -- Bug#40825: Error 1356 while selecting from a view 
+# --            with a "HAVING" clause though query works
+# -----------------------------------------------------------------
+
+CREATE TABLE t1 (c INT);
+
+CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
+SHOW CREATE VIEW v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`c` AS `view_column` from `t1` having `view_column`	latin1	latin1_swedish_ci
+SELECT * FROM v1;
+view_column
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+# -- End of test case for Bug#40825
+
+# -----------------------------------------------------------------
 # -- End of 5.0 tests.
 # -----------------------------------------------------------------
 DROP DATABASE IF EXISTS `d-1`;
@@ -3817,6 +3836,14 @@ call p();
 call p();
 drop view a;
 drop procedure p;
+#
+# Bug #44860: ALTER TABLE on view crashes server
+#
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 AS SELECT a FROM t1;
+ALTER TABLE v1;
+DROP VIEW v1;
+DROP TABLE t1;
 # -----------------------------------------------------------------
 # -- End of 5.1 tests.
 # -----------------------------------------------------------------

=== added file 'mysql-test/suite/binlog/r/binlog_incident.result'
--- a/mysql-test/suite/binlog/r/binlog_incident.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_incident.result	2009-05-11 11:32:38 +0000
@@ -0,0 +1,12 @@
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+SELECT * FROM t1;
+a
+1
+2
+3
+REPLACE INTO t1 VALUES (4);
+DROP TABLE t1;
+FLUSH LOGS;
+Contain RELOAD DATABASE
+1

=== modified file 'mysql-test/suite/binlog/r/binlog_stm_ps.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_ps.result	2009-04-03 18:21:57 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_ps.result	2009-05-20 10:28:43 +0000
@@ -11,7 +11,7 @@ prepare s from "insert into t1 select 10
 set @a=100;
 execute s using @a;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 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 t1 (a int)

=== added file 'mysql-test/suite/binlog/r/binlog_tbl_metadata.result'
--- a/mysql-test/suite/binlog/r/binlog_tbl_metadata.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_tbl_metadata.result	2009-05-12 11:53:46 +0000
@@ -0,0 +1,156 @@
+RESET MASTER;
+DROP TABLE IF EXISTS `t1`;
+CREATE TABLE `t1` (
+`c1` int(11) NOT NULL AUTO_INCREMENT,
+`c2` varchar(30) NOT NULL,
+`c3` varchar(30) DEFAULT NULL,
+`c4` varchar(30) DEFAULT NULL,
+`c5` varchar(30) DEFAULT NULL,
+`c6` varchar(30) DEFAULT NULL,
+`c7` varchar(30) DEFAULT NULL,
+`c8` varchar(30) DEFAULT NULL,
+`c9` varchar(30) DEFAULT NULL,
+`c10` varchar(30) DEFAULT NULL,
+`c11` varchar(30) DEFAULT NULL,
+`c12` varchar(30) DEFAULT NULL,
+`c13` varchar(30) DEFAULT NULL,
+`c14` varchar(30) DEFAULT NULL,
+`c15` varchar(30) DEFAULT NULL,
+`c16` varchar(30) DEFAULT NULL,
+`c17` varchar(30) DEFAULT NULL,
+`c18` varchar(30) DEFAULT NULL,
+`c19` varchar(30) DEFAULT NULL,
+`c20` varchar(30) DEFAULT NULL,
+`c21` varchar(30) DEFAULT NULL,
+`c22` varchar(30) DEFAULT NULL,
+`c23` varchar(30) DEFAULT NULL,
+`c24` varchar(30) DEFAULT NULL,
+`c25` varchar(30) DEFAULT NULL,
+`c26` varchar(30) DEFAULT NULL,
+`c27` varchar(30) DEFAULT NULL,
+`c28` varchar(30) DEFAULT NULL,
+`c29` varchar(30) DEFAULT NULL,
+`c30` varchar(30) DEFAULT NULL,
+`c31` varchar(30) DEFAULT NULL,
+`c32` varchar(30) DEFAULT NULL,
+`c33` varchar(30) DEFAULT NULL,
+`c34` varchar(30) DEFAULT NULL,
+`c35` varchar(30) DEFAULT NULL,
+`c36` varchar(30) DEFAULT NULL,
+`c37` varchar(30) DEFAULT NULL,
+`c38` varchar(30) DEFAULT NULL,
+`c39` varchar(30) DEFAULT NULL,
+`c40` varchar(30) DEFAULT NULL,
+`c41` varchar(30) DEFAULT NULL,
+`c42` varchar(30) DEFAULT NULL,
+`c43` varchar(30) DEFAULT NULL,
+`c44` varchar(30) DEFAULT NULL,
+`c45` varchar(30) DEFAULT NULL,
+`c46` varchar(30) DEFAULT NULL,
+`c47` varchar(30) DEFAULT NULL,
+`c48` varchar(30) DEFAULT NULL,
+`c49` varchar(30) DEFAULT NULL,
+`c50` varchar(30) DEFAULT NULL,
+`c51` varchar(30) DEFAULT NULL,
+`c52` varchar(30) DEFAULT NULL,
+`c53` varchar(30) DEFAULT NULL,
+`c54` varchar(30) DEFAULT NULL,
+`c55` varchar(30) DEFAULT NULL,
+`c56` varchar(30) DEFAULT NULL,
+`c57` varchar(30) DEFAULT NULL,
+`c58` varchar(30) DEFAULT NULL,
+`c59` varchar(30) DEFAULT NULL,
+`c60` varchar(30) DEFAULT NULL,
+`c61` varchar(30) DEFAULT NULL,
+`c62` varchar(30) DEFAULT NULL,
+`c63` varchar(30) DEFAULT NULL,
+`c64` varchar(30) DEFAULT NULL,
+`c65` varchar(30) DEFAULT NULL,
+`c66` varchar(30) DEFAULT NULL,
+`c67` varchar(30) DEFAULT NULL,
+`c68` varchar(30) DEFAULT NULL,
+`c69` varchar(30) DEFAULT NULL,
+`c70` varchar(30) DEFAULT NULL,
+`c71` varchar(30) DEFAULT NULL,
+`c72` varchar(30) DEFAULT NULL,
+`c73` varchar(30) DEFAULT NULL,
+`c74` varchar(30) DEFAULT NULL,
+`c75` varchar(30) DEFAULT NULL,
+`c76` varchar(30) DEFAULT NULL,
+`c77` varchar(30) DEFAULT NULL,
+`c78` varchar(30) DEFAULT NULL,
+`c79` varchar(30) DEFAULT NULL,
+`c80` varchar(30) DEFAULT NULL,
+`c81` varchar(30) DEFAULT NULL,
+`c82` varchar(30) DEFAULT NULL,
+`c83` varchar(30) DEFAULT NULL,
+`c84` varchar(30) DEFAULT NULL,
+`c85` varchar(30) DEFAULT NULL,
+`c86` varchar(30) DEFAULT NULL,
+`c87` varchar(30) DEFAULT NULL,
+`c88` varchar(30) DEFAULT NULL,
+`c89` varchar(30) DEFAULT NULL,
+`c90` varchar(30) DEFAULT NULL,
+`c91` varchar(30) DEFAULT NULL,
+`c92` varchar(30) DEFAULT NULL,
+`c93` varchar(30) DEFAULT NULL,
+`c94` varchar(30) DEFAULT NULL,
+`c95` varchar(30) DEFAULT NULL,
+`c96` varchar(30) DEFAULT NULL,
+`c97` varchar(30) DEFAULT NULL,
+`c98` varchar(30) DEFAULT NULL,
+`c99` varchar(30) DEFAULT NULL,
+`c100` varchar(30) DEFAULT NULL,
+`c101` varchar(30) DEFAULT NULL,
+`c102` varchar(30) DEFAULT NULL,
+`c103` varchar(30) DEFAULT NULL,
+`c104` varchar(30) DEFAULT NULL,
+`c105` varchar(30) DEFAULT NULL,
+`c106` varchar(30) DEFAULT NULL,
+`c107` varchar(30) DEFAULT NULL,
+`c108` varchar(30) DEFAULT NULL,
+`c109` varchar(30) DEFAULT NULL,
+`c110` varchar(30) DEFAULT NULL,
+`c111` varchar(30) DEFAULT NULL,
+`c112` varchar(30) DEFAULT NULL,
+`c113` varchar(30) DEFAULT NULL,
+`c114` varchar(30) DEFAULT NULL,
+`c115` varchar(30) DEFAULT NULL,
+`c116` varchar(30) DEFAULT NULL,
+`c117` varchar(30) DEFAULT NULL,
+`c118` varchar(30) DEFAULT NULL,
+`c119` varchar(30) DEFAULT NULL,
+`c120` varchar(30) DEFAULT NULL,
+`c121` varchar(30) DEFAULT NULL,
+`c122` varchar(30) DEFAULT NULL,
+`c123` varchar(30) DEFAULT NULL,
+`c124` varchar(30) DEFAULT NULL,
+`c125` varchar(30) DEFAULT NULL,
+`c126` varchar(30) DEFAULT NULL,
+`c127` varchar(30) DEFAULT NULL,
+`c128` varchar(30) DEFAULT NULL,
+`c129` varchar(30) DEFAULT NULL,
+`c130` varchar(30) DEFAULT NULL,
+`c131` varchar(30) DEFAULT NULL,
+`c132` varchar(30) DEFAULT NULL,
+`c133` varchar(30) DEFAULT NULL,
+`c134` varchar(30) DEFAULT NULL,
+`c135` varchar(30) DEFAULT NULL,
+`c136` varchar(30) DEFAULT NULL,
+`c137` varchar(30) DEFAULT NULL,
+`c138` varchar(30) DEFAULT NULL,
+`c139` varchar(30) DEFAULT NULL,
+`c140` varchar(30) DEFAULT NULL,
+`c141` varchar(30) DEFAULT NULL,
+`c142` varchar(30) DEFAULT NULL,
+`c143` varchar(30) DEFAULT NULL,
+`c144` varchar(30) DEFAULT NULL,
+`c145` varchar(30) DEFAULT NULL,
+`c146` varchar(30) DEFAULT NULL,
+PRIMARY KEY (`c1`)
+) ENGINE=InnoDB;
+LOCK TABLES `t1` WRITE;
+INSERT INTO `t1` VALUES ('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','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');
+DROP TABLE `t1`;
+FLUSH LOGS;
+=== Using mysqlbinlog to detect failure. Before the patch mysqlbinlog would find a corrupted event, thence would fail.

=== modified file 'mysql-test/suite/binlog/r/binlog_unsafe.result'
--- a/mysql-test/suite/binlog/r/binlog_unsafe.result	2009-04-03 18:21:57 +0000
+++ b/mysql-test/suite/binlog/r/binlog_unsafe.result	2009-05-20 10:28:43 +0000
@@ -10,25 +10,25 @@ INSERT DELAYED INTO t1 VALUES (5);
 ---- Insert directly ----
 INSERT INTO t1 VALUES (@@global.sync_binlog);
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 INSERT INTO t1 VALUES (@@session.insert_id);
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 INSERT INTO t1 VALUES (@@global.auto_increment_increment);
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 INSERT INTO t2 SELECT UUID();
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 INSERT INTO t2 VALUES (@@session.sql_mode);
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 INSERT INTO t2 VALUES (@@global.init_slave);
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 INSERT INTO t2 VALUES (@@hostname);
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 ---- Insert from stored procedure ----
 CREATE PROCEDURE proc()
 BEGIN
@@ -42,13 +42,13 @@ INSERT INTO t2 VALUES (@@hostname);
 END|
 CALL proc();
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 ---- Insert from stored function ----
 CREATE FUNCTION func()
 RETURNS INT
@@ -66,13 +66,13 @@ SELECT func();
 func()
 0
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 ---- Insert from trigger ----
 CREATE TRIGGER trig
 BEFORE INSERT ON trigger_table
@@ -88,14 +88,14 @@ INSERT INTO t2 VALUES (@@hostname);
 END|
 INSERT INTO trigger_table VALUES ('bye.');
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 ---- Insert from prepared statement ----
 PREPARE p1 FROM 'INSERT INTO t1 VALUES (@@global.sync_binlog)';
 PREPARE p2 FROM 'INSERT INTO t1 VALUES (@@session.insert_id)';
@@ -106,25 +106,25 @@ PREPARE p6 FROM 'INSERT INTO t2 VALUES (
 PREPARE p7 FROM 'INSERT INTO t2 VALUES (@@hostname)';
 EXECUTE p1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 EXECUTE p2;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 EXECUTE p3;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 EXECUTE p4;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 EXECUTE p5;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 EXECUTE p6;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 EXECUTE p7;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 ---- Insert from nested call of triggers / functions / procedures ----
 CREATE PROCEDURE proc1()
 INSERT INTO trigger_table VALUES ('ha!')|
@@ -154,13 +154,13 @@ EXECUTE prep6;
 func5()
 0
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 ==== Variables that should *not* be unsafe ====
 INSERT INTO t1 VALUES (@@session.pseudo_thread_id);
 INSERT INTO t1 VALUES (@@session.pseudo_thread_id);
@@ -195,16 +195,16 @@ DROP TABLE t1, t2, t3, trigger_table, tr
 CREATE TABLE t1(a INT, b INT, KEY(a), PRIMARY KEY(b));
 INSERT INTO t1 SELECT * FROM t1 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 REPLACE INTO t1 SELECT * FROM t1 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 UPDATE t1 SET a=1 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 DELETE FROM t1 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 CREATE PROCEDURE p1()
 BEGIN
 INSERT INTO t1 SELECT * FROM t1 LIMIT 1;
@@ -214,10 +214,10 @@ DELETE FROM t1 LIMIT 1;
 END|
 CALL p1();
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 DROP PROCEDURE p1;
 DROP TABLE t1;
 DROP TABLE IF EXISTS t1;
@@ -225,16 +225,16 @@ CREATE TABLE t1 (a VARCHAR(100), b VARCH
 INSERT INTO t1 VALUES ('a','b');
 UPDATE t1 SET b = '%s%s%s%s%s%s%s%s%s%s%s%s%s%s' WHERE a = 'a' LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 DROP TABLE t1;
 DROP TABLE IF EXISTS t1, t2;
 CREATE TABLE t1(i INT PRIMARY KEY);
 CREATE TABLE t2(i INT PRIMARY KEY);
 CREATE TABLE t3(i INT, ch CHAR(50));
-"Should issue message Statement is not safe to log in statement format."
+"Should issue message Statement may not be safe to log in statement format."
 INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 CREATE FUNCTION func6()
 RETURNS INT
 BEGIN
@@ -243,10 +243,10 @@ INSERT INTO t1 VALUES (11);
 INSERT INTO t1 VALUES (12);
 RETURN 0;
 END|
-"Should issue message Statement is not safe to log in statement format only once"
+"Should issue message Statement may not be safe to log in statement format only once"
 INSERT INTO t3 VALUES(func6(), UUID());
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 "Check whether SET @@SQL_LOG_BIN = 0/1 doesn't work in substatements"
 CREATE FUNCTION fun_check_log_bin() RETURNS INT
 BEGIN
@@ -259,7 +259,7 @@ SELECT fun_check_log_bin();
 fun_check_log_bin()
 100
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 "SQL_LOG_BIN should be ON still"
 SHOW VARIABLES LIKE "SQL_LOG_BIN";
 Variable_name	Value
@@ -315,16 +315,16 @@ CREATE TABLE t1(i INT PRIMARY KEY);
 CREATE TABLE t2(i INT PRIMARY KEY);
 INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 INSERT INTO t1 VALUES(@@global.sync_binlog);
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 UPDATE t1 SET i = 999 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 DELETE FROM t1 LIMIT 1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 DROP TABLE t1, t2;
 SET @@SESSION.SQL_MODE = @save_sql_mode;
 "End of tests"

=== added file 'mysql-test/suite/binlog/t/binlog_incident-master.opt'
--- a/mysql-test/suite/binlog/t/binlog_incident-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_incident-master.opt	2009-05-11 11:32:38 +0000
@@ -0,0 +1 @@
+--loose-debug=+d,incident_database_resync_on_replace
\ No newline at end of file

=== added file 'mysql-test/suite/binlog/t/binlog_incident.test'
--- a/mysql-test/suite/binlog/t/binlog_incident.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_incident.test	2009-05-11 11:32:38 +0000
@@ -0,0 +1,27 @@
+# The purpose of this test is to provide a reference for how the
+# incident log event is represented in the output from the mysqlbinlog
+# program.
+
+source include/have_log_bin.inc;
+source include/have_debug.inc;
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+CREATE TABLE t1 (a INT);
+
+INSERT INTO t1 VALUES (1),(2),(3);
+SELECT * FROM t1;
+
+# This will generate an incident log event and store it in the binary
+# log before the replace statement.
+REPLACE INTO t1 VALUES (4);
+
+DROP TABLE t1;
+FLUSH LOGS;
+
+exec $MYSQL_BINLOG --start-position=106 $MYSQLD_DATADIR/master-bin.000001 >$MYSQLTEST_VARDIR/tmp/binlog_incident-bug44442.sql;
+--disable_query_log
+eval SELECT cont LIKE '%RELOAD DATABASE; # Shall generate syntax error%' AS `Contain RELOAD DATABASE` FROM (SELECT load_file('$MYSQLTEST_VARDIR/tmp/binlog_incident-bug44442.sql') AS cont) AS tbl;
+--enable_query_log
+
+remove_file $MYSQLTEST_VARDIR/tmp/binlog_incident-bug44442.sql;
\ No newline at end of file

=== added file 'mysql-test/suite/binlog/t/binlog_tbl_metadata.test'
--- a/mysql-test/suite/binlog/t/binlog_tbl_metadata.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_tbl_metadata.test	2009-05-12 11:53:46 +0000
@@ -0,0 +1,199 @@
+#
+# BUG#42749: infinite loop writing to row based binlog - processlist shows
+# "freeing items"
+#
+# WHY
+# ===
+#   
+#   This bug would make table map event to report data_written one byte less
+#   than what would actually be written in its body. This would cause one byte shorter
+#   event end_log_pos. The ultimate impact was that it would make fixing the
+#   position in MYSQL_BIN_LOG::write_cache bogus or end up in an infinite loop.
+#
+# HOW
+# ===
+#
+#   Checking that the patch fixes the problem is done as follows:
+#     i) a table with several fields is created;
+#    ii) an insert is performed;
+#   iii) the logs are flushed;
+#    iv) mysqlbinlog is used to check if it succeeds.
+# 
+#   In step iv), before the bug was fixed, the test case would fail with
+#   mysqlbinlog reporting that it was unable to succeed in reading the event.
+#
+
+-- source include/have_log_bin.inc
+-- source include/have_innodb.inc
+-- source include/have_binlog_format_row.inc
+-- connection default
+
+RESET MASTER;
+
+-- disable_warnings
+DROP TABLE IF EXISTS `t1`;
+-- enable_warnings
+
+CREATE TABLE `t1` (
+  `c1` int(11) NOT NULL AUTO_INCREMENT,
+  `c2` varchar(30) NOT NULL,
+  `c3` varchar(30) DEFAULT NULL,
+  `c4` varchar(30) DEFAULT NULL,
+  `c5` varchar(30) DEFAULT NULL,
+  `c6` varchar(30) DEFAULT NULL,
+  `c7` varchar(30) DEFAULT NULL,
+  `c8` varchar(30) DEFAULT NULL,
+  `c9` varchar(30) DEFAULT NULL,
+  `c10` varchar(30) DEFAULT NULL,
+  `c11` varchar(30) DEFAULT NULL,
+  `c12` varchar(30) DEFAULT NULL,
+  `c13` varchar(30) DEFAULT NULL,
+  `c14` varchar(30) DEFAULT NULL,
+  `c15` varchar(30) DEFAULT NULL,
+  `c16` varchar(30) DEFAULT NULL,
+  `c17` varchar(30) DEFAULT NULL,
+  `c18` varchar(30) DEFAULT NULL,
+  `c19` varchar(30) DEFAULT NULL,
+  `c20` varchar(30) DEFAULT NULL,
+  `c21` varchar(30) DEFAULT NULL,
+  `c22` varchar(30) DEFAULT NULL,
+  `c23` varchar(30) DEFAULT NULL,
+  `c24` varchar(30) DEFAULT NULL,
+  `c25` varchar(30) DEFAULT NULL,
+  `c26` varchar(30) DEFAULT NULL,
+  `c27` varchar(30) DEFAULT NULL,
+  `c28` varchar(30) DEFAULT NULL,
+  `c29` varchar(30) DEFAULT NULL,
+  `c30` varchar(30) DEFAULT NULL,
+  `c31` varchar(30) DEFAULT NULL,
+  `c32` varchar(30) DEFAULT NULL,
+  `c33` varchar(30) DEFAULT NULL,
+  `c34` varchar(30) DEFAULT NULL,
+  `c35` varchar(30) DEFAULT NULL,
+  `c36` varchar(30) DEFAULT NULL,
+  `c37` varchar(30) DEFAULT NULL,
+  `c38` varchar(30) DEFAULT NULL,
+  `c39` varchar(30) DEFAULT NULL,
+  `c40` varchar(30) DEFAULT NULL,
+  `c41` varchar(30) DEFAULT NULL,
+  `c42` varchar(30) DEFAULT NULL,
+  `c43` varchar(30) DEFAULT NULL,
+  `c44` varchar(30) DEFAULT NULL,
+  `c45` varchar(30) DEFAULT NULL,
+  `c46` varchar(30) DEFAULT NULL,
+  `c47` varchar(30) DEFAULT NULL,
+  `c48` varchar(30) DEFAULT NULL,
+  `c49` varchar(30) DEFAULT NULL,
+  `c50` varchar(30) DEFAULT NULL,
+  `c51` varchar(30) DEFAULT NULL,
+  `c52` varchar(30) DEFAULT NULL,
+  `c53` varchar(30) DEFAULT NULL,
+  `c54` varchar(30) DEFAULT NULL,
+  `c55` varchar(30) DEFAULT NULL,
+  `c56` varchar(30) DEFAULT NULL,
+  `c57` varchar(30) DEFAULT NULL,
+  `c58` varchar(30) DEFAULT NULL,
+  `c59` varchar(30) DEFAULT NULL,
+  `c60` varchar(30) DEFAULT NULL,
+  `c61` varchar(30) DEFAULT NULL,
+  `c62` varchar(30) DEFAULT NULL,
+  `c63` varchar(30) DEFAULT NULL,
+  `c64` varchar(30) DEFAULT NULL,
+  `c65` varchar(30) DEFAULT NULL,
+  `c66` varchar(30) DEFAULT NULL,
+  `c67` varchar(30) DEFAULT NULL,
+  `c68` varchar(30) DEFAULT NULL,
+  `c69` varchar(30) DEFAULT NULL,
+  `c70` varchar(30) DEFAULT NULL,
+  `c71` varchar(30) DEFAULT NULL,
+  `c72` varchar(30) DEFAULT NULL,
+  `c73` varchar(30) DEFAULT NULL,
+  `c74` varchar(30) DEFAULT NULL,
+  `c75` varchar(30) DEFAULT NULL,
+  `c76` varchar(30) DEFAULT NULL,
+  `c77` varchar(30) DEFAULT NULL,
+  `c78` varchar(30) DEFAULT NULL,
+  `c79` varchar(30) DEFAULT NULL,
+  `c80` varchar(30) DEFAULT NULL,
+  `c81` varchar(30) DEFAULT NULL,
+  `c82` varchar(30) DEFAULT NULL,
+  `c83` varchar(30) DEFAULT NULL,
+  `c84` varchar(30) DEFAULT NULL,
+  `c85` varchar(30) DEFAULT NULL,
+  `c86` varchar(30) DEFAULT NULL,
+  `c87` varchar(30) DEFAULT NULL,
+  `c88` varchar(30) DEFAULT NULL,
+  `c89` varchar(30) DEFAULT NULL,
+  `c90` varchar(30) DEFAULT NULL,
+  `c91` varchar(30) DEFAULT NULL,
+  `c92` varchar(30) DEFAULT NULL,
+  `c93` varchar(30) DEFAULT NULL,
+  `c94` varchar(30) DEFAULT NULL,
+  `c95` varchar(30) DEFAULT NULL,
+  `c96` varchar(30) DEFAULT NULL,
+  `c97` varchar(30) DEFAULT NULL,
+  `c98` varchar(30) DEFAULT NULL,
+  `c99` varchar(30) DEFAULT NULL,
+  `c100` varchar(30) DEFAULT NULL,
+  `c101` varchar(30) DEFAULT NULL,
+  `c102` varchar(30) DEFAULT NULL,
+  `c103` varchar(30) DEFAULT NULL,
+  `c104` varchar(30) DEFAULT NULL,
+  `c105` varchar(30) DEFAULT NULL,
+  `c106` varchar(30) DEFAULT NULL,
+  `c107` varchar(30) DEFAULT NULL,
+  `c108` varchar(30) DEFAULT NULL,
+  `c109` varchar(30) DEFAULT NULL,
+  `c110` varchar(30) DEFAULT NULL,
+  `c111` varchar(30) DEFAULT NULL,
+  `c112` varchar(30) DEFAULT NULL,
+  `c113` varchar(30) DEFAULT NULL,
+  `c114` varchar(30) DEFAULT NULL,
+  `c115` varchar(30) DEFAULT NULL,
+  `c116` varchar(30) DEFAULT NULL,
+  `c117` varchar(30) DEFAULT NULL,
+  `c118` varchar(30) DEFAULT NULL,
+  `c119` varchar(30) DEFAULT NULL,
+  `c120` varchar(30) DEFAULT NULL,
+  `c121` varchar(30) DEFAULT NULL,
+  `c122` varchar(30) DEFAULT NULL,
+  `c123` varchar(30) DEFAULT NULL,
+  `c124` varchar(30) DEFAULT NULL,
+  `c125` varchar(30) DEFAULT NULL,
+  `c126` varchar(30) DEFAULT NULL,
+  `c127` varchar(30) DEFAULT NULL,
+  `c128` varchar(30) DEFAULT NULL,
+  `c129` varchar(30) DEFAULT NULL,
+  `c130` varchar(30) DEFAULT NULL,
+  `c131` varchar(30) DEFAULT NULL,
+  `c132` varchar(30) DEFAULT NULL,
+  `c133` varchar(30) DEFAULT NULL,
+  `c134` varchar(30) DEFAULT NULL,
+  `c135` varchar(30) DEFAULT NULL,
+  `c136` varchar(30) DEFAULT NULL,
+  `c137` varchar(30) DEFAULT NULL,
+  `c138` varchar(30) DEFAULT NULL,
+  `c139` varchar(30) DEFAULT NULL,
+  `c140` varchar(30) DEFAULT NULL,
+  `c141` varchar(30) DEFAULT NULL,
+  `c142` varchar(30) DEFAULT NULL,
+  `c143` varchar(30) DEFAULT NULL,
+  `c144` varchar(30) DEFAULT NULL,
+  `c145` varchar(30) DEFAULT NULL,
+  `c146` varchar(30) DEFAULT NULL,
+  PRIMARY KEY (`c1`)
+) ENGINE=InnoDB;
+
+LOCK TABLES `t1` WRITE;
+
+INSERT INTO `t1` VALUES ('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','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');
+
+DROP TABLE `t1`;
+
+FLUSH LOGS;
+
+-- echo === Using mysqlbinlog to detect failure. Before the patch mysqlbinlog would find a corrupted event, thence would fail.
+
+-- let $MYSQLD_DATADIR= `SELECT @@datadir`;
+-- exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug42749.binlog
+-- remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug42749.binlog

=== modified file 'mysql-test/suite/binlog/t/binlog_unsafe.test'
--- a/mysql-test/suite/binlog/t/binlog_unsafe.test	2009-04-03 18:21:57 +0000
+++ b/mysql-test/suite/binlog/t/binlog_unsafe.test	2009-05-20 10:28:43 +0000
@@ -289,7 +289,7 @@ CREATE TABLE t1(i INT PRIMARY KEY);
 CREATE TABLE t2(i INT PRIMARY KEY);
 CREATE TABLE t3(i INT, ch CHAR(50));
 
---echo "Should issue message Statement is not safe to log in statement format."
+--echo "Should issue message Statement may not be safe to log in statement format."
 INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
 
 DELIMITER |;
@@ -302,7 +302,7 @@ BEGIN
   RETURN 0;
 END|
 DELIMITER ;|
---echo "Should issue message Statement is not safe to log in statement format only once"
+--echo "Should issue message Statement may not be safe to log in statement format only once"
 INSERT INTO t3 VALUES(func6(), UUID());
 
 --echo "Check whether SET @@SQL_LOG_BIN = 0/1 doesn't work in substatements"

=== modified file 'mysql-test/suite/funcs_1/datadict/is_routines.inc'
--- a/mysql-test/suite/funcs_1/datadict/is_routines.inc	2009-02-01 17:15:58 +0000
+++ b/mysql-test/suite/funcs_1/datadict/is_routines.inc	2009-04-01 08:59:10 +0000
@@ -96,10 +96,11 @@ CREATE FUNCTION function_for_routines() 
 SELECT specific_name,routine_catalog,routine_schema,routine_name,routine_type,
        routine_body,external_name,external_language,parameter_style,sql_path
 FROM information_schema.routines
-WHERE routine_catalog   IS NOT NULL OR external_name   IS NOT NULL
+WHERE routine_schema = 'test' AND
+   (routine_catalog   IS NOT NULL OR external_name   IS NOT NULL
    OR external_language IS NOT NULL OR sql_path        IS NOT NULL
    OR routine_body      <> 'SQL'    OR parameter_style <> 'SQL'
-   OR specific_name     <> routine_name;
+   OR specific_name     <> routine_name);
 
 DROP PROCEDURE sp_for_routines;
 DROP FUNCTION  function_for_routines;

=== modified file 'mysql-test/suite/funcs_1/r/is_routines.result'
--- a/mysql-test/suite/funcs_1/r/is_routines.result	2008-11-13 09:50:20 +0000
+++ b/mysql-test/suite/funcs_1/r/is_routines.result	2009-04-01 09:33:36 +0000
@@ -111,10 +111,11 @@ CREATE FUNCTION function_for_routines() 
 SELECT specific_name,routine_catalog,routine_schema,routine_name,routine_type,
 routine_body,external_name,external_language,parameter_style,sql_path
 FROM information_schema.routines
-WHERE routine_catalog   IS NOT NULL OR external_name   IS NOT NULL
+WHERE routine_schema = 'test' AND
+(routine_catalog   IS NOT NULL OR external_name   IS NOT NULL
 OR external_language IS NOT NULL OR sql_path        IS NOT NULL
 OR routine_body      <> 'SQL'    OR parameter_style <> 'SQL'
-   OR specific_name     <> routine_name;
+   OR specific_name     <> routine_name);
 specific_name	routine_catalog	routine_schema	routine_name	routine_type	routine_body	external_name	external_language	parameter_style	sql_path
 DROP PROCEDURE sp_for_routines;
 DROP FUNCTION  function_for_routines;

=== added file 'mysql-test/suite/ibmdb2i/include/have_i54.inc'
--- a/mysql-test/suite/ibmdb2i/include/have_i54.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ibmdb2i/include/have_i54.inc	2009-05-14 10:35:09 +0000
@@ -0,0 +1,20 @@
+# Check for IBM i 6.1 or later
+--disable_query_log
+system uname -rv > $MYSQLTEST_VARDIR/tmp/version;
+--disable_warnings
+drop table if exists uname_vr;
+--enable_warnings
+create temporary table uname_vr (r int, v int);
+--disable_warnings
+eval LOAD DATA INFILE "$MYSQLTEST_VARDIR/tmp/version" into table uname_vr fields terminated by ' ';
+--enable_warnings
+let $ok = `select count(*) from uname_vr where v = 5 and r = 4`;
+drop table uname_vr;
+remove_file $MYSQLTEST_VARDIR/tmp/version;
+--enable_query_log
+if (!$ok)
+{
+  skip "Need IBM i 5.4 or later";
+}
+  
+

=== added file 'mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44232.result'
--- a/mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44232.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44232.result	2009-05-14 10:35:09 +0000
@@ -0,0 +1,4 @@
+create table t1 (c char(1) character set armscii8) engine=ibmdb2i;
+ERROR HY000: Can't create table 'test.t1' (errno: 2504)
+create table t1 (c char(1) character set eucjpms ) engine=ibmdb2i;
+ERROR HY000: Can't create table 'test.t1' (errno: 2504)

=== added file 'mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44610.result'
--- a/mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44610.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ibmdb2i/r/ibmdb2i_bug_44610.result	2009-05-17 16:25:23 +0000
@@ -0,0 +1,18 @@
+create table ABC (i int) engine=ibmdb2i;
+drop table ABC;
+create table `1234567890ABC` (i int) engine=ibmdb2i;
+drop table `1234567890ABC`;
+create table `!@#$%` (i int) engine=ibmdb2i;
+drop table `!@#$%`;
+create table `ABCD#########` (i int) engine=ibmdb2i;
+drop table `ABCD#########`;
+create table `_` (i int) engine=ibmdb2i;
+drop table `_`;
+create table `abc##def` (i int) engine=ibmdb2i;
+drop table `abc##def`;
+set names utf8;
+create table İ (s1 int) engine=ibmdb2i;
+drop table İ;
+create table İİ (s1 int) engine=ibmdb2i;
+drop table İİ;
+set names latin1;

=== added file 'mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44232.test'
--- a/mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44232.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44232.test	2009-05-14 10:35:09 +0000
@@ -0,0 +1,8 @@
+--source suite/ibmdb2i/include/have_ibmdb2i.inc
+--source suite/ibmdb2i/include/have_i54.inc
+
+--error 1005
+create table t1 (c char(1) character set armscii8) engine=ibmdb2i;
+
+--error 1005
+create table t1 (c char(1) character set eucjpms ) engine=ibmdb2i;

=== added file 'mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44610.test'
--- a/mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44610.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ibmdb2i/t/ibmdb2i_bug_44610.test	2009-05-17 16:25:23 +0000
@@ -0,0 +1,28 @@
+source suite/ibmdb2i/include/have_ibmdb2i.inc;
+
+# Test RCDFMT generation for a variety of kinds of table names
+create table ABC (i int) engine=ibmdb2i;
+drop table ABC;
+
+create table `1234567890ABC` (i int) engine=ibmdb2i;
+drop table `1234567890ABC`;
+
+create table `!@#$%` (i int) engine=ibmdb2i;
+drop table `!@#$%`;
+
+create table `ABCD#########` (i int) engine=ibmdb2i;
+drop table `ABCD#########`;
+
+create table `_` (i int) engine=ibmdb2i;
+drop table `_`;
+
+create table `abc##def` (i int) engine=ibmdb2i;
+drop table `abc##def`;
+
+set names utf8;
+create table İ (s1 int) engine=ibmdb2i;
+drop table İ;
+
+create table İİ (s1 int) engine=ibmdb2i;
+drop table İİ;
+set names latin1;

=== modified file 'mysql-test/suite/rpl/r/rpl_slave_load_tmpdir_not_exist.result'
--- a/mysql-test/suite/rpl/r/rpl_slave_load_tmpdir_not_exist.result	2009-03-23 01:07:25 +0000
+++ b/mysql-test/suite/rpl/r/rpl_slave_load_tmpdir_not_exist.result	2009-04-19 01:21:33 +0000
@@ -3,4 +3,4 @@ MASTER_CONNECT_RETRY=1,
 MASTER_HOST='127.0.0.1',
 MASTER_PORT=MASTER_MYPORT;
 START SLAVE;
-Unable to use slave's temporary directory ../../../error - Can't read dir of '../../../error' (Errcode: 2)
+12

=== modified file 'mysql-test/suite/rpl/r/rpl_slave_skip.result'
--- a/mysql-test/suite/rpl/r/rpl_slave_skip.result	2009-01-23 12:22:05 +0000
+++ b/mysql-test/suite/rpl/r/rpl_slave_skip.result	2009-05-05 09:38:19 +0000
@@ -39,8 +39,8 @@ a	b
 SELECT * FROM t2;
 c	d
 1	2
-2	16
-3	54
+2	8
+3	18
 **** On Slave ****
 START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=762;
 SHOW SLAVE STATUS;
@@ -50,7 +50,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	1133
+Read_Master_Log_Pos	1115
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000001

=== modified file 'mysql-test/suite/rpl/r/rpl_stm_loadfile.result'
--- a/mysql-test/suite/rpl/r/rpl_stm_loadfile.result	2009-04-03 18:21:57 +0000
+++ b/mysql-test/suite/rpl/r/rpl_stm_loadfile.result	2009-05-20 10:28:43 +0000
@@ -10,7 +10,7 @@ CREATE TABLE test.t1 (a INT, blob_column
 INSERT INTO test.t1  VALUES(1,'test');
 UPDATE test.t1 SET blob_column=LOAD_FILE('../../std_data/words2.dat') WHERE a=1;
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 create procedure test.p1()
 begin
 INSERT INTO test.t1  VALUES(2,'test');
@@ -18,7 +18,7 @@ UPDATE test.t1 SET blob_column=LOAD_FILE
 end|
 CALL test.p1();
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 SELECT * FROM test.t1 ORDER BY blob_column;
 a	blob_column
 1	abase

=== modified file 'mysql-test/suite/rpl/r/rpl_temporary.result'
--- a/mysql-test/suite/rpl/r/rpl_temporary.result	2009-03-27 11:20:37 +0000
+++ b/mysql-test/suite/rpl/r/rpl_temporary.result	2009-05-22 23:29:41 +0000
@@ -6,6 +6,25 @@ drop table if exists t1,t2,t3,t4,t5,t6,t
 start slave;
 call mtr.add_suppression("Slave: Can\'t find record in \'user\' Error_code: 1032");
 reset master;
+DROP TABLE IF EXISTS t1;
+CREATE TEMPORARY TABLE t1 (a char(1));
+INSERT INTO t1 VALUES ('a');
+include/stop_slave.inc
+include/start_slave.inc
+INSERT INTO t1 VALUES ('b');
+DROP TABLE IF EXISTS t1;
+CREATE TEMPORARY TABLE `t1`(`a` tinyint,`b` char(1))engine=myisam;
+INSERT INTO `t1` set `a`=128,`b`='128';
+Warnings:
+Warning	1264	Out of range value for column 'a' at row 1
+Warning	1265	Data truncated for column 'b' at row 1
+include/stop_slave.inc
+include/start_slave.inc
+INSERT INTO `t1` set `a`=128,`b`='128';
+Warnings:
+Warning	1264	Out of range value for column 'a' at row 1
+Warning	1265	Data truncated for column 'b' at row 1
+DROP TABLE t1;
 SET @save_select_limit=@@session.sql_select_limit;
 SET @@session.sql_select_limit=10, @@session.pseudo_thread_id=100;
 ERROR 42000: Access denied; you need the SUPER privilege for this operation

=== modified file 'mysql-test/suite/rpl/r/rpl_udf.result'
--- a/mysql-test/suite/rpl/r/rpl_udf.result	2009-04-03 18:21:57 +0000
+++ b/mysql-test/suite/rpl/r/rpl_udf.result	2009-05-20 10:28:43 +0000
@@ -182,19 +182,19 @@ CREATE TABLE t1(sum INT, price FLOAT(24)
 affected rows: 0
 INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00));
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 affected rows: 1
 INSERT INTO t1 VALUES(myfunc_int(10), myfunc_double(5.00));
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 affected rows: 1
 INSERT INTO t1 VALUES(myfunc_int(200), myfunc_double(25.00));
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 affected rows: 1
 INSERT INTO t1 VALUES(myfunc_int(1), myfunc_double(500.00));
 Warnings:
-Note	1592	Statement is not safe to log in statement format.
+Note	1592	Statement may not be safe to log in statement format.
 affected rows: 1
 SELECT * FROM t1 ORDER BY sum;
 sum	price

=== modified file 'mysql-test/suite/rpl/t/disabled.def'
--- a/mysql-test/suite/rpl/t/disabled.def	2009-04-15 11:43:17 +0000
+++ b/mysql-test/suite/rpl/t/disabled.def	2009-05-18 16:53:06 +0000
@@ -10,4 +10,5 @@
 #
 ##############################################################################
 
-rpl_cross_version      : BUG#42311 2009-03-27 joro rpl_cross_version fails on macosx
+rpl_cross_version      : Bug#42311 2009-03-27 joro rpl_cross_version fails on macosx
+rpl_init_slave         : Bug#44920 2009-05-18 pcrews MTR2 is not processing master.opt input properly on Windows

=== modified file 'mysql-test/suite/rpl/t/rpl_incident.test'
--- a/mysql-test/suite/rpl/t/rpl_incident.test	2008-08-14 09:38:22 +0000
+++ b/mysql-test/suite/rpl/t/rpl_incident.test	2009-05-02 19:28:54 +0000
@@ -14,42 +14,13 @@ REPLACE INTO t1 VALUES (4);
 SELECT * FROM t1;
 
 connection slave;
-source include/wait_for_slave_sql_to_stop.inc;
+# Wait until SQL thread stops with error LOST_EVENT on master
+let $slave_sql_errno= 1590;
+source include/wait_for_slave_sql_error.inc;
 
 # The 4 should not be inserted into the table, since the incident log
 # event should have stop the slave.
 --echo **** On Slave ****
-#### BEGIN DEBUG INFO ADDED BY SVEN 2008-07-18 -- SEE BUG#38077 ####
-let $tables= query_get_value(SHOW TABLES, Tables_in_test, 1);
-if (`SELECT '$tables' != 't1'`)
-{
-  --echo **** TEST CASE BUG! PRINTING DEBUG INFO! ****
-  --echo **** Dear developer, if you see this in the output of a test
-  --echo **** case run, please add all the information below as a
-  --echo **** comment to BUG#38077. If it's a pushbuild failure, please
-  --echo **** include a link to the push page.
-  --echo **** Thank you! /Sven
-  SHOW BINLOG EVENTS;
-  --echo **** master binlog ****
-  --error 0,1
-  --exec $MYSQL_BINLOG --hexdump $MYSQLTEST_VARDIR/log/master-bin.000001
-  --echo **** slave binlog ****
-  --error 0,1
-  --exec $MYSQL_BINLOG --hexdump $MYSQLTEST_VARDIR/log/slave-bin.000001
-  --echo **** slave status ****
-  query_vertical SHOW SLAVE STATUS;
-  --echo **** slave's master status ****
-  SHOW MASTER STATUS;
-  --echo **** slave binlog events ****
-  --echo [on master]
-  connection master;
-  --echo **** master status ****
-  SHOW MASTER STATUS;
-  --echo **** master binlog events ****
-  SHOW BINLOG EVENTS;
-  exit;
-}
-#### END DEBUG INFO ####
 SELECT * FROM t1;
 
 --replace_result $MASTER_MYPORT MASTER_PORT

=== modified file 'mysql-test/suite/rpl/t/rpl_slave_load_tmpdir_not_exist.test'
--- a/mysql-test/suite/rpl/t/rpl_slave_load_tmpdir_not_exist.test	2009-03-23 01:07:25 +0000
+++ b/mysql-test/suite/rpl/t/rpl_slave_load_tmpdir_not_exist.test	2009-04-19 01:21:33 +0000
@@ -20,5 +20,5 @@ eval CHANGE MASTER TO MASTER_USER='root'
 START SLAVE;
 
 source include/wait_for_slave_sql_to_stop.inc;
-let $error=query_get_value("show slave status", Last_SQL_Error, 1);
-echo $error;
+let $errno=query_get_value("show slave status", Last_SQL_Errno, 1);
+echo $errno;

=== modified file 'mysql-test/suite/rpl/t/rpl_temporary.test'
--- a/mysql-test/suite/rpl/t/rpl_temporary.test	2009-03-27 11:20:37 +0000
+++ b/mysql-test/suite/rpl/t/rpl_temporary.test	2009-05-22 23:29:41 +0000
@@ -22,6 +22,77 @@ call mtr.add_suppression("Slave: Can\'t 
 
 sync_with_master;
 reset master;
+
+# ##################################################################
+# BUG#41725: slave crashes when inserting into temporary table after
+#            stop/start slave
+#
+#  This test checks that both reported issues (assertion failure and
+#  crash) go away. It is implemented as follows:
+#    
+#    case 1: assertion failure
+#      i) create and insert into temporary table on master
+#     ii) sync slave with master
+#    iii) stop and restart slave
+#     iv) insert into master another value
+#      v) sync slave with master
+#
+#
+#    case 2: crash (SIGSEV)
+#      i) create and insert into temporary table on master (insert
+#         produces warnings)
+#     ii) sync slave with master
+#    iii) stop and restart slave
+#     iv) insert into master more values
+#      v) sync slave with master
+
+# case 1: Assertion in Field_string::store() failed because current 
+#         thread reference differed from table->in_use after slave 
+#         restart
+
+connection master;
+
+disable_warnings;
+DROP TABLE IF EXISTS t1;
+enable_warnings;
+
+CREATE TEMPORARY TABLE t1 (a char(1));
+INSERT INTO t1 VALUES ('a');
+sync_slave_with_master;
+
+source include/stop_slave.inc;
+source include/start_slave.inc;
+
+connection master;
+INSERT INTO t1 VALUES ('b');
+sync_slave_with_master;
+
+# case 2: crash on sp_rcontext::find_handler because it used 
+#         reference to invalid THD object after slave restart
+
+connection master;
+
+disable_warnings;
+DROP TABLE IF EXISTS t1;
+enable_warnings;
+CREATE TEMPORARY TABLE `t1`(`a` tinyint,`b` char(1))engine=myisam;
+INSERT INTO `t1` set `a`=128,`b`='128';
+
+sync_slave_with_master;
+
+source include/stop_slave.inc;
+source include/start_slave.inc;
+
+connection master;
+INSERT INTO `t1` set `a`=128,`b`='128';
+sync_slave_with_master;
+
+# cleanup
+
+connection master;
+DROP TABLE t1;
+sync_slave_with_master;
+
 connection master;
 
 connect (con1,localhost,root,,);

=== modified file 'mysql-test/suite/rpl_ndb/t/rpl_ndb_2other-slave.opt'
--- a/mysql-test/suite/rpl_ndb/t/rpl_ndb_2other-slave.opt	2008-01-04 14:33:01 +0000
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_2other-slave.opt	2009-05-18 11:39:13 +0000
@@ -1 +1 @@
---innodb --ndbcluster=0 --log-slave-updates=0
+--innodb --loose-ndbcluster=OFF --log-slave-updates=0

=== modified file 'mysql-test/suite/sys_vars/r/innodb_data_home_dir_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_data_home_dir_basic.result	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_data_home_dir_basic.result	2009-05-21 20:22:46 +0000
@@ -1,16 +1,16 @@
 '#---------------------BS_STVARS_025_01----------------------#'
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
 COUNT(@@GLOBAL.innodb_data_home_dir)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_025_02----------------------#'
 SET @@GLOBAL.innodb_data_home_dir=1;
 ERROR HY000: Variable 'innodb_data_home_dir' is a read only variable
 Expected error 'Read only variable'
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
 COUNT(@@GLOBAL.innodb_data_home_dir)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_025_03----------------------#'
 SELECT @@GLOBAL.innodb_data_home_dir = VARIABLE_VALUE
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
@@ -20,8 +20,8 @@ NULL
 1 Expected
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
 COUNT(@@GLOBAL.innodb_data_home_dir)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
 WHERE VARIABLE_NAME='innodb_data_home_dir';
@@ -36,8 +36,8 @@ NULL
 '#---------------------BS_STVARS_025_05----------------------#'
 SELECT COUNT(@@innodb_data_home_dir);
 COUNT(@@innodb_data_home_dir)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(@@local.innodb_data_home_dir);
 ERROR HY000: Variable 'innodb_data_home_dir' is a GLOBAL variable
 Expected error 'Variable is a GLOBAL variable'
@@ -46,8 +46,8 @@ ERROR HY000: Variable 'innodb_data_home_
 Expected error 'Variable is a GLOBAL variable'
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
 COUNT(@@GLOBAL.innodb_data_home_dir)
-1
-1 Expected
+0
+0 Expected
 SELECT innodb_data_home_dir = @@SESSION.innodb_data_home_dir;
 ERROR 42S22: Unknown column 'innodb_data_home_dir' in 'field list'
 Expected error 'Readonly variable'

=== modified file 'mysql-test/suite/sys_vars/r/innodb_flush_method_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_flush_method_basic.result	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_flush_method_basic.result	2009-05-21 20:22:46 +0000
@@ -1,16 +1,16 @@
 '#---------------------BS_STVARS_029_01----------------------#'
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
 COUNT(@@GLOBAL.innodb_flush_method)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_029_02----------------------#'
 SET @@GLOBAL.innodb_flush_method=1;
 ERROR HY000: Variable 'innodb_flush_method' is a read only variable
 Expected error 'Read only variable'
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
 COUNT(@@GLOBAL.innodb_flush_method)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_029_03----------------------#'
 SELECT @@GLOBAL.innodb_flush_method = VARIABLE_VALUE
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
@@ -20,8 +20,8 @@ NULL
 1 Expected
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
 COUNT(@@GLOBAL.innodb_flush_method)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
 WHERE VARIABLE_NAME='innodb_flush_method';
@@ -36,8 +36,8 @@ NULL
 '#---------------------BS_STVARS_029_05----------------------#'
 SELECT COUNT(@@innodb_flush_method);
 COUNT(@@innodb_flush_method)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(@@local.innodb_flush_method);
 ERROR HY000: Variable 'innodb_flush_method' is a GLOBAL variable
 Expected error 'Variable is a GLOBAL variable'
@@ -46,8 +46,8 @@ ERROR HY000: Variable 'innodb_flush_meth
 Expected error 'Variable is a GLOBAL variable'
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
 COUNT(@@GLOBAL.innodb_flush_method)
-1
-1 Expected
+0
+0 Expected
 SELECT innodb_flush_method = @@SESSION.innodb_flush_method;
 ERROR 42S22: Unknown column 'innodb_flush_method' in 'field list'
 Expected error 'Readonly variable'

=== modified file 'mysql-test/suite/sys_vars/r/rpl_init_slave_func.result'
--- a/mysql-test/suite/sys_vars/r/rpl_init_slave_func.result	2009-03-20 17:11:22 +0000
+++ b/mysql-test/suite/sys_vars/r/rpl_init_slave_func.result	2009-05-21 20:22:46 +0000
@@ -12,7 +12,7 @@ DROP TABLE IF EXISTS t1;
 CREATE TEMPORARY TABLE t1 AS SELECT @@global.init_slave AS my_column;
 DESCRIBE t1;
 Field	Type	Null	Key	Default	Extra
-my_column	varchar(59)	NO			
+my_column	varchar(59)	YES		NULL	
 DROP TABLE t1;
 SELECT @@global.init_slave = 'SET @@global.max_connections = @@global.max_connections + 1';
 @@global.init_slave = 'SET @@global.max_connections = @@global.max_connections + 1'

=== modified file 'mysql-test/suite/sys_vars/r/ssl_capath_basic.result'
--- a/mysql-test/suite/sys_vars/r/ssl_capath_basic.result	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/r/ssl_capath_basic.result	2009-05-21 20:22:46 +0000
@@ -1,16 +1,16 @@
 '#---------------------BS_STVARS_046_01----------------------#'
 SELECT COUNT(@@GLOBAL.ssl_capath);
 COUNT(@@GLOBAL.ssl_capath)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_046_02----------------------#'
 SET @@GLOBAL.ssl_capath=1;
 ERROR HY000: Variable 'ssl_capath' is a read only variable
 Expected error 'Read only variable'
 SELECT COUNT(@@GLOBAL.ssl_capath);
 COUNT(@@GLOBAL.ssl_capath)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_046_03----------------------#'
 SELECT @@GLOBAL.ssl_capath = VARIABLE_VALUE
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
@@ -20,8 +20,8 @@ NULL
 1 Expected
 SELECT COUNT(@@GLOBAL.ssl_capath);
 COUNT(@@GLOBAL.ssl_capath)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
 WHERE VARIABLE_NAME='ssl_capath';
@@ -36,8 +36,8 @@ NULL
 '#---------------------BS_STVARS_046_05----------------------#'
 SELECT COUNT(@@ssl_capath);
 COUNT(@@ssl_capath)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(@@local.ssl_capath);
 ERROR HY000: Variable 'ssl_capath' is a GLOBAL variable
 Expected error 'Variable is a GLOBAL variable'
@@ -46,8 +46,8 @@ ERROR HY000: Variable 'ssl_capath' is a 
 Expected error 'Variable is a GLOBAL variable'
 SELECT COUNT(@@GLOBAL.ssl_capath);
 COUNT(@@GLOBAL.ssl_capath)
-1
-1 Expected
+0
+0 Expected
 SELECT ssl_capath = @@SESSION.ssl_capath;
 ERROR 42S22: Unknown column 'ssl_capath' in 'field list'
 Expected error 'Readonly variable'

=== modified file 'mysql-test/suite/sys_vars/r/ssl_cipher_basic.result'
--- a/mysql-test/suite/sys_vars/r/ssl_cipher_basic.result	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/r/ssl_cipher_basic.result	2009-05-21 20:22:46 +0000
@@ -1,16 +1,16 @@
 '#---------------------BS_STVARS_048_01----------------------#'
 SELECT COUNT(@@GLOBAL.ssl_cipher);
 COUNT(@@GLOBAL.ssl_cipher)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_048_02----------------------#'
 SET @@GLOBAL.ssl_cipher=1;
 ERROR HY000: Variable 'ssl_cipher' is a read only variable
 Expected error 'Read only variable'
 SELECT COUNT(@@GLOBAL.ssl_cipher);
 COUNT(@@GLOBAL.ssl_cipher)
-1
-1 Expected
+0
+0 Expected
 '#---------------------BS_STVARS_048_03----------------------#'
 SELECT @@GLOBAL.ssl_cipher = VARIABLE_VALUE
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
@@ -20,8 +20,8 @@ NULL
 1 Expected
 SELECT COUNT(@@GLOBAL.ssl_cipher);
 COUNT(@@GLOBAL.ssl_cipher)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
 WHERE VARIABLE_NAME='ssl_cipher';
@@ -36,8 +36,8 @@ NULL
 '#---------------------BS_STVARS_048_05----------------------#'
 SELECT COUNT(@@ssl_cipher);
 COUNT(@@ssl_cipher)
-1
-1 Expected
+0
+0 Expected
 SELECT COUNT(@@local.ssl_cipher);
 ERROR HY000: Variable 'ssl_cipher' is a GLOBAL variable
 Expected error 'Variable is a GLOBAL variable'
@@ -46,8 +46,8 @@ ERROR HY000: Variable 'ssl_cipher' is a 
 Expected error 'Variable is a GLOBAL variable'
 SELECT COUNT(@@GLOBAL.ssl_cipher);
 COUNT(@@GLOBAL.ssl_cipher)
-1
-1 Expected
+0
+0 Expected
 SELECT ssl_cipher = @@SESSION.ssl_cipher;
 ERROR 42S22: Unknown column 'ssl_cipher' in 'field list'
 Expected error 'Readonly variable'

=== modified file 'mysql-test/suite/sys_vars/t/innodb_data_home_dir_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_data_home_dir_basic.test	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_data_home_dir_basic.test	2009-05-21 20:22:46 +0000
@@ -29,7 +29,7 @@
 #   Displaying default value                                       #
 ####################################################################
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
---echo 1 Expected
+--echo 0 Expected
 
 
 --echo '#---------------------BS_STVARS_025_02----------------------#'
@@ -42,7 +42,7 @@ SET @@GLOBAL.innodb_data_home_dir=1;
 --echo Expected error 'Read only variable'
 
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
---echo 1 Expected
+--echo 0 Expected
 
 
 
@@ -58,7 +58,7 @@ WHERE VARIABLE_NAME='innodb_data_home_di
 --echo 1 Expected
 
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
---echo 1 Expected
+--echo 0 Expected
 
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
@@ -82,7 +82,7 @@ SELECT @@innodb_data_home_dir = @@GLOBAL
 ################################################################################
 
 SELECT COUNT(@@innodb_data_home_dir);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_INCORRECT_GLOBAL_LOCAL_VAR
 SELECT COUNT(@@local.innodb_data_home_dir);
@@ -93,7 +93,7 @@ SELECT COUNT(@@SESSION.innodb_data_home_
 --echo Expected error 'Variable is a GLOBAL variable'
 
 SELECT COUNT(@@GLOBAL.innodb_data_home_dir);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_BAD_FIELD_ERROR
 SELECT innodb_data_home_dir = @@SESSION.innodb_data_home_dir;

=== modified file 'mysql-test/suite/sys_vars/t/innodb_flush_method_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_flush_method_basic.test	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_flush_method_basic.test	2009-05-21 20:22:46 +0000
@@ -29,7 +29,7 @@
 #   Displaying default value                                       #
 ####################################################################
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
---echo 1 Expected
+--echo 0 Expected
 
 
 --echo '#---------------------BS_STVARS_029_02----------------------#'
@@ -42,7 +42,7 @@ SET @@GLOBAL.innodb_flush_method=1;
 --echo Expected error 'Read only variable'
 
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
---echo 1 Expected
+--echo 0 Expected
 
 
 
@@ -58,7 +58,7 @@ WHERE VARIABLE_NAME='innodb_flush_method
 --echo 1 Expected
 
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
---echo 1 Expected
+--echo 0 Expected
 
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
@@ -82,7 +82,7 @@ SELECT @@innodb_flush_method = @@GLOBAL.
 ################################################################################
 
 SELECT COUNT(@@innodb_flush_method);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_INCORRECT_GLOBAL_LOCAL_VAR
 SELECT COUNT(@@local.innodb_flush_method);
@@ -93,7 +93,7 @@ SELECT COUNT(@@SESSION.innodb_flush_meth
 --echo Expected error 'Variable is a GLOBAL variable'
 
 SELECT COUNT(@@GLOBAL.innodb_flush_method);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_BAD_FIELD_ERROR
 SELECT innodb_flush_method = @@SESSION.innodb_flush_method;

=== modified file 'mysql-test/suite/sys_vars/t/ssl_capath_basic.test'
--- a/mysql-test/suite/sys_vars/t/ssl_capath_basic.test	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/t/ssl_capath_basic.test	2009-05-21 20:22:46 +0000
@@ -27,7 +27,7 @@
 #   Displaying default value                                       #
 ####################################################################
 SELECT COUNT(@@GLOBAL.ssl_capath);
---echo 1 Expected
+--echo 0 Expected
 
 
 --echo '#---------------------BS_STVARS_046_02----------------------#'
@@ -40,7 +40,7 @@ SET @@GLOBAL.ssl_capath=1;
 --echo Expected error 'Read only variable'
 
 SELECT COUNT(@@GLOBAL.ssl_capath);
---echo 1 Expected
+--echo 0 Expected
 
 
 
@@ -56,7 +56,7 @@ WHERE VARIABLE_NAME='ssl_capath';
 --echo 1 Expected
 
 SELECT COUNT(@@GLOBAL.ssl_capath);
---echo 1 Expected
+--echo 0 Expected
 
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
@@ -80,7 +80,7 @@ SELECT @@ssl_capath = @@GLOBAL.ssl_capat
 ################################################################################
 
 SELECT COUNT(@@ssl_capath);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_INCORRECT_GLOBAL_LOCAL_VAR
 SELECT COUNT(@@local.ssl_capath);
@@ -91,7 +91,7 @@ SELECT COUNT(@@SESSION.ssl_capath);
 --echo Expected error 'Variable is a GLOBAL variable'
 
 SELECT COUNT(@@GLOBAL.ssl_capath);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_BAD_FIELD_ERROR
 SELECT ssl_capath = @@SESSION.ssl_capath;

=== modified file 'mysql-test/suite/sys_vars/t/ssl_cipher_basic.test'
--- a/mysql-test/suite/sys_vars/t/ssl_cipher_basic.test	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/t/ssl_cipher_basic.test	2009-05-21 20:22:46 +0000
@@ -27,7 +27,7 @@
 #   Displaying default value                                       #
 ####################################################################
 SELECT COUNT(@@GLOBAL.ssl_cipher);
---echo 1 Expected
+--echo 0 Expected
 
 
 --echo '#---------------------BS_STVARS_048_02----------------------#'
@@ -40,7 +40,7 @@ SET @@GLOBAL.ssl_cipher=1;
 --echo Expected error 'Read only variable'
 
 SELECT COUNT(@@GLOBAL.ssl_cipher);
---echo 1 Expected
+--echo 0 Expected
 
 
 
@@ -56,7 +56,7 @@ WHERE VARIABLE_NAME='ssl_cipher';
 --echo 1 Expected
 
 SELECT COUNT(@@GLOBAL.ssl_cipher);
---echo 1 Expected
+--echo 0 Expected
 
 SELECT COUNT(VARIABLE_VALUE)
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
@@ -80,7 +80,7 @@ SELECT @@ssl_cipher = @@GLOBAL.ssl_ciphe
 ################################################################################
 
 SELECT COUNT(@@ssl_cipher);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_INCORRECT_GLOBAL_LOCAL_VAR
 SELECT COUNT(@@local.ssl_cipher);
@@ -91,7 +91,7 @@ SELECT COUNT(@@SESSION.ssl_cipher);
 --echo Expected error 'Variable is a GLOBAL variable'
 
 SELECT COUNT(@@GLOBAL.ssl_cipher);
---echo 1 Expected
+--echo 0 Expected
 
 --Error ER_BAD_FIELD_ERROR
 SELECT ssl_cipher = @@SESSION.ssl_cipher;

=== modified file 'mysql-test/t/archive_bitfield.test'
--- a/mysql-test/t/archive_bitfield.test	2006-01-12 05:16:51 +0000
+++ b/mysql-test/t/archive_bitfield.test	2009-05-15 10:15:56 +0000
@@ -94,5 +94,11 @@ INSERT INTO `t1` VALUES
 (NULL,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'100000',b'010010',b'011111',4,5,5,5,5,5,5,5,5,5,3,2,1),
 (NULL,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'000000',b'001100',b'111111',4,5,5,5,5,5,5,5,5,5,3,2,1),
 (NULL,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,b'111111',b'000000',b'000000',4,5,5,5,5,5,5,5,5,5,3,2,1);
+# Determine the number of open sessions
+--source include/count_sessions.inc
 --exec $MYSQL_DUMP --hex-blob --compact --order-by-primary --skip-extended-insert --no-create-info test t1
 drop table t1;
+# Wait till the number of open sessions is <= the number before the run with $MYSQL_DUMP
+# = The session caused by mysqldump has finished its disconnect
+--source include/wait_until_count_sessions.inc
+

=== modified file 'mysql-test/t/cast.test'
--- a/mysql-test/t/cast.test	2008-01-10 10:37:54 +0000
+++ b/mysql-test/t/cast.test	2009-05-21 08:06:43 +0000
@@ -269,3 +269,18 @@ SELECT HOUR(NULL),
 DROP TABLE t1;
 
 --echo End of 5.0 tests
+
+--echo #
+--echo #  Bug #44766: valgrind error when using convert() in a subquery
+--echo #
+
+CREATE TABLE t1(a tinyint);
+INSERT INTO t1 VALUES (127);
+SELECT 1 FROM
+(
+ SELECT CONVERT(t2.a USING UTF8) FROM t1, t1 t2 LIMIT 1
+) AS s LIMIT 1;
+DROP TABLE t1;
+
+
+--echo End of 5.1 tests

=== modified file 'mysql-test/t/client_xml.test'
--- a/mysql-test/t/client_xml.test	2008-07-18 12:00:45 +0000
+++ b/mysql-test/t/client_xml.test	2009-05-15 10:15:56 +0000
@@ -18,6 +18,10 @@ create table t1 (
   `a>b` text
 );
 insert into t1 values (1, 2, 'a&b a<b a>b');
+
+# Determine the number of open sessions
+--source include/count_sessions.inc
+
 --exec $MYSQL --xml test -e "select * from t1"
 --exec $MYSQL_DUMP --xml --skip-create test
 
@@ -33,3 +37,8 @@ drop table t1;
 
 # Restore global concurrent_insert value
 set @@global.concurrent_insert= @old_concurrent_insert;
+
+# Wait till the number of open sessions is <= the number before the runs with
+# $MYSQL and $MYSQL_DUMP
+# = The session caused by mysql and mysqldump have finished their disconnect
+--source include/wait_until_count_sessions.inc

=== modified file 'mysql-test/t/consistent_snapshot.test'
--- a/mysql-test/t/consistent_snapshot.test	2009-03-03 20:34:18 +0000
+++ b/mysql-test/t/consistent_snapshot.test	2009-05-11 23:54:00 +0000
@@ -12,9 +12,9 @@ connect (con1,localhost,root,,);
 --echo # Establish connection con2 (user=root)
 connect (con2,localhost,root,,);
 
-### Test 1:
-### - While a consistent snapshot transaction is executed,
-###   no external inserts should be visible to the transaction.
+--echo ### Test 1:
+--echo ### - While a consistent snapshot transaction is executed,
+--echo ###   no external inserts should be visible to the transaction.
 
 --echo # Switch to connection con1
 connection con1;
@@ -31,9 +31,9 @@ SELECT * FROM t1; # if consistent snapsh
 # should see nothing.
 COMMIT;
 
-### Test 2:
-### - For any non-consistent snapshot transaction, external
-###   committed inserts should be visible to the transaction.
+--echo ### Test 2:
+--echo ### - For any non-consistent snapshot transaction, external
+--echo ###   committed inserts should be visible to the transaction.
 
 DELETE FROM t1;
 START TRANSACTION; # Now we omit WITH CONSISTENT SNAPSHOT
@@ -48,6 +48,24 @@ SELECT * FROM t1; # if consistent snapsh
 # should see 1.
 COMMIT;
 
+--echo ### Test 3:
+--echo ### - Bug#44664: valgrind warning for COMMIT_AND_CHAIN and ROLLBACK_AND_CHAIN
+--echo ###   Chaining a transaction does not retain consistency level.
+
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+DELETE FROM t1;
+COMMIT WORK AND CHAIN;
+
+--echo # Switch to connection con2
+connection con2;
+INSERT INTO t1 VALUES(1);
+
+--echo # Switch to connection con1
+connection con1;
+SELECT * FROM t1; # if consistent snapshot was not set, as expected, we
+# should see 1.
+COMMIT;
+
 --echo # Switch to connection default + close connections con1 and con2
 connection default;
 disconnect con1;

=== modified file 'mysql-test/t/csv.test'
--- a/mysql-test/t/csv.test	2009-01-23 12:22:05 +0000
+++ b/mysql-test/t/csv.test	2009-05-15 10:15:56 +0000
@@ -1800,10 +1800,11 @@ connect (con1,localhost,root,,);
 # EE_FILENOTFOUND 29
 --error 29
 select * from t1;
+--disconnect con1
+--source include/wait_until_disconnected.inc
 connection default;
 unlock tables;
 drop table t1;
---disconnect con1
 
 #
 # Bug#41441 repair csv table crashes debug server

=== modified file 'mysql-test/t/ctype_cp932_binlog_stm.test'
--- a/mysql-test/t/ctype_cp932_binlog_stm.test	2007-05-30 10:23:47 +0000
+++ b/mysql-test/t/ctype_cp932_binlog_stm.test	2009-05-05 06:55:22 +0000
@@ -34,4 +34,10 @@ delimiter ;|
 --error 1220
 SHOW BINLOG EVENTS FROM 364;
 
+--echo Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment.
+CREATE TABLE t1 (a varchar(16)) character set cp932;
+INSERT INTO t1 VALUES (0x8372835E),(0x8352835E);
+SELECT hex(a), hex(lower(a)), hex(upper(a)) FROM t1 ORDER BY binary(a);
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/ctype_sjis.test'
--- a/mysql-test/t/ctype_sjis.test	2008-02-20 18:49:26 +0000
+++ b/mysql-test/t/ctype_sjis.test	2009-05-05 06:55:22 +0000
@@ -83,3 +83,13 @@ SET NAMES sjis;
 SELECT HEX('�����@�\') FROM DUAL;
 
 # End of 4.1 tests
+
+--echo # Start of 5.1 tests
+
+--echo Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment.
+CREATE TABLE t1 (a varchar(16)) character set sjis;
+INSERT INTO t1 VALUES (0x8372835E),(0x8352835E);
+SELECT hex(a), hex(lower(a)), hex(upper(a)) FROM t1 ORDER BY binary(a);
+DROP TABLE t1;
+
+--echo # End of 5.1 tests

=== modified file 'mysql-test/t/ddl_i18n_koi8r.test'
--- a/mysql-test/t/ddl_i18n_koi8r.test	2009-03-04 12:45:49 +0000
+++ b/mysql-test/t/ddl_i18n_koi8r.test	2009-05-15 10:15:56 +0000
@@ -1128,15 +1128,22 @@ SHOW CREATE TABLE mysqltest2.t2|
 #
 # Cleanup.
 #
+delimiter ;|
 
---connection default
+--connection con2
 --echo
---echo ---> connection: default
-
+--echo ---> connection: con2
 --disconnect con2
+--source include/wait_until_disconnected.inc
+--connection con3
+--echo
+--echo ---> connection: con3
 --disconnect con3
+--source include/wait_until_disconnected.inc
+--connection default
+--echo
+--echo ---> connection: default
+USE test;
+DROP DATABASE mysqltest1;
+DROP DATABASE mysqltest2;
 
-use test|
-
-DROP DATABASE mysqltest1|
-DROP DATABASE mysqltest2|

=== modified file 'mysql-test/t/ddl_i18n_utf8.test'
--- a/mysql-test/t/ddl_i18n_utf8.test	2009-03-04 12:45:49 +0000
+++ b/mysql-test/t/ddl_i18n_utf8.test	2009-05-15 10:15:56 +0000
@@ -1128,15 +1128,22 @@ SHOW CREATE TABLE mysqltest2.t2|
 #
 # Cleanup.
 #
+delimiter ;|
 
---connection default
+--connection con2
 --echo
---echo ---> connection: default
-
+--echo ---> connection: con2
 --disconnect con2
+--source include/wait_until_disconnected.inc
+--connection con3
+--echo
+--echo ---> connection: con3
 --disconnect con3
+--source include/wait_until_disconnected.inc
+--connection default
+--echo
+--echo ---> connection: default
+USE test;
+DROP DATABASE mysqltest1;
+DROP DATABASE mysqltest2;
 
-use test|
-
-DROP DATABASE mysqltest1|
-DROP DATABASE mysqltest2|

=== modified file 'mysql-test/t/derived.test'
--- a/mysql-test/t/derived.test	2007-10-29 11:11:05 +0000
+++ b/mysql-test/t/derived.test	2009-05-15 10:15:56 +0000
@@ -273,7 +273,9 @@ select t2.* from ((select * from t1) as 
 select t2.* from (select * from t1) as A inner join t2 on A.ID = t2.FID;
 drop table t1, t2;
 
+connection con1;
 disconnect con1;
+--source include/wait_until_disconnected.inc
 connection default;
 drop user mysqltest_1;
 

=== modified file 'mysql-test/t/disabled.def'
--- a/mysql-test/t/disabled.def	2009-03-25 16:00:04 +0000
+++ b/mysql-test/t/disabled.def	2009-05-18 16:53:06 +0000
@@ -10,8 +10,6 @@
 #
 ##############################################################################
 kill                     : Bug#37780 2008-12-03 HHunger need some changes to be robust enough for pushbuild.
-innodb_bug39438          : BUG#42383 2009-01-28 lsoares "This fails in embedded and on windows.  Note that this test is not run on windows and on embedded in PB for main trees currently"
+innodb_bug39438          : Bug#42383 2009-01-28 lsoares "This fails in embedded and on windows.  Note that this test is not run on windows and on embedded in PB for main trees currently"
 query_cache_28249        : Bug#43861 2009-03-25 main.query_cache_28249 fails sporadically
-
-#concurrent_innodb_safelog: disabled for embedded server due to bug#43733 Select on processlist let the embedded server crash (concurrent_innodb_safelog).
-#concurrent_innodb_unsafelog: disabled for embedded server due to bug#43733.
+init_connect             : Bug#44920 2009-05-18 pcrews MTR2 is not processing master.opt input properly on Windows

=== modified file 'mysql-test/t/drop.test'
--- a/mysql-test/t/drop.test	2009-03-04 12:45:49 +0000
+++ b/mysql-test/t/drop.test	2009-05-15 10:15:56 +0000
@@ -117,8 +117,11 @@ connection addconroot1;
 --reap
 connection addconroot2;
 --reap
-disconnect addconroot1;
 disconnect addconroot2;
+--source include/wait_until_disconnected.inc
+connection addconroot1;
+disconnect addconroot1;
+--source include/wait_until_disconnected.inc
 connection default;
 
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/events_grant.test'
--- a/mysql-test/t/events_grant.test	2007-05-26 14:36:38 +0000
+++ b/mysql-test/t/events_grant.test	2009-05-15 10:15:56 +0000
@@ -97,7 +97,9 @@ DROP EVENT one_event;
 connection default;
 --echo "One event should not be there"
 SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_DEFINITION, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_SCHEMA, EVENT_NAME;
+connection ev_con1;
 disconnect ev_con1;
+--source include/wait_until_disconnected.inc
 connection default;
 DROP USER ev_test@localhost;
 DROP DATABASE events_test2;
@@ -106,9 +108,6 @@ DROP DATABASE events_test2;
 # End of tests
 #
 
-let $wait_condition=
-  select count(*) = 0 from information_schema.processlist
-  where db='events_test' and command = 'Connect' and user=current_user();
---source include/wait_condition.inc
+--source include/check_events_off.inc
 
 DROP DATABASE events_test;

=== modified file 'mysql-test/t/events_stress.test'
--- a/mysql-test/t/events_stress.test	2007-05-26 14:36:38 +0000
+++ b/mysql-test/t/events_stress.test	2009-05-15 10:15:56 +0000
@@ -109,7 +109,7 @@ connection conn3;
 --send
 DROP DATABASE events_conn3_db;
 connection default;
---send
+# --send
 DROP DATABASE events_conn1_test2;
 DROP DATABASE events_conn1_test3;
 SET GLOBAL event_scheduler=off;
@@ -135,3 +135,7 @@ DROP USER event_user3@localhost;
 #
 
 DROP DATABASE events_test;
+
+# Cleanup
+SET GLOBAL event_scheduler=off;
+--source include/check_events_off.inc

=== modified file 'mysql-test/t/events_trans_notembedded.test'
--- a/mysql-test/t/events_trans_notembedded.test	2007-05-26 14:36:38 +0000
+++ b/mysql-test/t/events_trans_notembedded.test	2009-05-15 10:15:56 +0000
@@ -50,6 +50,7 @@ delete from t1;
 commit work;
 # Cleanup
 disconnect conn1;
+--source include/wait_until_disconnected.inc
 connection default;
 drop user mysqltest_user1@localhost;
 drop database mysqltest_db2;

=== modified file 'mysql-test/t/fix_priv_tables.test'
--- a/mysql-test/t/fix_priv_tables.test	2008-08-04 19:54:44 +0000
+++ b/mysql-test/t/fix_priv_tables.test	2009-05-15 10:15:56 +0000
@@ -51,8 +51,13 @@ echo;
 -- disable_query_log
 
 # Run the mysql_fix_privilege_tables.sql using "mysql --force"
+# Determine the number of open sessions
+--source include/count_sessions.inc
 --exec $MYSQL --force mysql < $MYSQL_FIX_PRIVILEGE_TABLES > $MYSQLTEST_VARDIR/tmp/fix_priv_tables.log 2>&1
 --remove_file $MYSQLTEST_VARDIR/tmp/fix_priv_tables.log
+# Wait till the number of open sessions is <= the number before the run with $MYSQL
+# = The session caused by mysql has finished its disconnect
+--source include/wait_until_count_sessions.inc
 
 -- enable_query_log
 -- enable_result_log

=== modified file 'mysql-test/t/flush.test'
--- a/mysql-test/t/flush.test	2008-03-23 16:35:00 +0000
+++ b/mysql-test/t/flush.test	2009-05-15 10:15:56 +0000
@@ -171,6 +171,7 @@ set session low_priority_updates=default
 connect (con1,localhost,root,,);
 send select benchmark(200, (select sin(1))) > 1000;
 disconnect con1;
+--source include/wait_until_disconnected.inc
 connection default;
 
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/func_compress.test'
--- a/mysql-test/t/func_compress.test	2009-01-31 16:10:43 +0000
+++ b/mysql-test/t/func_compress.test	2009-05-21 17:51:48 +0000
@@ -50,6 +50,7 @@ set @@global.max_allowed_packet=1048576*
 --connect (newconn, localhost, root,,)
 eval select compress(repeat('aaaaaaaaaa', IF('$LOW_MEMORY', 10, 10000000))) is null;
 disconnect newconn;
+--source include/wait_until_disconnected.inc
 connection default;
 set @@global.max_allowed_packet=default;
 
@@ -88,4 +89,24 @@ select *, uncompress(a) from t1;
 select *, uncompress(a), uncompress(a) is null from t1;
 drop table t1;
 
+#
+# Bug #44796: valgrind: too many my_longlong10_to_str_8bit warnings after 
+#             uncompressed_length
+#
+
+CREATE TABLE t1 (c1 INT);
+INSERT INTO t1 VALUES (1), (1111), (11111);
+
+# Disable warnings to avoid dependency on max_allowed_packet value
+--disable_warnings
+SELECT UNCOMPRESS(c1), UNCOMPRESSED_LENGTH(c1) FROM t1;
+--enable_warnings
+
+# We do not need the results, just make sure there are no valgrind errors
+--disable_result_log
+EXPLAIN EXTENDED SELECT * FROM (SELECT UNCOMPRESSED_LENGTH(c1) FROM t1) AS s;
+--enable_result_log
+
+DROP TABLE t1;
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/func_concat.test'
--- a/mysql-test/t/func_concat.test	2008-05-13 15:27:46 +0000
+++ b/mysql-test/t/func_concat.test	2009-05-21 08:06:43 +0000
@@ -78,3 +78,37 @@ SELECT * FROM t1 WHERE CONCAT(c1,' ',c2)
 DROP TABLE t1;
 
 --echo # End of 5.0 tests
+
+
+--echo #
+--echo # Bug #44743: Join in combination with concat does not always work
+--echo #
+CREATE TABLE t1 (
+  a VARCHAR(100) NOT NULL DEFAULT '0',
+  b VARCHAR(2) NOT NULL DEFAULT '',
+  c VARCHAR(2) NOT NULL DEFAULT '',
+  d TEXT NOT NULL,
+  PRIMARY KEY (a, b, c),
+  KEY (a)
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO t1 VALUES ('gui_A', 'a', 'b', 'str1'),
+  ('gui_AB', 'a', 'b', 'str2'), ('gui_ABC', 'a', 'b', 'str3');
+
+CREATE TABLE t2 (
+  a VARCHAR(100) NOT NULL DEFAULT '',
+  PRIMARY KEY (a)
+) DEFAULT CHARSET=latin1;
+
+INSERT INTO t2 VALUES ('A'), ('AB'), ('ABC');
+
+SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+  LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+
+EXPLAIN SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
+  LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
+
+DROP TABLE t1, t2;
+
+
+--echo # End of 5.1 tests

=== modified file 'mysql-test/t/func_in.test'
--- a/mysql-test/t/func_in.test	2008-12-31 11:55:04 +0000
+++ b/mysql-test/t/func_in.test	2009-05-25 08:00:40 +0000
@@ -439,4 +439,21 @@ SELECT CASE c1 WHEN c1 + 1 THEN 1 END, A
 
 DROP TABLE t1;
 
+#
+# Bug #44399: crash with statement using TEXT columns, aggregates, GROUP BY, 
+# and HAVING
+#
+
+CREATE TABLE t1(a TEXT, b INT, c INT UNSIGNED, d DECIMAL(12,2), e REAL);
+INSERT INTO t1 VALUES('iynfj', 1, 1, 1, 1);
+INSERT INTO t1 VALUES('innfj', 2, 2, 2, 2);
+SELECT SUM( DISTINCT a ) FROM t1 GROUP BY a HAVING a IN ( AVG( 1 ), 1 + a);
+SELECT SUM( DISTINCT b ) FROM t1 GROUP BY b HAVING b IN ( AVG( 1 ), 1 + b);
+SELECT SUM( DISTINCT c ) FROM t1 GROUP BY c HAVING c IN ( AVG( 1 ), 1 + c);
+SELECT SUM( DISTINCT d ) FROM t1 GROUP BY d HAVING d IN ( AVG( 1 ), 1 + d);
+SELECT SUM( DISTINCT e ) FROM t1 GROUP BY e HAVING e IN ( AVG( 1 ), 1 + e);
+SELECT SUM( DISTINCT e ) FROM t1 GROUP BY b,c,d HAVING (b,c,d) IN 
+  ((AVG( 1 ), 1 + c, 1 + d), (AVG( 1 ), 2 + c, 2 + d));
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/func_math.test'
--- a/mysql-test/t/func_math.test	2009-02-23 12:42:31 +0000
+++ b/mysql-test/t/func_math.test	2009-05-18 04:21:25 +0000
@@ -282,4 +282,22 @@ SELECT 1e300 / 1e-300;
 SELECT EXP(750);
 SELECT POW(10, 309);
 
+--echo #
+--echo # Bug #44768: SIGFPE crash when selecting rand from a view
+--echo #             containing null
+--echo #
+
+CREATE OR REPLACE VIEW v1 AS SELECT NULL AS a;
+SELECT RAND(a) FROM v1;
+DROP VIEW v1;
+
+SELECT RAND(a) FROM (SELECT NULL AS a) b;
+
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (NULL);
+SELECT RAND(i) FROM t1;
+DROP TABLE t1;
+
+--echo #
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/func_str.test'
--- a/mysql-test/t/func_str.test	2009-04-23 07:43:42 +0000
+++ b/mysql-test/t/func_str.test	2009-05-13 18:39:35 +0000
@@ -1282,6 +1282,16 @@ INSERT INTO t1 VALUES ('2008-12-31','aaa
 SELECT DATE_FORMAT(c, GET_FORMAT(DATE, 'eur')) h, CONCAT(UPPER(aa),', ', aa) i FROM t1;
 DROP TABLE t1;
 
+
+--echo #
+--echo # BUG#44774: load_file function produces valgrind warnings
+--echo #
+CREATE TABLE t1 (a TINYBLOB);
+INSERT INTO t1 VALUES ('aaaaaaaa');
+SELECT LOAD_FILE(a) FROM t1;
+DROP TABLE t1;
+
+
 --echo End of 5.0 tests
 
 #

=== modified file 'mysql-test/t/heap_btree.test'
--- a/mysql-test/t/heap_btree.test	2007-10-19 20:12:14 +0000
+++ b/mysql-test/t/heap_btree.test	2009-05-06 09:30:14 +0000
@@ -253,5 +253,13 @@ insert into t1 values (1, 1), (3, 3), (2
 select * from t1 where a is null;
 drop table t1;
 
+-- echo #
+-- echo # bug#39918 - memory (heap) engine crashing while executing self join with delete
+-- echo #
+
+CREATE TABLE t1(a INT, KEY USING BTREE (a)) ENGINE=MEMORY;
+INSERT INTO t1 VALUES(1),(1);
+DELETE a1 FROM t1 AS a1, t1 AS a2 WHERE a1.a=a2.a;
+DROP TABLE t1;
 --echo End of 5.0 tests
 

=== modified file 'mysql-test/t/information_schema_db.test'
--- a/mysql-test/t/information_schema_db.test	2008-10-02 09:37:07 +0000
+++ b/mysql-test/t/information_schema_db.test	2009-05-15 09:59:31 +0000
@@ -53,7 +53,7 @@ order by table_name;
 end|
 delimiter ;|
 
-create table t1 
+create table t1
 (f1 int(10) unsigned not null,
  f2 varchar(100) not null,
  primary key (f1), unique key (f2));
@@ -105,8 +105,8 @@ drop function f2;
 drop view v1, v2;
 
 #
-# Bug#20543: select on information_schema strange warnings, view, different
-#             schemas/users
+# Bug#20543 select on information_schema strange warnings, view, different
+#           schemas/users
 #
 #
 create database testdb_1;
@@ -125,7 +125,7 @@ grant insert on v1 to testdb_2@localhost
 create view v5 as select f1 from t1;
 grant show view on v5 to testdb_2@localhost;
 
---error 1227
+--error ER_SPECIFIC_ACCESS_DENIED_ERROR
 create definer=`no_such_user`@`no_such_host` view v6 as select f1 from t1;
 
 connection default;
@@ -169,46 +169,53 @@ use testdb_1;
 revoke show view on v6 from testdb_2@localhost;
 connection testdb_2;
 
---error 1142
+--error ER_TABLEACCESS_DENIED_ERROR
 show fields from testdb_1.v5;
---error 1142
+--error ER_TABLEACCESS_DENIED_ERROR
 show create view testdb_1.v5;
 
---error 1142
+--error ER_TABLEACCESS_DENIED_ERROR
 show fields from testdb_1.v6;
---error 1142
+--error ER_TABLEACCESS_DENIED_ERROR
 show create view testdb_1.v6;
 
---error 1142
+--error ER_TABLEACCESS_DENIED_ERROR
 show fields from testdb_1.v7;
---error 1142
+--error ER_TABLEACCESS_DENIED_ERROR
 show create view testdb_1.v7;
 
---error 1345
+--error ER_VIEW_NO_EXPLAIN
 show create view v4;
-#--error 1345
+#--error ER_VIEW_NO_EXPLAIN
 show fields from v4;
 
 show fields from v2;
 show fields from testdb_1.v1;
 show create view v2;
---error 1142
+--error ER_TABLEACCESS_DENIED_ERROR
 show create view testdb_1.v1;
 
-select table_name from information_schema.columns a 
+select table_name from information_schema.columns a
 where a.table_name = 'v2';
-select view_definition from information_schema.views a 
+select view_definition from information_schema.views a
 where a.table_name = 'v2';
-select view_definition from information_schema.views a 
+select view_definition from information_schema.views a
 where a.table_name = 'testdb_1.v1';
 
---error 1356
+--error ER_VIEW_INVALID
 select * from v2;
 
 connection default;
 use test;
 drop view testdb_1.v1, v2, testdb_1.v3, v4;
 drop database testdb_1;
+connection testdb_1;
+disconnect testdb_1;
+--source include/wait_until_disconnected.inc
+connection testdb_2;
+disconnect testdb_2;
+--source include/wait_until_disconnected.inc
+connection default;
 drop user testdb_1@localhost;
 drop user testdb_2@localhost;
 
@@ -239,4 +246,7 @@ show create view testdb_1.v1;
 connection default;
 drop user mysqltest_1@localhost;
 drop database testdb_1;
+connection user1;
 disconnect user1;
+--source include/wait_until_disconnected.inc
+connection default;

=== modified file 'mysql-test/t/init_file.test'
--- a/mysql-test/t/init_file.test	2009-02-01 09:18:09 +0000
+++ b/mysql-test/t/init_file.test	2009-04-02 11:00:44 +0000
@@ -14,7 +14,7 @@ SELECT * INTO @X FROM init_file.startup 
 SELECT * INTO @Y FROM init_file.startup limit 1,1;
 SELECT YEAR(@X)-YEAR(@Y);
 # Enable this DROP DATABASE only after resolving bug #42507
-# DROP DATABASE init_file;
+DROP DATABASE init_file;
 
 --echo ok
 --echo end of 4.1 tests
@@ -28,4 +28,9 @@ select * from t1;
 #   30, 3, 11, 13
 select * from t2;
 # Enable this DROP TABLE only after resolving bug #42507
-#drop table t1, t2;
+drop table t1, t2;
+
+# MTR will restart server anyway, but by forcing it we avoid being warned
+# about the apparent side effect
+
+call mtr.force_restart();

=== added file 'mysql-test/t/innodb_bug42101-nonzero-master.opt'
--- a/mysql-test/t/innodb_bug42101-nonzero-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_bug42101-nonzero-master.opt	2009-05-19 08:20:28 +0000
@@ -0,0 +1 @@
+--innodb_commit_concurrency=1

=== added file 'mysql-test/t/innodb_bug42101-nonzero.test'
--- a/mysql-test/t/innodb_bug42101-nonzero.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_bug42101-nonzero.test	2009-05-19 08:20:28 +0000
@@ -0,0 +1,19 @@
+#
+# Bug#42101  	Race condition in innodb_commit_concurrency
+# http://bugs.mysql.com/42101
+#
+
+-- source include/have_innodb.inc
+
+--error ER_WRONG_ARGUMENTS
+set global innodb_commit_concurrency=0;
+select @@innodb_commit_concurrency;
+set global innodb_commit_concurrency=1;
+select @@innodb_commit_concurrency;
+set global innodb_commit_concurrency=42;
+select @@innodb_commit_concurrency;
+--error ER_WRONG_ARGUMENTS
+set global innodb_commit_concurrency=0;
+select @@innodb_commit_concurrency;
+set global innodb_commit_concurrency=1;
+select @@innodb_commit_concurrency;

=== added file 'mysql-test/t/innodb_bug42101.test'
--- a/mysql-test/t/innodb_bug42101.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_bug42101.test	2009-05-19 08:20:28 +0000
@@ -0,0 +1,17 @@
+#
+# Bug#42101  	Race condition in innodb_commit_concurrency
+# http://bugs.mysql.com/42101
+#
+
+-- source include/have_innodb.inc
+
+set global innodb_commit_concurrency=0;
+select @@innodb_commit_concurrency;
+--error ER_WRONG_ARGUMENTS
+set global innodb_commit_concurrency=1;
+select @@innodb_commit_concurrency;
+--error ER_WRONG_ARGUMENTS
+set global innodb_commit_concurrency=42;
+select @@innodb_commit_concurrency;
+set global innodb_commit_concurrency=0;
+select @@innodb_commit_concurrency;

=== modified file 'mysql-test/t/innodb_mysql.test'
--- a/mysql-test/t/innodb_mysql.test	2009-03-27 16:08:14 +0000
+++ b/mysql-test/t/innodb_mysql.test	2009-05-05 09:38:19 +0000
@@ -332,4 +332,31 @@ DROP TABLE t1;
 DROP TABLE t2;
 DROP TABLE t3;
 
+#
+# Bug#43580: Issue with Innodb on multi-table update
+#
+CREATE TABLE t1 (a INT, b INT, KEY (a)) ENGINE = INNODB;
+CREATE TABLE t2 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
+
+CREATE TABLE t3 (a INT, b INT KEY, KEY (a)) ENGINE = INNODB;
+CREATE TABLE t4 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
+
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6);
+INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+
+INSERT INTO t3 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105), (6, 106);
+INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+
+UPDATE t1, t2 SET t1.a = t1.a + 100, t2.b = t1.a + 10 
+WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b;
+--sorted_result
+SELECT * FROM t2;
+
+UPDATE t3, t4 SET t3.a = t3.a + 100, t4.b = t3.a + 10 
+WHERE t3.a BETWEEN 2 AND 4 AND t4.a = t3.b - 100;
+--sorted_result
+SELECT * FROM t4;
+
+DROP TABLE t1, t2, t3, t4;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/insert_select.test'
--- a/mysql-test/t/insert_select.test	2007-09-24 13:23:40 +0000
+++ b/mysql-test/t/insert_select.test	2009-05-04 12:45:36 +0000
@@ -324,6 +324,16 @@ SELECT * FROM t2;
 DROP TABLE t1, t2;
 
 #
+# Bug#44306: Assertion fail on duplicate key error in 'INSERT ... SELECT' 
+# statements
+#
+CREATE TABLE t1 ( a INT KEY, b INT );
+INSERT INTO t1 VALUES ( 0, 1 );
+--error ER_DUP_ENTRY
+INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
+DROP TABLE t1;
+
+#
 # Bug #26207: inserts don't work with shortened index
 #
 SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

=== modified file 'mysql-test/t/lowercase_fs_off.test'
--- a/mysql-test/t/lowercase_fs_off.test	2006-11-14 18:45:52 +0000
+++ b/mysql-test/t/lowercase_fs_off.test	2009-05-15 10:15:56 +0000
@@ -14,16 +14,18 @@ flush privileges;
 connect (sample,localhost,sample,password,d1);
 connection sample;
 select database();
---error 1044
+--error ER_DBACCESS_DENIED_ERROR
 create database d2;
---error 1044
+--error ER_DBACCESS_DENIED_ERROR
 create database D1;
 disconnect sample;
+--source include/wait_until_disconnected.inc
 
 connection master;
 drop user 'sample'@'localhost';
 drop database if exists d1;
 disconnect master;
+--source include/wait_until_disconnected.inc
 connection default;
 
 # End of 4.1 tests

=== modified file 'mysql-test/t/mysql.test'
--- a/mysql-test/t/mysql.test	2009-03-24 20:53:25 +0000
+++ b/mysql-test/t/mysql.test	2009-05-15 17:36:59 +0000
@@ -342,6 +342,13 @@ EOF
 
 remove_file $MYSQLTEST_VARDIR/tmp/bug31060.sql;
 
+#
+# Bug #39101: client -i (--ignore-spaces) option does not seem to work
+#
+--exec $MYSQL -i -e "SELECT COUNT (*)"
+--exec $MYSQL --ignore-spaces -e "SELECT COUNT (*)"
+--exec $MYSQL -b -i -e "SELECT COUNT (*)"
+
 --echo End of 5.0 tests
 
 #
@@ -367,4 +374,10 @@ remove_file $MYSQLTEST_VARDIR/tmp/bug310
 
 drop tables t1, t2;
 
+#
+# Bug #27884: mysql --html does not quote HTML special characters in output
+# 
+--exec $MYSQL --html test -e "select '< & >' as '<'"
+
+--echo
 --echo End of tests

=== modified file 'mysql-test/t/mysqlbinlog.test'
--- a/mysql-test/t/mysqlbinlog.test	2009-03-06 14:56:17 +0000
+++ b/mysql-test/t/mysqlbinlog.test	2009-05-08 17:24:15 +0000
@@ -367,4 +367,16 @@ echo *** Unsigned server_id $s_id_max is
 eval SET @@global.server_id= $save_server_id;
 --remove_file $binlog_file
 
+#
+# Bug #41943: mysqlbinlog.exe crashes if --hexdump option is used
+#
+
+RESET MASTER;
+FLUSH LOGS;
+
+# We do not need the results, just make sure that mysqlbinlog does not crash
+--exec $MYSQL_BINLOG --hexdump --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT  master-bin.000001 >/dev/null
+
+--echo End of 5.0 tests
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/mysqldump.test'
--- a/mysql-test/t/mysqldump.test	2009-04-21 10:25:04 +0000
+++ b/mysql-test/t/mysqldump.test	2009-05-22 15:24:45 +0000
@@ -1,6 +1,5 @@
 # Embedded server doesn't support external clients
 --source include/not_embedded.inc
---source include/have_log_bin.inc
 
 # Binlog is required
 --source include/have_log_bin.inc

=== added file 'mysql-test/t/mysqldump_restore.test'
--- a/mysql-test/t/mysqldump_restore.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/mysqldump_restore.test	2009-05-22 14:38:17 +0000
@@ -0,0 +1,111 @@
+###############################################################################
+# mysqldump_restore.test
+#
+# Purpose:  Tests if mysqldump output can be used to successfully restore
+#           tables and data.  
+#           We CREATE a table, mysqldump it to a file, ALTER the original
+#           table's name, recreate the table from the mysqldump file, then
+#           utilize include/diff_tables to compare the original and recreated
+#           tables.
+#
+#           We use several examples from mysqldump.test here and include
+#           the relevant bug numbers and headers from that test.
+#
+# NOTE:     This test is not currently complete and offers only basic
+#           cases of mysqldump output being restored. 
+#           Also, does NOT work with -X (xml) output!
+#           
+# Author:   pcrews
+# Created:  2009-05-21
+# Last Change:
+# Change date:
+###############################################################################
+
+# Embedded server doesn't support external clients
+--source include/not_embedded.inc
+--source include/have_log_bin.inc
+
+--echo # Set concurrent_insert = 0 to prevent random errors
+--echo # will reset to original value at the end of the test
+SET @old_concurrent_insert = @@global.concurrent_insert;
+SET @@global.concurrent_insert = 0;
+
+# Define mysqldumpfile here.  It is used to capture mysqldump output
+# in order to test the output's ability to restore an exact copy of the table
+let $mysqldumpfile = $MYSQLTEST_VARDIR/tmp/mysqldumpfile.sql;
+
+--echo # Pre-test cleanup
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo # Begin tests
+--echo #
+--echo # Bug#2005 Long decimal comparison bug.
+--echo #
+CREATE TABLE t1 (a DECIMAL(64, 20));
+INSERT INTO t1 VALUES ("1234567890123456789012345678901234567890"),
+("0987654321098765432109876543210987654321");
+--exec $MYSQL_DUMP --compact test t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+--echo #
+--echo # Bug#3361 mysqldump quotes DECIMAL values inconsistently
+--echo #
+CREATE TABLE t1 (a DECIMAL(10,5), b FLOAT);
+# Check at first how mysql work with quoted decimal
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ANSI_QUOTES';
+INSERT INTO t1 VALUES (1.2345, 2.3456);
+INSERT INTO t1 VALUES ('1.2345', 2.3456);
+--error ER_BAD_FIELD_ERROR
+INSERT INTO t1 VALUES ("1.2345", 2.3456);
+SET SQL_MODE=@OLD_SQL_MODE;
+
+# check how mysqldump make quoting
+--exec $MYSQL_DUMP --compact test t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+--echo #
+--echo # Bug#1994 mysqldump does not correctly dump UCS2 data
+--echo # Bug#4261 mysqldump 10.7 (mysql 4.1.2) --skip-extended-insert drops NULL from inserts
+--echo #
+CREATE TABLE t1 (a  VARCHAR(255)) DEFAULT CHARSET koi8r;
+INSERT INTO t1  VALUES (_koi8r x'C1C2C3C4C5'), (NULL);
+--exec $MYSQL_DUMP --skip-comments --skip-extended-insert test t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+--echo #
+--echo # WL#2319 Exclude Tables from dump
+--echo #
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+INSERT INTO t2 VALUES (4),(5),(6);
+--exec $MYSQL_DUMP --skip-comments --ignore-table=test.t1 test > $mysqldumpfile
+let $table_name = test.t2;
+--source include/mysqldump.inc
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#8830 mysqldump --skip-extended-insert causes --hex-blob to dump wrong values
+--echo #
+CREATE TABLE t1 (`b` blob);
+INSERT INTO `t1` VALUES (0x602010000280100005E71A);
+--exec $MYSQL_DUMP --skip-extended-insert --hex-blob test --skip-comments t1 > $mysqldumpfile
+let $table_name = test.t1;
+--source include/mysqldump.inc
+
+--echo # End tests
+
+--echo # Cleanup
+--echo # Reset concurrent_insert to its original value
+SET @@global.concurrent_insert = @old_concurrent_insert;
+--echo # remove mysqldumpfile
+--error 0,1
+--remove_file $mysqldumpfile

=== modified file 'mysql-test/t/openssl_1.test'
--- a/mysql-test/t/openssl_1.test	2009-04-11 09:46:14 +0000
+++ b/mysql-test/t/openssl_1.test	2009-05-25 13:00:18 +0000
@@ -238,7 +238,18 @@ DROP TABLE t1;
 --enable_query_log
 select 'is still running; no cipher request crashed the server' as result from dual;
 
-##
+#
+# Bug#42158: leak: SSL_get_peer_certificate() doesn't have matching X509_free()
+#
+
+GRANT SELECT ON test.* TO bug42158@localhost REQUIRE X509;
+FLUSH PRIVILEGES;
+connect(con1,localhost,bug42158,,,,,SSL);
+SHOW STATUS LIKE 'Ssl_cipher';
+disconnect con1;
+connection default;
+DROP USER bug42158@localhost;
+
 --echo End of 5.1 tests
 
 # Wait till we reached the initial number of concurrent sessions

=== modified file 'mysql-test/t/subselect3.test'
--- a/mysql-test/t/subselect3.test	2009-01-28 18:48:41 +0000
+++ b/mysql-test/t/subselect3.test	2009-04-30 19:27:10 +0000
@@ -669,6 +669,25 @@ SELECT ROW(1,2) = (SELECT NULL,    1), R
 SELECT ROW(1,2) = (SELECT    1,    1), ROW(1,2) IN (SELECT    1,    1);
 SELECT ROW(1,2) = (SELECT    1,    2), ROW(1,2) IN (SELECT    1,    2);
 
+#
+# Bug #37362      Crash in do_field_eq
+#
+CREATE TABLE t1 (a INT, b INT, c INT);
+INSERT INTO t1 VALUES (1,1,1), (1,1,1);
+
+--error 1054
+EXPLAIN EXTENDED 
+  SELECT c FROM 
+    ( SELECT 
+      (SELECT COUNT(a) FROM 
+        (SELECT COUNT(b) FROM t1) AS x GROUP BY c
+      ) FROM t1 GROUP BY b
+    ) AS y;
+SHOW WARNINGS;
+
+DROP TABLE t1;
+
+
 --echo End of 5.0 tests
 
 #

=== modified file 'mysql-test/t/type_time.test'
--- a/mysql-test/t/type_time.test	2007-07-15 17:51:36 +0000
+++ b/mysql-test/t/type_time.test	2009-05-15 08:16:00 +0000
@@ -77,3 +77,16 @@ insert into t1 values('2007-07-02', 1);
 insert into t1 values('2007-07-02', 2);
 SELECT sum(f3) FROM t1 where f2='2007-07-01 00:00:00' group by f2;
 drop table t1;
+
+
+--echo #
+--echo # Bug #44792: valgrind warning when casting from time to time
+--echo #
+
+CREATE TABLE t1 (c TIME);
+INSERT INTO t1 VALUES ('0:00:00');
+SELECT CAST(c AS TIME) FROM t1;
+DROP TABLE t1;
+
+
+--echo End of 5.0 tests

=== modified file 'mysql-test/t/union.test'
--- a/mysql-test/t/union.test	2009-03-27 13:00:20 +0000
+++ b/mysql-test/t/union.test	2009-05-15 07:11:07 +0000
@@ -1089,4 +1089,16 @@ CREATE TABLE t2 AS SELECT d FROM t1 UNIO
 SHOW FIELDS FROM t2;
 DROP TABLE t1, t2;
 
+#
+# Bug#43612 crash with explain extended, union, order by
+#
+CREATE TABLE t1(a INT);
+EXPLAIN EXTENDED
+SELECT a FROM t1
+UNION
+SELECT a FROM t1
+ORDER BY a;
+DROP TABLE t1;
+
+
 --echo End of 5.0 tests

=== modified file 'mysql-test/t/user_var.test'
--- a/mysql-test/t/user_var.test	2009-04-11 09:46:14 +0000
+++ b/mysql-test/t/user_var.test	2009-05-15 13:03:22 +0000
@@ -286,6 +286,18 @@ select @lastid != id, @lastid, @lastid :
 drop table t1;
 
 #
+# Bug#42009: SELECT into variable gives different results to direct SELECT
+#
+CREATE TABLE t1(a INT, b INT);
+INSERT INTO t1 VALUES (0, 0), (2, 1), (2, 3), (1, 1), (30, 20);
+SELECT a, b INTO @a, @b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
+SELECT @a, @b;
+SELECT a, b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b;
+DROP TABLE t1;
+
+--echo End of 5.0 tests
+
+#
 # Bug#42188: crash and/or memory corruption with user variables in trigger
 #
 

=== modified file 'mysql-test/t/variables.test'
--- a/mysql-test/t/variables.test	2009-03-16 15:11:45 +0000
+++ b/mysql-test/t/variables.test	2009-05-22 06:44:11 +0000
@@ -1201,4 +1201,20 @@ SET GLOBAL server_id = -1;
 SELECT @@GLOBAL.server_id;
 SET GLOBAL server_id = @old_server_id;
 
+#
+# Bug #42778: delete order by null global variable causes 
+#             assertion .\filesort.cc, line 797
+#
+
+SELECT @@GLOBAL.INIT_FILE, @@GLOBAL.INIT_FILE IS NULL;
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES ();
+SET @bug42778= @@sql_safe_updates;
+SET @@sql_safe_updates= 0;
+DELETE FROM t1 ORDER BY (@@GLOBAL.INIT_FILE) ASC LIMIT 10;
+SET @@sql_safe_updates= @bug42778;
+
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/t/view.test'
--- a/mysql-test/t/view.test	2009-03-06 14:56:17 +0000
+++ b/mysql-test/t/view.test	2009-05-19 04:25:36 +0000
@@ -3681,6 +3681,29 @@ DROP VIEW v1;
 DROP TABLE t1;
 
 --echo # -----------------------------------------------------------------
+--echo # -- Bug#40825: Error 1356 while selecting from a view 
+--echo # --            with a "HAVING" clause though query works
+--echo # -----------------------------------------------------------------
+--echo
+
+CREATE TABLE t1 (c INT);
+
+--echo
+
+CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
+SHOW CREATE VIEW v1;
+SELECT * FROM v1;
+
+--echo
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo
+--echo # -- End of test case for Bug#40825
+--echo
+
+--echo # -----------------------------------------------------------------
 --echo # -- End of 5.0 tests.
 --echo # -----------------------------------------------------------------
 

@@ -3836,6 +3859,17 @@ drop procedure p;
 
 ###########################################################################
 
+
+--echo #
+--echo # Bug #44860: ALTER TABLE on view crashes server
+--echo #
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 AS SELECT a FROM t1;
+ALTER TABLE v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+
 --echo # -----------------------------------------------------------------
 --echo # -- End of 5.1 tests.
 --echo # -----------------------------------------------------------------

=== modified file 'mysys/mf_format.c'
--- a/mysys/mf_format.c	2007-05-10 09:59:39 +0000
+++ b/mysys/mf_format.c	2009-04-19 01:21:33 +0000
@@ -79,7 +79,7 @@ char * fn_format(char * to, const char *
     /* To long path, return original or NULL */
     size_t tmp_length;
     if (flag & MY_SAFE_PATH)
-      return NullS;
+      DBUG_RETURN(NullS);
     tmp_length= strlength(startpos);
     DBUG_PRINT("error",("dev: '%s'  ext: '%s'  length: %u",dev,ext,
                         (uint) length));

=== modified file 'mysys/mf_getdate.c'
--- a/mysys/mf_getdate.c	2007-07-30 08:33:50 +0000
+++ b/mysys/mf_getdate.c	2009-05-13 15:48:00 +0000
@@ -45,15 +45,15 @@ void get_date(register char * to, int fl
    skr=date ? (time_t) date : my_time(0);
 #if defined(HAVE_LOCALTIME_R) && defined(_REENTRANT)
    if (flag & GETDATE_GMT)
-     localtime_r(&skr,&tm_tmp);
-   else
      gmtime_r(&skr,&tm_tmp);
+   else
+     localtime_r(&skr,&tm_tmp);
    start_time= &tm_tmp;
 #else
    if (flag & GETDATE_GMT)
-     start_time= localtime(&skr);
-   else
      start_time= gmtime(&skr);
+   else
+     start_time= localtime(&skr);
 #endif
    if (flag & GETDATE_SHORT_DATE)
      sprintf(to,"%02d%02d%02d",

=== modified file 'mysys/my_getopt.c'
--- a/mysys/my_getopt.c	2009-03-17 17:24:35 +0000
+++ b/mysys/my_getopt.c	2009-05-14 12:03:33 +0000
@@ -410,7 +410,8 @@ invalid value '%s'",
 	  argument= optend;
 	}
 	else if (optp->arg_type == OPT_ARG &&
-		 (optp->var_type & GET_TYPE_MASK) == GET_BOOL)
+		 (((optp->var_type & GET_TYPE_MASK) == GET_BOOL) ||
+                   (optp->var_type & GET_TYPE_MASK) == GET_ENUM))
 	{
 	  if (optend == disabled_my_option)
 	    *((my_bool*) value)= (my_bool) 0;

=== modified file 'scripts/mysql_convert_table_format.sh'
--- a/scripts/mysql_convert_table_format.sh	2007-12-28 00:07:42 +0000
+++ b/scripts/mysql_convert_table_format.sh	2009-04-28 18:47:34 +0000
@@ -23,18 +23,30 @@ $opt_help=$opt_version=$opt_verbose=$opt
 $opt_user=$opt_database=$opt_password=undef;
 $opt_host="localhost";
 $opt_socket="";
-$opt_type="MYISAM";
+$opt_engine="MYISAM";
 $opt_port=0;
 $exit_status=0;
 
-GetOptions("force","help","host=s","password=s","user=s","type=s","verbose","version","socket=s", "port=i") || 
-  usage(0);
+GetOptions(
+  "e|engine|type=s"       => \$opt_type,
+  "f|force"               => \$opt_force,
+  "help|?"               => \$opt_help,
+  "h|host=s"              => \$opt_host,
+  "p|password=s"          => \$opt_password,
+  "u|user=s"              => \$opt_user,
+  "v|verbose"             => \$opt_verbose,
+  "V|version"             => \$opt_version,
+  "S|socket=s"            => \$opt_socket, 
+  "P|port=i"              => \$opt_port
+) || usage(0);
+
 usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version);
+
 $opt_database=shift(@ARGV);
 
-if (uc($opt_type) eq "HEAP")
+if (grep { /^$opt_engine$/i } qw(HEAP MEMORY BLACKHOLE))
 {
-  print "Converting to type HEAP would delete your tables; aborting\n";
+  print "Converting to '$opt_engine' would delete your data; aborting\n";
   exit(1);
 }
 
@@ -54,21 +66,29 @@ $dbh = DBI->connect("DBI:mysql:$opt_data
 		    { PrintError => 0})
   || die "Can't connect to database $opt_database: $DBI::errstr\n";
 
-if ($#ARGV < 0)
+my @tables;
+
+push(@ARGV, "%") if(!@ARGV);
+
+foreach $pattern (@ARGV)
 {
-  # Fetch all table names from the database
   my ($sth,$row);
-  $sth=$dbh->prepare("show tables");
-  $sth->execute || die "Can't get tables from $opt_database; $DBI::errstr\n";
+  $sth=$dbh->prepare("SHOW TABLES LIKE ?");
+  $rv= $sth->execute($pattern);
+  if(!int($rv))
+  {
+    warn "Can't get tables matching '$pattern' from $opt_database; $DBI::errstr\n"; 
+    exit(1) unless $opt_force;
+  }
   while (($row = $sth->fetchrow_arrayref))
   {
-    push(@ARGV,$row->[0]);
+    push(@tables, $row->[0]);
   }
   $sth->finish;
 }
 
 print "Converting tables:\n" if ($opt_verbose);
-foreach $table (@ARGV)
+foreach $table (@tables)
 {
   my ($sth,$row);
 
@@ -76,14 +96,15 @@ foreach $table (@ARGV)
   $sth=$dbh->prepare("show table status like '$table'");  
   if ($sth->execute && ($row = $sth->fetchrow_arrayref))
   {
-    if (uc($row->[1]) eq uc($opt_type))
+    if (uc($row->[1]) eq uc($opt_engine))
     {
-      print "$table is already of type $opt_type;  Ignored\n";
+      print "$table already uses the '$opt_engine' engine;  Ignored\n";
       next;
     }
   }
   print "converting $table\n" if ($opt_verbose);
-  if (!$dbh->do("ALTER TABLE $table ENGINE=$opt_type"))
+  $table=~ s/`/``/g;
+  if (!$dbh->do("ALTER TABLE `$table` ENGINE=$opt_engine"))
   {
     print STDERR "Can't convert $table: Error $DBI::errstr\n";
     exit(1) if (!$opt_force);
@@ -103,43 +124,43 @@ sub usage
 
   print <<EOF;
 
-Conversion of a MySQL tables to other table types.
+Conversion of a MySQL tables to other storage engines
 
- Usage: $0 database [tables]
+ Usage: $0 database [table[ table ...]]
  If no tables has been specifed, all tables in the database will be converted.
+ You can also use wildcards, ie "my%"
 
  The following options are available:
 
---force
+-f, --force
   Continue even if there is some error.
 
---help or --Information
+-?, --help
   Shows this help
 
---host='host name' (Default $opt_host)
-  Host name where the database server is located.
+-e, --engine=ENGINE
+  Converts tables to the given storage engine (Default: $opt_engine)
 
---password='password'
+-h, --host=HOST
+  Host name where the database server is located. (Default: $opt_host)
+
+-p, --password=PASSWORD
   Password for the current user.
 
---port=port
+-P, --port=PORT
   TCP/IP port to connect to if host is not "localhost".
 
---socket='/path/to/socket'
+-S, --socket=SOCKET
   Socket to connect with.
 
---ENGINE='table-type'
-  Converts tables to the given table type (Default: $opt_type)
-  MySQL 3.23 supports at least the BDB, ISAM and MYISAM types.
-
---user='user_name'
+-u, --user=USER
   User name to log into the SQL server.
 
---verbose
+-v, --verbose
   This is a test specific option that is only used when debugging a test.
   Print more information about what is going on.
 
---version
+-V, --version
   Shows the version of this program.
 EOF
   exit(1);

=== modified file 'scripts/mysql_find_rows.sh'
--- a/scripts/mysql_find_rows.sh	2006-12-31 00:02:27 +0000
+++ b/scripts/mysql_find_rows.sh	2009-05-09 21:43:48 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000, 2004 MySQL AB
 # 
 # This program is free software; you can redistribute it and/or modify

=== modified file 'scripts/mysql_fix_extensions.sh'
--- a/scripts/mysql_fix_extensions.sh	2001-12-24 14:55:47 +0000
+++ b/scripts/mysql_fix_extensions.sh	2009-05-09 21:43:48 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # This is a utility for MySQL. It is not needed by any standard part
 # of MySQL.
 

=== modified file 'scripts/mysql_setpermission.sh'
--- a/scripts/mysql_setpermission.sh	2009-03-31 10:59:22 +0000
+++ b/scripts/mysql_setpermission.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 ## Emacs, this is -*- perl -*- mode? :-)
 ##
 ##        Permission setter for MySQL

=== modified file 'scripts/mysql_zap.sh'
--- a/scripts/mysql_zap.sh	2006-12-31 00:02:27 +0000
+++ b/scripts/mysql_zap.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2002, 2004 MySQL AB
 # 
 # This program is free software; you can redistribute it and/or modify
@@ -27,8 +27,8 @@ $opt_f= 0;
 $opt_t= 0;
 $opt_a = "";
 
-$BSD = -f '/vmunix' || $ENV{"OS"} eq "SunOS4" || $^O eq 'darwin';
-$LINUX = $^O eq 'linux';
+$BSD = -f '/vmunix' || $ENV{"OS"} eq "SunOS4";
+$LINUX = $^O eq 'linux' || $^O eq 'darwin';
 $pscmd = $BSD ? "/bin/ps -auxww" : $LINUX ? "/bin/ps axuw" : "/bin/ps -ef";
 
 open(TTYIN, "</dev/tty") || die "can't read /dev/tty: $!";

=== modified file 'scripts/mysqlaccess.sh'
--- a/scripts/mysqlaccess.sh	2007-01-09 08:32:56 +0000
+++ b/scripts/mysqlaccess.sh	2009-05-09 21:43:48 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # ****************************
 package MySQLaccess;
 #use strict;

=== modified file 'scripts/mysqld_multi.sh'
--- a/scripts/mysqld_multi.sh	2009-04-02 19:42:29 +0000
+++ b/scripts/mysqld_multi.sh	2009-04-28 18:28:03 +0000
@@ -316,11 +316,11 @@ sub start_mysqlds()
 	$tmp.= " $options[$j]";
       }
     }
-    if ($opt_verbose && $com =~ m/\/safe_mysqld$/ && !$info_sent)
+    if ($opt_verbose && $com =~ m/\/(safe_mysqld|mysqld_safe)$/ && !$info_sent)
     {
-      print "WARNING: safe_mysqld is being used to start mysqld. In this case you ";
+      print "WARNING: $1 is being used to start mysqld. In this case you ";
       print "may need to pass\n\"ledir=...\" under groups [mysqldN] to ";
-      print "safe_mysqld in order to find the actual mysqld binary.\n";
+      print "$1 in order to find the actual mysqld binary.\n";
       print "ledir (library executable directory) should be the path to the ";
       print "wanted mysqld binary.\n\n";
       $info_sent= 1;
@@ -670,9 +670,9 @@ language   = @datadir@/mysql/english
 user       = unix_user1
 
 [mysqld3]
-mysqld     = /path/to/safe_mysqld/safe_mysqld
+mysqld     = /path/to/mysqld_safe
 ledir      = /path/to/mysqld-binary/
-mysqladmin = /path/to/mysqladmin/mysqladmin
+mysqladmin = /path/to/mysqladmin
 socket     = /tmp/mysql.sock3
 port       = 3308
 pid-file   = @localstatedir@3/hostname.pid3

=== modified file 'scripts/mysqld_safe.sh'
--- a/scripts/mysqld_safe.sh	2009-03-16 19:28:06 +0000
+++ b/scripts/mysqld_safe.sh	2009-05-25 16:21:40 +0000
@@ -67,7 +67,7 @@ my_which ()
   ret=0
   for file
   do
-    for dir in "$PATH"
+    for dir in $PATH
     do
       if [ -f "$dir/$file" ]
       then
@@ -391,8 +391,8 @@ then
   fi
   # Change the err log to the right user, if it is in use
   if [ $want_syslog -eq 0 ]; then
-    touch $err_log
-    chown $user $err_log
+    touch "$err_log"
+    chown $user "$err_log"
   fi
   if test -n "$open_files"
   then
@@ -509,9 +509,9 @@ fi
 #
 # If there exists an old pid file, check if the daemon is already running
 # Note: The switches to 'ps' may depend on your operating system
-if test -f $pid_file
+if test -f "$pid_file"
 then
-  PID=`cat $pid_file`
+  PID=`cat "$pid_file"`
   if @CHECK_PID@
   then
     if @FIND_PROC@
@@ -520,8 +520,8 @@ then
       exit 1
     fi
   fi
-  rm -f $pid_file
-  if test -f $pid_file
+  rm -f "$pid_file"
+  if test -f "$pid_file"

   then
     log_error "Fatal error: Can't remove the pid file:
 $pid_file
@@ -563,11 +563,11 @@ test -n "$NOHUP_NICENESS" && cmd="$cmd <
 log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
 while true
 do
-  rm -f $safe_mysql_unix_port $pid_file	# Some extra safety
+  rm -f $safe_mysql_unix_port "$pid_file"	# Some extra safety
 
   eval_log_error "$cmd"
 
-  if test ! -f $pid_file		# This is removed if normal shutdown
+  if test ! -f "$pid_file"		# This is removed if normal shutdown
   then
     break
   fi

=== modified file 'scripts/mysqldumpslow.sh'
--- a/scripts/mysqldumpslow.sh	2009-02-24 08:07:40 +0000
+++ b/scripts/mysqldumpslow.sh	2009-05-07 17:40:00 +0000
@@ -20,7 +20,7 @@ GetOptions(\%opt,
     'v|verbose+',# verbose
     'help+',	# write usage info
     'd|debug+',	# debug
-    's=s',	# what to sort by (t, at, l, al, r, ar etc)
+    's=s',	# what to sort by (al, at, ar, c, t, l, r)
     'r!',	# reverse the sort order (largest last instead of first)
     't=i',	# just show the top n queries
     'a!',	# don't abstract all numbers to N and strings to 'S'
@@ -163,7 +163,14 @@ Parse and summarize the MySQL slow query
 
   -v           verbose
   -d           debug
-  -s ORDER     what to sort by (t, at, l, al, r, ar etc), 'at' is default
+  -s ORDER     what to sort by (al, at, ar, c, l, r, t), 'at' is default
+                al: average lock time
+                ar: average rows sent
+                at: average query time
+                 c: count
+                 l: lock time
+                 r: rows sent
+                 t: query time  
   -r           reverse the sort order (largest last instead of first)
   -t NUM       just show the top n queries
   -a           don't abstract all numbers to N and strings to 'S'

=== modified file 'sql-bench/as3ap.sh'
--- a/sql-bench/as3ap.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/as3ap.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/bench-count-distinct.sh'
--- a/sql-bench/bench-count-distinct.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/bench-count-distinct.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/bench-init.pl.sh'
--- a/sql-bench/bench-init.pl.sh	2009-02-03 12:46:25 +0000
+++ b/sql-bench/bench-init.pl.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2003, 2005 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/compare-results.sh'
--- a/sql-bench/compare-results.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/compare-results.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/copy-db.sh'
--- a/sql-bench/copy-db.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/copy-db.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/crash-me.sh'
--- a/sql-bench/crash-me.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/crash-me.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # -*- perl -*-
 # Copyright (C) 2000-2006 MySQL AB
 #

=== modified file 'sql-bench/innotest1.sh'
--- a/sql-bench/innotest1.sh	2008-05-22 22:25:21 +0000
+++ b/sql-bench/innotest1.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 ############################################################################
 #     Stress test for MySQL/InnoDB combined database
 #     (c) 2002 Innobase Oy & MySQL AB

=== modified file 'sql-bench/innotest1a.sh'
--- a/sql-bench/innotest1a.sh	2008-05-22 22:25:21 +0000
+++ b/sql-bench/innotest1a.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 ############################################################################
 #     Stress test for MySQL/InnoDB combined database
 #     (c) 2002 Innobase Oy & MySQL AB

=== modified file 'sql-bench/innotest1b.sh'
--- a/sql-bench/innotest1b.sh	2008-05-22 22:25:21 +0000
+++ b/sql-bench/innotest1b.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 ############################################################################
 #     Stress test for MySQL/InnoDB combined database
 #     (c) 2002 Innobase Oy & MySQL AB

=== modified file 'sql-bench/innotest2.sh'
--- a/sql-bench/innotest2.sh	2008-05-22 22:25:21 +0000
+++ b/sql-bench/innotest2.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 ############################################################################
 #     Stress test for MySQL/InnoDB combined database
 #     (c) 2002 Innobase Oy & MySQL AB

=== modified file 'sql-bench/innotest2a.sh'
--- a/sql-bench/innotest2a.sh	2008-05-22 22:25:21 +0000
+++ b/sql-bench/innotest2a.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 ############################################################################
 #     Stress test for MySQL/Innobase combined database
 #     (c) 2000 Innobase Oy & MySQL AB

=== modified file 'sql-bench/innotest2b.sh'
--- a/sql-bench/innotest2b.sh	2008-05-22 22:25:21 +0000
+++ b/sql-bench/innotest2b.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 ############################################################################
 #     Stress test for MySQL/Innobase combined database
 #     (c) 2000 Innobase Oy & MySQL AB

=== modified file 'sql-bench/run-all-tests.sh'
--- a/sql-bench/run-all-tests.sh	2007-02-23 11:13:55 +0000
+++ b/sql-bench/run-all-tests.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/server-cfg.sh'
--- a/sql-bench/server-cfg.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/server-cfg.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # -*- perl -*-
 # Copyright (C) 2000-2006 MySQL AB
 #

=== modified file 'sql-bench/test-ATIS.sh'
--- a/sql-bench/test-ATIS.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/test-ATIS.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-alter-table.sh'
--- a/sql-bench/test-alter-table.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/test-alter-table.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-big-tables.sh'
--- a/sql-bench/test-big-tables.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/test-big-tables.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-connect.sh'
--- a/sql-bench/test-connect.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/test-connect.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-create.sh'
--- a/sql-bench/test-create.sh	2009-02-13 12:35:38 +0000
+++ b/sql-bench/test-create.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-insert.sh'
--- a/sql-bench/test-insert.sh	2007-02-23 11:13:55 +0000
+++ b/sql-bench/test-insert.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-select.sh'
--- a/sql-bench/test-select.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/test-select.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-transactions.sh'
--- a/sql-bench/test-transactions.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/test-transactions.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-bench/test-wisconsin.sh'
--- a/sql-bench/test-wisconsin.sh	2006-12-31 00:32:21 +0000
+++ b/sql-bench/test-wisconsin.sh	2009-05-29 13:40:55 +0000
@@ -1,4 +1,4 @@
-#!@PERL@
+#!/usr/bin/perl
 # Copyright (C) 2000-2001, 2003 MySQL AB
 #
 # This library is free software; you can redistribute it and/or

=== modified file 'sql-common/client.c'
--- a/sql-common/client.c	2009-03-19 13:42:36 +0000
+++ b/sql-common/client.c	2009-05-20 17:34:37 +0000
@@ -120,6 +120,7 @@ const char 	*def_shared_memory_base_name
 
 static void mysql_close_free_options(MYSQL *mysql);
 static void mysql_close_free(MYSQL *mysql);
+static void mysql_prune_stmt_list(MYSQL *mysql);
 
 #if !(defined(__WIN__) || defined(__NETWARE__))
 static int wait_for_data(my_socket fd, uint timeout);
@@ -924,6 +925,7 @@ void end_server(MYSQL *mysql)
     vio_delete(mysql->net.vio);
     reset_sigpipe(mysql);
     mysql->net.vio= 0;          /* Marker */
+    mysql_prune_stmt_list(mysql);
   }
   net_end(&mysql->net);
   free_old_query(mysql);
@@ -2526,30 +2528,9 @@ my_bool mysql_reconnect(MYSQL *mysql)
   tmp_mysql.reconnect= 1;
   tmp_mysql.free_me= mysql->free_me;
 
-  /*
-    For each stmt in mysql->stmts, move it to tmp_mysql if it is
-    in state MYSQL_STMT_INIT_DONE, otherwise close it.
-  */
-  {
-    LIST *element= mysql->stmts;
-    for (; element; element= element->next)
-    {
-      MYSQL_STMT *stmt= (MYSQL_STMT *) element->data;
-      if (stmt->state != MYSQL_STMT_INIT_DONE)
-      {
-        stmt->mysql= 0;
-        stmt->last_errno= CR_SERVER_LOST;
-        strmov(stmt->last_error, ER(CR_SERVER_LOST));
-        strmov(stmt->sqlstate, unknown_sqlstate);
-      }
-      else
-      {
-        tmp_mysql.stmts= list_add(tmp_mysql.stmts, &stmt->list);
-      }
-      /* No need to call list_delete for statement here */
-    }
-    mysql->stmts= NULL;
-  }
+  /* Move prepared statements (if any) over to the new mysql object */
+  tmp_mysql.stmts= mysql->stmts;
+  mysql->stmts= 0;
 
   /* Don't free options as these are now used in tmp_mysql */
   bzero((char*) &mysql->options,sizeof(mysql->options));
@@ -2639,6 +2620,46 @@ static void mysql_close_free(MYSQL *mysq
 }
 
 
+/**
+  For use when the connection to the server has been lost (in which case 
+  the server has discarded all information about prepared statements
+  associated with the connection).
+
+  Mark all statements in mysql->stmts by setting stmt->mysql= 0 if the
+  statement has transitioned beyond the MYSQL_STMT_INIT_DONE state, and
+  unlink the statement from the mysql->stmts list.
+
+  The remaining pruned list of statements (if any) is kept in mysql->stmts.
+
+  @param mysql       pointer to the MYSQL object
+
+  @return none
+*/
+static void mysql_prune_stmt_list(MYSQL *mysql)
+{
+  LIST *element= mysql->stmts;
+  LIST *pruned_list= 0;
+
+  for (; element; element= element->next)
+  {
+    MYSQL_STMT *stmt= (MYSQL_STMT *) element->data;
+    if (stmt->state != MYSQL_STMT_INIT_DONE)
+    {
+      stmt->mysql= 0;
+      stmt->last_errno= CR_SERVER_LOST;
+      strmov(stmt->last_error, ER(CR_SERVER_LOST));
+      strmov(stmt->sqlstate, unknown_sqlstate);
+    }
+    else
+    {
+      pruned_list= list_add(pruned_list, element);
+    }
+  }
+
+  mysql->stmts= pruned_list;
+}
+
+
 /*
   Clear connection pointer of every statement: this is necessary
   to give error on attempt to use a prepared statement of closed

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2009-04-09 09:38:50 +0000
+++ b/sql/field.cc	2009-05-15 08:42:57 +0000
@@ -5307,7 +5307,7 @@ bool Field_time::get_time(MYSQL_TIME *lt
     ltime->neg= 1;
     tmp=-tmp;
   }
-  ltime->day= 0;
+  ltime->year= ltime->month= ltime->day= 0;
   ltime->hour=   (int) (tmp/10000);
   tmp-=ltime->hour*10000;
   ltime->minute= (int) tmp/100;

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2008-12-10 20:14:50 +0000
+++ b/sql/handler.h	2009-05-04 10:00:15 +0000
@@ -876,9 +876,9 @@ typedef struct {
   ulonglong delete_length;
   ha_rows records;
   ulong mean_rec_length;
-  time_t create_time;
-  time_t check_time;
-  time_t update_time;
+  ulong create_time;
+  ulong check_time;
+  ulong update_time;
   ulonglong check_sum;
 } PARTITION_INFO;
 
@@ -1037,9 +1037,9 @@ public:
   ha_rows records;
   ha_rows deleted;			/* Deleted records */
   ulong mean_rec_length;		/* physical reclength */
-  time_t create_time;			/* When table was created */
-  time_t check_time;
-  time_t update_time;
+  ulong create_time;			/* When table was created */
+  ulong check_time;
+  ulong update_time;
   uint block_size;			/* index block size */
 
   ha_statistics():

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2009-05-08 19:04:07 +0000
+++ b/sql/item.cc	2009-05-25 08:00:40 +0000
@@ -2472,8 +2472,9 @@ longlong_from_string_with_check (CHARSET
     TODO: Give error if we wanted a signed integer and we got an unsigned
     one
   */
-  if (err > 0 ||
-      (end != org_end && !check_if_only_end_space(cs, end, org_end)))
+  if (!current_thd->no_errors &&
+      (err > 0 ||
+       (end != org_end && !check_if_only_end_space(cs, end, org_end))))
   {
     push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                         ER_TRUNCATED_WRONG_VALUE,
@@ -3268,9 +3269,57 @@ Item_param::set_param_type_and_swap_valu
 }
 
 /****************************************************************************
+  Item_copy
+****************************************************************************/
+Item_copy *Item_copy::create (Item *item)
+{
+  switch (item->result_type())
+  {
+    case STRING_RESULT:
+      return new Item_copy_string (item);
+    case REAL_RESULT: 
+      return new Item_copy_float (item);
+    case INT_RESULT:
+      return item->unsigned_flag ? 
+        new Item_copy_uint (item) : new Item_copy_int (item);
+    case DECIMAL_RESULT:
+      return new Item_copy_decimal (item);
+
+    case ROW_RESULT:
+      DBUG_ASSERT (0);
+  }
+  /* should not happen */
+  return NULL;
+}
+
+/****************************************************************************
   Item_copy_string
 ****************************************************************************/
 
+double Item_copy_string::val_real()
+{
+  int err_not_used;
+  char *end_not_used;
+  return (null_value ? 0.0 :
+          my_strntod(str_value.charset(), (char*) str_value.ptr(),
+                     str_value.length(), &end_not_used, &err_not_used));
+}
+
+longlong Item_copy_string::val_int()
+{
+  int err;
+  return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
+                                          str_value.length(),10, (char**) 0,
+                                          &err); 
+}
+
+
+int Item_copy_string::save_in_field(Field *field, bool no_conversions)
+{
+  return save_str_value_in_field(field, &str_value);
+}
+
+
 void Item_copy_string::copy()
 {
   String *res=item->val_str(&str_value);
@@ -3293,12 +3342,163 @@ my_decimal *Item_copy_string::val_decima
 {
   // Item_copy_string is used without fix_fields call
   if (null_value)
-    return 0;
+    return (my_decimal *) 0;
   string2my_decimal(E_DEC_FATAL_ERROR, &str_value, decimal_value);
   return (decimal_value);
 }
 
 
+/****************************************************************************
+  Item_copy_int
+****************************************************************************/
+
+void Item_copy_int::copy()
+{
+  cached_value= item->val_int();
+  null_value=item->null_value;
+}
+
+static int save_int_value_in_field (Field *field, longlong nr, 
+                                    bool null_value, bool unsigned_flag);
+
+int Item_copy_int::save_in_field(Field *field, bool no_conversions)
+{
+  return save_int_value_in_field(field, cached_value, 
+                                 null_value, unsigned_flag);
+}
+
+
+String *Item_copy_int::val_str(String *str)
+{
+  if (null_value)
+    return (String *) 0;
+
+  str->set(cached_value, &my_charset_bin);
+  return str;
+}
+
+
+my_decimal *Item_copy_int::val_decimal(my_decimal *decimal_value)
+{
+  if (null_value)
+    return (my_decimal *) 0;
+
+  int2my_decimal(E_DEC_FATAL_ERROR, cached_value, unsigned_flag, decimal_value);
+  return decimal_value;
+}
+
+
+/****************************************************************************
+  Item_copy_uint
+****************************************************************************/
+
+String *Item_copy_uint::val_str(String *str)
+{
+  if (null_value)
+    return (String *) 0;
+
+  str->set((ulonglong) cached_value, &my_charset_bin);
+  return str;
+}
+
+
+/****************************************************************************
+  Item_copy_float
+****************************************************************************/
+
+String *Item_copy_float::val_str(String *str)
+{
+  if (null_value)
+    return (String *) 0;
+  else
+  {
+    double nr= val_real();
+    str->set_real(nr,decimals, &my_charset_bin);
+    return str;
+  }
+}
+
+
+my_decimal *Item_copy_float::val_decimal(my_decimal *decimal_value)
+{
+  if (null_value)
+    return (my_decimal *) 0;
+  else
+  {
+    double nr= val_real();
+    double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
+    return decimal_value;
+  }
+}
+
+
+int Item_copy_float::save_in_field(Field *field, bool no_conversions)
+{
+  if (null_value)
+    return set_field_to_null(field);
+  field->set_notnull();
+  return field->store(cached_value);
+}
+
+
+/****************************************************************************
+  Item_copy_decimal
+****************************************************************************/
+
+int Item_copy_decimal::save_in_field(Field *field, bool no_conversions)
+{
+  if (null_value)
+    return set_field_to_null(field);
+  field->set_notnull();
+  return field->store_decimal(&cached_value);
+}
+
+
+String *Item_copy_decimal::val_str(String *result)
+{
+  if (null_value)
+    return (String *) 0;
+  result->set_charset(&my_charset_bin);
+  my_decimal2string(E_DEC_FATAL_ERROR, &cached_value, 0, 0, 0, result);
+  return result;
+}
+
+
+double Item_copy_decimal::val_real()
+{
+  if (null_value)
+    return 0.0;
+  else
+  {
+    double result;
+    my_decimal2double(E_DEC_FATAL_ERROR, &cached_value, &result);
+    return result;
+  }
+}
+
+
+longlong Item_copy_decimal::val_int()
+{
+  if (null_value)
+    return LL(0);
+  else
+  {
+    longlong result;
+    my_decimal2int(E_DEC_FATAL_ERROR, &cached_value, unsigned_flag, &result);
+    return result;
+  }
+}
+
+
+void Item_copy_decimal::copy()
+{
+  my_decimal *nr= item->val_decimal(&cached_value);
+  if (nr && nr != &cached_value)
+    memcpy (&cached_value, nr, sizeof (my_decimal)); 
+  null_value= item->null_value;
+}
+
+
 /*
   Functions to convert item to field (for send_fields)
 */
@@ -3390,14 +3590,12 @@ static void mark_as_dependent(THD *thd, 
   current->mark_as_dependent(last);
   if (thd->lex->describe & DESCRIBE_EXTENDED)
   {
-    char warn_buff[MYSQL_ERRMSG_SIZE];
-    sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
-            db_name, (db_name[0] ? "." : ""),
-            table_name, (table_name [0] ? "." : ""),
-            resolved_item->field_name,
-	    current->select_number, last->select_number);
-    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
-		 ER_WARN_FIELD_RESOLVED, warn_buff);
+    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+		 ER_WARN_FIELD_RESOLVED, ER(ER_WARN_FIELD_RESOLVED),
+                 db_name, (db_name[0] ? "." : ""),
+                 table_name, (table_name [0] ? "." : ""),
+                 resolved_item->field_name,
+                 current->select_number, last->select_number);
   }
 }
 
@@ -4875,7 +5073,10 @@ int Item_null::save_safe_in_field(Field 
 /*
   This implementation can lose str_value content, so if the
   Item uses str_value to store something, it should
-  reimplement it's ::save_in_field() as Item_string, for example, does
+  reimplement it's ::save_in_field() as Item_string, for example, does.
+
+  Note: all Item_XXX::val_str(str) methods must NOT rely on the fact that
+  str != str_value. For example, see fix for bug #44743.
 */
 
 int Item::save_in_field(Field *field, bool no_conversions)
@@ -4945,10 +5146,9 @@ int Item_uint::save_in_field(Field *fiel
   return Item_int::save_in_field(field, no_conversions);
 }
 
-
-int Item_int::save_in_field(Field *field, bool no_conversions)
+static int save_int_value_in_field (Field *field, longlong nr, 
+                                    bool null_value, bool unsigned_flag)
 {
-  longlong nr=val_int();
   if (null_value)
     return set_field_to_null(field);
   field->set_notnull();
@@ -4956,6 +5156,12 @@ int Item_int::save_in_field(Field *field
 }
 
 
+int Item_int::save_in_field(Field *field, bool no_conversions)
+{
+  return save_int_value_in_field (field, val_int(), null_value, unsigned_flag);
+}
+
+
 int Item_decimal::save_in_field(Field *field, bool no_conversions)
 {
   field->set_notnull();
@@ -5812,7 +6018,8 @@ void Item_ref::print(String *str, enum_q
         !table_name && name && alias_name_used)
     {
       THD *thd= current_thd;
-      append_identifier(thd, str, name, (uint) strlen(name));
+      append_identifier(thd, str, (*ref)->real_item()->name,
+                        (*ref)->real_item()->name_length);
     }
     else
       (*ref)->print(str, query_type);

=== modified file 'sql/item.h'
--- a/sql/item.h	2009-04-01 11:10:03 +0000
+++ b/sql/item.h	2009-05-25 08:00:40 +0000
@@ -2443,48 +2443,203 @@ public:
 #include "item_xmlfunc.h"
 #endif
 
-class Item_copy_string :public Item
+/**
+  Base class to implement typed value caching Item classes
+
+  Item_copy_ classes are very similar to the corresponding Item_
+  classes (e.g. Item_copy_int is similar to Item_int) but they add
+  the following additional functionality to Item_ :
+    1. Nullability
+    2. Possibility to store the value not only on instantiation time,
+       but also later.
+  Item_copy_ classes are a functionality subset of Item_cache_ 
+  classes, as e.g. they don't support comparisons with the original Item
+  as Item_cache_ classes do.
+  Item_copy_ classes are used in GROUP BY calculation.
+  TODO: Item_copy should be made an abstract interface and Item_copy_
+  classes should inherit both the respective Item_ class and the interface.
+  Ideally we should drop Item_copy_ classes altogether and merge 
+  their functionality to Item_cache_ (and these should be made to inherit
+  from Item_).
+*/
+
+class Item_copy :public Item
 {
+protected:  
+
+  /**
+    Stores the type of the resulting field that would be used to store the data
+    in the cache. This is to avoid calls to the original item.
+  */
   enum enum_field_types cached_field_type;
-public:
+
+  /** The original item that is copied */
   Item *item;
-  Item_copy_string(Item *i) :item(i)
+
+  /**
+    Stores the result type of the original item, so it can be returned
+    without calling the original item's method
+  */
+  Item_result cached_result_type;
+
+  /**
+    Constructor of the Item_copy class
+
+    stores metadata information about the original class as well as a 
+    pointer to it.
+  */
+  Item_copy(Item *i)
   {
+    item= i;
     null_value=maybe_null=item->maybe_null;
     decimals=item->decimals;
     max_length=item->max_length;
     name=item->name;
     cached_field_type= item->field_type();
+    cached_result_type= item->result_type();
+    unsigned_flag= item->unsigned_flag;
   }
+
+public:
+  /** 
+    Factory method to create the appropriate subclass dependent on the type of 
+    the original item.
+
+    @param item      the original item.
+  */  
+  static Item_copy *create (Item *item);
+
+  /** 
+    Update the cache with the value of the original item
+   
+    This is the method that updates the cached value.
+    It must be explicitly called by the user of this class to store the value 
+    of the orginal item in the cache.
+  */  
+  virtual void copy() = 0;
+
+  Item *get_item() { return item; }
+  /** All of the subclasses should have the same type tag */
   enum Type type() const { return COPY_STR_ITEM; }
-  enum Item_result result_type () const { return STRING_RESULT; }
   enum_field_types field_type() const { return cached_field_type; }
-  double val_real()
+  enum Item_result result_type () const { return cached_result_type; }
+
+  void make_field(Send_field *field) { item->make_field(field); }
+  table_map used_tables() const { return (table_map) 1L; }
+  bool const_item() const { return 0; }
+  bool is_null() { return null_value; }
+
+  /*  
+    Override the methods below as pure virtual to make sure all the 
+    sub-classes implement them.
+  */  
+
+  virtual String *val_str(String*) = 0;
+  virtual my_decimal *val_decimal(my_decimal *) = 0;
+  virtual double val_real() = 0;
+  virtual longlong val_int() = 0;
+  virtual int save_in_field(Field *field, bool no_conversions) = 0;
+};
+
+/**
+ Implementation of a string cache.
+ 
+ Uses Item::str_value for storage
+*/ 
+class Item_copy_string : public Item_copy
+{
+public:
+  Item_copy_string (Item *item) : Item_copy(item) {}
+
+  String *val_str(String*);
+  my_decimal *val_decimal(my_decimal *);
+  double val_real();
+  longlong val_int();
+  void copy();
+  int save_in_field(Field *field, bool no_conversions);
+};
+
+
+class Item_copy_int : public Item_copy
+{
+protected:  
+  longlong cached_value; 
+public:
+  Item_copy_int (Item *i) : Item_copy(i) {}
+  int save_in_field(Field *field, bool no_conversions);
+
+  virtual String *val_str(String*);
+  virtual my_decimal *val_decimal(my_decimal *);
+  virtual double val_real()
   {
-    int err_not_used;
-    char *end_not_used;
-    return (null_value ? 0.0 :
-	    my_strntod(str_value.charset(), (char*) str_value.ptr(),
-		       str_value.length(), &end_not_used, &err_not_used));
+    return null_value ? 0.0 : (double) cached_value;
   }
-  longlong val_int()
+  virtual longlong val_int()
+  {
+    return null_value ? LL(0) : cached_value;
+  }
+  virtual void copy();
+};
+
+
+class Item_copy_uint : public Item_copy_int
+{
+public:
+  Item_copy_uint (Item *item) : Item_copy_int(item) 
+  {
+    unsigned_flag= 1;
+  }
+
+  String *val_str(String*);
+  double val_real()
   {
-    int err;
-    return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
-                                            str_value.length(),10, (char**) 0,
-                                            &err); 
+    return null_value ? 0.0 : (double) (ulonglong) cached_value;
   }
+};
+
+
+class Item_copy_float : public Item_copy
+{
+protected:  
+  double cached_value; 
+public:
+  Item_copy_float (Item *i) : Item_copy(i) {}
+  int save_in_field(Field *field, bool no_conversions);
+
   String *val_str(String*);
   my_decimal *val_decimal(my_decimal *);
-  void make_field(Send_field *field) { item->make_field(field); }
-  void copy();
-  int save_in_field(Field *field, bool no_conversions)
+  double val_real()
   {
-    return save_str_value_in_field(field, &str_value);
+    return null_value ? 0.0 : cached_value;
   }
-  table_map used_tables() const { return (table_map) 1L; }
-  bool const_item() const { return 0; }
-  bool is_null() { return null_value; }
+  longlong val_int()
+  {
+    return (longlong) rint(val_real());
+  }
+  void copy()
+  {
+    cached_value= item->val_real();
+    null_value= item->null_value;
+  }
+};
+
+
+class Item_copy_decimal : public Item_copy
+{
+protected:  
+  my_decimal cached_value;
+public:
+  Item_copy_decimal (Item *i) : Item_copy(i) {}
+  int save_in_field(Field *field, bool no_conversions);
+
+  String *val_str(String*);
+  my_decimal *val_decimal(my_decimal *) 
+  { 
+    return null_value ? NULL: &cached_value; 
+  }
+  double val_real();
+  longlong val_int();
+  void copy();
 };
 
 

=== modified file 'sql/item_cmpfunc.cc'
--- a/sql/item_cmpfunc.cc	2009-02-19 13:59:00 +0000
+++ b/sql/item_cmpfunc.cc	2009-05-25 08:00:40 +0000
@@ -2724,16 +2724,6 @@ void Item_func_case::fix_length_and_dec(
     nagg++;
     if (!(found_types= collect_cmp_types(agg, nagg)))
       return;
-    if (with_sum_func || current_thd->lex->current_select->group_list.elements)
-    {
-      /*
-        See TODO commentary in the setup_copy_fields function:
-        item in a group may be wrapped with an Item_copy_string item.
-        That item has a STRING_RESULT result type, so we need
-        to take this type into account.
-      */
-      found_types |= (1 << item_cmp_type(left_result_type, STRING_RESULT));
-    }
 
     for (i= 0; i <= (uint)DECIMAL_RESULT; i++)
     {

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2009-05-08 19:04:07 +0000
+++ b/sql/item_func.cc	2009-05-21 20:22:46 +0000
@@ -2143,9 +2143,6 @@ bool Item_func_rand::fix_fields(THD *thd
     if (!rand && !(rand= (struct rand_struct*)
                    thd->stmt_arena->alloc(sizeof(*rand))))
       return TRUE;
-
-    if (args[0]->const_item())
-      seed_random (args[0]);
   }
   else
   {
@@ -2175,8 +2172,21 @@ void Item_func_rand::update_used_tables(
 double Item_func_rand::val_real()
 {
   DBUG_ASSERT(fixed == 1);
-  if (arg_count && !args[0]->const_item())
-    seed_random (args[0]);
+  if (arg_count)
+  {
+    if (!args[0]->const_item())
+      seed_random(args[0]);
+    else if (first_eval)
+    {
+      /*
+        Constantness of args[0] may be set during JOIN::optimize(), if arg[0]
+        is a field item of "constant" table. Thus, we have to evaluate
+        seed_random() for constant arg there but not at the fix_fields method.
+      */
+      first_eval= FALSE;
+      seed_random(args[0]);
+    }
+  }
   return my_rnd(rand);
 }
 
@@ -4178,6 +4188,41 @@ Item_func_set_user_var::check(bool use_r
 
 
 /**
+  @brief Evaluate and store item's result.
+  This function is invoked on "SELECT ... INTO @var ...".
+  
+  @param    item    An item to get value from.
+*/
+
+void Item_func_set_user_var::save_item_result(Item *item)
+{
+  DBUG_ENTER("Item_func_set_user_var::save_item_result");
+
+  switch (cached_result_type) {
+  case REAL_RESULT:
+    save_result.vreal= item->val_result();
+    break;
+  case INT_RESULT:
+    save_result.vint= item->val_int_result();
+    unsigned_flag= item->unsigned_flag;
+    break;
+  case STRING_RESULT:
+    save_result.vstr= item->str_result(&value);
+    break;
+  case DECIMAL_RESULT:
+    save_result.vdec= item->val_decimal_result(&decimal_buff);
+    break;
+  case ROW_RESULT:
+  default:
+    // Should never happen
+    DBUG_ASSERT(0);
+    break;
+  }
+  DBUG_VOID_RETURN;
+}
+
+
+/**
   This functions is invoked on
   SET \@variable or \@variable:= expression.
 
@@ -4835,10 +4880,20 @@ bool Item_func_get_system_var::is_writte
 }
 
 
+void Item_func_get_system_var::update_null_value()
+{
+  THD *thd= current_thd;
+  int save_no_errors= thd->no_errors;
+  thd->no_errors= TRUE;
+  Item::update_null_value();
+  thd->no_errors= save_no_errors;
+}
+
+
 void Item_func_get_system_var::fix_length_and_dec()
 {
   char *cptr;
-  maybe_null=0;
+  maybe_null= TRUE;
   max_length= 0;
 
   if (var->check_type(var_type))

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2009-04-11 09:46:14 +0000
+++ b/sql/item_func.h	2009-05-21 20:22:46 +0000
@@ -696,14 +696,16 @@ public:
 class Item_func_rand :public Item_real_func
 {
   struct rand_struct *rand;
+  bool first_eval; // TRUE if val_real() is called 1st time
 public:
-  Item_func_rand(Item *a) :Item_real_func(a), rand(0) {}
+  Item_func_rand(Item *a) :Item_real_func(a), rand(0), first_eval(TRUE) {}
   Item_func_rand()	  :Item_real_func() {}
   double val_real();
   const char *func_name() const { return "rand"; }
   bool const_item() const { return 0; }
   void update_used_tables();
   bool fix_fields(THD *thd, Item **ref);
+  void cleanup() { first_eval= TRUE; Item_real_func::cleanup(); }
 private:
   void seed_random (Item * val);  
 };
@@ -1341,6 +1343,7 @@ public:
   bool send(Protocol *protocol, String *str_arg);
   void make_field(Send_field *tmp_field);
   bool check(bool use_result_field);
+  void save_item_result(Item *item);
   bool update();
   enum Item_result result_type () const { return cached_result_type; }
   bool fix_fields(THD *thd, Item **ref);
@@ -1452,6 +1455,7 @@ public:
                            LEX_STRING *component_arg, const char *name_arg,
                            size_t name_len_arg);
   enum Functype functype() const { return GSYSVAR_FUNC; }
+  void update_null_value();
   void fix_length_and_dec();
   void print(String *str, enum_query_type query_type);
   bool const_item() const { return true; }

=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc	2009-04-23 07:47:54 +0000
+++ b/sql/item_strfunc.cc	2009-05-21 12:16:17 +0000
@@ -2706,8 +2706,15 @@ String *Item_func_conv_charset::val_str(
   DBUG_ASSERT(fixed == 1);
   if (use_cached_value)
     return null_value ? 0 : &str_value;
-  String *arg= args[0]->val_str(str);
+  /* 
+    Here we don't pass 'str' as a parameter to args[0]->val_str()
+    as 'str' may points to 'str_value' (e.g. see Item::save_in_field()),
+    which we use below to convert string. 
+    Use argument's 'str_value' instead.
+  */
+  String *arg= args[0]->val_str(&args[0]->str_value);;
   uint dummy_errors;
+  arg= args[0]->val_str(&args[0]->str_value);  
   if (!arg)
   {
     null_value=1;
@@ -2943,7 +2950,7 @@ String *Item_load_file::val_str(String *
       )
     goto err;
 
-  (void) fn_format(path, file_name->c_ptr(), mysql_real_data_home, "",
+  (void) fn_format(path, file_name->c_ptr_safe(), mysql_real_data_home, "",
 		   MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
 
   /* Read only allowed from within dir specified by secure_file_priv */
@@ -2969,7 +2976,7 @@ String *Item_load_file::val_str(String *
   }
   if (tmp_value.alloc(stat_info.st_size))
     goto err;
-  if ((file = my_open(file_name->c_ptr(), O_RDONLY, MYF(0))) < 0)
+  if ((file = my_open(file_name->ptr(), O_RDONLY, MYF(0))) < 0)
     goto err;
   if (my_read(file, (uchar*) tmp_value.ptr(), stat_info.st_size, MYF(MY_NABP)))
   {
@@ -3219,7 +3226,21 @@ longlong Item_func_uncompressed_length::
   if (res->is_empty()) return 0;
 
   /*
-    res->ptr() using is safe because we have tested that string is not empty,
+    If length is <= 4 bytes, data is corrupt. This is the best we can do
+    to detect garbage input without decompressing it.
+  */
+  if (res->length() <= 4)
+  {
+    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                        ER_ZLIB_Z_DATA_ERROR,
+                        ER(ER_ZLIB_Z_DATA_ERROR));
+    null_value= 1;
+    return 0;
+  }
+
+ /*
+    res->ptr() using is safe because we have tested that string is at least
+    5 bytes long.
     res->c_ptr() is not used because:
       - we do not need \0 terminated string to get first 4 bytes
       - c_ptr() tests simbol after string end (uninitialiozed memory) which

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-05-08 19:04:07 +0000
+++ b/sql/log_event.cc	2009-05-15 13:03:22 +0000
@@ -7862,10 +7862,11 @@ Table_map_log_event::Table_map_log_event
 
   /*
     Now set the size of the data to the size of the field metadata array
-    plus one or two bytes for number of elements in the field metadata array.
+    plus one or three bytes (see pack.c:net_store_length) for number of 
+    elements in the field metadata array.
   */
   if (m_field_metadata_size > 255)
-    m_data_size+= m_field_metadata_size + 2; 
+    m_data_size+= m_field_metadata_size + 3; 
   else
     m_data_size+= m_field_metadata_size + 1; 
 
@@ -9312,7 +9313,7 @@ Incident_log_event::print(FILE *file,
 
   Write_on_release_cache cache(&print_event_info->head_cache, file);
   print_header(&cache, print_event_info, FALSE);
-  my_b_printf(&cache, "\n# Incident: %s", description());
+  my_b_printf(&cache, "\n# Incident: %s\nRELOAD DATABASE; # Shall generate syntax error\n", description());
 }
 #endif
 

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2009-02-22 13:40:52 +0000
+++ b/sql/rpl_rli.cc	2009-04-19 01:21:33 +0000
@@ -104,9 +104,16 @@ int init_relay_log_info(Relay_log_info* 
   rli->tables_to_lock= 0;
   rli->tables_to_lock_count= 0;
 
-  fn_format(rli->slave_patternload_file, PREFIX_SQL_LOAD, slave_load_tmpdir, "",
-            MY_PACK_FILENAME | MY_UNPACK_FILENAME |
-            MY_RETURN_REAL_PATH);
+  char pattern[FN_REFLEN];
+  if (fn_format(pattern, PREFIX_SQL_LOAD, slave_load_tmpdir, "",
+            MY_SAFE_PATH | MY_RETURN_REAL_PATH) == NullS)
+  {
+    pthread_mutex_unlock(&rli->data_lock);
+    sql_print_error("Unable to use slave's temporary directory %s",
+                    slave_load_tmpdir);
+    DBUG_RETURN(1);
+  }
+  unpack_filename(rli->slave_patternload_file, pattern);
   rli->slave_patternload_file_size= strlen(rli->slave_patternload_file);
 
   /*

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2009-04-14 14:19:15 +0000
+++ b/sql/share/errmsg.txt	2009-05-20 08:24:22 +0000
@@ -6076,7 +6076,7 @@ ER_SLAVE_INCIDENT
 ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT
         eng "Table has no partition for some existing values"
 ER_BINLOG_UNSAFE_STATEMENT
-        eng "Statement is not safe to log in statement format."
+        eng "Statement may not be safe to log in statement format."
         swe "Detta �inte s�rt att logga i statement-format."
 ER_SLAVE_FATAL_ERROR
         eng "Fatal error: %s"

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2009-05-08 19:04:07 +0000
+++ b/sql/slave.cc	2009-05-22 23:29:41 +0000
@@ -389,6 +389,13 @@ void init_slave_skip_errors(const char* 
   DBUG_VOID_RETURN;
 }
 
+static void set_thd_in_use_temporary_tables(Relay_log_info *rli)
+{
+  TABLE *table;
+
+  for (table= rli->save_temporary_tables ; table ; table= table->next)
+    table->in_use= rli->sql_thd;
+}
 
 int terminate_slave_threads(Master_info* mi,int thread_mask,bool skip_lock)
 {
@@ -2668,14 +2675,21 @@ err:
   LOAD DATA INFILE.
  */
 static 
-int check_temp_dir(char* tmp_dir, char *tmp_file)
+int check_temp_dir(char* tmp_file)
 {
   int fd;
   MY_DIR *dirp;
+  char tmp_dir[FN_REFLEN];
+  size_t tmp_dir_size;
 
   DBUG_ENTER("check_temp_dir");
 
   /*
+    Get the directory from the temporary file.
+  */
+  dirname_part(tmp_dir, tmp_file, &tmp_dir_size);
+
+  /*
     Check if the directory exists.
    */
   if (!(dirp=my_dir(tmp_dir,MYF(MY_WME))))
@@ -2750,6 +2764,7 @@ pthread_handler_t handle_slave_sql(void 
   }
   thd->init_for_queries();
   thd->temporary_tables = rli->save_temporary_tables; // restore temp tables
+  set_thd_in_use_temporary_tables(rli);   // (re)set sql_thd in use for saved temp tables
   pthread_mutex_lock(&LOCK_thread_count);
   threads.append(thd);
   pthread_mutex_unlock(&LOCK_thread_count);
@@ -2830,7 +2845,7 @@ log '%s' at position %s, relay log '%s' 
                     llstr(rli->group_master_log_pos,llbuff),rli->group_relay_log_name,
                     llstr(rli->group_relay_log_pos,llbuff1));
 
-  if (check_temp_dir(slave_load_tmpdir, rli->slave_patternload_file))
+  if (check_temp_dir(rli->slave_patternload_file))
   {
     rli->report(ERROR_LEVEL, thd->main_da.sql_errno(), 
                 "Unable to use slave's temporary directory %s - %s", 
@@ -2996,6 +3011,7 @@ the slave SQL thread with \"SLAVE START\
   DBUG_ASSERT(rli->sql_thd == thd);
   THD_CHECK_SENTRY(thd);
   rli->sql_thd= 0;
+  set_thd_in_use_temporary_tables(rli);  // (re)set sql_thd in use for saved temp tables
   pthread_mutex_lock(&LOCK_thread_count);
   THD_CHECK_SENTRY(thd);
   delete thd;

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2009-04-08 23:42:51 +0000
+++ b/sql/sql_acl.cc	2009-05-25 13:00:18 +0000
@@ -936,6 +936,7 @@ int acl_getroot(THD *thd, USER_RESOURCES
 #ifdef HAVE_OPENSSL
     Vio *vio=thd->net.vio;
     SSL *ssl= (SSL*) vio->ssl_arg;
+    X509 *cert;
 #endif
 
     /*
@@ -964,8 +965,11 @@ int acl_getroot(THD *thd, USER_RESOURCES
       */
       if (vio_type(vio) == VIO_TYPE_SSL &&
 	  SSL_get_verify_result(ssl) == X509_V_OK &&
-	  SSL_get_peer_certificate(ssl))
+	  (cert= SSL_get_peer_certificate(ssl)))
+      {
 	user_access= acl_user->access;
+        X509_free(cert);
+      }
       break;
     case SSL_TYPE_SPECIFIED: /* Client should have specified attrib */
       /*
@@ -974,7 +978,6 @@ int acl_getroot(THD *thd, USER_RESOURCES
 	If cipher name is specified, we compare it to actual cipher in
 	use.
       */
-      X509 *cert;
       if (vio_type(vio) != VIO_TYPE_SSL ||
 	  SSL_get_verify_result(ssl) != X509_V_OK)
 	break;
@@ -1014,6 +1017,7 @@ int acl_getroot(THD *thd, USER_RESOURCES
             sql_print_information("X509 issuer mismatch: should be '%s' "
 			      "but is '%s'", acl_user->x509_issuer, ptr);
           free(ptr);
+          X509_free(cert);
           user_access=NO_ACCESS;
           break;
         }
@@ -1033,12 +1037,15 @@ int acl_getroot(THD *thd, USER_RESOURCES
             sql_print_information("X509 subject mismatch: should be '%s' but is '%s'",
                             acl_user->x509_subject, ptr);
           free(ptr);
+          X509_free(cert);
           user_access=NO_ACCESS;
           break;
         }
         user_access= acl_user->access;
         free(ptr);
       }
+      /* Deallocate the X509 certificate. */
+      X509_free(cert);
       break;
 #else  /* HAVE_OPENSSL */
     default:

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-04-17 05:51:51 +0000
+++ b/sql/sql_base.cc	2009-05-15 13:03:22 +0000
@@ -5585,6 +5585,13 @@ static void update_field_dependencies(TH
       other_bitmap=   table->read_set;
     }
 
+    /* 
+       The test-and-set mechanism in the bitmap is not reliable during
+       multi-UPDATE statements under MARK_COLUMNS_READ mode
+       (thd->mark_used_columns == MARK_COLUMNS_READ), as this bitmap contains
+       only those columns that are used in the SET clause. I.e they are being
+       set here. See multi_update::prepare()
+    */
     if (bitmap_fast_test_and_set(current_bitmap, field->field_index))
     {
       if (thd->mark_used_columns == MARK_COLUMNS_WRITE)

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-04-03 18:21:57 +0000
+++ b/sql/sql_class.cc	2009-05-15 13:25:29 +0000
@@ -2599,7 +2599,7 @@ bool select_dumpvar::send_data(List<Item
     {
       Item_func_set_user_var *suv= new Item_func_set_user_var(mv->s, item);
       suv->fix_fields(thd, 0);
-      suv->check(0);
+      suv->save_item_result(item);
       suv->update();
     }
   }

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2009-04-08 23:42:51 +0000
+++ b/sql/sql_delete.cc	2009-05-15 13:25:29 +0000
@@ -582,6 +582,11 @@ int mysql_multi_delete_prepare(THD *thd)
       }
     }
   }
+  /*
+    Reset the exclude flag to false so it doesn't interfare
+    with further calls to unique_table
+  */
+  lex->select_lex.exclude_from_table_unique_test= FALSE;
   DBUG_RETURN(FALSE);
 }
 
@@ -617,11 +622,24 @@ multi_delete::initialize_tables(JOIN *jo
     DBUG_RETURN(1);
 
   table_map tables_to_delete_from=0;
+  delete_while_scanning= 1;
   for (walk= delete_tables; walk; walk= walk->next_local)
+  {
     tables_to_delete_from|= walk->table->map;
+    if (delete_while_scanning &&
+        unique_table(thd, walk, join->tables_list, false))
+    {
+      /*
+        If the table we are going to delete from appears
+        in join, we need to defer delete. So the delete
+        doesn't interfers with the scaning of results.
+      */
+      delete_while_scanning= 0;
+    }
+  }
+
 
   walk= delete_tables;
-  delete_while_scanning= 1;
   for (JOIN_TAB *tab=join->join_tab, *end=join->join_tab+join->tables;
        tab < end;
        tab++)

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-04-09 11:30:44 +0000
+++ b/sql/sql_parse.cc	2009-05-15 13:40:09 +0000
@@ -195,11 +195,8 @@ bool begin_trans(THD *thd)
     error= -1;
   else
   {
-    LEX *lex= thd->lex;
     thd->options|= OPTION_BEGIN;
     thd->server_status|= SERVER_STATUS_IN_TRANS;
-    if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
-      error= ha_start_consistent_snapshot(thd);
   }
   return error;
 }
@@ -4027,6 +4024,11 @@ end_with_restore_list:
     }
     if (begin_trans(thd))
       goto error;
+    if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
+    {
+      if (ha_start_consistent_snapshot(thd))
+        goto error;
+    }
     my_ok(thd);
     break;
   case SQLCOM_COMMIT:

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2009-03-16 10:37:13 +0000
+++ b/sql/sql_plugin.cc	2009-05-18 08:10:30 +0000
@@ -29,6 +29,18 @@
 
 extern struct st_mysql_plugin *mysqld_builtins[];
 
+/**
+  @note The order of the enumeration is critical.
+  @see construct_options
+*/
+static const char *global_plugin_typelib_names[]=
+  { "OFF", "ON", "FORCE", NULL };
+enum enum_plugin_load_policy {PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE};
+static TYPELIB global_plugin_typelib=
+  { array_elements(global_plugin_typelib_names)-1,
+    "", global_plugin_typelib_names, NULL };
+
+
 char *opt_plugin_load= NULL;
 char *opt_plugin_dir_ptr;
 char opt_plugin_dir[FN_REFLEN];
@@ -192,7 +204,7 @@ static void plugin_load(MEM_ROOT *tmp_ro
 static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
                              const char *list);
 static int test_plugin_options(MEM_ROOT *, struct st_plugin_int *,
-                               int *, char **, my_bool);
+                               int *, char **);
 static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
                              struct st_plugin_int **);
 static void unlock_variables(THD *thd, struct system_variables *vars);
@@ -751,7 +763,7 @@ static bool plugin_add(MEM_ROOT *tmp_roo
       tmp.name.length= name_len;
       tmp.ref_count= 0;
       tmp.state= PLUGIN_IS_UNINITIALIZED;
-      if (test_plugin_options(tmp_root, &tmp, argc, argv, true))
+      if (test_plugin_options(tmp_root, &tmp, argc, argv))
         tmp.state= PLUGIN_IS_DISABLED;
 
       if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
@@ -997,7 +1009,6 @@ static int plugin_initialize(struct st_p
   DBUG_ENTER("plugin_initialize");
 
   safe_mutex_assert_owner(&LOCK_plugin);
-
   if (plugin_type_initialize[plugin->plugin->type])
   {
     if ((*plugin_type_initialize[plugin->plugin->type])(plugin))
@@ -1083,6 +1094,20 @@ uchar *get_bookmark_hash_key(const uchar
   return (uchar*) var->key;
 }
 
+static inline void convert_dash_to_underscore(char *str, int len)
+{
+  for (char *p= str; p <= str+len; p++)
+    if (*p == '-')
+      *p= '_';
+}
+
+static inline void convert_underscore_to_dash(char *str, int len)
+{
+  for (char *p= str; p <= str+len; p++)
+    if (*p == '_')
+      *p= '-';
+}
+
 
 /*
   The logic is that we first load and initialize all compiled in plugins.
@@ -1094,11 +1119,12 @@ uchar *get_bookmark_hash_key(const uchar
 int plugin_init(int *argc, char **argv, int flags)
 {
   uint i;
-  bool def_enabled, is_myisam;
+  bool is_myisam;
   struct st_mysql_plugin **builtins;
   struct st_mysql_plugin *plugin;
   struct st_plugin_int tmp, *plugin_ptr, **reap;
   MEM_ROOT tmp_root;
+  bool reaped_mandatory_plugin= FALSE;
   DBUG_ENTER("plugin_init");
 
   if (initialized)
@@ -1142,17 +1168,13 @@ int plugin_init(int *argc, char **argv, 
           !my_strnncoll(&my_charset_latin1, (const uchar*) plugin->name,
                         6, (const uchar*) "InnoDB", 6))
         continue;
-      /* by default, ndbcluster and federated are disabled */
-      def_enabled=
-        my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0 &&
-        my_strcasecmp(&my_charset_latin1, plugin->name, "FEDERATED") != 0;
       bzero(&tmp, sizeof(tmp));
       tmp.plugin= plugin;
       tmp.name.str= (char *)plugin->name;
       tmp.name.length= strlen(plugin->name);
       tmp.state= 0;
       free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
-      if (test_plugin_options(&tmp_root, &tmp, argc, argv, def_enabled))
+      if (test_plugin_options(&tmp_root, &tmp, argc, argv))
         tmp.state= PLUGIN_IS_DISABLED;
       else
         tmp.state= PLUGIN_IS_UNINITIALIZED;
@@ -1227,6 +1249,8 @@ int plugin_init(int *argc, char **argv, 
   while ((plugin_ptr= *(--reap)))
   {
     pthread_mutex_unlock(&LOCK_plugin);
+    if (plugin_ptr->is_mandatory)
+      reaped_mandatory_plugin= TRUE;
     plugin_deinitialize(plugin_ptr, true);
     pthread_mutex_lock(&LOCK_plugin);
     plugin_del(plugin_ptr);
@@ -1234,6 +1258,8 @@ int plugin_init(int *argc, char **argv, 
 
   pthread_mutex_unlock(&LOCK_plugin);
   my_afree(reap);
+  if (reaped_mandatory_plugin)
+    goto err;
 
 end:
   free_root(&tmp_root, MYF(0));
@@ -1299,7 +1325,7 @@ bool plugin_register_builtin(THD *thd, s
   pthread_mutex_lock(&LOCK_plugin);
   rw_wrlock(&LOCK_system_variables_hash);
 
-  if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL, true))
+  if (test_plugin_options(thd->mem_root, &tmp, &dummy_argc, NULL))
     goto end;
   tmp.state= PLUGIN_IS_UNINITIALIZED;
   if ((result= register_builtin(plugin, &tmp, &ptr)))
@@ -2889,59 +2915,78 @@ my_bool get_one_plugin_option(int optid 
 }
 
 
+/**
+  Creates a set of my_option objects associated with a specified plugin-
+  handle.
+
+  @param mem_root Memory allocator to be used.
+  @param tmp A pointer to a plugin handle
+  @param[out] options A pointer to a pre-allocated static array
+
+  The set is stored in the pre-allocated static array supplied to the function.
+  The size of the array is calculated as (number_of_plugin_varaibles*2+3). The
+  reason is that each option can have a prefix '--plugin-' in addtion to the
+  shorter form '--&lt;plugin-name&gt;'. There is also space allocated for
+  terminating NULL pointers.
+
+  @return
+    @retval -1 An error occurred
+    @retval 0 Success
+*/
+
 static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
-                             my_option *options, my_bool **enabled,
-                             bool can_disable)
+                             my_option *options)
 {
   const char *plugin_name= tmp->plugin->name;
-  uint namelen= strlen(plugin_name), optnamelen;
-  uint buffer_length= namelen * 4 + (can_disable ? 75 : 10);
-  char *name= (char*) alloc_root(mem_root, buffer_length) + 1;
-  char *optname, *p;
+  const LEX_STRING plugin_dash = { C_STRING_WITH_LEN("plugin-") };
+  uint plugin_name_len= strlen(plugin_name);
+  uint optnamelen;
+  const int max_comment_len= 180;
+  char *comment= (char *) alloc_root(mem_root, max_comment_len + 1);
+  char *optname;
+
   int index= 0, offset= 0;
   st_mysql_sys_var *opt, **plugin_option;
   st_bookmark *v;
-  DBUG_ENTER("construct_options");
-  DBUG_PRINT("plugin", ("plugin: '%s'  enabled: %d  can_disable: %d",
-                        plugin_name, **enabled, can_disable));
 
-  /* support --skip-plugin-foo syntax */
-  memcpy(name, plugin_name, namelen + 1);
-  my_casedn_str(&my_charset_latin1, name);
-  strxmov(name + namelen + 1, "plugin-", name, NullS);
-  /* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */
+  /** Used to circumvent the const attribute on my_option::name */
+  char *plugin_name_ptr, *plugin_name_with_prefix_ptr;
 
-  for (p= name + namelen*2 + 8; p > name; p--)
-    if (*p == '_')
-      *p= '-';
+  DBUG_ENTER("construct_options");
 
-  if (can_disable)
-  {
-    strxmov(name + namelen*2 + 10, "Enable ", plugin_name, " plugin. "
-            "Disable with --skip-", name," (will save memory).", NullS);
-    /*
-      Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 +
-      20 + namelen + 20 + 1 == namelen * 4 + 67.
-    */
+  options[0].name= plugin_name_ptr= (char*) alloc_root(mem_root,
+                                                       plugin_name_len + 1);
+  strcpy(plugin_name_ptr, plugin_name);
+  my_casedn_str(&my_charset_latin1, plugin_name_ptr);
+  convert_underscore_to_dash(plugin_name_ptr, plugin_name_len);
+  /* support --skip-plugin-foo syntax */
+  options[1].name= plugin_name_with_prefix_ptr= (char*) alloc_root(mem_root,
+                                                plugin_name_len +
+                                                plugin_dash.length + 1);
+  strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, options[0].name, NullS);
 
-    options[0].comment= name + namelen*2 + 10;
-  }
+  options[0].id= options[1].id= 256; /* must be >255. dup id ok */
+  options[0].var_type= options[1].var_type= GET_ENUM;
+  options[0].arg_type= options[1].arg_type= OPT_ARG;
+  options[0].def_value= options[1].def_value= 1; /* ON */
+  options[0].typelib= options[1].typelib= &global_plugin_typelib;
+
+  strxnmov(comment, max_comment_len, "Enable or disable ", plugin_name,
+          " plugin. Possible values are ON, OFF, FORCE (don't start "
+          "if the plugin fails to load).", NullS);
+  options[0].comment= comment;
 
   /*
-    NOTE: 'name' is one char above the allocated buffer!
-    NOTE: This code assumes that 'my_bool' and 'char' are of same size.
+    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.
   */
-  *((my_bool *)(name -1))= **enabled;
-  *enabled= (my_bool *)(name - 1);
+  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;
 
-
-  options[1].name= (options[0].name= name) + namelen + 1;
-  options[0].id= options[1].id= 256; /* must be >255. dup id ok */
-  options[0].var_type= options[1].var_type= GET_BOOL;
-  options[0].arg_type= options[1].arg_type= NO_ARG;
-  options[0].def_value= options[1].def_value= **enabled;
-  options[0].value= options[0].u_max_value=
-  options[1].value= options[1].u_max_value= (uchar**) (name - 1);
   options+= 2;
 
   /*
@@ -2955,7 +3000,7 @@ static int construct_options(MEM_ROOT *m
     opt= *plugin_option;
     if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
       continue;
-    if (!(register_var(name, opt->name, opt->flags)))
+    if (!(register_var(plugin_name_ptr, opt->name, opt->flags)))
       continue;
     switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
     case PLUGIN_VAR_BOOL:
@@ -3020,7 +3065,7 @@ static int construct_options(MEM_ROOT *m
       if (!opt->update)
       {
         opt->update= update_func_str;
-        if (!(opt->flags & PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY))
+        if (!(opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)))
         {
           opt->flags|= PLUGIN_VAR_READONLY;
           sql_print_warning("Server variable %s of plugin %s was forced "
@@ -3062,14 +3107,14 @@ static int construct_options(MEM_ROOT *m
     if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
     {
       optnamelen= strlen(opt->name);
-      optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
-      strxmov(optname, name, "-", opt->name, NullS);
-      optnamelen= namelen + optnamelen + 1;
+      optname= (char*) alloc_root(mem_root, plugin_name_len + optnamelen + 2);
+      strxmov(optname, plugin_name_ptr, "-", opt->name, NullS);
+      optnamelen= plugin_name_len + optnamelen + 1;
     }
     else
     {
       /* this should not fail because register_var should create entry */
-      if (!(v= find_bookmark(name, opt->name, opt->flags)))
+      if (!(v= find_bookmark(plugin_name_ptr, opt->name, opt->flags)))
       {
         sql_print_error("Thread local variable '%s' not allocated "
                         "in plugin '%s'.", opt->name, plugin_name);
@@ -3085,10 +3130,7 @@ static int construct_options(MEM_ROOT *m
                                    (optnamelen= v->name_len) + 1);
     }
 
-    /* convert '_' to '-' */
-    for (p= optname; *p; p++)
-      if (*p == '_')
-        *p= '-';
+    convert_underscore_to_dash(optname, optnamelen);
 
     options->name= optname;
     options->comment= opt->comment;
@@ -3103,10 +3145,13 @@ static int construct_options(MEM_ROOT *m
     else
       options->value= options->u_max_value= *(uchar***) (opt + 1);
 
+    char *option_name_ptr;
     options[1]= options[0];
-    options[1].name= p= (char*) alloc_root(mem_root, optnamelen + 8);
-    options[1].comment= 0; // hidden
-    strxmov(p, "plugin-", optname, NullS);
+    options[1].name= option_name_ptr= (char*) alloc_root(mem_root,
+                                                        plugin_dash.length +
+                                                        optnamelen + 1);
+    options[1].comment= 0; /* Hidden from the help text */
+    strxmov(option_name_ptr, plugin_dash.str, optname, NullS);
 
     options+= 2;
   }
@@ -3120,55 +3165,57 @@ static my_option *construct_help_options
 {
   st_mysql_sys_var **opt;
   my_option *opts;
-  my_bool dummy, can_disable;
-  my_bool *dummy2= &dummy;
   uint count= EXTRA_OPTIONS;
   DBUG_ENTER("construct_help_options");
 
-  for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2);
+  for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2)
+    ;
 
   if (!(opts= (my_option*) alloc_root(mem_root, sizeof(my_option) * count)))
     DBUG_RETURN(NULL);
 
   bzero(opts, sizeof(my_option) * count);
 
-  dummy= TRUE; /* plugin is enabled. */
-
-  can_disable=
-      my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") &&
-      my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY");
-
-  if (construct_options(mem_root, p, opts, &dummy2, can_disable))
+  if (construct_options(mem_root, p, opts))
     DBUG_RETURN(NULL);
 
   DBUG_RETURN(opts);
 }
 
 
-/*
-  SYNOPSIS
-    test_plugin_options()
-    tmp_root                    temporary scratch space
-    plugin                      internal plugin structure
-    argc                        user supplied arguments
-    argv                        user supplied arguments
-    default_enabled             default plugin enable status
-  RETURNS:
-    0 SUCCESS - plugin should be enabled/loaded
-  NOTE:
-    Requires that a write-lock is held on LOCK_system_variables_hash
+/**
+  Create and register system variables supplied from the plugin and
+  assigns initial values from corresponding command line arguments.
+
+  @param tmp_root Temporary scratch space
+  @param[out] plugin Internal plugin structure
+  @param argc Number of command line arguments
+  @param argv Command line argument vector
+
+  The plugin will be updated with a policy on how to handle errors during
+  initialization.
+
+  @note Requires that a write-lock is held on LOCK_system_variables_hash
+
+  @return How initialization of the plugin should be handled.
+    @retval  0 Initialization should proceed.
+    @retval  1 Plugin is disabled.
+    @retval -1 An error has occurred.
 */
+
 static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
-                               int *argc, char **argv, my_bool default_enabled)
+                               int *argc, char **argv)
 {
   struct sys_var_chain chain= { NULL, NULL };
-  my_bool enabled_saved= default_enabled, can_disable;
-  my_bool *enabled= &default_enabled;
+  my_bool can_disable;
+  bool disable_plugin;
+  enum_plugin_load_policy plugin_load_policy= PLUGIN_ON;
+
   MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ?
                       &tmp->mem_root : &plugin_mem_root;
   st_mysql_sys_var **opt;
   my_option *opts= NULL;
-  char *p, *varname;
+  char *varname;
   int error;
   st_mysql_sys_var *o;
   sys_var *v;
@@ -3177,13 +3224,17 @@ static int test_plugin_options(MEM_ROOT 
   DBUG_ENTER("test_plugin_options");
   DBUG_ASSERT(tmp->plugin && tmp->name.str);
 
+  /*
+    The 'federated' and 'ndbcluster' storage engines are always disabled by
+    default.
+  */
+  if (!(my_strcasecmp(&my_charset_latin1, tmp->name.str, "federated") &&
+      my_strcasecmp(&my_charset_latin1, tmp->name.str, "ndbcluster")))
+    plugin_load_policy= PLUGIN_OFF;
+
   for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
     count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
 
-  can_disable=
-      my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") &&
-      my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY");
-
   if (count > EXTRA_OPTIONS || (*argc > 1))
   {
     if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
@@ -3193,12 +3244,18 @@ static int test_plugin_options(MEM_ROOT 
     }
     bzero(opts, sizeof(my_option) * count);
 
-    if (construct_options(tmp_root, tmp, opts, &enabled, can_disable))
+    if (construct_options(tmp_root, tmp, opts))
     {
       sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
       DBUG_RETURN(-1);
     }
 
+    /*
+      We adjust the default value to account for the hardcoded exceptions
+      we have set for the federated and ndbcluster storage engines.
+    */
+    opts[0].def_value= opts[1].def_value= (int)plugin_load_policy;
+
     error= handle_options(argc, &argv, opts, get_one_plugin_option);
     (*argc)++; /* add back one for the program name */
 
@@ -3208,64 +3265,79 @@ static int test_plugin_options(MEM_ROOT 
                        tmp->name.str);
        goto err;
     }
+    /*
+     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;
   }
 
-  if (!*enabled && !can_disable)
+  disable_plugin= (plugin_load_policy == PLUGIN_OFF);
+  /*
+    The 'MyISAM' and 'Memory' storage engines currently can't be disabled.
+  */
+  can_disable=
+    my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") &&
+    my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY");
+
+  tmp->is_mandatory= (plugin_load_policy == PLUGIN_FORCE) || !can_disable;
+
+  if (disable_plugin && !can_disable)
   {
     sql_print_warning("Plugin '%s' cannot be disabled", tmp->name.str);
-    *enabled= TRUE;
+    disable_plugin= FALSE;
   }
 
-  error= 1;
+  /*
+    If the plugin is disabled it should not be initialized.
+  */
+  if (disable_plugin)
+  {
+    if (global_system_variables.log_warnings)
+      sql_print_information("Plugin '%s' is disabled.",
+                            tmp->name.str);
+    if (opts)
+      my_cleanup_options(opts);
+    DBUG_RETURN(1);
+  }
 
-  if (*enabled)
+  error= 1;
+  for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
   {
-    for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
+    if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
+      continue;
+    if ((var= find_bookmark(tmp->name.str, o->name, o->flags)))
+      v= new (mem_root) sys_var_pluginvar(var->key + 1, o);
+    else
     {
-      if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
-        continue;
-
-      if ((var= find_bookmark(tmp->name.str, o->name, o->flags)))
-        v= new (mem_root) sys_var_pluginvar(var->key + 1, o);
-      else
-      {
-        len= tmp->name.length + strlen(o->name) + 2;
-        varname= (char*) alloc_root(mem_root, len);
-        strxmov(varname, tmp->name.str, "-", o->name, NullS);
-        my_casedn_str(&my_charset_latin1, varname);
-
-        for (p= varname; *p; p++)
-          if (*p == '-')
-            *p= '_';
-
-        v= new (mem_root) sys_var_pluginvar(varname, o);
-      }
-      DBUG_ASSERT(v); /* check that an object was actually constructed */
-
-      /*
-        Add to the chain of variables.
-        Done like this for easier debugging so that the
-        pointer to v is not lost on optimized builds.
-      */
-      v->chain_sys_var(&chain);
+      len= tmp->name.length + strlen(o->name) + 2;
+      varname= (char*) alloc_root(mem_root, len);
+      strxmov(varname, tmp->name.str, "-", o->name, NullS);
+      my_casedn_str(&my_charset_latin1, varname);
+      convert_dash_to_underscore(varname, len-1);
+      v= new (mem_root) sys_var_pluginvar(varname, o);
     }
-    if (chain.first)
+    DBUG_ASSERT(v); /* check that an object was actually constructed */
+    /*
+      Add to the chain of variables.
+      Done like this for easier debugging so that the
+      pointer to v is not lost on optimized builds.
+    */
+    v->chain_sys_var(&chain);
+  } /* end for */
+  if (chain.first)
+  {
+    chain.last->next = NULL;
+    if (mysql_add_sys_var_chain(chain.first, NULL))
     {
-      chain.last->next = NULL;
-      if (mysql_add_sys_var_chain(chain.first, NULL))
-      {
-        sql_print_error("Plugin '%s' has conflicting system variables",
-                        tmp->name.str);
-        goto err;
-      }
-      tmp->system_vars= chain.first;
+      sql_print_error("Plugin '%s' has conflicting system variables",
+                      tmp->name.str);
+      goto err;
     }
-    DBUG_RETURN(0);
+    tmp->system_vars= chain.first;
   }
-
-  if (enabled_saved && global_system_variables.log_warnings)
-    sql_print_information("Plugin '%s' disabled by command line option",
-                          tmp->name.str);
+  DBUG_RETURN(0);
+  
 err:
   if (opts)
     my_cleanup_options(opts);

=== modified file 'sql/sql_plugin.h'
--- a/sql/sql_plugin.h	2008-12-17 15:45:34 +0000
+++ b/sql/sql_plugin.h	2009-05-14 12:03:33 +0000
@@ -79,6 +79,7 @@ struct st_plugin_int
   void *data;                   /* plugin type specific, e.g. handlerton */
   MEM_ROOT mem_root;            /* memory for dynamic plugin structures */
   sys_var *system_vars;         /* server variables for this plugin */
+  bool is_mandatory;            /* If true then plugin must not fail to load */
 };
 
 

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2009-02-13 16:41:47 +0000
+++ b/sql/sql_prepare.cc	2009-05-20 14:17:47 +0000
@@ -2461,6 +2461,9 @@ void mysql_stmt_execute(THD *thd, char *
 
   stmt->execute_loop(&expanded_query, open_cursor, packet, packet_end);
 
+  /* Close connection socket; for use with client testing (Bug#43560). */
+  DBUG_EXECUTE_IF("close_conn_after_stmt_execute", vio_close(thd->net.vio););
+
   DBUG_VOID_RETURN;
 
 }

=== modified file 'sql/sql_rename.cc'
--- a/sql/sql_rename.cc	2009-04-13 13:09:10 +0000
+++ b/sql/sql_rename.cc	2009-05-19 04:25:36 +0000
@@ -261,6 +261,8 @@ do_rename(THD *thd, TABLE_LIST *ren_tabl
     old_alias= ren_table->table_name;
     new_alias= new_table_name;
   }
+  DBUG_ASSERT(new_alias);
+
   build_table_filename(name, sizeof(name),
                        new_db, new_alias, reg_ext, 0);
   if (!access(name,F_OK))

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2009-05-13 07:51:39 +0000
+++ b/sql/sql_select.cc	2009-05-25 08:00:40 +0000
@@ -2248,6 +2248,14 @@ JOIN::destroy()
   cond_equal= 0;
 
   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();
+  }
   if (exec_tmp_table1)
     free_tmp_table(thd, exec_tmp_table1);
   if (exec_tmp_table2)
@@ -7084,15 +7092,17 @@ return_zero_rows(JOIN *join, select_resu
   if (!(result->send_fields(fields,
                               Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)))
   {
+    bool send_error= FALSE;
     if (send_row)
     {
       List_iterator_fast<Item> it(fields);
       Item *item;
       while ((item= it++))
 	item->no_rows_in_result();
-      result->send_data(fields);
+      send_error= result->send_data(fields);
     }
-    result->send_eof();				// Should be safe
+    if (!send_error)
+      result->send_eof();				// Should be safe
   }
   /* Update results for FOUND_ROWS */
   join->thd->limit_found_rows= join->thd->examined_row_count= 0;
@@ -13845,7 +13855,7 @@ SORT_FIELD *make_unireg_sortorder(ORDER 
       pos->field= ((Item_sum*) item)->get_tmp_table_field();
     else if (item->type() == Item::COPY_STR_ITEM)
     {						// Blob patch
-      pos->item= ((Item_copy_string*) item)->item;
+      pos->item= ((Item_copy*) item)->get_item();
     }
     else
       pos->item= *order->item;
@@ -14916,7 +14926,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PA
       pos= item;
       if (item->field->flags & BLOB_FLAG)
       {
-	if (!(pos= new Item_copy_string(pos)))
+	if (!(pos= Item_copy::create(pos)))
 	  goto err;
        /*
          Item_copy_string::copy for function can call 
@@ -14970,7 +14980,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PA
 	 on how the value is to be used: In some cases this may be an
 	 argument in a group function, like: IF(ISNULL(col),0,COUNT(*))
       */
-      if (!(pos=new Item_copy_string(pos)))
+      if (!(pos= Item_copy::create(pos)))
 	goto err;
       if (i < border)                           // HAVING, ORDER and GROUP BY
       {
@@ -15023,8 +15033,8 @@ copy_fields(TMP_TABLE_PARAM *param)
     (*ptr->do_copy)(ptr);
 
   List_iterator_fast<Item> it(param->copy_funcs);
-  Item_copy_string *item;
-  while ((item = (Item_copy_string*) it++))
+  Item_copy *item;
+  while ((item = (Item_copy*) it++))
     item->copy();
 }
 

=== modified file 'sql/sql_string.cc'
--- a/sql/sql_string.cc	2009-03-24 13:58:52 +0000
+++ b/sql/sql_string.cc	2009-05-21 08:06:43 +0000
@@ -328,6 +328,9 @@ bool String::copy(const char *str, uint3
 		  CHARSET_INFO *from_cs, CHARSET_INFO *to_cs, uint *errors)
 {
   uint32 offset;
+  
+  DBUG_ASSERT(str != Ptr);
+  
   if (!needs_conversion(arg_length, from_cs, to_cs, &offset))
   {
     *errors= 0;

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-04-23 17:55:32 +0000
+++ b/sql/sql_table.cc	2009-05-19 04:25:36 +0000
@@ -3126,7 +3126,7 @@ static bool prepare_blob_field(THD *thd,
     }
     sql_field->sql_type= MYSQL_TYPE_BLOB;
     sql_field->flags|= BLOB_FLAG;
-    sprintf(warn_buff, ER(ER_AUTO_CONVERT), sql_field->field_name,
+    my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_AUTO_CONVERT), sql_field->field_name,
             (sql_field->charset == &my_charset_bin) ? "VARBINARY" : "VARCHAR",
             (sql_field->charset == &my_charset_bin) ? "BLOB" : "TEXT");
     push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
@@ -6140,6 +6140,20 @@ bool mysql_alter_table(THD *thd,char *ne
   if (frm_type == FRMTYPE_VIEW && !(alter_info->flags & ~ALTER_RENAME))
   {
     /*
+      The following branch handles "ALTER VIEW v1 /no arguments/;"
+      This feature is not documented one. 
+      However, before "OPTIMIZE TABLE t1;" was implemented, 
+      ALTER TABLE with no alter_specifications was used to force-rebuild
+      the table. That's why this grammar is allowed. That's why we ignore
+      it for views. So just do nothing in such a case.
+    */
+    if (!new_name)
+    {
+      my_ok(thd);
+      DBUG_RETURN(FALSE);
+    }
+
+    /*
       Avoid problems with a rename on a table that we have locked or
       if the user is trying to to do this in a transcation context
     */

=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc	2008-11-10 20:21:49 +0000
+++ b/sql/sql_union.cc	2009-05-15 07:11:07 +0000
@@ -653,10 +653,22 @@ bool st_select_lex_unit::cleanup()
       join->tables= 0;
     }
     error|= fake_select_lex->cleanup();
-    if (fake_select_lex->order_list.elements)
+    /*
+      There are two cases when we should clean order items:
+      1. UNION with SELECTs which all enclosed into braces
+        in this case global_parameters == fake_select_lex
+      2. UNION where last SELECT is not enclosed into braces
+        in this case global_parameters == 'last select'
+      So we should use global_parameters->order_list for
+      proper order list clean up.
+      Note: global_parameters and fake_select_lex are always
+            initialized for UNION
+    */
+    DBUG_ASSERT(global_parameters);
+    if (global_parameters->order_list.elements)
     {
       ORDER *ord;
-      for (ord= (ORDER*)fake_select_lex->order_list.first; ord; ord= ord->next)
+      for (ord= (ORDER*)global_parameters->order_list.first; ord; ord= ord->next)
         (*ord->item)->cleanup();
     }
   }

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2009-04-08 23:42:51 +0000
+++ b/sql/sql_update.cc	2009-05-15 13:03:22 +0000
@@ -818,7 +818,7 @@ int mysql_update(THD *thd,
   if (error < 0)
   {
     char buff[STRING_BUFFER_USUAL_SIZE];
-    sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
+    my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
 	    (ulong) thd->cuted_fields);
     thd->row_count_func=
       (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
@@ -1031,7 +1031,6 @@ reopen_tables:
         DBUG_RETURN(TRUE);
       }
 
-      table->mark_columns_needed_for_update();
       DBUG_PRINT("info",("setting table `%s` for update", tl->alias));
       /*
         If table will be updated we should not downgrade lock for it and
@@ -1275,12 +1274,40 @@ int multi_update::prepare(List<Item> &no
   }
 
   /*
+    We gather the set of columns read during evaluation of SET expression in
+    TABLE::tmp_set by pointing TABLE::read_set to it and then restore it after
+    setup_fields().
+  */
+  for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf)
+  {
+    TABLE *table= table_ref->table;
+    if (tables_to_update & table->map)
+    {
+      DBUG_ASSERT(table->read_set == &table->def_read_set);
+      table->read_set= &table->tmp_set;
+      bitmap_clear_all(table->read_set);
+    }
+  }
+
+  /*
     We have to check values after setup_tables to get covering_keys right in
     reference tables
   */
 
-  if (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0))
-    DBUG_RETURN(1);
+  int error= setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0);
+
+  for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf)
+  {
+    TABLE *table= table_ref->table;
+    if (tables_to_update & table->map)
+    {
+      table->read_set= &table->def_read_set;
+      bitmap_union(table->read_set, &table->tmp_set);
+    }
+  }
+  
+  if (error)
+    DBUG_RETURN(1);    
 
   /*
     Save tables beeing updated in update_tables
@@ -1375,6 +1402,8 @@ int multi_update::prepare(List<Item> &no
     a row in this table will never be read twice. This is true under
     the following conditions:
 
+    - No column is both written to and read in SET expressions.
+
     - We are doing a table scan and the data is in a separate file (MyISAM) or
       if we don't update a clustered key.
 
@@ -1389,6 +1418,9 @@ int multi_update::prepare(List<Item> &no
   WARNING
     This code is a bit dependent of how make_join_readinfo() works.
 
+    The field table->tmp_set is used for keeping track of which fields are
+    read during evaluation of the SET expression. See multi_update::prepare.
+
   RETURN
     0		Not safe to update
     1		Safe to update
@@ -1409,6 +1441,8 @@ static bool safe_update_on_fly(THD *thd,
   case JT_REF_OR_NULL:
     return !is_key_used(table, join_tab->ref.key, table->write_set);
   case JT_ALL:
+    if (bitmap_is_overlapping(&table->tmp_set, table->write_set))
+      return FALSE;
     /* If range search on index */
     if (join_tab->quick)
       return !join_tab->quick->is_keys_used(table->write_set);
@@ -1464,17 +1498,18 @@ multi_update::initialize_tables(JOIN *jo
     ORDER     group;
     TMP_TABLE_PARAM *tmp_param;
 
-    table->mark_columns_needed_for_update();
     if (ignore)
       table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
     if (table == main_table)			// First table in join
     {
       if (safe_update_on_fly(thd, join->join_tab, table_ref, all_tables))
       {
-	table_to_update= main_table;		// Update table on the fly
+        table->mark_columns_needed_for_update();
+	table_to_update= table;			// Update table on the fly
 	continue;
       }
     }
+    table->mark_columns_needed_for_update();
     table->prepare_for_position();
 
     /*
@@ -2066,8 +2101,8 @@ bool multi_update::send_eof()
 
   id= thd->arg_of_last_insert_id_function ?
     thd->first_successful_insert_id_in_prev_stmt : 0;
-  sprintf(buff, ER(ER_UPDATE_INFO), (ulong) found, (ulong) updated,
-	  (ulong) thd->cuted_fields);
+  my_snprintf(buff, sizeof(buff), ER(ER_UPDATE_INFO),
+              (ulong) found, (ulong) updated, (ulong) thd->cuted_fields);
   thd->row_count_func=
     (thd->client_capabilities & CLIENT_FOUND_ROWS) ? found : updated;
   ::my_ok(thd, (ulong) thd->row_count_func, id, buff);

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2009-03-24 13:58:52 +0000
+++ b/sql/table.cc	2009-05-27 10:42:19 +0000
@@ -779,7 +779,7 @@ static int open_binary_frm(THD *thd, TAB
   strpos=disk_buff+6;
 
   if (!(rec_per_key= (ulong*) alloc_root(&share->mem_root,
-					 sizeof(ulong*)*key_parts)))
+                                         sizeof(ulong)*key_parts)))
     goto err;
 
   for (i=0 ; i < keys ; i++, keyinfo++)

=== modified file 'sql/unireg.cc'
--- a/sql/unireg.cc	2009-03-17 20:29:24 +0000
+++ b/sql/unireg.cc	2009-05-04 20:33:23 +0000
@@ -37,8 +37,7 @@ static bool pack_header(uchar *forminfo,
 			List<Create_field> &create_fields,
 			uint info_length, uint screens, uint table_options,
 			ulong data_offset, handler *file);
-static uint get_interval_id(uint *int_count,List<Create_field> &create_fields,
-			    Create_field *last_field);
+static uint get_interval_id(uint *,List<Create_field> &, Create_field *);
 static bool pack_fields(File file, List<Create_field> &create_fields,
                         ulong data_offset);
 static bool make_empty_rec(THD *thd, int file, enum legacy_db_type table_type,

=== modified file 'storage/archive/ha_archive.cc'
--- a/storage/archive/ha_archive.cc	2009-03-26 14:27:34 +0000
+++ b/storage/archive/ha_archive.cc	2009-05-15 13:03:22 +0000
@@ -1474,8 +1474,8 @@ int ha_archive::info(uint flag)
 
     stats.mean_rec_length= table->s->reclength + buffer.alloced_length();
     stats.data_file_length= file_stat.st_size;
-    stats.create_time= file_stat.st_ctime;
-    stats.update_time= file_stat.st_mtime;
+    stats.create_time= (ulong) file_stat.st_ctime;
+    stats.update_time= (ulong) file_stat.st_mtime;
     stats.max_data_file_length= share->rows_recorded * stats.mean_rec_length;
   }
   stats.delete_length= 0;

=== modified file 'storage/federated/ha_federated.cc'
--- a/storage/federated/ha_federated.cc	2009-02-13 16:41:47 +0000
+++ b/storage/federated/ha_federated.cc	2009-05-15 13:03:22 +0000
@@ -2850,10 +2850,10 @@ int ha_federated::info(uint flag)
       stats.data_file_length= stats.records * stats.mean_rec_length;
 
       if (row[12] != NULL)
-        stats.update_time=     (time_t) my_strtoll10(row[12], (char**) 0,
+        stats.update_time=     (ulong) my_strtoll10(row[12], (char**) 0,
                                                       &error);
       if (row[13] != NULL)
-        stats.check_time=      (time_t) my_strtoll10(row[13], (char**) 0,
+        stats.check_time=      (ulong) my_strtoll10(row[13], (char**) 0,
                                                       &error);
     }
     /*

=== modified file 'storage/ibmdb2i/db2i_charsetSupport.cc'
--- a/storage/ibmdb2i/db2i_charsetSupport.cc	2009-03-09 21:20:14 +0000
+++ b/storage/ibmdb2i/db2i_charsetSupport.cc	2009-05-17 17:20:20 +0000
@@ -129,8 +129,8 @@ struct IconvMap
 {
   struct HashKey
   {
-    uint16 direction; // This is a uint16 instead of a uchar to avoid garbage data in the key from compiler padding
-    uint16 db2CCSID;
+    uint32 direction; // These are uint32s to avoid garbage data in the key from compiler padding
+    uint32 db2CCSID;
     const CHARSET_INFO* myCharset;
   } hashKey;
   iconv_t iconvDesc;
@@ -268,8 +268,15 @@ static int32 getNewTextDesc(const int32 
       RESULT_INT32);
   if (unlikely(arguments->base.result.s_int32.r_int32 < 0))
   {
-     getErrTxt(DB2I_ERR_ILECALL,"QlgCvtTextDescToDesc",arguments->base.result.s_int32.r_int32);
-     DBUG_RETURN(DB2I_ERR_ILECALL);
+    if (arguments->base.result.s_int32.r_int32 == Qlg_InDescriptorNotFound)
+    {
+      DBUG_RETURN(DB2I_ERR_UNSUPP_CHARSET);
+    }
+    else
+    {
+      getErrTxt(DB2I_ERR_ILECALL,"QlgCvtTextDescToDesc",arguments->base.result.s_int32.r_int32);
+      DBUG_RETURN(DB2I_ERR_ILECALL);
+    }
   }
   
   // Store the conversion information into a cache entry
@@ -428,8 +435,13 @@ int32 convertIANAToDb2Ccsid(const char* 
   int aixEncodingScheme;
   int db2EncodingScheme;
   rc = convertTextDesc(Qlg_TypeIANA, Qlg_TypeAS400CCSID, parmIANADesc, aixCcsidString);
-  if (rc != 0)
+  if (unlikely(rc))
+  {
+    if (rc == DB2I_ERR_UNSUPP_CHARSET)
+      getErrTxt(DB2I_ERR_UNSUPP_CHARSET, parmIANADesc);
+    
     return rc;
+  }
   aixCcsid = atoi(aixCcsidString);
   rc = getEncodingScheme(aixCcsid, aixEncodingScheme);     
   if (rc != 0) 
@@ -646,32 +658,38 @@ static int32 openNewConversion(enum_conv
      there equivalent iconv descriptions.
   */
   rc = convertTextDesc(Qlg_TypeIANA, Qlg_TypeAix41, mysqlCSName, mysqlAix41Desc);
-  if (rc)
+  if (unlikely(rc))
+  {
+    if (rc == DB2I_ERR_UNSUPP_CHARSET)
+      getErrTxt(DB2I_ERR_UNSUPP_CHARSET, mysqlCSName);
+    
     DBUG_RETURN(rc);
+  }
   CHARSET_INFO *cs= &my_charset_bin;
   (uint)(cs->cset->long10_to_str)(cs,db2CcsidString,sizeof(db2CcsidString), 10, db2CCSID);  
   rc = convertTextDesc(Qlg_TypeAS400CCSID, Qlg_TypeAix41, db2CcsidString, db2Aix41Desc);
-  if (rc)
-      DBUG_RETURN(rc);
+  if (unlikely(rc))
+  {
+    if (rc == DB2I_ERR_UNSUPP_CHARSET)
+      getErrTxt(DB2I_ERR_UNSUPP_CHARSET, mysqlCSName);
+    
+    DBUG_RETURN(rc);
+  }
   
   /* Call iconv to open the conversion. */
   if (direction == toDB2)
   {
     newConversion = iconv_open(db2Aix41Desc, mysqlAix41Desc);
-    if (newConversion == (iconv_t) -1)
-    {
-       getErrTxt(DB2I_ERR_ICONV_OPEN, mysqlAix41Desc, db2Aix41Desc,  errno);
-       DBUG_RETURN(DB2I_ERR_ICONV_OPEN);
-    }
   }
   else
   {
     newConversion = iconv_open(mysqlAix41Desc, db2Aix41Desc);
-    if (newConversion == (iconv_t) -1)
-    {
-       getErrTxt(DB2I_ERR_ICONV_OPEN, db2Aix41Desc, mysqlAix41Desc, errno);
-       DBUG_RETURN(DB2I_ERR_ICONV_OPEN);
-    }
+  }
+
+  if (unlikely(newConversion == (iconv_t) -1))
+  {
+    getErrTxt(DB2I_ERR_UNSUPP_CHARSET, mysqlCSName);
+    DBUG_RETURN(DB2I_ERR_UNSUPP_CHARSET);
   }
  
   /* Insert the new conversion into the cache. */

=== modified file 'storage/ibmdb2i/db2i_conversion.cc'
--- a/storage/ibmdb2i/db2i_conversion.cc	2009-03-09 21:20:14 +0000
+++ b/storage/ibmdb2i/db2i_conversion.cc	2009-05-05 09:33:52 +0000
@@ -151,7 +151,7 @@ int ha_ibmdb2i::convertFieldChars(enum_c
   
   if (unlikely(conversion == (iconv_t)(-1)))
   {
-    return (DB2I_ERR_ICONV_OPEN);
+    return (DB2I_ERR_UNSUPP_CHARSET);
   }
 
   size_t initOLen= olen;
@@ -670,6 +670,13 @@ int ha_ibmdb2i::getFieldTypeMapping(Fiel
               if (rtnCode)
                 return rtnCode;
             }
+            
+            // Check whether there is a character conversion available.
+            iconv_t temp;
+            int32 rc = getConversion(toDB2, fieldCharSet, db2Ccsid, temp);
+            if (unlikely(rc))
+              return rc;
+            
             sprintf(stringBuildBuffer, " CCSID %d ", db2Ccsid);
             mapping.append(stringBuildBuffer);
           }

=== modified file 'storage/ibmdb2i/db2i_errors.cc'
--- a/storage/ibmdb2i/db2i_errors.cc	2009-03-09 21:20:14 +0000
+++ b/storage/ibmdb2i/db2i_errors.cc	2009-05-05 09:33:52 +0000
@@ -52,7 +52,7 @@ static const char* engineErrors[MAX_MSGS
   {"Error opening codeset conversion from %.64s to %.64s (errno = %d)"},      
   {"Invalid %-.10s name '%-.128s'"},                                          
   {"Unsupported move from '%-.128s' to '%-.128s' on RENAME TABLE statement"}, 
-  {"Unsupported schema '%-.128s' specified on RENAME TABLE statement"},       
+  {"The %-.64s character set is not supported."},       
   {"Auto_increment is not allowed for a partitioned table"},                  
   {"Character set conversion error due to unknown encoding scheme %d"},       
   {""}, 

=== modified file 'storage/ibmdb2i/db2i_errors.h'
--- a/storage/ibmdb2i/db2i_errors.h	2009-03-09 21:20:14 +0000
+++ b/storage/ibmdb2i/db2i_errors.h	2009-05-05 09:33:52 +0000
@@ -54,7 +54,7 @@ enum DB2I_errors
   DB2I_ERR_ICONV_OPEN,
   DB2I_ERR_INVALID_NAME,
   DB2I_ERR_RENAME_MOVE,
-  DB2I_ERR_RENAME_QTEMP,
+  DB2I_ERR_UNSUPP_CHARSET,
   DB2I_ERR_PART_AUTOINC,
   DB2I_ERR_UNKNOWN_ENCODING,
   DB2I_ERR_RESERVED,

=== modified file 'storage/ibmdb2i/ha_ibmdb2i.cc'
--- a/storage/ibmdb2i/ha_ibmdb2i.cc	2009-04-29 11:21:14 +0000
+++ b/storage/ibmdb2i/ha_ibmdb2i.cc	2009-05-17 16:25:23 +0000
@@ -2273,7 +2273,12 @@ int ha_ibmdb2i::create(const char *name,
   
   if (isTemporary)
     query.append(STRING_WITH_LEN(" ON COMMIT PRESERVE ROWS "));
-    
+  
+  if (create_info->alias)
+    generateAndAppendRCDFMT(create_info->alias, query);
+  else if (((TABLE_LIST*)(thd->lex->select_lex.table_list.first))->table_name)  
+    generateAndAppendRCDFMT((char*)((TABLE_LIST*)(thd->lex->select_lex.table_list.first))->table_name, query);
+        
   DBUG_PRINT("ha_ibmdb2i::create", ("Sent to DB2: %s",query.c_ptr()));
   SqlStatementStream sqlStream(query.length());
   sqlStream.addStatement(query,fileSortSequence,fileSortSequenceLibrary);

=== modified file 'storage/ibmdb2i/ha_ibmdb2i.h'
--- a/storage/ibmdb2i/ha_ibmdb2i.h	2009-03-09 21:20:14 +0000
+++ b/storage/ibmdb2i/ha_ibmdb2i.h	2009-05-17 16:25:23 +0000
@@ -746,5 +746,56 @@ private:
       free_root(&conversionBufferMemroot, MYF(0));
     }    
   }
- 
+  
+  
+/**
+  Generate a valid RCDFMT name based on the name of the table.
+  
+  The RCDFMT name is devised by munging the name of the table,
+  uppercasing all ascii alpha-numeric characters and replacing all other
+  characters with underscores until up to ten characters have been generated.
+    
+  @param tableName  The name of the table, as given on the MySQL
+                    CREATE TABLE statement
+  @param[out] query  The string to receive the generated RCDFMT name
+*/
+  static void generateAndAppendRCDFMT(const char* tableName, String& query)
+  {
+    char rcdfmt[11];
+    
+    // The RCDFMT name must begin with an alpha character.
+    // We enforce this by skipping to the first alpha character in the table
+    // name. If no alpha character exists, we use 'X' for the RCDFMT name;
+    
+    while (*tableName &&
+           (!my_isascii(*tableName) ||
+            !my_isalpha(system_charset_info, *tableName)))
+    {
+      tableName += my_mbcharlen(system_charset_info, *tableName);
+    }
+    
+    if (unlikely(!(*tableName)))
+    { 
+      rcdfmt[0]= 'X';
+      rcdfmt[1]= 0;
+    }
+    else
+    {
+      int r= 0;
+      while ((r < sizeof(rcdfmt)-1) && *tableName)
+      {
+        if (my_isascii(*tableName) &&
+            my_isalnum(system_charset_info, *tableName))
+          rcdfmt[r] = my_toupper(system_charset_info, *tableName);
+        else
+          rcdfmt[r] = '_';
+        
+        ++r;
+        tableName += my_mbcharlen(system_charset_info, *tableName);
+      }
+      rcdfmt[r]= 0;
+    }
+    query.append(STRING_WITH_LEN(" RCDFMT "));
+    query.append(rcdfmt);
+  }
 };

=== modified file 'storage/innobase/dict/dict0dict.c'
--- a/storage/innobase/dict/dict0dict.c	2008-12-14 20:59:50 +0000
+++ b/storage/innobase/dict/dict0dict.c	2009-05-19 08:31:29 +0000
@@ -2616,7 +2616,7 @@ scan_more:
 		} else if (quote) {
 			/* Within quotes: do not look for
 			starting quotes or comments. */
-		} else if (*sptr == '"' || *sptr == '`') {
+		} else if (*sptr == '"' || *sptr == '`' || *sptr == '\'') {
 			/* Starting quote: remember the quote character. */
 			quote = *sptr;
 		} else if (*sptr == '#'
@@ -3932,7 +3932,7 @@ dict_table_print_low(
 		(ulong) UT_LIST_GET_LEN(table->indexes),
 		(ulong) table->stat_n_rows);
 
-	for (i = 0; i + 1 < (ulint) table->n_cols; i++) {
+	for (i = 0; i < (ulint) table->n_cols; i++) {
 		dict_col_print_low(table, dict_table_get_nth_col(table, i));
 		fputs("; ", stderr);
 	}

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2009-04-15 12:41:54 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2009-05-19 08:20:28 +0000
@@ -101,6 +101,7 @@ static long innobase_mirrored_log_groups
 	innobase_additional_mem_pool_size, innobase_file_io_threads,
 	innobase_lock_wait_timeout, innobase_force_recovery,
 	innobase_open_files, innobase_autoinc_lock_mode;
+static ulong innobase_commit_concurrency = 0;
 
 static long long innobase_buffer_pool_size, innobase_log_file_size;
 
@@ -165,6 +166,38 @@ static handler *innobase_create_handler(
 
 static const char innobase_hton_name[]= "InnoDB";
 
+/*****************************************************************
+Check for a valid value of innobase_commit_concurrency. */
+static
+int
+innobase_commit_concurrency_validate(
+/*=================================*/
+						/* out: 0 for valid
+						innodb_commit_concurrency */
+	THD*				thd,	/* in: thread handle */
+	struct st_mysql_sys_var*	var,	/* in: pointer to system
+						variable */
+	void*				save,	/* out: immediate result
+						for update function */
+	struct st_mysql_value*		value)	/* in: incoming string */
+{
+	long long	intbuf;
+	ulong		commit_concurrency;
+
+	DBUG_ENTER("innobase_commit_concurrency_validate");
+
+	if (value->val_int(value, &intbuf)) {
+		/* The value is NULL. That is invalid. */
+		DBUG_RETURN(1);
+	}
+
+	*reinterpret_cast<ulong*>(save) = commit_concurrency
+		= static_cast<ulong>(intbuf);
+
+	/* Allow the value to be updated, as long as it remains zero
+	or nonzero. */
+	DBUG_RETURN(!(!commit_concurrency == !innobase_commit_concurrency));
+}
 
 static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
   "Enable InnoDB support for the XA two-phase commit",
@@ -1951,11 +1984,11 @@ innobase_commit(
 		Note, the position is current because of
 		prepare_commit_mutex */
 retry:
-		if (srv_commit_concurrency > 0) {
+		if (innobase_commit_concurrency > 0) {
 			pthread_mutex_lock(&commit_cond_m);
 			commit_threads++;
 
-			if (commit_threads > srv_commit_concurrency) {
+			if (commit_threads > innobase_commit_concurrency) {
 				commit_threads--;
 				pthread_cond_wait(&commit_cond,
 					&commit_cond_m);
@@ -1972,7 +2005,7 @@ retry:
 
 		innobase_commit_low(trx);
 
-		if (srv_commit_concurrency > 0) {
+		if (innobase_commit_concurrency > 0) {
 			pthread_mutex_lock(&commit_cond_m);
 			commit_threads--;
 			pthread_cond_signal(&commit_cond);
@@ -6012,7 +6045,7 @@ ha_innobase::info(
 		nor the CHECK TABLE time, nor the UPDATE or INSERT time. */
 
 		if (os_file_get_status(path,&stat_info)) {
-			stats.create_time = stat_info.ctime;
+			stats.create_time = (ulong) stat_info.ctime;
 		}
 	}
 
@@ -8289,10 +8322,10 @@ static MYSQL_SYSVAR_LONGLONG(buffer_pool
   "The size of the memory buffer InnoDB uses to cache data and indexes of its tables.",
   NULL, NULL, 8*1024*1024L, 1024*1024L, LONGLONG_MAX, 1024*1024L);
 
-static MYSQL_SYSVAR_ULONG(commit_concurrency, srv_commit_concurrency,
+static MYSQL_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency,
   PLUGIN_VAR_RQCMDARG,
   "Helps in performance tuning in heavily concurrent environments.",
-  NULL, NULL, 0, 0, 1000, 0);
+  innobase_commit_concurrency_validate, NULL, 0, 0, 1000, 0);
 
 static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter,
   PLUGIN_VAR_RQCMDARG,

=== modified file 'storage/innobase/include/srv0srv.h'
--- a/storage/innobase/include/srv0srv.h	2009-04-24 11:28:46 +0000
+++ b/storage/innobase/include/srv0srv.h	2009-05-19 08:20:28 +0000
@@ -109,7 +109,6 @@ extern ulint	srv_max_dirty_pages_pct;
 
 extern ulint	srv_force_recovery;
 extern ulong	srv_thread_concurrency;
-extern ulong	srv_commit_concurrency;
 
 extern ulint	srv_max_n_threads;
 

=== modified file 'storage/innobase/page/page0cur.c'
--- a/storage/innobase/page/page0cur.c	2009-04-24 11:28:46 +0000
+++ b/storage/innobase/page/page0cur.c	2009-05-19 07:52:19 +0000
@@ -538,7 +538,7 @@ page_cur_open_on_rnd_user_rec(
 
 		rnd = page_rnd % page_get_n_recs(page);
 	} else {
-		rnd = (ulint) page_cur_lcg_prng() % page_get_n_recs(page);
+		rnd = (ulint) (page_cur_lcg_prng() % page_get_n_recs(page));
 	}
 
 	rec = page_get_infimum_rec(page);

=== modified file 'storage/innobase/srv/srv0srv.c'
--- a/storage/innobase/srv/srv0srv.c	2009-04-24 11:28:46 +0000
+++ b/storage/innobase/srv/srv0srv.c	2009-05-19 08:20:28 +0000
@@ -285,7 +285,6 @@ computer. Bigger computers need bigger v
 concurrency check. */
 
 ulong	srv_thread_concurrency	= 0;
-ulong	srv_commit_concurrency	= 0;
 
 os_fast_mutex_t	srv_conc_mutex;		/* this mutex protects srv_conc data
 					structures */

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2009-04-30 12:52:48 +0000
+++ b/storage/myisam/ha_myisam.cc	2009-05-27 10:42:19 +0000
@@ -1784,7 +1784,7 @@ int ha_myisam::info(uint flag)
     stats.data_file_length=  misam_info.data_file_length;
     stats.index_file_length= misam_info.index_file_length;
     stats.delete_length=     misam_info.delete_length;
-    stats.check_time=        misam_info.check_time;
+    stats.check_time=        (ulong) misam_info.check_time;
     stats.mean_rec_length=   misam_info.mean_reclength;
   }
   if (flag & HA_STATUS_CONST)
@@ -1792,7 +1792,7 @@ int ha_myisam::info(uint flag)
     TABLE_SHARE *share= table->s;
     stats.max_data_file_length=  misam_info.max_data_file_length;
     stats.max_index_file_length= misam_info.max_index_file_length;
-    stats.create_time= misam_info.create_time;
+    stats.create_time= (ulong) misam_info.create_time;
     ref_length= misam_info.reflength;
     share->db_options_in_use= misam_info.options;
     stats.block_size= myisam_block_size;        /* record block size */
@@ -1807,7 +1807,7 @@ int ha_myisam::info(uint flag)
     if (share->key_parts)
       memcpy((char*) table->key_info[0].rec_per_key,
 	     (char*) misam_info.rec_per_key,
-	     sizeof(table->key_info[0].rec_per_key[0])*share->key_parts);
+             sizeof(table->key_info[0].rec_per_key[0])*share->key_parts);
     if (share->tmp_table == NO_TMP_TABLE)
       pthread_mutex_unlock(&share->mutex);
 
@@ -1831,7 +1831,7 @@ int ha_myisam::info(uint flag)
     my_store_ptr(dup_ref, ref_length, misam_info.dupp_key_pos);
   }
   if (flag & HA_STATUS_TIME)
-    stats.update_time = misam_info.update_time;
+    stats.update_time = (ulong) misam_info.update_time;
   if (flag & HA_STATUS_AUTO)
     stats.auto_increment_value= misam_info.auto_increment;
 

=== modified file 'storage/myisam/myisamchk.c'
--- a/storage/myisam/myisamchk.c	2009-04-09 08:06:47 +0000
+++ b/storage/myisam/myisamchk.c	2009-05-27 08:11:28 +0000
@@ -287,8 +287,8 @@ static struct my_option my_long_options[
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
     (uchar**) &check_param.use_buffers, (uchar**) &check_param.use_buffers, 0,
-    GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
-    (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
+    GET_ULL, REQUIRED_ARG, USE_BUFFER_INIT, MALLOC_OVERHEAD,
+    SIZE_T_MAX, MALLOC_OVERHEAD,  IO_SIZE, 0},
   { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,  "",
     (uchar**) &opt_key_cache_block_size,
     (uchar**) &opt_key_cache_block_size, 0,
@@ -1102,7 +1102,7 @@ static int myisamchk(MI_CHECK *param, ch
       {
 	if (param->testflag & (T_EXTEND | T_MEDIUM))
 	  VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size,
-                              param->use_buffers, 0, 0));
+                              (size_t) param->use_buffers, 0, 0));
 	VOID(init_io_cache(&param->read_cache,datafile,
 			   (uint) param->read_buffer_length,
 			   READ_CACHE,
@@ -1525,8 +1525,8 @@ static int mi_sort_records(MI_CHECK *par
   if (share->state.key_root[sort_key] == HA_OFFSET_ERROR)
     DBUG_RETURN(0);				/* Nothing to do */
 
-  init_key_cache(dflt_key_cache, opt_key_cache_block_size, param->use_buffers,
-                 0, 0);
+  init_key_cache(dflt_key_cache, opt_key_cache_block_size,
+                 (size_t) param->use_buffers, 0, 0);
   if (init_io_cache(&info->rec_cache,-1,(uint) param->write_buffer_length,
 		   WRITE_CACHE,share->pack.header_length,1,
 		   MYF(MY_WME | MY_WAIT_IF_FULL)))

=== modified file 'storage/myisammrg/ha_myisammrg.cc'
--- a/storage/myisammrg/ha_myisammrg.cc	2009-04-08 06:55:19 +0000
+++ b/storage/myisammrg/ha_myisammrg.cc	2009-05-27 10:42:19 +0000
@@ -925,11 +925,11 @@ int ha_myisammrg::info(uint flag)
         with such a number, it'll be an error later anyway.
       */
       bzero((char*) table->key_info[0].rec_per_key,
-            sizeof(table->key_info[0].rec_per_key) * table->s->key_parts);
+            sizeof(table->key_info[0].rec_per_key[0]) * table->s->key_parts);
 #endif
       memcpy((char*) table->key_info[0].rec_per_key,
 	     (char*) mrg_info.rec_per_key,
-             sizeof(table->key_info[0].rec_per_key) *
+             sizeof(table->key_info[0].rec_per_key[0]) *
              min(file->keys, table->s->key_parts));
     }
   }

=== modified file 'storage/ndb/src/kernel/blocks/backup/read.cpp'
--- a/storage/ndb/src/kernel/blocks/backup/read.cpp	2006-12-23 19:20:40 +0000
+++ b/storage/ndb/src/kernel/blocks/backup/read.cpp	2009-04-28 18:21:47 +0000
@@ -50,7 +50,7 @@ main(int argc, const char * argv[]){
 
   ndb_init();
   if(argc <= 1){
-    printf("Usage: %s <filename>", argv[0]);
+    printf("Usage: %s <filename>\n", argv[0]);
     exit(1);
   }
   FILE * f = fopen(argv[1], "rb");

=== modified file 'strings/ctype-cp932.c'
--- a/strings/ctype-cp932.c	2007-11-29 10:35:15 +0000
+++ b/strings/ctype-cp932.c	2009-05-05 06:55:22 +0000
@@ -5489,10 +5489,10 @@ static MY_CHARSET_HANDLER my_charset_han
   my_mb_wc_cp932,	/* mb_wc */
   my_wc_mb_cp932,	/* wc_mb */
   my_mb_ctype_mb,
-  my_caseup_str_8bit,
-  my_casedn_str_8bit,
-  my_caseup_8bit,
-  my_casedn_8bit,
+  my_caseup_str_mb,
+  my_casedn_str_mb,
+  my_caseup_mb,
+  my_casedn_mb,
   my_snprintf_8bit,
   my_long10_to_str_8bit,
   my_longlong10_to_str_8bit,

=== modified file 'strings/ctype-sjis.c'
--- a/strings/ctype-sjis.c	2007-10-04 07:10:15 +0000
+++ b/strings/ctype-sjis.c	2009-05-05 06:55:22 +0000
@@ -4650,10 +4650,10 @@ static MY_CHARSET_HANDLER my_charset_han
   my_mb_wc_sjis,	/* mb_wc */
   my_wc_mb_sjis,	/* wc_mb */
   my_mb_ctype_mb,
-  my_caseup_str_8bit,
-  my_casedn_str_8bit,
-  my_caseup_8bit,
-  my_casedn_8bit,
+  my_caseup_str_mb,
+  my_casedn_str_mb,
+  my_caseup_mb,
+  my_casedn_mb,
   my_snprintf_8bit,
   my_long10_to_str_8bit,
   my_longlong10_to_str_8bit,

=== modified file 'tests/mysql_client_test.c'
--- a/tests/mysql_client_test.c	2009-04-30 07:54:45 +0000
+++ b/tests/mysql_client_test.c	2009-05-23 13:19:58 +0000
@@ -103,7 +103,7 @@ if (!opt_silent) \
 
 static void print_error(const char *msg);
 static void print_st_error(MYSQL_STMT *stmt, const char *msg);
-static void client_disconnect(void);
+static void client_disconnect(MYSQL* mysql, my_bool drop_db);
 
 
 /*
@@ -271,10 +271,20 @@ mysql_simple_prepare(MYSQL *mysql_arg, c
 }
 
 
-/* Connect to the server */
-
-static void client_connect(ulong flag)
+/**
+   Connect to the server with options given by arguments to this application,
+   stored in global variables opt_host, opt_user, opt_password, opt_db, 
+   opt_port and opt_unix_socket.
+
+   @param flag[in]           client_flag passed on to mysql_real_connect
+   @param protocol[in]       MYSQL_PROTOCOL_* to use for this connection
+   @param auto_reconnect[in] set to 1 for auto reconnect
+   
+   @return pointer to initialized and connected MYSQL object
+*/
+static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect)
 {
+  MYSQL* mysql;
   int  rc;
   static char query[MAX_TEST_QUERY_LENGTH];
   myheader_r("client_connect");
@@ -291,6 +301,7 @@ static void client_connect(ulong flag)
   }
   /* enable local infile, in non-binary builds often disabled by default */
   mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0);
+  mysql_options(mysql, MYSQL_OPT_PROTOCOL, &protocol);
 
   if (!(mysql_real_connect(mysql, opt_host, opt_user,
                            opt_password, opt_db ? opt_db:"test", opt_port,
@@ -302,7 +313,7 @@ static void client_connect(ulong flag)
     fprintf(stdout, "\n Check the connection options using --help or -?\n");
     exit(1);
   }
-  mysql->reconnect= 1;
+  mysql->reconnect= auto_reconnect;
 
   if (!opt_silent)
     fprintf(stdout, "OK");
@@ -329,12 +340,14 @@ static void client_connect(ulong flag)
 
   if (!opt_silent)
     fprintf(stdout, "OK");
+
+  return mysql;
 }
 
 
 /* Close the connection */
 
-static void client_disconnect()
+static void client_disconnect(MYSQL* mysql, my_bool drop_db)
 {
   static char query[MAX_TEST_QUERY_LENGTH];
 
@@ -342,13 +355,16 @@ static void client_disconnect()
 
   if (mysql)
   {
-    if (!opt_silent)
-      fprintf(stdout, "\n dropping the test database '%s' ...", current_db);
-    strxmov(query, "DROP DATABASE IF EXISTS ", current_db, NullS);
+    if (drop_db)
+    {
+      if (!opt_silent)
+        fprintf(stdout, "\n dropping the test database '%s' ...", current_db);
+      strxmov(query, "DROP DATABASE IF EXISTS ", current_db, NullS);
 
-    mysql_query(mysql, query);
-    if (!opt_silent)
-      fprintf(stdout, "OK");
+      mysql_query(mysql, query);
+      if (!opt_silent)
+        fprintf(stdout, "OK");
+    }
 
     if (!opt_silent)
       fprintf(stdout, "\n closing the connection ...");
@@ -2464,6 +2480,9 @@ static void test_ps_query_cache()
 
   myheader("test_ps_query_cache");
 
+  rc= mysql_query(mysql, "SET SQL_MODE=''");
+  myquery(rc);
+
   /* prepare the table */
 
   rc= mysql_query(mysql, "drop table if exists t1");
@@ -2506,6 +2525,9 @@ static void test_ps_query_cache()
         mysql_close(lmysql);
         DIE_UNLESS(0);
       }
+      rc= mysql_query(lmysql, "SET SQL_MODE=''");
+      myquery(rc);
+
       if (!opt_silent)
         fprintf(stdout, "OK");
     }
@@ -4240,6 +4262,10 @@ static void test_fetch_date()
 
   myheader("test_fetch_date");
 
+  /* Will not work if sql_mode is NO_ZERO_DATE (implicit if TRADITIONAL) /*/
+  rc= mysql_query(mysql, "SET SQL_MODE=''");
+  myquery(rc);
+
   rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bind_result");
   myquery(rc);
 
@@ -4954,6 +4980,9 @@ static void test_stmt_close()
   /* set AUTOCOMMIT to ON*/
   mysql_autocommit(lmysql, TRUE);
 
+  rc= mysql_query(lmysql, "SET SQL_MODE = ''");
+  myquery(rc);
+
   rc= mysql_query(lmysql, "DROP TABLE IF EXISTS test_stmt_close");
   myquery(rc);
 
@@ -12088,6 +12117,9 @@ static void test_bug6058()
 
   myheader("test_bug6058");
 
+  rc= mysql_query(mysql, "SET SQL_MODE=''");
+  myquery(rc);
+
   stmt_text= "SELECT CAST('0000-00-00' AS DATE)";
 
   rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
@@ -13303,6 +13335,9 @@ static void test_bug8378()
   if (!opt_silent)
     fprintf(stdout, "OK");
 
+  rc= mysql_query(lmysql, "SET SQL_MODE=''");
+  myquery(rc);
+
   len= mysql_real_escape_string(lmysql, out, TEST_BUG8378_IN, 4);
 
   /* No escaping should have actually happened. */
@@ -16390,12 +16425,27 @@ static void test_change_user()
   myquery(rc);
 
   sprintf(buff,
+          "grant select on %s.* to %s@'localhost' identified by '%s'",
+          db,
+          user_pw,
+          pw);
+  rc= mysql_query(mysql, buff);
+  myquery(rc);
+
+  sprintf(buff,
           "grant select on %s.* to %s@'%%'",
           db,
           user_no_pw);
   rc= mysql_query(mysql, buff);
   myquery(rc);
 
+  sprintf(buff,
+          "grant select on %s.* to %s@'localhost'",
+          db,
+          user_no_pw);
+  rc= mysql_query(mysql, buff);
+  myquery(rc);
+
 
   /* Try some combinations */
   rc= mysql_change_user(mysql, NULL, NULL, NULL);
@@ -16552,6 +16602,14 @@ static void test_change_user()
   rc= mysql_query(mysql, buff);
   myquery(rc);
 
+  sprintf(buff, "drop user %s@'localhost'", user_pw);
+  rc= mysql_query(mysql, buff);
+  myquery(rc);
+
+  sprintf(buff, "drop user %s@'localhost'", user_no_pw);
+  rc= mysql_query(mysql, buff);
+  myquery(rc);
+
   DBUG_VOID_RETURN;
 }
 
@@ -17220,6 +17278,11 @@ static void test_bug31669()
   rc= mysql_query(mysql, query);
   myquery(rc);
 
+  strxmov(query, "GRANT ALL PRIVILEGES ON *.* TO '", user, "'@'localhost' IDENTIFIED BY "
+                 "'", buff, "' WITH GRANT OPTION", NullS);
+  rc= mysql_query(mysql, query);
+  myquery(rc);
+
   rc= mysql_query(mysql, "FLUSH PRIVILEGES");
   myquery(rc);
 
@@ -17257,7 +17320,7 @@ static void test_bug31669()
   strxmov(query, "DELETE FROM mysql.user WHERE User='", user, "'", NullS);
   rc= mysql_query(mysql, query);
   myquery(rc);
-  DIE_UNLESS(mysql_affected_rows(mysql) == 1);
+  DIE_UNLESS(mysql_affected_rows(mysql) == 2);
 #endif
 
   DBUG_VOID_RETURN;
@@ -17469,6 +17532,9 @@ static void test_wl4166_2()
 
   myheader("test_wl4166_2");
 
+  rc= mysql_query(mysql, "SET SQL_MODE=''");
+  myquery(rc);
+
   rc= mysql_query(mysql, "drop table if exists t1");
   myquery(rc);
   rc= mysql_query(mysql, "create table t1 (c_int int, d_date date)");
@@ -17663,6 +17729,100 @@ static void test_bug40365(void)
 
 
 /**
+  Subtest for Bug#43560. Verifies that a loss of connection on the server side
+  is handled well by the mysql_stmt_execute() call, i.e., no SIGSEGV due to
+  a vio socket that is cleared upon closed connection.
+
+  Assumes the presence of the close_conn_after_stmt_execute debug feature in
+  the server. Verifies that it is connected to a debug server before proceeding
+  with the test.
+ */
+static void test_bug43560(void)
+{
+  MYSQL*       conn;
+  uint         rc;
+  MYSQL_STMT   *stmt= 0;
+  MYSQL_BIND   bind;
+  my_bool      is_null= 0;
+  char         buffer[256];
+  const uint   BUFSIZE= sizeof(buffer);
+  const char*  values[] = {"eins", "zwei", "drei", "viele", NULL};
+  const char   insert_str[] = "INSERT INTO t1 (c2) VALUES (?)";
+  unsigned long length;
+  
+  DBUG_ENTER("test_bug43560");
+  myheader("test_bug43560");
+
+  /* Make sure we only run against a debug server. */
+  if (!strstr(mysql->server_version, "debug"))
+  {
+    fprintf(stdout, "Skipping test_bug43560: server not DEBUG version\n");
+    DBUG_VOID_RETURN;
+  }
+
+  /*
+    Set up a separate connection for this test to avoid messing up the
+    general MYSQL object used in other subtests. Use TCP protocol to avoid
+    problems with the buffer semantics of AF_UNIX, and turn off auto reconnect.
+  */
+  conn= client_connect(0, MYSQL_PROTOCOL_TCP, 0);
+
+  rc= mysql_query(conn, "DROP TABLE IF EXISTS t1");
+  myquery(rc);
+  rc= mysql_query(conn,
+    "CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 CHAR(10))");
+  myquery(rc);
+
+  stmt= mysql_stmt_init(conn);
+  check_stmt(stmt);
+  rc= mysql_stmt_prepare(stmt, insert_str, strlen(insert_str));
+  check_execute(stmt, rc);
+
+  bind.buffer_type= MYSQL_TYPE_STRING;
+  bind.buffer_length= BUFSIZE;
+  bind.buffer= buffer;
+  bind.is_null= &is_null;
+  bind.length= &length;
+  rc= mysql_stmt_bind_param(stmt, &bind);
+  check_execute(stmt, rc);
+
+  /* First execute; should succeed. */
+  strncpy(buffer, values[0], BUFSIZE);
+  length= strlen(buffer);
+  rc= mysql_stmt_execute(stmt);
+  check_execute(stmt, rc);
+
+  /* 
+    Set up the server to close this session's server-side socket after
+    next execution of prep statement.
+  */
+  rc= mysql_query(conn,"SET SESSION debug='+d,close_conn_after_stmt_execute'");
+  myquery(rc);
+
+  /* Second execute; should fail due to socket closed during execution. */
+  strncpy(buffer, values[1], BUFSIZE);
+  length= strlen(buffer);
+  rc= mysql_stmt_execute(stmt);
+  DIE_UNLESS(rc && mysql_stmt_errno(stmt) == CR_SERVER_LOST);
+
+  /* 
+    Third execute; should fail (connection already closed), or SIGSEGV in
+    case of a Bug#43560 type regression in which case the whole test fails.
+  */
+  strncpy(buffer, values[2], BUFSIZE);
+  length= strlen(buffer);
+  rc= mysql_stmt_execute(stmt);
+  DIE_UNLESS(rc && mysql_stmt_errno(stmt) == CR_SERVER_LOST);
+
+  client_disconnect(conn, 0);
+  rc= mysql_query(mysql, "DROP TABLE t1");
+  myquery(rc);
+
+  DBUG_VOID_RETURN;
+}
+
+
+/**
   Bug#36326: nested transaction and select
 */
 
@@ -18090,6 +18250,7 @@ static struct my_tests_st my_tests[]= {
   { "test_wl4166_2", test_wl4166_2 },
   { "test_bug38486", test_bug38486 },
   { "test_bug40365", test_bug40365 },
+  { "test_bug43560", test_bug43560 },
 #ifdef HAVE_QUERY_CACHE
   { "test_bug36326", test_bug36326 },
 #endif
@@ -18218,7 +18379,8 @@ int main(int argc, char **argv)
                         (char**) embedded_server_groups))
     DIE("Can't initialize MySQL server");
 
-  client_connect(0);       /* connect to server */
+  /* connect to server with no flags, default protocol, auto reconnect true */
+  mysql= client_connect(0, MYSQL_PROTOCOL_DEFAULT, 1);
 
   total_time= 0;
   for (iter_count= 1; iter_count <= opt_count; iter_count++)
@@ -18248,7 +18410,7 @@ int main(int argc, char **argv)
 	  fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv);
 	  fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n",
 		  my_progname);
-	  client_disconnect();
+	  client_disconnect(mysql, 1);
 	  free_defaults(defaults_argv);
 	  exit(1);
 	}
@@ -18261,7 +18423,7 @@ int main(int argc, char **argv)
     /* End of tests */
   }
 
-  client_disconnect();    /* disconnect from server */
+  client_disconnect(mysql, 1);    /* disconnect from server */
 
   free_defaults(defaults_argv);
   print_test_output();

Attachment: [text/bzr-bundle] bzr/joerg@mysql.com-20090529134055-nnwgrfjdhr0ebmh8.bundle
Thread
bzr push into mysql-5.1 branch (joerg:2860 to 2862)Joerg Bruehe29 May