List:Commits« Previous MessageNext Message »
From:Mikael Ronstrom Date:August 7 2009 4:25pm
Subject:bzr commit into mysql-pe branch (mikael:3482) Bug#40281
View as plain text  
#At file:///home/mikael/mysql_clones/mysql-6.0-bugteam-bug32115/

 3482 Mikael Ronstrom	2009-08-07 [merge]
      Merge handling for mainly bug#40281
      removed:
        mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result
        mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt
        mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt
      added:
        mysql-test/r/innodb_mysql_lock.result
        mysql-test/r/partition_not_embedded.result
        mysql-test/r/partition_rename_longfilename.result
        mysql-test/std_data/loadxml2.dat
        mysql-test/suite/rpl/r/rpl_stop_middle_group.result
        mysql-test/t/innodb_mysql_lock-master.opt
        mysql-test/t/innodb_mysql_lock.test
        mysql-test/t/partition_not_embedded.test
        mysql-test/t/partition_rename_longfilename.test
      renamed:
        mysql-test/suite/rpl/t/rpl_row_stop_middle_update.test => mysql-test/suite/rpl/t/rpl_stop_middle_group.test
      modified:
        .bzr-mysql/default.conf
        CMakeLists.txt
        Makefile.am
        client/Makefile.am
        client/mysql.cc
        client/mysqldump.c
        client/mysqltest.cc
        config/ac-macros/misc.m4
        config/ac-macros/readline.m4
        include/config-netware.h
        include/config-win.h
        include/my_base.h
        include/myisammrg.h
        libmysql/Makefile.shared
        libmysqld/Makefile.am
        libmysqld/emb_qcache.h
        libmysqld/lib_sql.cc
        mysql-test/collections/default.experimental
        mysql-test/collections/mysql-azalea.push
        mysql-test/extra/scripts/monitor_disabled_tests/comments.txt
        mysql-test/r/create.result
        mysql-test/r/debug_sync.result
        mysql-test/r/func_str.result
        mysql-test/r/innodb_mysql.result
        mysql-test/r/insert.result
        mysql-test/r/insert_select.result
        mysql-test/r/loadxml.result
        mysql-test/r/lock.result
        mysql-test/r/locktrans_innodb.result
        mysql-test/r/locktrans_myisam.result
        mysql-test/r/merge.result
        mysql-test/r/myisam.result
        mysql-test/r/mysql.result
        mysql-test/r/mysqldump.result
        mysql-test/r/outfile_loaddata.result
        mysql-test/r/partition.result
        mysql-test/r/partition_csv.result
        mysql-test/r/partition_error.result
        mysql-test/r/show_check.result
        mysql-test/r/signal.result
        mysql-test/r/signal_demo3.result
        mysql-test/r/sp_notembedded.result
        mysql-test/r/sp_trans.result
        mysql-test/std_data/init_file.dat
        mysql-test/suite/backup/r/backup_db_grants.result
        mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result
        mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt
        mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test
        mysql-test/suite/parts/r/partition_syntax_innodb.result
        mysql-test/suite/parts/r/partition_syntax_myisam.result
        mysql-test/suite/rpl/r/rpl_innodb.result
        mysql-test/suite/rpl/r/rpl_locktrans_innodb.result
        mysql-test/suite/rpl/r/rpl_locktrans_myisam.result
        mysql-test/suite/rpl/r/rpl_semi_sync.result
        mysql-test/suite/rpl/r/rpl_sf.result
        mysql-test/suite/rpl/r/rpl_temp_table_mix_row.result
        mysql-test/suite/rpl/r/rpl_udf.result
        mysql-test/suite/rpl/t/disabled.def
        mysql-test/suite/rpl/t/rpl_innodb.test
        mysql-test/suite/rpl/t/rpl_semi_sync.test
        mysql-test/suite/rpl/t/rpl_sf.test
        mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test
        mysql-test/t/create.test
        mysql-test/t/disabled.def
        mysql-test/t/innodb_mysql.test
        mysql-test/t/innodb_notembedded.test
        mysql-test/t/insert.test
        mysql-test/t/insert_select.test
        mysql-test/t/loadxml.test
        mysql-test/t/lock.test
        mysql-test/t/merge.test
        mysql-test/t/myisam.test
        mysql-test/t/mysql.test
        mysql-test/t/mysql_upgrade.test
        mysql-test/t/mysqldump.test
        mysql-test/t/outfile_loaddata.test
        mysql-test/t/partition.test
        mysql-test/t/partition_csv.test
        mysql-test/t/partition_error.test
        mysql-test/t/show_check.test
        mysql-test/t/sp_notembedded.test
        mysql-test/t/sp_trans.test
        mysql-test/valgrind.supp
        mysys/Makefile.am
        mysys/array.c
        mysys/my_handler_errors.h
        netware/BUILD/compile-netware-START
        plugin/semisync/semisync_master.cc
        plugin/semisync/semisync_master_plugin.cc
        plugin/semisync/semisync_slave_plugin.cc
        scripts/make_binary_distribution.sh
        sql-bench/README*
        sql-common/client.c
        sql/Makefile.am
        sql/backup/be_thread.cc
        sql/derror.cc
        sql/event_data_objects.cc
        sql/event_scheduler.cc
        sql/events.cc
        sql/field.cc
        sql/ha_partition.cc
        sql/handler.cc
        sql/handler.h
        sql/item_func.cc
        sql/lex.h
        sql/log.cc
        sql/log_event.cc
        sql/log_event_old.cc
        sql/mysql_priv.h
        sql/mysqld.cc
        sql/net_serv.cc
        sql/protocol.cc
        sql/protocol.h
        sql/rpl_rli.cc
        sql/rpl_rli.h
        sql/set_var.cc
        sql/share/errmsg-utf8.txt
        sql/share/errmsg.txt
        sql/slave.cc
        sql/sp.cc
        sql/sp.h
        sql/sp_head.cc
        sql/sql_base.cc
        sql/sql_class.cc
        sql/sql_class.h
        sql/sql_error.cc
        sql/sql_error.h
        sql/sql_insert.cc
        sql/sql_lex.h
        sql/sql_load.cc
        sql/sql_parse.cc
        sql/sql_partition.cc
        sql/sql_prepare.cc
        sql/sql_repl.cc
        sql/sql_select.cc
        sql/sql_show.cc
        sql/sql_signal.cc
        sql/sql_signal.h
        sql/sql_string.cc
        sql/sql_string.h
        sql/sql_table.cc
        sql/sql_update.cc
        sql/sql_yacc.yy
        sql/table.cc
        sql/table.h
        sql/unireg.h
        storage/innobase/handler/ha_innodb.cc
        storage/myisam/ha_myisam.cc
        storage/myisam/myisam_backup_engine.cc
        storage/myisammrg/ha_myisammrg.cc
        storage/myisammrg/ha_myisammrg.h
        storage/myisammrg/myrg_info.c
        storage/ndb/src/mgmsrv/Makefile.am
        support-files/mysql.server.sh
        tests/grant.pl*
        tests/mysql_client_test.c
        mysql-test/suite/rpl/t/rpl_stop_middle_group.test

=== modified file '.bzr-mysql/default.conf'
--- a/.bzr-mysql/default.conf	2009-07-14 09:21:56 +0000
+++ b/.bzr-mysql/default.conf	2009-08-06 14:59:03 +0000
@@ -1,5 +1,5 @@
 [MYSQL]
-tree_location = "bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-azalea"
+tree_location = "bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-pe"
 post_commit_to = "commits@stripped"
 post_push_to = "commits@stripped"
-tree_name = "mysql-5.4"
+tree_name = "mysql-pe"

=== modified file 'CMakeLists.txt'
--- a/CMakeLists.txt	2009-07-16 12:51:04 +0000
+++ b/CMakeLists.txt	2009-07-31 20:21:25 +0000
@@ -14,6 +14,9 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)
+IF(COMMAND cmake_policy)
+  cmake_policy(SET CMP0005 NEW)
+ENDIF(COMMAND cmake_policy)
 
 PROJECT(MySql)
 
@@ -28,6 +31,13 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/inclu
 
 # Set standard options
 ADD_DEFINITIONS(-DHAVE_YASSL)
+ADD_DEFINITIONS(-DCMAKE_CONFIGD)
+ADD_DEFINITIONS(-DDEFAULT_MYSQL_HOME="c:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}/")
+ADD_DEFINITIONS(-DDEFAULT_BASEDIR="c:/Program Files/MySQL/")
+ADD_DEFINITIONS(-DMYSQL_DATADIR="c:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}/data")
+ADD_DEFINITIONS(-DDEFAULT_CHARSET_HOME="c:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}/")
+ADD_DEFINITIONS(-DPACKAGE=mysql)
+ADD_DEFINITIONS(-DSHAREDIR="share")
 
 # Set debug options
 SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DFORCE_INIT_OF_VARS")

=== modified file 'Makefile.am'
--- a/Makefile.am	2009-06-30 20:37:35 +0000
+++ b/Makefile.am	2009-08-03 08:43:44 +0000
@@ -144,44 +144,63 @@ test-force-mem:
 test-bt:
 	-cd mysql-test ; MTR_BUILD_THREAD=auto \
 	    @PERL@ ./mysql-test-run.pl --comment=normal --force --timer \
-	        --skip-ndbcluster --report-features
+	        --skip-ndbcluster --report-features \
+		--experimental=collections/default.experimental
 	-cd mysql-test ; MTR_BUILD_THREAD=auto \
 	    @PERL@ ./mysql-test-run.pl  --comment=ps    --force --timer \
-	        --skip-ndbcluster --ps-protocol
+	        --skip-ndbcluster --ps-protocol \
+		--experimental=collections/default.experimental
 	-if [ -e bin/ndbd -o -e storage/ndb/src/kernel/ndbd ] ; then \
 	  cd mysql-test ; \
 	    MTR_BUILD_THREAD=auto \
 	      @PERL@ ./mysql-test-run.pl --comment=ndb+rpl_ndb+ps --force --timer \
+		  --experimental=collections/default.experimental \
 	          --ps-protocol --mysqld=--binlog-format=row --suite=ndb,rpl_ndb ; \
 	    MTR_BUILD_THREAD=auto \
 	      @PERL@ ./mysql-test-run.pl --comment=ndb --force --timer \
+		  --experimental=collections/default.experimental \
 	          --with-ndbcluster-only ; \
 	else \
 	  echo "no program found for 'ndbcluster' tests - skipped testing" ; \
 	fi
 	-cd mysql-test ; MTR_BUILD_THREAD=auto \
-	    @PERL@ ./mysql-test-run.pl --force --comment=funcs1+ps --ps-protocol --reorder --suite=funcs_1
-	-cd mysql-test ; MTR_BUILD_THREAD=auto \
-	    @PERL@ ./mysql-test-run.pl --force --comment=funcs2 --suite=funcs_2
-	-cd mysql-test ; MTR_BUILD_THREAD=auto \
-	    @PERL@ ./mysql-test-run.pl --force --comment=partitions --suite=parts
-	-cd mysql-test ; MTR_BUILD_THREAD=auto \
-	    @PERL@ ./mysql-test-run.pl --force --comment=stress --suite=stress
-	-cd mysql-test ; MTR_BUILD_THREAD=auto \
-	    @PERL@ ./mysql-test-run.pl --force --comment=jp --suite=jp
+	    @PERL@ ./mysql-test-run.pl --force --comment=funcs1+ps \
+		--ps-protocol --reorder --suite=funcs_1 \
+		--experimental=collections/default.experimental
+	-cd mysql-test ; MTR_BUILD_THREAD=auto \
+	    @PERL@ ./mysql-test-run.pl --force --comment=funcs2 \
+		--suite=funcs_2 \
+		--experimental=collections/default.experimental
+	-cd mysql-test ; MTR_BUILD_THREAD=auto \
+	    @PERL@ ./mysql-test-run.pl --force --comment=partitions \
+		--suite=parts \
+		--experimental=collections/default.experimental
+	-cd mysql-test ; MTR_BUILD_THREAD=auto \
+	    @PERL@ ./mysql-test-run.pl --force --comment=stress \
+		--suite=stress \
+		--experimental=collections/default.experimental
+	-cd mysql-test ; MTR_BUILD_THREAD=auto \
+	    @PERL@ ./mysql-test-run.pl --force --comment=jp \
+		--suite=jp \
+		--experimental=collections/default.experimental
 	-if [ -d mysql-test/suite/nist ] ; then \
 	  cd mysql-test ; MTR_BUILD_THREAD=auto \
-	      @PERL@ ./mysql-test-run.pl --comment=nist --force --suite=nist ; \
+	      @PERL@ ./mysql-test-run.pl --comment=nist --force --suite=nist \
+		  --experimental=collections/default.experimental ; \
 	fi
 	-if [ -d mysql-test/suite/nist ] ; then \
 	  cd mysql-test ; MTR_BUILD_THREAD=auto \
-	      @PERL@ ./mysql-test-run.pl --comment=NIST+normal --force --suite=nist ; \
-	      @PERL@ ./mysql-test-run.pl --comment=NIST+ps --force --suite=nist --ps-protocol ; \
+	      @PERL@ ./mysql-test-run.pl --comment=NIST+normal --force \
+		  --suite=nist --experimental=collections/default.experimental ; \
+	      @PERL@ ./mysql-test-run.pl --comment=NIST+ps --force \
+		  --suite=nist --ps-protocol \
+		  --experimental=collections/default.experimental ; \
 	fi
 	-if [ -e bin/mysqltest_embedded -o -e libmysqld/examples/mysqltest_embedded ] ; then \
 	  cd mysql-test ; MTR_BUILD_THREAD=auto \
 	      @PERL@ ./mysql-test-run.pl --comment=embedded --force --timer \
-	          --embedded-server --skip-rpl --skip-ndbcluster ; \
+	          --embedded-server --skip-rpl --skip-ndbcluster \
+		  --experimental=collections/default.experimental ; \
 	else \
 	  echo "no program found for 'embedded' tests - skipped testing" ; \
 	fi

=== modified file 'client/Makefile.am'
--- a/client/Makefile.am	2009-07-13 19:38:47 +0000
+++ b/client/Makefile.am	2009-07-31 20:21:25 +0000
@@ -109,7 +109,7 @@ mysql_upgrade_SOURCES=          mysql_up
 # Fix for mit-threads
 DEFS =			-DMYSQL_CLIENT_NO_THREADS \
 			-DDEFAULT_MYSQL_HOME="\"$(prefix)\"" \
-			-DDATADIR="\"$(localstatedir)\""
+			-DMYSQL_DATADIR="\"$(localstatedir)\""
 
 sql_src=log_event.h mysql_priv.h rpl_constants.h \
 	rpl_utility.h rpl_tblmap.h rpl_tblmap.cc \

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2009-07-14 17:16:51 +0000
+++ b/client/mysql.cc	2009-07-31 01:24:46 +0000
@@ -171,6 +171,8 @@ static const char *xmlmeta[] = {
   "<", "&lt;",
   ">", "&gt;",
   "\"", "&quot;",
+  /* Turn \0 into a space. Why not &#0;? That's not valid XML or HTML. */
+  "\0", " ",
   0, 0
 };
 static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
@@ -3594,11 +3596,29 @@ print_table_data_vertically(MYSQL_RES *r
     mysql_field_seek(result,0);
     tee_fprintf(PAGER, 
 		"*************************** %d. row ***************************\n", row_count);
+
+    ulong *lengths= mysql_fetch_lengths(result);
+
     for (uint off=0; off < mysql_num_fields(result); off++)
     {
       field= mysql_fetch_field(result);
       tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name);
-      tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
+      if (cur[off])
+      {
+        unsigned int i;
+        const char *p;
+
+        for (i= 0, p= cur[off]; i < lengths[off]; i+= 1, p+= 1)
+        {
+          if (*p == '\0')
+            tee_putc((int)' ', PAGER);
+          else
+            tee_putc((int)*p, PAGER);
+        }
+        tee_putc('\n', PAGER);
+      }
+      else
+        tee_fprintf(PAGER, "NULL\n");
     }
   }
 }
@@ -3665,7 +3685,7 @@ xmlencode_print(const char *src, uint le
     tee_fputs("NULL", PAGER);
   else
   {
-    for (const char *p = src; *p && length; *p++, length--)
+    for (const char *p = src; length; *p++, length--)
     {
       const char *t;
       if ((t = array_value(xmlmeta, *p)))
@@ -3685,7 +3705,12 @@ safe_put_field(const char *pos,ulong len
   else
   {
     if (opt_raw_data)
-      tee_fputs(pos, PAGER);
+    {
+      unsigned long i;
+      /* Can't use tee_fputs(), it stops with NUL characters. */
+      for (i= 0; i < length; i++, pos++)
+        tee_putc(*pos, PAGER);
+    }
     else for (const char *end=pos+length ; pos != end ; pos++)
     {
 #ifdef USE_MB

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2009-07-16 12:51:04 +0000
+++ b/client/mysqldump.c	2009-08-03 19:24:36 +0000
@@ -3153,6 +3153,12 @@ static void dump_table(char *table, char
     dynstr_append_checked(&query_string, filename);
     dynstr_append_checked(&query_string, "'");
 
+    dynstr_append_checked(&query_string, " /*!50138 CHARACTER SET ");
+    dynstr_append_checked(&query_string, default_charset == mysql_universal_client_charset ?
+                                         my_charset_bin.name : /* backward compatibility */
+                                         default_charset);
+    dynstr_append_checked(&query_string, " */");
+
     if (fields_terminated || enclosed || opt_enclosed || escaped)
       dynstr_append_checked(&query_string, " FIELDS");
     

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2009-07-06 08:38:21 +0000
+++ b/client/mysqltest.cc	2009-07-24 14:04:20 +0000
@@ -6576,9 +6576,6 @@ void run_query_normal(struct st_connecti
 
     if (!disable_result_log)
     {
-      ulonglong affected_rows;    /* Ok to be undef if 'disable_info' is set */
-      LINT_INIT(affected_rows);
-
       if (res)
       {
 	MYSQL_FIELD *fields= mysql_fetch_fields(res);
@@ -6595,10 +6592,10 @@ void run_query_normal(struct st_connecti
 
       /*
         Need to call mysql_affected_rows() before the "new"
-        query to find the warnings
+        query to find the warnings.
       */
       if (!disable_info)
-        affected_rows= mysql_affected_rows(mysql);
+	append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql));
 
       /*
         Add all warnings to the result. We can't do this if we are in
@@ -6613,9 +6610,6 @@ void run_query_normal(struct st_connecti
 	  dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
 	}
       }
-
-      if (!disable_info)
-	append_info(ds, affected_rows, mysql_info(mysql));
     }
 
     if (res)
@@ -6988,6 +6982,13 @@ void run_query_stmt(MYSQL *mysql, struct
       */
     }
 
+    /*
+      Fetch info before fetching warnings, since it will be reset
+      otherwise.
+    */
+    if (!disable_info)
+      append_info(ds, mysql_stmt_affected_rows(stmt), mysql_info(mysql));
+
     if (!disable_warnings)
     {
       /* Get the warnings from execute */
@@ -7011,9 +7012,6 @@ void run_query_stmt(MYSQL *mysql, struct
       }
     }
 
-    if (!disable_info)
-      append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql));
-
   }
 
 end:

=== modified file 'config/ac-macros/misc.m4'
--- a/config/ac-macros/misc.m4	2009-03-25 13:27:59 +0000
+++ b/config/ac-macros/misc.m4	2009-08-05 20:46:51 +0000
@@ -619,6 +619,12 @@ AC_DEFUN([MYSQL_STACK_DIRECTION],[
        [AC_LANG_PROGRAM(
           [[
 	    #include <stdlib.h>
+
+ /* Prevent compiler optimization by HP's compiler, see bug#42213 */
+ #if defined(__HP_cc) || defined (__HP_aCC) || defined (__hpux)
+ #pragma noinline
+ #endif
+
  int find_stack_direction ()
  {
    static char *addr = 0;

=== modified file 'config/ac-macros/readline.m4'
--- a/config/ac-macros/readline.m4	2009-01-09 11:46:26 +0000
+++ b/config/ac-macros/readline.m4	2009-08-06 00:24:09 +0000
@@ -76,12 +76,16 @@ AC_CHECK_HEADERS(wctype.h)
 AC_CHECK_HEADERS(wchar.h)
 AC_CHECK_HEADERS(langinfo.h)
 
-AC_CHECK_FUNC(mbsrtowcs, AC_DEFINE([HAVE_MBSRTOWCS],[],[Define if you have mbsrtowcs]))
-AC_CHECK_FUNC(mbrtowc, AC_DEFINE([HAVE_MBRTOWC],[],[Define if you have mbrtowc]))
-AC_CHECK_FUNC(mbrlen, AC_DEFINE([HAVE_MBRLEN],[],[Define if you have mbrlen]))
-AC_CHECK_FUNC(wctomb, AC_DEFINE([HAVE_WCTOMB],[],[Define if you have wctomb]))
-AC_CHECK_FUNC(wcwidth, AC_DEFINE([HAVE_WCWIDTH],[],[Define if you have wcwidth]))
-AC_CHECK_FUNC(wcsdup, AC_DEFINE([HAVE_WCSDUP],[],[Define if you check wcsdup]))
+AC_CHECK_FUNC(mbrlen, AC_DEFINE(HAVE_MBRLEN,[],[Define if you have mbrlen]))
+AC_CHECK_FUNC(mbscmp, AC_DEFINE(HAVE_MBSCMP,[],[Define if you have mbscmp]))
+AC_CHECK_FUNC(mbsrtowcs, AC_DEFINE(HAVE_MBSRTOWCS,[],[Define if you have mbsrtowcs]))
+
+AC_CHECK_FUNC(wcrtomb, AC_DEFINE(HAVE_WCRTOMB,[],[Define if you have wcrtomb]))
+AC_CHECK_FUNC(mbrtowc, AC_DEFINE(HAVE_MBRTOWC,[],[Define if you have mbrtowc]))
+AC_CHECK_FUNC(wcscoll, AC_DEFINE(HAVE_WCSCOLL,[],[Define if you have wcscoll]))
+AC_CHECK_FUNC(wcsdup, AC_DEFINE(HAVE_WCSDUP,[],[Define if you have wcsdup]))
+AC_CHECK_FUNC(wcwidth, AC_DEFINE(HAVE_WCWIDTH,[],[Define if you have wcwidth]))
+AC_CHECK_FUNC(wctype, AC_DEFINE(HAVE_WCTYPE,[],[Define if you have wctype]))
 
   AC_CACHE_CHECK([for mbstate_t], [mysql_cv_have_mbstate_t],
     [AC_COMPILE_IFELSE(
@@ -103,17 +107,52 @@ if test $mysql_cv_have_mbstate_t = yes; 
         AC_DEFINE([HAVE_MBSTATE_T],[],[Define if mysql_cv_have_mbstate_t=yes])
 fi
 
-  AC_CACHE_CHECK([for nl_langinfo and CODESET], [mysql_cv_langinfo_codeset],
-    [AC_LINK_IFELSE(
-       [AC_LANG_PROGRAM(
-	  [[#include <langinfo.h>]],
-	  [[char* cs = nl_langinfo(CODESET);]]
-       )],
-       [mysql_cv_langinfo_codeset=yes],
-       [mysql_cv_langinfo_codeset=no]
-    )]
-  )
+AC_CHECK_FUNCS(iswlower iswupper towlower towupper iswctype)
+
+AC_CACHE_CHECK([for nl_langinfo and CODESET], mysql_cv_langinfo_codeset,
+[AC_TRY_LINK(
+[#include <langinfo.h>],
+[char* cs = nl_langinfo(CODESET);],
+mysql_cv_langinfo_codeset=yes, mysql_cv_langinfo_codeset=no)])
 if test $mysql_cv_langinfo_codeset = yes; then
   AC_DEFINE([HAVE_LANGINFO_CODESET],[],[Define if mysql_cv_langinfo_codeset=yes])
 fi
+
+dnl check for wchar_t in <wchar.h>
+AC_CACHE_CHECK([for wchar_t in wchar.h], bash_cv_type_wchar_t,
+[AC_TRY_COMPILE(
+[#include <wchar.h>
+],
+[
+        wchar_t foo;
+        foo = 0;
+], bash_cv_type_wchar_t=yes, bash_cv_type_wchar_t=no)])
+if test $bash_cv_type_wchar_t = yes; then
+        AC_DEFINE(HAVE_WCHAR_T, 1, [systems should define this type here])
+fi
+
+dnl check for wctype_t in <wctype.h>
+AC_CACHE_CHECK([for wctype_t in wctype.h], bash_cv_type_wctype_t,
+[AC_TRY_COMPILE(
+[#include <wctype.h>],
+[
+        wctype_t foo;
+        foo = 0;
+], bash_cv_type_wctype_t=yes, bash_cv_type_wctype_t=no)])
+if test $bash_cv_type_wctype_t = yes; then
+        AC_DEFINE(HAVE_WCTYPE_T, 1, [systems should define this type here])
+fi
+
+dnl check for wint_t in <wctype.h>
+AC_CACHE_CHECK([for wint_t in wctype.h], bash_cv_type_wint_t,
+[AC_TRY_COMPILE(
+[#include <wctype.h>],
+[
+        wint_t foo;
+        foo = 0;
+], bash_cv_type_wint_t=yes, bash_cv_type_wint_t=no)])
+if test $bash_cv_type_wint_t = yes; then
+        AC_DEFINE(HAVE_WINT_T, 1, [systems should define this type here])
+fi
+
 ])

=== modified file 'include/config-netware.h'
--- a/include/config-netware.h	2009-05-15 13:45:06 +0000
+++ b/include/config-netware.h	2009-07-31 20:21:25 +0000
@@ -130,7 +130,7 @@ extern "C" {
 #define DEFAULT_BASEDIR       "sys:/"
 #define SHAREDIR              "share/"
 #define DEFAULT_CHARSET_HOME  "sys:/mysql/"
-#define DATADIR               "data/"
+#define MYSQL_DATADIR         "data/"
 
 /* 64-bit file system calls */
 #define SIZEOF_OFF_T          8

=== modified file 'include/config-win.h'
--- a/include/config-win.h	2009-07-16 12:51:04 +0000
+++ b/include/config-win.h	2009-07-31 20:21:25 +0000
@@ -345,13 +345,15 @@ inline ulonglong double2ulonglong(double
 #ifdef _CUSTOMCONFIG_
 #include <custom_conf.h>
 #else
+#ifndef CMAKE_CONFIGD
 #define DEFAULT_MYSQL_HOME	"c:\\mysql"
-#define DATADIR         	"c:\\mysql\\data"
+#define MYSQL_DATADIR          "c:\\mysql\\data"
 #define PACKAGE			"mysql"
 #define DEFAULT_BASEDIR		"C:\\"
 #define SHAREDIR		"share"
 #define DEFAULT_CHARSET_HOME	"C:/mysql/"
 #endif
+#endif
 #ifndef DEFAULT_HOME_ENV
 #define DEFAULT_HOME_ENV MYSQL_HOME
 #endif

=== modified file 'include/my_base.h'
--- a/include/my_base.h	2009-04-01 21:36:07 +0000
+++ b/include/my_base.h	2009-07-28 14:16:37 +0000
@@ -274,7 +274,17 @@ enum ha_base_keytype {
                          HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY | \
                          HA_RTREE_INDEX)
 
-#define HA_KEY_HAS_PART_KEY_SEG 65536   /* Key contains partial segments */
+/*
+  Key contains partial segments.
+
+  This flag is internal to the MySQL server by design. It is not supposed
+  neither to be saved in FRM-files, nor to be passed to storage engines.
+  It is intended to pass information into internal static sort_keys(KEY *,
+  KEY *) function.
+
+  This flag can be calculated -- it's based on key lengths comparison.
+*/
+#define HA_KEY_HAS_PART_KEY_SEG 65536
 
 	/* Automatic bits in key-flag */
 
@@ -468,7 +478,8 @@ enum ha_base_keytype {
 #define HA_ERR_TABLESPACE_NOT_EMPTY 180
 #define HA_ERR_TABLESPACE_DATAFILE_EXIST 181
 #define HA_ERR_ROW_NOT_VISIBLE    182
-#define HA_ERR_LAST               182    /* Copy of last error nr */
+#define HA_ERR_TOO_MANY_CONCURRENT_TRXS 183 /*Too many active concurrent transactions */
+#define HA_ERR_LAST               183    /* Copy of last error nr */
 
 /* Number of different errors */
 #define HA_ERR_ERRORS            (HA_ERR_LAST - HA_ERR_FIRST + 1)

=== modified file 'include/myisammrg.h'
--- a/include/myisammrg.h	2009-07-10 11:34:03 +0000
+++ b/include/myisammrg.h	2009-07-30 10:34:41 +0000
@@ -47,6 +47,7 @@ typedef struct st_mymerge_info		/* Struc
   ulonglong deleted;			/* Deleted records in database */
   ulonglong recpos;			/* Pos for last used record */
   ulonglong data_file_length;
+  ulonglong dupp_key_pos;               /* Offset of the Duplicate key in the merge table */
   uint	reclength;			/* Recordlength */
   int	errkey;				/* With key was dupplicated on err */
   uint	options;			/* HA_OPTION_... used */

=== modified file 'libmysql/Makefile.shared'
--- a/libmysql/Makefile.shared	2009-03-16 17:00:38 +0000
+++ b/libmysql/Makefile.shared	2009-07-31 20:21:25 +0000
@@ -69,7 +69,7 @@ BUILT_SOURCES		= link_sources
 CLEANFILES =		$(target_libadd) $(SHLIBOBJS) \
 			$(target) $(BUILT_SOURCES)
 DEFS =			-DDEFAULT_CHARSET_HOME="\"$(MYSQLBASEdir)\"" \
-			-DDATADIR="\"$(MYSQLDATAdir)\"" \
+			-DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \
 			-DDEFAULT_HOME_ENV=MYSQL_HOME \
 			-DDEFAULT_GROUP_SUFFIX_ENV=MYSQL_GROUP_SUFFIX \
 			-DDEFAULT_SYSCONFDIR="\"$(sysconfdir)\"" \

=== modified file 'libmysqld/Makefile.am'
--- a/libmysqld/Makefile.am	2009-05-04 15:51:55 +0000
+++ b/libmysqld/Makefile.am	2009-07-31 20:21:25 +0000
@@ -26,7 +26,7 @@ pkgplugindir =		$(pkglibdir)/plugin
 EXTRA_DIST =		libmysqld.def CMakeLists.txt
 DEFS =			-DEMBEDDED_LIBRARY -DMYSQL_SERVER \
 			-DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \
-			-DDATADIR="\"$(MYSQLDATAdir)\"" \
+			-DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \
 			-DSHAREDIR="\"$(MYSQLSHAREdir)\"" \
 			@DEFS@ \
 			-DLIBDIR="\"$(MYSQLLIBdir)\"" \

=== modified file 'libmysqld/emb_qcache.h'
--- a/libmysqld/emb_qcache.h	2007-12-14 13:50:26 +0000
+++ b/libmysqld/emb_qcache.h	2009-07-30 16:22:41 +0000
@@ -79,4 +79,4 @@ public:
 uint emb_count_querycache_size(THD *thd);
 int emb_load_querycache_result(THD *thd, Querycache_stream *src);
 void emb_store_querycache_result(Querycache_stream *dst, THD* thd);
-void net_send_eof(THD *thd, uint server_status, uint total_warn_count);
+bool net_send_eof(THD *thd, uint server_status, uint total_warn_count);

=== modified file 'libmysqld/lib_sql.cc'
--- a/libmysqld/lib_sql.cc	2009-08-07 09:26:33 +0000
+++ b/libmysqld/lib_sql.cc	2009-08-07 16:25:06 +0000
@@ -803,11 +803,11 @@ MYSQL_DATA *THD::alloc_new_dataset()
 */
 
 static
-void
+bool
 write_eof_packet(THD *thd, uint server_status, uint statement_warn_count)
 {
   if (!thd->mysql)            // bootstrap file handling
-    return;
+    return FALSE;
   /*
     The following test should never be true, but it's better to do it
     because if 'is_fatal_error' is set the server is not going to execute
@@ -822,6 +822,7 @@ write_eof_packet(THD *thd, uint server_s
   */
   thd->cur_data->embedded_info->warning_count=
     (thd->spcont ? 0 : min(statement_warn_count, 65535));
+  return FALSE;
 }
 
 
@@ -1036,7 +1037,7 @@ bool Protocol_binary::write()
   @return The function does not return errors.
 */
 
-void
+bool
 net_send_ok(THD *thd,
             uint server_status, uint statement_warn_count,
             ulonglong affected_rows, ulonglong id, const char *message)
@@ -1046,18 +1047,18 @@ net_send_ok(THD *thd,
   MYSQL *mysql= thd->mysql;
 
   if (!mysql)            // bootstrap file handling
-    DBUG_VOID_RETURN;
+    DBUG_RETURN(FALSE);
   if (!(data= thd->alloc_new_dataset()))
-    return;
+    DBUG_RETURN(TRUE);
   data->embedded_info->affected_rows= affected_rows;
   data->embedded_info->insert_id= id;
   if (message)
     strmake(data->embedded_info->info, message,
             sizeof(data->embedded_info->info)-1);
 
-  write_eof_packet(thd, server_status, statement_warn_count);
+  bool error= write_eof_packet(thd, server_status, statement_warn_count);
   thd->cur_data= 0;
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(error);
 }
 
 
@@ -1066,25 +1067,39 @@ net_send_ok(THD *thd,
 
   @sa net_send_ok
 
-  @return This function does not return errors.
+  @return
+    @retval TRUE  An error occured
+    @retval FALSE Success
 */
 
-void
+bool
 net_send_eof(THD *thd, uint server_status, uint statement_warn_count)
 {
-  write_eof_packet(thd, server_status, statement_warn_count);
+  bool error= write_eof_packet(thd, server_status, statement_warn_count);
   thd->cur_data= 0;
+  return error;
 }
 
 
-void net_send_error_packet(THD *thd, uint sql_errno, const char *err,
+bool net_send_error_packet(THD *thd, uint sql_errno, const char *err,
                            const char* sqlstate)
 {
   uint error;
   uchar converted_err[MYSQL_ERRMSG_SIZE];
   uint32 converted_err_len;
-  MYSQL_DATA *data= thd->cur_data ? thd->cur_data : thd->alloc_new_dataset();
-  struct embedded_query_result *ei= data->embedded_info;
+  MYSQL_DATA *data= thd->cur_data;
+  struct embedded_query_result *ei;
+
+  if (!thd->mysql)            // bootstrap file handling
+  {
+    fprintf(stderr, "ERROR: %d  %s\n", sql_errno, err);
+    return FALSE;
+  }
+
+  if (!data)
+    data= thd->alloc_new_dataset();
+
+  ei= data->embedded_info;
   ei->last_errno= sql_errno;
   converted_err_len= convert_error_message((char*)converted_err,
                                            sizeof(converted_err),
@@ -1095,6 +1110,7 @@ void net_send_error_packet(THD *thd, uin
   strmov(ei->sqlstate, sqlstate);
   ei->server_status= thd->server_status;
   thd->cur_data= 0;
+  return FALSE;
 }
 
 

=== modified file 'mysql-test/collections/default.experimental'
--- a/mysql-test/collections/default.experimental	2009-07-10 13:13:33 +0000
+++ b/mysql-test/collections/default.experimental	2009-08-03 14:37:07 +0000
@@ -15,5 +15,13 @@ main.ctype_gbk_binlog                   
 main.information_schema                  # Bug#42893 2009-06-23 guilhem main.information_schema times out sporadically
 
 rpl.rpl_backup_multi                     # BUG#45284
+
 rpl.rpl_killed_ddl                       # Bug#45520 2009-07-10 alik rpl_killed_ddl fails sporadically in pb2
+rpl.rpl_killed_ddl 'row'                 # Bug#45520 2009-07-10 alik rpl_killed_ddl fails sporadically in pb2
+rpl.rpl_killed_ddl 'stmt'                # Bug#45520 2009-07-10 alik rpl_killed_ddl fails sporadically in pb2
+rpl.rpl_killed_ddl 'mix'                 # Bug#45520 2009-07-10 alik rpl_killed_ddl fails sporadically in pb2
+
 rpl.rpl_row_create_table                 # Bug#45576 2009-07-10 alik rpl_row_create_table fails on PB2
+
+ndb.ndb_restore                          # Bug#37778 2009-07-30 alik ndb.ndb_restore fails randomly
+ndb.ndb_restore_print                    # Bug#37778 2009-07-30 alik ndb.ndb_restore fails randomly

=== modified file 'mysql-test/collections/mysql-azalea.push'
--- a/mysql-test/collections/mysql-azalea.push	2009-05-28 08:50:33 +0000
+++ b/mysql-test/collections/mysql-azalea.push	2009-07-29 12:59:56 +0000
@@ -1,5 +1,5 @@
-perl mysql-test-run.pl --comment=n_mix                            --mysqld=--binlog-format=mixed                                                --suite=main,backup,backup_engines,backup_ptr,binlog,federated,rpl  --experimental=collections/default.experimental --timer --force 
-perl mysql-test-run.pl --comment=ps_row            --ps-protocol  --mysqld=--binlog-format=row                                                  --suite=main,backup,backup_engines,backup_ptr,binlog,federated,rpl  --experimental=collections/default.experimental --timer --force 
-perl mysql-test-run.pl --comment=embedded          --embedded                                                                                   --suite=main,backup,backup_engines,backup_ptr,binlog,federated,rpl  --experimental=collections/default.experimental --timer --force 
-perl mysql-test-run.pl --comment=rpl_binlog_row                   --mysqld=--binlog-format=row                                                  --suite=rpl,binlog                                                  --experimental=collections/default.experimental --timer --force 
-perl mysql-test-run.pl --comment=funcs_1                                                                                                        --suite=funcs_1                                                     --experimental=collections/default.experimental --timer --force 
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=n_mix --mysqld=--binlog-format=mixed --suite=main,backup,backup_engines,backup_ptr,binlog,federated,rpl
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=ps_row --ps-protocol --mysqld=--binlog-format=row --suite=main,backup,backup_engines,backup_ptr,binlog,federated,rpl
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=embedded --embedded --suite=main,backup,backup_engines,backup_ptr,binlog,federated,rpl
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=rpl_binlog_row --mysqld=--binlog-format=row --suite=rpl,binlog
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=funcs_1 --suite=funcs_1

=== modified file 'mysql-test/extra/scripts/monitor_disabled_tests/comments.txt'
--- a/mysql-test/extra/scripts/monitor_disabled_tests/comments.txt	2009-07-11 20:16:40 +0000
+++ b/mysql-test/extra/scripts/monitor_disabled_tests/comments.txt	2009-07-23 10:22:21 +0000
@@ -57165,6 +57165,41 @@ suite/rpl/t/rpl_row_sp012.test:# Create 
 suite/rpl/t/rpl_row_sp012.test:# Need to wait for the rights to be applied at the slave
 suite/rpl/t/rpl_row_sp012.test:# Cleanup
 suite/rpl/t/rpl_row_sp012.test:# End of 5.0 test case
+suite/rpl/t/rpl_stop_middle_group.test:# Proving that stopping in the middle of applying a group of events
+suite/rpl/t/rpl_stop_middle_group.test:# does not have immediate effect if a non-transaction table has been changed.
+suite/rpl/t/rpl_stop_middle_group.test:# The slave sql thread has to try to finish applying first.
+suite/rpl/t/rpl_stop_middle_group.test:# The tests rely on simulation of the killed status.
+suite/rpl/t/rpl_stop_middle_group.test:# The matter of testing correlates to some of `rpl_start_stop_slave' that does
+suite/rpl/t/rpl_stop_middle_group.test:# not require `have_debug'.
+suite/rpl/t/rpl_stop_middle_group.test:# slave will catch the killed status but won't shut down immediately
+suite/rpl/t/rpl_stop_middle_group.test:# only after the whole group has done (commit)
+suite/rpl/t/rpl_stop_middle_group.test:# checking: no error and the group is finished
+suite/rpl/t/rpl_stop_middle_group.test:#
+suite/rpl/t/rpl_stop_middle_group.test:# bug#45940 issues around rli->last_event_start_time
+suite/rpl/t/rpl_stop_middle_group.test:# Testing of slave stopped after it had waited (in vain) for
+suite/rpl/t/rpl_stop_middle_group.test:# the group be finished.
+suite/rpl/t/rpl_stop_middle_group.test:# It could not be finished because of simulation of failure to
+suite/rpl/t/rpl_stop_middle_group.test:# receive the terminal part
+suite/rpl/t/rpl_stop_middle_group.test:# The test relay on simulation of the incomplete group in the relay log
+suite/rpl/t/rpl_stop_middle_group.test:# Two cases are verified: a mixed transacton and a mixed multi-table update.
+suite/rpl/t/rpl_stop_middle_group.test:#
+suite/rpl/t/rpl_stop_middle_group.test:# The mixed transacton.
+suite/rpl/t/rpl_stop_middle_group.test:#
+suite/rpl/t/rpl_stop_middle_group.test:#connection slave;
+suite/rpl/t/rpl_stop_middle_group.test:# slave will catch the killed status, won't shut down immediately
+suite/rpl/t/rpl_stop_middle_group.test:# but does it eventually having the whole group unfinished (not committed)
+suite/rpl/t/rpl_stop_middle_group.test:# checking: the error and group unfinished
+suite/rpl/t/rpl_stop_middle_group.test:#
+suite/rpl/t/rpl_stop_middle_group.test:# The mixed multi-table update
+suite/rpl/t/rpl_stop_middle_group.test:#
+suite/rpl/t/rpl_stop_middle_group.test:#connection slave;
+suite/rpl/t/rpl_stop_middle_group.test:# slave will catch the killed status, won't shut down immediately
+suite/rpl/t/rpl_stop_middle_group.test:# but does it eventually having the whole group unfinished (not committed)
+suite/rpl/t/rpl_stop_middle_group.test:# 
+suite/rpl/t/rpl_stop_middle_group.test:# checking: the error and group unfinished 
+suite/rpl/t/rpl_stop_middle_group.test:#
+suite/rpl/t/rpl_stop_middle_group.test:# clean-up
+suite/rpl/t/rpl_stop_middle_group.test:#
 suite/rpl/t/rpl_variables.test:# ==== Purpose ====
 suite/rpl/t/rpl_variables.test:#
 suite/rpl/t/rpl_variables.test:# Test that queries referencing variables are replicated correctly in
@@ -57815,6 +57850,7 @@ suite/rpl/t/rpl_innodb.test:# stay in t1
 suite/rpl/t/rpl_innodb.test:# Must return no rows here
 suite/rpl/t/rpl_innodb.test:# Must return no rows here
 suite/rpl/t/rpl_innodb.test:# t1 has two rows here: the transaction not rolled back since t1 uses MyISAM
+suite/rpl/t/rpl_innodb.test:# Need to wait until RENAME is received
 suite/rpl/t/rpl_stm_log.test:# Requires statement logging
 suite/rpl/t/rpl_stm_log.test:# -- [DISABLED Bug#45238]
 suite/rpl/t/rpl_stm_log.test:# End of 4.1 tests
@@ -58712,6 +58748,16 @@ suite/rpl/t/rpl_backup_shutdown.test:# r
 suite/rpl/t/rpl_backup_shutdown.test:# Stop master server
 suite/rpl/t/rpl_backup_shutdown.test:# Clean up section
 suite/rpl/t/rpl_semi_sync.test:#let $engine_type= MyISAM;
+suite/rpl/t/rpl_semi_sync.test:# BUG#45672 When semi-sync is enabled on master, it would allocate
+suite/rpl/t/rpl_semi_sync.test:# transaction node even without semi-sync slave connected, and would
+suite/rpl/t/rpl_semi_sync.test:# finally result in transaction node allocation error.
+suite/rpl/t/rpl_semi_sync.test:#
+suite/rpl/t/rpl_semi_sync.test:# Semi-sync master will pre-allocate 'max_connections' transaction
+suite/rpl/t/rpl_semi_sync.test:# nodes, so here we do more than that much transactions to check if it
+suite/rpl/t/rpl_semi_sync.test:# will fail or not.
+suite/rpl/t/rpl_semi_sync.test:# select @@global.max_connections + 1;
+suite/rpl/t/rpl_semi_sync.test:# BUG#45673
+suite/rpl/t/rpl_semi_sync.test:# reset master to make sure the following test will start with a clean environment
 suite/rpl/t/rpl_semi_sync.test:# NOTE: Rpl_semi_sync_master_client will only be updated when
 suite/rpl/t/rpl_semi_sync.test:# semi-sync slave has started binlog dump request
 suite/rpl/t/rpl_semi_sync.test:# The first semi-sync check should be on because after slave stop,
@@ -58721,8 +58767,20 @@ suite/rpl/t/rpl_semi_sync.test:# times o
 suite/rpl/t/rpl_semi_sync.test:# Save the master position for later use.
 suite/rpl/t/rpl_semi_sync.test:# The third semi-sync check should be on again.
 suite/rpl/t/rpl_semi_sync.test:##show status like 'Rpl_semi_sync_master_status';
+suite/rpl/t/rpl_semi_sync.test:# Kill the dump thread on master for previous slave connection and
+suite/rpl/t/rpl_semi_sync.test:# wait for it to exit
+suite/rpl/t/rpl_semi_sync.test:  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+suite/rpl/t/rpl_semi_sync.test:# Wait for dump thread to start, Rpl_semi_sync_master_clients will be
+suite/rpl/t/rpl_semi_sync.test:# 1 after dump thread started.
+suite/rpl/t/rpl_semi_sync.test:# Kill the dump thread on master for previous slave connection and wait for it to exit
+suite/rpl/t/rpl_semi_sync.test:  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
 suite/rpl/t/rpl_semi_sync.test:# Do not binlog the following statement because it will generate
 suite/rpl/t/rpl_semi_sync.test:# different events for ROW and STATEMENT format
+suite/rpl/t/rpl_semi_sync.test:# Wait for the semi-sync binlog dump thread to start
+suite/rpl/t/rpl_semi_sync.test:# Disable semi-sync on master
+suite/rpl/t/rpl_semi_sync.test:# Kill the dump thread on master for previous slave connection and wait for it to exit
+suite/rpl/t/rpl_semi_sync.test:  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+suite/rpl/t/rpl_semi_sync.test:# Uninstall semi-sync plugin on master
 suite/rpl/t/rpl000013.test:# This test is to verify that DROP TEMPORARY TABLE
 suite/rpl/t/rpl000013.test:# is automatically binlogged and sent to slave
 suite/rpl/t/rpl000013.test:# when a temp table is dropped by disconnection
@@ -59202,14 +59260,6 @@ suite/rpl/t/rpl_log_pos.test:#
 suite/rpl/t/rpl_log_pos.test:# Testing of setting slave to wrong log position with master_log_pos
 suite/rpl/t/rpl_log_pos.test:#
 suite/rpl/t/rpl_log_pos.test:# Passes with rbr no problem, removed statement include [jbm]
-suite/rpl/t/rpl_row_stop_middle_update.test:# master is asked to create small Rows events: if only one event is
-suite/rpl/t/rpl_row_stop_middle_update.test:# created, stopping slave at the end of that one will show no bug, we
-suite/rpl/t/rpl_row_stop_middle_update.test:# need at least two (and stop after first); in this test we use three.
-suite/rpl/t/rpl_row_stop_middle_update.test:# slave will automatically stop the sql thread thanks to the .opt
-suite/rpl/t/rpl_row_stop_middle_update.test:# file; it will initiate the stop request after the first
-suite/rpl/t/rpl_row_stop_middle_update.test:# Rows_log_event (out of 3) but should wait until the last one is
-suite/rpl/t/rpl_row_stop_middle_update.test:# executed before stopping.
-suite/rpl/t/rpl_row_stop_middle_update.test:# check that we inserted all rows (waited until the last Rows event)
 suite/rpl/t/rpl_auto_increment.test:#####################################
 suite/rpl/t/rpl_auto_increment.test:# Wrapper for rpl_auto_increment.test#
 suite/rpl/t/rpl_auto_increment.test:#####################################

=== modified file 'mysql-test/r/create.result'
--- a/mysql-test/r/create.result	2009-05-28 21:29:31 +0000
+++ b/mysql-test/r/create.result	2009-07-29 10:25:07 +0000
@@ -1899,6 +1899,20 @@ DROP TABLE t1;
 create table `me:i`(id int);
 drop table `me:i`;
 
+# --
+# -- Bug#45829: CREATE TABLE TRANSACTIONAL PAGE_CHECKSUM ROW_FORMAT=PAGE accepted, does nothing
+# --
+
+drop table if exists t1,t2,t3;
+create table t1 (a int) transactional=0;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'transactional=0' at line 1
+create table t2 (a int) page_checksum=1;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'page_checksum=1' at line 1
+create table t3 (a int) row_format=page;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'page' at line 1
+
+# -- End of Bug#45829
+
 End of 5.1 tests
 
 # --

=== modified file 'mysql-test/r/debug_sync.result'
--- a/mysql-test/r/debug_sync.result	2009-06-12 02:01:08 +0000
+++ b/mysql-test/r/debug_sync.result	2009-07-31 17:53:36 +0000
@@ -146,7 +146,7 @@ Variable_name	Value
 debug_sync	ON - current signal: 'something'
 SET DEBUG_SYNC= 'now WAIT_FOR nothing TIMEOUT 0';
 Warnings:
-Warning	1741	debug sync point wait timed out
+Warning	1743	debug sync point wait timed out
 SET DEBUG_SYNC= 'now SIGNAL nothing';
 SHOW VARIABLES LIKE 'DEBUG_SYNC';
 Variable_name	Value

=== modified file 'mysql-test/r/func_str.result'
--- a/mysql-test/r/func_str.result	2009-07-02 08:19:17 +0000
+++ b/mysql-test/r/func_str.result	2009-07-31 17:53:36 +0000
@@ -2560,7 +2560,7 @@ SELECT format(12345678901234567890.123, 
 format(12345678901234567890.123, 3, NULL)
 12,345,678,901,234,567,890.123
 Warnings:
-Warning	1790	Unknown locale: 'NULL'
+Warning	1792	Unknown locale: 'NULL'
 SELECT format(12345678901234567890.123, 3, 'ar_AE');
 format(12345678901234567890.123, 3, 'ar_AE')
 12,345,678,901,234,567,890.123
@@ -2680,5 +2680,5 @@ SELECT format(123, 1, 'Non-existent-loca
 format(123, 1, 'Non-existent-locale')
 123.0
 Warnings:
-Warning	1790	Unknown locale: 'Non-existent-locale'
+Warning	1792	Unknown locale: 'Non-existent-locale'
 End of 5.4 tests

=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result	2009-07-13 17:45:27 +0000
+++ b/mysql-test/r/innodb_mysql.result	2009-07-31 19:46:24 +0000
@@ -2214,6 +2214,26 @@ id	select_type	table	type	possible_keys	
 DROP TABLE t1;
 End of 5.1 tests
 #
+# Test for bug #39932 "create table fails if column for FK is in different
+#                      case than in corr index".
+#
+drop tables if exists t1, t2;
+create table t1 (pk int primary key) engine=InnoDB;
+# Even although the below statement uses uppercased field names in
+# foreign key definition it still should be able to find explicitly
+# created supporting index. So it should succeed and should not
+# create any additional supporting indexes.
+create table t2 (fk int, key x (fk),
+constraint x foreign key (FK) references t1 (PK)) engine=InnoDB;
+show create table t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `fk` int(11) DEFAULT NULL,
+  KEY `x` (`fk`),
+  CONSTRAINT `x` FOREIGN KEY (`fk`) REFERENCES `t1` (`pk`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+drop table t2, t1;
+#
 # BUG#42744: Crash when using a join buffer to join a table with a blob
 # column and an additional column used for duplicate elimination.
 #

=== added file 'mysql-test/r/innodb_mysql_lock.result'
--- a/mysql-test/r/innodb_mysql_lock.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_mysql_lock.result	2009-07-08 12:09:38 +0000
@@ -0,0 +1,24 @@
+#
+# Bug #22876 Four-way deadlock
+#
+DROP TABLE IF EXISTS t1;
+# Connection 1
+set @@autocommit=0;
+CREATE TABLE t1(s1 INT UNIQUE) ENGINE=innodb;
+INSERT INTO t1 VALUES (1);
+# Connection 2
+set @@autocommit=0;
+INSERT INTO t1 VALUES (2);
+INSERT INTO t1 VALUES (1);
+# Connection 3
+set @@autocommit=0;
+DROP TABLE t1;
+# Connection 1
+# Connection 1 is now holding the lock.
+# Issuing insert from connection 1 while connection 2&3 
+# is waiting for the lock should give a deadlock error.
+INSERT INTO t1 VALUES (2);
+ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
+# Cleanup
+commit;
+commit;

=== modified file 'mysql-test/r/insert.result'
--- a/mysql-test/r/insert.result	2009-07-13 17:45:27 +0000
+++ b/mysql-test/r/insert.result	2009-07-31 19:46:24 +0000
@@ -631,3 +631,43 @@ CREATE TABLE t2(f1 CHAR(1));
 INSERT INTO t2 SELECT f1 FROM t1;
 DROP TABLE t1, t2;
 End of 5.0 tests.
+#
+# Bug#34898 "mysql_info() reports 0 warnings while
+# mysql_warning_count() reports 1"
+# Check that the number of warnings reported by
+# mysql_info() is correct.
+#
+drop table if exists t1;
+create table t1 (data varchar(4) not null);
+set sql_mode='error_for_division_by_zero';
+#
+# Demonstrate that the number of warnings matches
+# the information in mysql_info().
+#
+insert t1 (data) values ('letter'), (1/0);
+affected rows: 2
+info: Records: 2  Duplicates: 0  Warnings: 3
+Warnings:
+Warning	1265	Data truncated for column 'data' at row 1
+Warning	1365	Division by 0
+Warning	1048	Column 'data' cannot be null
+update t1 set data='envelope' where 1/0 or 1;
+affected rows: 2
+info: Rows matched: 2  Changed: 2  Warnings: 3
+Warnings:
+Warning	1365	Division by 0
+Warning	1265	Data truncated for column 'data' at row 1
+Warning	1265	Data truncated for column 'data' at row 2
+insert t1 (data) values (default), (1/0), ('dead beef');
+affected rows: 3
+info: Records: 3  Duplicates: 0  Warnings: 4
+Warnings:
+Warning	1364	Field 'data' doesn't have a default value
+Warning	1365	Division by 0
+Warning	1048	Column 'data' cannot be null
+Warning	1265	Data truncated for column 'data' at row 3
+set sql_mode=default;
+drop table t1;
+#
+# End of 5.4 tests
+#

=== modified file 'mysql-test/r/insert_select.result'
--- a/mysql-test/r/insert_select.result	2009-05-04 12:45:36 +0000
+++ b/mysql-test/r/insert_select.result	2009-07-24 12:09:35 +0000
@@ -833,3 +833,16 @@ Table	Op	Msg_type	Msg_text
 test.t2	check	status	OK
 drop table t1,t2;
 ##################################################################
+#
+# Bug #46075: Assertion failed: 0, file .\protocol.cc, line 416
+#
+CREATE TABLE t1(a INT);
+SET max_heap_table_size = 16384;
+SET @old_myisam_data_pointer_size = @@myisam_data_pointer_size;
+SET GLOBAL myisam_data_pointer_size = 2;
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+INSERT IGNORE INTO t1 SELECT t1.a FROM t1,t1 t2,t1 t3,t1 t4,t1 t5,t1 t6,t1 t7;
+Got one of the listed errors
+SET GLOBAL myisam_data_pointer_size = @old_myisam_data_pointer_size;
+DROP TABLE t1;
+End of 5.0 tests

=== modified file 'mysql-test/r/loadxml.result'
--- a/mysql-test/r/loadxml.result	2008-04-08 08:06:05 +0000
+++ b/mysql-test/r/loadxml.result	2009-07-30 11:32:37 +0000
@@ -58,3 +58,15 @@ select 1 as xml;
 xml
 1
 drop table t1;
+create table t1 (
+id int(11) not null,
+text text,
+primary key (id)
+) engine=MyISAM default charset=latin1;
+load xml infile '../../std_data/loadxml2.dat' into table t1;
+select * from t1;
+id	text
+1	line1
+line2
+line3
+drop table t1;

=== modified file 'mysql-test/r/lock.result'
--- a/mysql-test/r/lock.result	2009-03-27 22:06:26 +0000
+++ b/mysql-test/r/lock.result	2009-07-02 14:24:05 +0000
@@ -282,5 +282,27 @@ insert into t1 values (1);
 # Ensure that metadata locks held by the transaction are released.
 drop table t1;
 #
+# Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against 
+#           LOCK TABLE 
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(a INT);
+LOCK TABLE t1 READ;
+FLUSH TABLES;
+ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
+LOCK TABLE t1 WRITE;
+FLUSH TABLES;
+#
+# If you allow the next combination, you reintroduce bug Bug#45066
+# 
+LOCK TABLE t1 READ;
+FLUSH TABLES WITH READ LOCK;
+ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
+LOCK TABLE t1 WRITE;
+FLUSH TABLES WITH READ LOCK;
+ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
+UNLOCK TABLES;
+DROP TABLE t1;
+#
 # End of 6.0 tests.
 #

=== modified file 'mysql-test/r/locktrans_innodb.result'
--- a/mysql-test/r/locktrans_innodb.result	2009-06-04 14:08:54 +0000
+++ b/mysql-test/r/locktrans_innodb.result	2009-07-31 17:53:36 +0000
@@ -95,12 +95,12 @@ ERROR 42000: You have an error in your S
 # Implicit lock method conversion due to mix in statement.
 LOCK TABLE t1 READ, t2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't2'
 UNLOCK TABLES;
 # Lock t1 share (converted to read), t2 write.
 LOCK TABLE t1 IN SHARE MODE, t2 WRITE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't1'
 # Show t1 is read locked, t2 write locked.
 INSERT INTO t1 SELECT * FROM t2;
 ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
@@ -111,8 +111,8 @@ INSERT INTO t2 SELECT * FROM t1;
 # Lock t1 exclusive (converted to write), t2 share (converted to read).
 LOCK TABLE t1 IN EXCLUSIVE MODE, t2 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 # Show t1 is write locked, t2 read locked.
 INSERT INTO t1 SELECT * FROM t2;
 INSERT INTO t2 SELECT * FROM t1;
@@ -136,8 +136,8 @@ ERROR HY000: Cannot convert to non-trans
 ## Error is reported on first table only. Show both errors:
 SHOW WARNINGS;
 Level	Code	Message
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't1'
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't2'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't1'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't2'
 UNLOCK TABLES;
 SET @@SQL_MODE= @wl3561_save_sql_mode;
 #
@@ -157,7 +157,7 @@ CREATE TABLE t4 (c4 INT) ENGINE= MyISAM;
 # Request a transactional lock, which is converted to non-transactional.
 LOCK TABLE t4 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Try a conflict with the existing non-transactional lock.
 INSERT INTO t4 VALUES(444);
 ERROR HY000: Table 't4' was locked with a READ lock and can't be updated
@@ -174,8 +174,8 @@ CREATE VIEW v1 AS SELECT * FROM t3, t4 W
 # Request a share lock on the view, which is converted to read locks.
 LOCK TABLE v1 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Show that read locks on the base tables prohibit writing ...
 INSERT INTO t3 SELECT * FROM t4;
 ERROR HY000: Table 't3' was locked with a READ lock and can't be updated
@@ -191,7 +191,7 @@ COUNT(*)
 ## Report conversion on view due to existing non-transactional locks.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'v1'
+Warning	1639	Converted to non-transactional lock on 'v1'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);
@@ -200,8 +200,8 @@ UNLOCK TABLES;
 ## Now report conversion on base table again.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);

=== modified file 'mysql-test/r/locktrans_myisam.result'
--- a/mysql-test/r/locktrans_myisam.result	2009-06-04 14:08:54 +0000
+++ b/mysql-test/r/locktrans_myisam.result	2009-07-31 17:53:36 +0000
@@ -21,8 +21,8 @@ UNLOCK TABLES;
 # Valid syntax for transactional locks.
 LOCK TABLE t1 IN SHARE MODE, t2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 UNLOCK TABLES;
 #
 # Valid syntax for aliases with and without 'AS'.
@@ -30,19 +30,19 @@ LOCK TABLE t1 AS a1 READ, t2 a2 WRITE;
 UNLOCK TABLES;
 LOCK TABLE t1 AS a1 IN SHARE MODE, t2 a2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'a1'
-Warning	1637	Converted to non-transactional lock on 'a2'
+Warning	1639	Converted to non-transactional lock on 'a1'
+Warning	1639	Converted to non-transactional lock on 'a2'
 UNLOCK TABLES;
 #
 # Transactional locks taken on a view.
 CREATE VIEW v1 AS SELECT * FROM t1, t2 WHERE t1.c1 = t2.c2;
 LOCK TABLE v1 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'v1'
+Warning	1639	Converted to non-transactional lock on 'v1'
 UNLOCK TABLES;
 DROP VIEW v1;
 #
@@ -95,12 +95,12 @@ ERROR 42000: You have an error in your S
 # Implicit lock method conversion due to mix in statement.
 LOCK TABLE t1 READ, t2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't2'
 UNLOCK TABLES;
 # Lock t1 share (converted to read), t2 write.
 LOCK TABLE t1 IN SHARE MODE, t2 WRITE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't1'
 # Show t1 is read locked, t2 write locked.
 INSERT INTO t1 SELECT * FROM t2;
 ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
@@ -111,8 +111,8 @@ INSERT INTO t2 SELECT * FROM t1;
 # Lock t1 exclusive (converted to write), t2 share (converted to read).
 LOCK TABLE t1 IN EXCLUSIVE MODE, t2 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 # Show t1 is write locked, t2 read locked.
 INSERT INTO t1 SELECT * FROM t2;
 INSERT INTO t2 SELECT * FROM t1;
@@ -136,8 +136,8 @@ ERROR HY000: Cannot convert to non-trans
 ## Error is reported on first table only. Show both errors:
 SHOW WARNINGS;
 Level	Code	Message
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't1'
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't2'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't1'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't2'
 UNLOCK TABLES;
 SET @@SQL_MODE= @wl3561_save_sql_mode;
 #
@@ -157,7 +157,7 @@ CREATE TABLE t4 (c4 INT) ENGINE= MyISAM;
 # Request a transactional lock, which is converted to non-transactional.
 LOCK TABLE t4 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Try a conflict with the existing non-transactional lock.
 INSERT INTO t4 VALUES(444);
 ERROR HY000: Table 't4' was locked with a READ lock and can't be updated
@@ -174,8 +174,8 @@ CREATE VIEW v1 AS SELECT * FROM t3, t4 W
 # Request a share lock on the view, which is converted to read locks.
 LOCK TABLE v1 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Show that read locks on the base tables prohibit writing ...
 INSERT INTO t3 SELECT * FROM t4;
 ERROR HY000: Table 't3' was locked with a READ lock and can't be updated
@@ -191,7 +191,7 @@ COUNT(*)
 ## Report conversion on view due to existing non-transactional locks.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'v1'
+Warning	1639	Converted to non-transactional lock on 'v1'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);
@@ -200,8 +200,8 @@ UNLOCK TABLES;
 ## Now report conversion on base table again.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);

=== modified file 'mysql-test/r/merge.result'
--- a/mysql-test/r/merge.result	2009-07-16 08:00:34 +0000
+++ b/mysql-test/r/merge.result	2009-07-31 04:03:41 +0000
@@ -2015,6 +2015,52 @@ insert into m1 (col1) values (1);
 insert into m1 (col1) values (1);
 ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
 drop table m1, t1;
+#
+# Bug#45800 crash when replacing into a merge table and there is a duplicate
+#
+# Replace duplicate value in child table when merge table doesn't have key
+CREATE TABLE t1 (c1 INT PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE m1 (c1 INT NOT NULL) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+INSERT INTO m1  VALUES (666);
+SELECT * FROM m1;
+c1
+666
+# insert the duplicate value into the merge table
+REPLACE INTO m1 VALUES (666);
+SELECT * FROM m1;
+c1
+666
+DROP TABLE m1, t1;
+# Insert... on duplicate key update (with duplicate values in the table)
+CREATE TABLE t1 (c1 INT PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE m1 (c1 INT NOT NULL) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+INSERT INTO m1  VALUES (666);
+SELECT * FROM m1;
+c1
+666
+# insert the duplicate value into the merge table
+INSERT INTO m1 VALUES (666) ON DUPLICATE KEY UPDATE c1=c1+1;
+SELECT * FROM m1;
+c1
+667
+DROP TABLE m1, t1;
+# Insert duplicate value on MERGE table, where, MERGE has a key but MyISAM has more keys
+CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE (c1), UNIQUE (c2));
+CREATE TABLE m1 (c1 INT, c2 INT, UNIQUE (c1)) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+INSERT INTO m1 VALUES (1,2);
+# insert the duplicate value into the merge table
+INSERT INTO m1 VALUES (3,2);
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+DROP TABLE m1,t1;
+# Try to define MERGE and MyISAM with keys on different columns
+CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE (c1));
+CREATE TABLE m1 (c1 INT, c2 INT, UNIQUE (c2)) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+# Try accessing the merge table for inserts (error occurs)
+INSERT INTO m1 VALUES (1,2);
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
+INSERT INTO m1 VALUES (1,4);
+ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
+DROP TABLE m1,t1;
 CREATE TABLE t1 (
 col1 INT(10)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

=== modified file 'mysql-test/r/myisam.result'
--- a/mysql-test/r/myisam.result	2009-06-02 13:04:43 +0000
+++ b/mysql-test/r/myisam.result	2009-07-29 10:25:07 +0000
@@ -2243,16 +2243,6 @@ Key Start Len Index   Type
 1   2     30  multip. varchar              
 2   33    30  multip. char NULL            
 DROP TABLE t1;
-create table t1 (n int not null, c char(1)) transactional=1;
-Warnings:
-Warning	1478	Table storage engine 'MyISAM' does not support the create option 'TRANSACTIONAL=1'
-show create table t1;
-Table	Create Table
-t1	CREATE TABLE `t1` (
-  `n` int(11) NOT NULL,
-  `c` char(1) DEFAULT NULL
-) ENGINE=MyISAM DEFAULT CHARSET=latin1 TRANSACTIONAL=1
-drop table t1;
 CREATE TABLE t1 (line LINESTRING NOT NULL) engine=myisam;
 INSERT INTO t1 VALUES (GeomFromText("POINT(0 0)"));
 checksum table t1;

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	2009-07-14 17:16:51 +0000
+++ b/mysql-test/r/mysql.result	2009-08-01 00:07:31 +0000
@@ -405,5 +405,27 @@ Error (Code 1050): Table 't2' already ex
 drop tables t1, t2;
 Variable_name	Value
 lc_messages	ru_RU
-<TABLE BORDER=1><TR><TH>&lt;</TH></TR><TR><TD>&lt; &amp; &gt;</TD></TR></TABLE>
+<TABLE BORDER=1><TR><TH>&lt;</TH></TR><TR><TD>&lt;
> &amp; &gt;</TD></TR></TABLE>create table t1 (a char(5));
+insert into t1 values ('\0b\0');
+a
+\0b\0
+a
+\0b\0
++------+
+| a    |
++------+
+|  b   |
++------+
+*************************** 1. row ***************************
+a:  b 
+<TABLE BORDER=1><TR><TH>a</TH></TR><TR><TD> b
> </TD></TR></TABLE><?xml version="1.0"?>
+
+<resultset statement="select a from t1
+" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <row>
+	<field name="a"> b </field>
+  </row>
+</resultset>
+drop table t1;
+
 End of tests

=== modified file 'mysql-test/r/mysqldump.result'
--- a/mysql-test/r/mysqldump.result	2009-07-14 17:16:51 +0000
+++ b/mysql-test/r/mysqldump.result	2009-07-31 17:53:36 +0000
@@ -4504,5 +4504,64 @@ DROP PROCEDURE IF EXISTS pr1;
 DROP TRIGGER IF EXISTS tr1;
 DROP TABLE IF EXISTS t1;
 #
+# Bug #30946: mysqldump silently ignores --default-character-set
+#             when used with --tab
+#
+# Also see outfile_loaddata.test
+#
+SET NAMES utf8;
+CREATE TABLE t1 (a INT, b CHAR(10) CHARSET koi8r, c CHAR(10) CHARSET latin1);
+CREATE TABLE t2 LIKE t1;
+INSERT INTO t1 VALUES (1, 'ABC-АБВ', 'DEF-ÂÃÄ'), (2, NULL, NULL);
+# error on multi-character ENCLOSED/ESCAPED BY
+# default '--default-charset' (binary):
+##################################################
+1	ABC-�	DEF-��+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+# utf8:
+##################################################
+1	ABC-АБВ	DEF-ÂÃÄ
+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET utf8;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+# latin1 (data corruption is expected):
+##################################################
+1	ABC-???	DEF-��+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET latin1 ;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-???	DEF-ÂÃÄ
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+# koi8r (data corruption is expected):
+##################################################
+1	ABC-�	DEF-???
+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET koi8r;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-???
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+SET NAMES default;
+DROP TABLE t1, t2;
+#
 # End of 5.1 tests
 #

=== modified file 'mysql-test/r/outfile_loaddata.result'
--- a/mysql-test/r/outfile_loaddata.result	2007-11-20 16:15:20 +0000
+++ b/mysql-test/r/outfile_loaddata.result	2009-07-31 17:14:52 +0000
@@ -91,13 +91,152 @@ SELECT HEX(c1) FROM t1;
 HEX(c1)
 C3
 SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug32533.txt' FIELDS ENCLOSED BY 0xC3 FROM t1;
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
 TRUNCATE t1;
 SELECT HEX(LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug32533.txt'));
 HEX(LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug32533.txt'))
 C35CC3C30A
 LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug32533.txt' INTO TABLE t1 FIELDS ENCLOSED BY 0xC3;
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
 SELECT HEX(c1) FROM t1;
 HEX(c1)
 C3
 DROP TABLE t1;
 # End of 5.0 tests.
+#
+# Bug #30946: mysqldump silently ignores --default-character-set
+#             when used with --tab
+#
+# Also see mysqldump.test
+#
+SET NAMES utf8;
+CREATE TABLE t1 (a INT, b CHAR(10) CHARSET koi8r, c CHAR(10) CHARSET latin1);
+CREATE TABLE t2 LIKE t1;
+INSERT INTO t1 VALUES (1, 'ABC-АБВ', 'DEF-ÂÃÄ'), (2, NULL, NULL);
+# Error on multi-character ENCLOSED/ESCAPED BY
+SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS ENCLOSED BY '12345';
+ERROR 42000: Field separator argument is not what is expected; check the manual
+SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS ESCAPED BY '12345';
+ERROR 42000: Field separator argument is not what is expected; check the manual
+# "Not implemented" warning on multibyte  ENCLOSED/ESCAPED BY character,
+# LOAD DATA rises error or has unpredictable result -- to be fixed later
+SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS ENCLOSED BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary FIELDS ENCLOSED BY 'ъ';
+ERROR 42000: Field separator argument is not what is expected; check the manual
+SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS ESCAPED BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary FIELDS ESCAPED BY 'ъ';
+ERROR 42000: Field separator argument is not what is expected; check the manual
+SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS TERMINATED BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+##################################################
+1ъABC-�ъDEF-��+2ъ\Nъ\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary FIELDS TERMINATED BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1265	Data truncated for column 'a' at row 1
+Warning	1261	Row 1 doesn't contain data for all columns
+Warning	1261	Row 1 doesn't contain data for all columns
+Warning	1265	Data truncated for column 'a' at row 2
+Warning	1261	Row 2 doesn't contain data for all columns
+Warning	1261	Row 2 doesn't contain data for all columns
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	NULL	NULL
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' LINES STARTING BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+##################################################
+ъ1	ABC-�	DEF-��+ъ2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary LINES STARTING BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' LINES TERMINATED BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+##################################################
+1	ABC-�	DEF-���2	\N	\Nъ##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary LINES TERMINATED BY 'ъ';
+Warnings:
+Warning	1638	Non-ASCII separator arguments are not fully supported
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-ÂÃÄ
+1	ABC-АБВ	DEF-ÂÃÄÑŠ2
+2	NULL	NULL
+# Default (binary) charset:
+SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FROM t1;
+##################################################
+1	ABC-�	DEF-��+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-ÂÃ expected):
+SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' CHARACTER SET latin1 FROM t1;
+Warnings:
+Warning	1366	Incorrect string value: '\xE1\xE2\xF7' for column 'b' at row 1
+##################################################
+1	ABC-???	DEF-��+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET latin1 ;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-???	DEF-ÂÃÄ
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+# KOI8-R charset (INTO OUTFILE warning is expected):
+SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' CHARACTER SET koi8r FROM t1;
+Warnings:
+Warning	1366	Incorrect string value: '\xC2\xC3\xC4' for column 'c' at row 1
+##################################################
+1	ABC-�	DEF-???
+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET koi8r;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-???
+1	ABC-АБВ	DEF-ÂÃÄ
+2	NULL	NULL
+# UTF-8 charset:
+SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' CHARACTER SET utf8 FROM t1;
+##################################################
+1	ABC-АБВ	DEF-ÂÃÄ
+2	\N	\N
+##################################################
+TRUNCATE t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET utf8;
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+a	b	c
+1	ABC-АБВ	DEF-;
+# End of 5.1 tests.

=== modified file 'mysql-test/r/partition.result'
--- a/mysql-test/r/partition.result	2009-07-02 15:51:04 +0000
+++ b/mysql-test/r/partition.result	2009-08-06 12:41:22 +0000
@@ -1,5 +1,36 @@
-SET @old_general_log= @@global.general_log;
 drop table if exists t1, t2;
+create table t1 (a int NOT NULL, b varchar(5) NOT NULL)
+default charset=utf8
+partition by list (a)
+subpartition by key (b)
+(partition p0 values in (1),
+partition p1 values in (2));
+drop table t1;
+create table t1 (a int, b int, key(a))
+partition by list (a)
+subpartition by key (b)
+(partition p0 values in (1),
+partition p1 values in (2));
+insert into t1 values (1,1),(2,1),(2,2),(2,3);
+show indexes from t1;
+Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_Comment
+t1	1	a	1	a	A	NULL	NULL	NULL	YES	BTREE		
+analyze table t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	OK
+show indexes from t1;
+Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_Comment
+t1	1	a	1	a	A	1	NULL	NULL	YES	BTREE		
+drop table t1;
+create table t1 (a int)
+partition by hash (a);
+create index i on t1 (a);
+insert into t1 values (1);
+insert into t1 select * from t1;
+create index i on t1 (a);
+ERROR 42000: Duplicate key name 'i'
+create index i2 on t1 (a);
+drop table t1;
 CREATE TABLE t1 (a INT, FOREIGN KEY (a) REFERENCES t0 (a))
 ENGINE=MyISAM
 PARTITION BY HASH (a);
@@ -1120,7 +1151,13 @@ partition by range (a)
 subpartition by hash(a)
 (partition p0 values less than (0),
 partition p1 values less than (1) (subpartition sp0));
-ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '))' at line 5
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'subpartition sp0))' at line 5
+create table t1 (a int, b int)
+partition by list (a)
+subpartition by hash(a)
+(partition p0 values in (0),
+partition p1 values in (1) (subpartition sp0));
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'subpartition sp0))' at line 5
 create table t1 (a int)
 partition by hash (a)
 (partition p0 (subpartition sp0));
@@ -1672,17 +1709,6 @@ create table t (s1 int) engine=myisam pa
 create trigger t_ad after delete on t for each row insert into t values (old.s1);
 insert into t values (1);
 drop table t;
-USE mysql;
-TRUNCATE TABLE general_log;
-SET @old_general_log_state = @@global.general_log;
-SET GLOBAL general_log = 0;
-ALTER TABLE general_log ENGINE = MyISAM;
-ALTER TABLE general_log PARTITION BY RANGE (TO_DAYS(event_time))
-(PARTITION p0 VALUES LESS THAN (733144), PARTITION p1 VALUES LESS THAN (3000000));
-ERROR HY000: Incorrect usage of PARTITION and log table
-ALTER TABLE general_log ENGINE = CSV;
-SET GLOBAL general_log = @old_general_log_state;
-use test;
 create table t2 (b int);
 create table t1 (b int)
 PARTITION BY RANGE (t2.b) (
@@ -2042,5 +2068,23 @@ CREATE TABLE t1(id INT,KEY(id)) ENGINE=M
 PARTITION BY HASH(id) PARTITIONS 2;
 DROP TABLE t1;
 SET SESSION SQL_MODE=DEFAULT;
+#
+# BUG#45816 - assertion failure with index containing double 
+#             column on partitioned table
+#
+CREATE TABLE t1 (
+a INT DEFAULT NULL,
+b DOUBLE DEFAULT NULL,
+c INT DEFAULT NULL,
+KEY idx2(b,a)
+) PARTITION BY HASH(c) PARTITIONS 3;
+INSERT INTO t1 VALUES (6,8,9);
+INSERT INTO t1 VALUES (6,8,10);
+SELECT  1 FROM t1 JOIN t1 AS t2 USING (a) FOR UPDATE;
+1
+1
+1
+1
+1
+DROP TABLE t1;
 End of 5.1 tests
-SET @@global.general_log= @old_general_log;

=== modified file 'mysql-test/r/partition_csv.result'
--- a/mysql-test/r/partition_csv.result	2007-10-22 18:10:51 +0000
+++ b/mysql-test/r/partition_csv.result	2009-07-31 23:39:26 +0000
@@ -5,11 +5,50 @@ partition by list (a)
 (partition p0 values in (null));
 ERROR HY000: Engine cannot be used in partitioned tables
 USE mysql;
+TRUNCATE TABLE general_log;
+SET @old_general_log_state = @@global.general_log;
 SET GLOBAL general_log = 0;
 ALTER TABLE general_log ENGINE = MyISAM;
 ALTER TABLE general_log PARTITION BY RANGE (TO_DAYS(event_time))
-(PARTITION p0 VALUES LESS THAN (733144),
-PARTITION p1 VALUES LESS THAN (3000000));
+(PARTITION p0 VALUES LESS THAN (733144), PARTITION p1 VALUES LESS THAN (3000000));
 ERROR HY000: Incorrect usage of PARTITION and log table
 ALTER TABLE general_log ENGINE = CSV;
+SET GLOBAL general_log = @old_general_log_state;
+use test;
+#
+# Bug#40281: partitioning the general log table crashes the server
+#
+# set up partitioned log, and switch to it
+USE mysql;
+SET @old_general_log_state = @@global.general_log;
+SET GLOBAL general_log = 0;
+CREATE TABLE gl_partitioned LIKE general_log;
+ALTER TABLE gl_partitioned ENGINE=myisam;
+ALTER TABLE gl_partitioned PARTITION BY HASH (thread_id) PARTITIONS 10;
+ALTER TABLE general_log RENAME TO gl_nonpartitioned;
+ALTER TABLE gl_partitioned RENAME TO general_log;
+SELECT @@global.log_output INTO @old_glo;
+SET GLOBAL log_output='table';
+SET GLOBAL general_log =1;
+# do some things to be logged to partitioned log, should fail
+USE /* 1 */ test;
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1);
+SELECT * FROM t1;
+i
+1
+USE mysql;
+SET GLOBAL general_log =0;
+ALTER TABLE general_log RENAME TO gl_partitioned;
+ALTER TABLE gl_nonpartitioned RENAME TO general_log;
+# show whether we actually logged anything (no) to general_log
+SELECT COUNT(argument) FROM gl_partitioned;
+COUNT(argument)
+0
+DROP TABLE gl_partitioned;
+SET GLOBAL log_output = @old_glo;
 SET GLOBAL general_log = 1;
+USE /* 2 */ test;
+DROP TABLE t1;
+SET GLOBAL general_log = @old_general_log_state;
+End of 5.1 tests

=== modified file 'mysql-test/r/partition_error.result'
--- a/mysql-test/r/partition_error.result	2009-02-20 12:37:37 +0000
+++ b/mysql-test/r/partition_error.result	2009-07-23 15:41:27 +0000
@@ -1,4 +1,9 @@
 drop table if exists t1;
+CREATE TABLE t1 (a int, b int) PARTITION BY HASH (a) PARTITIONS 2;
+INSERT INTO t1 VALUES (1,2);
+INSERT INTO t1 (a) SELECT * FROM t1;
+ERROR 21S01: Column count doesn't match value count at row 1
+DROP TABLE t1;
 CREATE TABLE t1 (a INTEGER NOT NULL, PRIMARY KEY (a));
 INSERT INTO t1 VALUES (1),(1);
 ERROR 23000: Duplicate entry '1' for key 'PRIMARY'

=== added file 'mysql-test/r/partition_not_embedded.result'
--- a/mysql-test/r/partition_not_embedded.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/partition_not_embedded.result	2009-07-27 11:20:43 +0000
@@ -0,0 +1,81 @@
+DROP TABLE IF EXISTS t1, t2;
+# Bug#30102 test
+CREATE TABLE t1 (a INT)
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (6),
+PARTITION `p1....................` VALUES LESS THAN (9),
+PARTITION p2 VALUES LESS THAN MAXVALUE);
+# List of files in database `test`, all original t1-files here
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p2.MYD
+t1#P#p2.MYI
+t1.frm
+t1.par
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
+# Renaming to a file name where the first partition is 250 chars
+# and the second partition is 350 chars
+RENAME TABLE t1 TO `t2_new..............................................end`;
+Got one of the listed errors
+# List of files in database `test`, should not be any t2-files here
+# List of files in database `test`, should be all t1-files here
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p2.MYD
+t1#P#p2.MYI
+t1.frm
+t1.par
+SELECT * FROM t1;
+a
+1
+10
+2
+3
+4
+5
+6
+7
+8
+9
+# List of files in database `test`, should be all t1-files here
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p2.MYD
+t1#P#p2.MYI
+t1.frm
+t1.par
+# Renaming to a file name where the first partition is 156 chars
+# and the second partition is 256 chars
+RENAME TABLE t1 TO `t2_............................_end`;
+Got one of the listed errors
+# List of files in database `test`, should not be any t2-files here
+# List of files in database `test`, should be all t1-files here
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p2.MYD
+t1#P#p2.MYI
+t1.frm
+t1.par
+SELECT * FROM t1;
+a
+1
+10
+2
+3
+4
+5
+6
+7
+8
+9
+DROP TABLE t1;
+# Should not be any files left here
+# End of bug#30102 test.

=== added file 'mysql-test/r/partition_rename_longfilename.result'
--- a/mysql-test/r/partition_rename_longfilename.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/partition_rename_longfilename.result	2009-07-27 11:20:43 +0000
@@ -0,0 +1,66 @@
+DROP TABLE IF EXISTS t1, t2;
+CREATE TABLE t1 (a INT)
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (6),
+PARTITION `p1....................` VALUES LESS THAN (9),
+PARTITION p2 VALUES LESS THAN MAXVALUE);
+# List of files in database `test`, all original t1-files here
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p2.MYD
+t1#P#p2.MYI
+t1.frm
+t1.par
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
+# Renaming to a file name where the first partition is 155 chars
+# and the second partition is 255 chars
+RENAME TABLE t1 TO `t2_............................end`;
+# List of files in database `test`, should not be any t1-files here
+# List of files in database `test`, should be all t2-files here
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002eend#P#p0.MYD
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002eend#P#p0.MYI
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002eend#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002eend#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002eend#P#p2.MYD
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002eend#P#p2.MYI
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t2_@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002eend.par
+SELECT * FROM `t2_............................end`;
+a
+1
+10
+2
+3
+4
+5
+6
+7
+8
+9
+RENAME TABLE `t2_............................end` to t1;
+# List of files in database `test`, should be all t1-files here
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@stripped
+t1#P#p1@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e@002e.MYI
+t1#P#p2.MYD
+t1#P#p2.MYI
+t1.frm
+t1.par
+SELECT * FROM t1;
+a
+1
+10
+2
+3
+4
+5
+6
+7
+8
+9
+DROP TABLE t1;
+# Should not be any files left here
+# End of bug#30102 test.

=== modified file 'mysql-test/r/show_check.result'
--- a/mysql-test/r/show_check.result	2009-06-16 07:41:38 +0000
+++ b/mysql-test/r/show_check.result	2009-07-27 15:57:53 +0000
@@ -1442,3 +1442,5 @@ SHOW ENGINE MYISAM MUTEX;
 SHOW ENGINE MYISAM STATUS;
 DROP USER test_u@localhost;
 End of 5.1 tests
+SHOW VARIABLES LIKE 'deadlock%';
+Variable_name	Value

=== modified file 'mysql-test/r/signal.result'
--- a/mysql-test/r/signal.result	2009-07-03 05:54:09 +0000
+++ b/mysql-test/r/signal.result	2009-07-31 17:53:36 +0000
@@ -580,7 +580,7 @@ SIGNAL foo;
 ERROR 42000: Undefined CONDITION: foo
 SIGNAL SQLSTATE '01000';
 Warnings:
-Warning	1778	Unhandled user-defined warning condition
+Warning	1780	Unhandled user-defined warning condition
 SIGNAL SQLSTATE '02000';
 ERROR 02000: Unhandled user-defined not found condition
 SIGNAL SQLSTATE '23000';
@@ -694,7 +694,7 @@ SIGNAL warn;
 end $$
 call test_signal() $$
 Warnings:
-Warning	1778	Unhandled user-defined warning condition
+Warning	1780	Unhandled user-defined warning condition
 drop procedure test_signal $$
 create procedure test_signal()
 begin
@@ -704,7 +704,7 @@ SIGNAL warn;
 end $$
 call test_signal() $$
 Warnings:
-Warning	1778	Unhandled user-defined warning condition
+Warning	1780	Unhandled user-defined warning condition
 drop procedure test_signal $$
 create procedure test_signal()
 begin
@@ -853,7 +853,7 @@ SIGNAL warn SET MESSAGE_TEXT = "Somethin
 end $$
 call test_signal() $$
 Warnings:
-Warning	1778	Something bad happened
+Warning	1780	Something bad happened
 drop procedure test_signal $$
 create procedure test_signal()
 begin
@@ -878,7 +878,7 @@ SIGNAL something SET MESSAGE_TEXT = _utf
 end $$
 call test_signal() $$
 Warnings:
-Warning	1778	This is a UTF8 text
+Warning	1780	This is a UTF8 text
 drop procedure test_signal $$
 create procedure test_signal()
 begin
@@ -887,7 +887,7 @@ SIGNAL something SET MESSAGE_TEXT = "";
 end $$
 call test_signal() $$
 Warnings:
-Warning	1778	
+Warning	1780	
 drop procedure test_signal $$
 create procedure test_signal()
 begin
@@ -896,10 +896,10 @@ SIGNAL warn SET MESSAGE_TEXT = "á a";
 end $$
 call test_signal() $$
 Warnings:
-Warning	1778	á a
+Warning	1780	á a
 show warnings $$
 Level	Code	Message
-Warning	1778	á a
+Warning	1780	á a
 drop procedure test_signal $$
 #
 # Test SET complex expressions
@@ -1162,17 +1162,17 @@ MYSQL_ERRNO = 10000;
 end $$
 call test_signal() $$
 Warnings:
-Warning	1783	Data truncated for condition item 'CLASS_ORIGIN'
-Warning	1783	Data truncated for condition item 'SUBCLASS_ORIGIN'
-Warning	1783	Data truncated for condition item 'CONSTRAINT_CATALOG'
-Warning	1783	Data truncated for condition item 'CONSTRAINT_SCHEMA'
-Warning	1783	Data truncated for condition item 'CONSTRAINT_NAME'
-Warning	1783	Data truncated for condition item 'CATALOG_NAME'
-Warning	1783	Data truncated for condition item 'SCHEMA_NAME'
-Warning	1783	Data truncated for condition item 'TABLE_NAME'
-Warning	1783	Data truncated for condition item 'COLUMN_NAME'
-Warning	1783	Data truncated for condition item 'CURSOR_NAME'
-Warning	1783	Data truncated for condition item 'MESSAGE_TEXT'
+Warning	1785	Data truncated for condition item 'CLASS_ORIGIN'
+Warning	1785	Data truncated for condition item 'SUBCLASS_ORIGIN'
+Warning	1785	Data truncated for condition item 'CONSTRAINT_CATALOG'
+Warning	1785	Data truncated for condition item 'CONSTRAINT_SCHEMA'
+Warning	1785	Data truncated for condition item 'CONSTRAINT_NAME'
+Warning	1785	Data truncated for condition item 'CATALOG_NAME'
+Warning	1785	Data truncated for condition item 'SCHEMA_NAME'
+Warning	1785	Data truncated for condition item 'TABLE_NAME'
+Warning	1785	Data truncated for condition item 'COLUMN_NAME'
+Warning	1785	Data truncated for condition item 'CURSOR_NAME'
+Warning	1785	Data truncated for condition item 'MESSAGE_TEXT'
 Warning	10000	11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222288888888
 drop procedure test_signal $$
 create procedure test_signal()

=== modified file 'mysql-test/r/signal_demo3.result'
--- a/mysql-test/r/signal_demo3.result	2009-06-04 14:28:56 +0000
+++ b/mysql-test/r/signal_demo3.result	2009-07-31 17:53:36 +0000
@@ -78,15 +78,15 @@ ERROR 45000: Oops in proc_1
 show warnings;
 Level	Code	Message
 Error	1051	Unknown table 'oops_it_is_not_here'
-Error	1780	Oops in proc_9
-Error	1780	Oops in proc_8
-Error	1780	Oops in proc_7
-Error	1780	Oops in proc_6
-Error	1780	Oops in proc_5
-Error	1780	Oops in proc_4
-Error	1780	Oops in proc_3
-Error	1780	Oops in proc_2
-Error	1780	Oops in proc_1
+Error	1782	Oops in proc_9
+Error	1782	Oops in proc_8
+Error	1782	Oops in proc_7
+Error	1782	Oops in proc_6
+Error	1782	Oops in proc_5
+Error	1782	Oops in proc_4
+Error	1782	Oops in proc_3
+Error	1782	Oops in proc_2
+Error	1782	Oops in proc_1
 SET @@session.max_error_count = 5;
 SELECT @@session.max_error_count;
 @@session.max_error_count
@@ -95,11 +95,11 @@ call proc_1();
 ERROR 45000: Oops in proc_1
 show warnings;
 Level	Code	Message
-Error	1780	Oops in proc_5
-Error	1780	Oops in proc_4
-Error	1780	Oops in proc_3
-Error	1780	Oops in proc_2
-Error	1780	Oops in proc_1
+Error	1782	Oops in proc_5
+Error	1782	Oops in proc_4
+Error	1782	Oops in proc_3
+Error	1782	Oops in proc_2
+Error	1782	Oops in proc_1
 SET @@session.max_error_count = 7;
 SELECT @@session.max_error_count;
 @@session.max_error_count
@@ -108,13 +108,13 @@ call proc_1();
 ERROR 45000: Oops in proc_1
 show warnings;
 Level	Code	Message
-Error	1780	Oops in proc_7
-Error	1780	Oops in proc_6
-Error	1780	Oops in proc_5
-Error	1780	Oops in proc_4
-Error	1780	Oops in proc_3
-Error	1780	Oops in proc_2
-Error	1780	Oops in proc_1
+Error	1782	Oops in proc_7
+Error	1782	Oops in proc_6
+Error	1782	Oops in proc_5
+Error	1782	Oops in proc_4
+Error	1782	Oops in proc_3
+Error	1782	Oops in proc_2
+Error	1782	Oops in proc_1
 SET @@session.max_error_count = 9;
 SELECT @@session.max_error_count;
 @@session.max_error_count
@@ -123,15 +123,15 @@ call proc_1();
 ERROR 45000: Oops in proc_1
 show warnings;
 Level	Code	Message
-Error	1780	Oops in proc_9
-Error	1780	Oops in proc_8
-Error	1780	Oops in proc_7
-Error	1780	Oops in proc_6
-Error	1780	Oops in proc_5
-Error	1780	Oops in proc_4
-Error	1780	Oops in proc_3
-Error	1780	Oops in proc_2
-Error	1780	Oops in proc_1
+Error	1782	Oops in proc_9
+Error	1782	Oops in proc_8
+Error	1782	Oops in proc_7
+Error	1782	Oops in proc_6
+Error	1782	Oops in proc_5
+Error	1782	Oops in proc_4
+Error	1782	Oops in proc_3
+Error	1782	Oops in proc_2
+Error	1782	Oops in proc_1
 drop database demo;
 SET @@global.max_error_count = @start_global_value;
 SELECT @@global.max_error_count;

=== modified file 'mysql-test/r/sp_notembedded.result'
--- a/mysql-test/r/sp_notembedded.result	2009-06-04 06:27:44 +0000
+++ b/mysql-test/r/sp_notembedded.result	2009-07-30 16:22:41 +0000
@@ -251,3 +251,25 @@ DROP PROCEDURE p1;
 DELETE FROM mysql.user WHERE User='mysqltest_1';
 FLUSH PRIVILEGES;
 set @@global.concurrent_insert= @old_concurrent_insert;
+#
+# Bug#44521 Prepared Statement: CALL p() - crashes: `! thd->main_da.is_sent' failed et.al.
+#
+SELECT GET_LOCK('Bug44521', 0);
+GET_LOCK('Bug44521', 0)
+1
+** Connection con1
+CREATE PROCEDURE p()
+BEGIN
+SELECT 1;
+SELECT GET_LOCK('Bug44521', 100);
+SELECT 2;
+END$
+CALL p();;
+** Default connection
+SELECT RELEASE_LOCK('Bug44521');
+RELEASE_LOCK('Bug44521')
+1
+DROP PROCEDURE p;
+# ------------------------------------------------------------------
+# -- End of 5.1 tests
+# ------------------------------------------------------------------

=== modified file 'mysql-test/r/sp_trans.result'
--- a/mysql-test/r/sp_trans.result	2009-02-19 14:10:58 +0000
+++ b/mysql-test/r/sp_trans.result	2009-07-29 08:27:59 +0000
@@ -554,3 +554,33 @@ f1	bug13575(f1)
 3	ccc
 drop function bug13575|
 drop table t3|
+#
+# End of 5.1 tests
+#
+# 
+# Bug #35877 Update .. WHERE with function, constraint violation, crash 
+#           
+DROP TABLE IF EXISTS t1_aux|
+DROP TABLE IF EXISTS t1_not_null|
+DROP FUNCTION IF EXISTS f1_two_inserts|
+# MyISAM test
+CREATE TABLE t1_not_null (f1 BIGINT, f2 BIGINT NOT NULL)|
+CREATE TABLE t1_aux (f1 BIGINT, f2 BIGINT)|
+INSERT INTO t1_aux VALUES (1,1)|
+CREATE FUNCTION f1_two_inserts() returns INTEGER
+BEGIN
+INSERT INTO t1_not_null SET f1 = 10, f2 = NULL;
+RETURN 1;
+END|
+UPDATE t1_aux SET f2 = 2 WHERE f1 = f1_two_inserts()|
+ERROR 23000: Column 'f2' cannot be null
+# InnoDB test
+ALTER TABLE t1_not_null ENGINE = InnoDB|
+ALTER TABLE t1_aux ENGINE = InnoDB|
+UPDATE t1_aux SET f2 = 2 WHERE f1 = f1_two_inserts()|
+ERROR 23000: Column 'f2' cannot be null
+DROP TABLE t1_aux, t1_not_null|
+DROP FUNCTION f1_two_inserts|
+#
+# End of 5.4 tests
+#

=== modified file 'mysql-test/std_data/init_file.dat'
--- a/mysql-test/std_data/init_file.dat	2007-02-19 13:57:54 +0000
+++ b/mysql-test/std_data/init_file.dat	2009-07-24 18:45:42 +0000
@@ -35,4 +35,11 @@ CREATE DATABASE IF NOT EXISTS init_file;
 CREATE TABLE IF NOT EXISTS init_file.startup ( startdate DATETIME );
 INSERT INTO init_file.startup VALUES ( NOW() );
 
+#
+# Bug#43587 "Putting event_scheduler=1 in init SQL file crashes mysqld"
+#
 
+SET GLOBAL event_scheduler = 'ON';
+CREATE EVENT ev1 ON SCHEDULE EVERY 1 DAY DISABLE DO SELECT 1;
+DROP EVENT ev1;
+SET GLOBAL event_scheduler = 'OFF';

=== added file 'mysql-test/std_data/loadxml2.dat'
--- a/mysql-test/std_data/loadxml2.dat	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/loadxml2.dat	2009-07-30 11:32:37 +0000
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+<database name="test_of_xml_import">
+	<table_structure name="t1">
+		<field Field="id" Type="int(11)" Null="NO" Key="PRI" Extra="" />
+		<field Field="text" Type="text" Null="YES" Key="" Extra="" />
+		<key Table="t1" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="id" Collation="A" Cardinality="1" Null="" Index_type="BTREE" Comment="" Index_Comment="" />
+		<options Name="t1" Engine="MyISAM" Version="10" Row_format="Dynamic" Rows="1" Avg_row_length="32" Data_length="32" Max_data_length="281474976710655" Index_length="2048" Data_free="0" Create_time="2009-06-18 10:02:37" Update_time="2009-06-18 10:02:43" Collation="latin1_swedish_ci" Create_options="" Comment="" />
+	</table_structure>
+	<table_data name="t1">
+	<row>
+		<field name="id">1</field>
+		<field name="text">line1
+line2
+line3</field>
+	</row>
+	</table_data>
+</database>
+</mysqldump>

=== modified file 'mysql-test/suite/backup/r/backup_db_grants.result'
--- a/mysql-test/suite/backup/r/backup_db_grants.result	2009-07-01 20:42:26 +0000
+++ b/mysql-test/suite/backup/r/backup_db_grants.result	2009-07-31 21:19:23 +0000
@@ -70,26 +70,26 @@ RESTORE FROM 'bup_db_grants.bak' OVERWRI
 backup_id
 #
 Warnings:
-#	1752	The grant 'ALTER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'ALTER ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'BACKUP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE TEMPORARY TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'DELETE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'DROP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'EVENT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'EXECUTE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'INDEX ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'INSERT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'LOCK TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'REFERENCES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'RESTORE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'SELECT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'SHOW VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'TRIGGER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'UPDATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'ALTER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'ALTER ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'BACKUP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE TEMPORARY TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'DELETE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'DROP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'EVENT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'EXECUTE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'INDEX ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'INSERT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'LOCK TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'REFERENCES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'RESTORE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'SELECT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'SHOW VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'TRIGGER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'UPDATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
 SHOW TABLES FROM bup_db_grants;
 Tables_in_bup_db_grants
 s1
@@ -123,29 +123,29 @@ RESTORE FROM 'bup_db_grants.bak' OVERWRI
 backup_id
 #
 Warnings:
-#	1752	The grant 'INSERT ON bup_db_grants.*' for the user 'bup_user2'@'%' was skipped because the user does not exist.
-#	1752	The grant 'INSERT(b) ON bup_db_grants.s1' for the user 'bup_user2'@'%' was skipped because the user does not exist.
-#	1752	The grant 'SELECT(b) ON bup_db_grants.s1' for the user 'bup_user2'@'%' was skipped because the user does not exist.
-#	1752	The grant 'ALTER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'ALTER ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'BACKUP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE TEMPORARY TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'CREATE VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'DELETE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'DROP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'EVENT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'EXECUTE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'INDEX ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'INSERT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'LOCK TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'REFERENCES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'RESTORE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'SELECT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'SHOW VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'TRIGGER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
-#	1752	The grant 'UPDATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'INSERT ON bup_db_grants.*' for the user 'bup_user2'@'%' was skipped because the user does not exist.
+#	1754	The grant 'INSERT(b) ON bup_db_grants.s1' for the user 'bup_user2'@'%' was skipped because the user does not exist.
+#	1754	The grant 'SELECT(b) ON bup_db_grants.s1' for the user 'bup_user2'@'%' was skipped because the user does not exist.
+#	1754	The grant 'ALTER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'ALTER ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'BACKUP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE ROUTINE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE TEMPORARY TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'CREATE VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'DELETE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'DROP ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'EVENT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'EXECUTE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'INDEX ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'INSERT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'LOCK TABLES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'REFERENCES ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'RESTORE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'SELECT ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'SHOW VIEW ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'TRIGGER ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
+#	1754	The grant 'UPDATE ON bup_db_grants.*' for the user 'no_user'@'%' was skipped because the user does not exist.
 SHOW TABLES FROM bup_db_grants;
 Tables_in_bup_db_grants
 s1

=== modified file 'mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result	2009-06-27 13:18:47 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result	2009-07-31 13:00:35 +0000
@@ -28,3 +28,23 @@ UPDATE t1 SET b='4' WHERE a=1 LIMIT 1;
 UPDATE t1 SET b='5' WHERE a=2 ORDER BY a LIMIT 1;
 DROP TABLE t1;
 DROP DATABASE b42851;
+USE test;
+#
+# Bug#46265: Can not disable warning about unsafe statements for binary logging
+#
+SET @old_log_warnings = @@log_warnings;
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(10));
+SET GLOBAL LOG_WARNINGS = 0;
+INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+Warnings:
+Note	1592	Statement may not be safe to log in statement format.
+SET GLOBAL LOG_WARNINGS = 1;
+INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+Warnings:
+Note	1592	Statement may not be safe to log in statement format.
+DROP TABLE t1;
+SET GLOBAL log_warnings = @old_log_warnings;
+# Count the number of times the "Unsafe" message was printed
+# to the error log.
+Occurrences: 1

=== modified file 'mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt'
--- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt	2009-06-27 13:18:47 +0000
+++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning-master.opt	2009-07-31 13:00:35 +0000
@@ -1 +1 @@
---binlog-ignore-db=b42851
+--binlog-ignore-db=b42851 --log-error

=== modified file 'mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test'
--- a/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test	2009-06-27 13:18:47 +0000
+++ b/mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test	2009-07-31 13:00:35 +0000
@@ -56,6 +56,8 @@ SET SQL_LOG_BIN= 1;
 
 -- echo ### FILTERED database => assertion: warnings ARE NOT shown
 
+let $old_db= `SELECT DATABASE()`;
+
 CREATE DATABASE b42851;
 USE b42851;
 
@@ -71,3 +73,36 @@ DROP TABLE t1;
 
 # clean up
 DROP DATABASE b42851;
+
+eval USE $old_db;
+
+--echo #
+--echo # Bug#46265: Can not disable warning about unsafe statements for binary logging
+--echo #
+
+SET @old_log_warnings = @@log_warnings;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+CREATE TABLE t1 (a VARCHAR(36), b VARCHAR(10));
+SET GLOBAL LOG_WARNINGS = 0;
+INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+SET GLOBAL LOG_WARNINGS = 1;
+INSERT INTO t1 VALUES(UUID(), 'Bug#46265');
+DROP TABLE t1;
+
+SET GLOBAL log_warnings = @old_log_warnings;
+
+let LOG_ERROR= `SELECT @@GLOBAL.log_error`;
+
+--echo # Count the number of times the "Unsafe" message was printed
+--echo # to the error log.
+
+perl;
+  $log_error= $ENV{'LOG_ERROR'};
+  open(FILE, "$log_error") or die("Unable to open $log_error: $!\n");
+  $count = () = grep(/Bug#46265/g,<FILE>);
+  print "Occurrences: $count\n";
+  close(FILE);
+EOF

=== modified file 'mysql-test/suite/parts/r/partition_syntax_innodb.result'
--- a/mysql-test/suite/parts/r/partition_syntax_innodb.result	2008-11-04 07:43:21 +0000
+++ b/mysql-test/suite/parts/r/partition_syntax_innodb.result	2009-08-03 10:12:36 +0000
@@ -764,7 +764,7 @@ f_char2 CHAR(20),
 f_charbig VARCHAR(1000) )
 PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) (PARTITION part1 VALUES LESS THAN (10), PARTITION part2 VALUES LESS THAN (20), PARTITION part3 VALUES LESS THAN (2147483646)
 (SUBPARTITION subpart31 , SUBPARTITION subpart32 )) ;
-ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '))' at line 7
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'SUBPARTITION subpart31 , SUBPARTITION subpart32 ))' at line 7
 CREATE TABLE t1 (  f_int1 INTEGER,
 f_int2 INTEGER,
 f_char1 CHAR(20),
@@ -772,7 +772,7 @@ f_char2 CHAR(20),
 f_charbig VARCHAR(1000) )
 PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) (PARTITION part1 VALUES LESS THAN (10), PARTITION part2 VALUES LESS THAN (20)
 (SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS THAN (2147483646)) ;
-ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '), PARTITION part3 VALUES LESS THAN (2147483646))' at line 7
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS T' at line 7
 CREATE TABLE t1 (  f_int1 INTEGER,
 f_int2 INTEGER,
 f_char1 CHAR(20),
@@ -781,8 +781,7 @@ f_charbig VARCHAR(1000) )
 PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) (PARTITION part1 VALUES LESS THAN (10), PARTITION part2 VALUES LESS THAN (20)
 (SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS THAN (2147483646)
 (SUBPARTITION subpart31 , SUBPARTITION subpart32 )) ;
-ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '), PARTITION part3 VALUES LESS THAN (2147483646)
-(SUBPARTITION subpart31 , SUBPA' at line 7
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS T' at line 7
 CREATE TABLE t1 (  f_int1 INTEGER,
 f_int2 INTEGER,
 f_char1 CHAR(20),

=== modified file 'mysql-test/suite/parts/r/partition_syntax_myisam.result'
--- a/mysql-test/suite/parts/r/partition_syntax_myisam.result	2008-11-12 20:04:19 +0000
+++ b/mysql-test/suite/parts/r/partition_syntax_myisam.result	2009-08-03 14:33:19 +0000
@@ -796,7 +796,7 @@ f_char2 CHAR(20),
 f_charbig VARCHAR(1000) )
 PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) (PARTITION part1 VALUES LESS THAN (10), PARTITION part2 VALUES LESS THAN (20), PARTITION part3 VALUES LESS THAN (2147483646)
 (SUBPARTITION subpart31 , SUBPARTITION subpart32 )) ;
-ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '))' at line 7
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'SUBPARTITION subpart31 , SUBPARTITION subpart32 ))' at line 7
 CREATE TABLE t1 (  f_int1 INTEGER,
 f_int2 INTEGER,
 f_char1 CHAR(20),
@@ -804,7 +804,7 @@ f_char2 CHAR(20),
 f_charbig VARCHAR(1000) )
 PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) (PARTITION part1 VALUES LESS THAN (10), PARTITION part2 VALUES LESS THAN (20)
 (SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS THAN (2147483646)) ;
-ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '), PARTITION part3 VALUES LESS THAN (2147483646))' at line 7
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS T' at line 7
 CREATE TABLE t1 (  f_int1 INTEGER,
 f_int2 INTEGER,
 f_char1 CHAR(20),
@@ -813,8 +813,7 @@ f_charbig VARCHAR(1000) )
 PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) (PARTITION part1 VALUES LESS THAN (10), PARTITION part2 VALUES LESS THAN (20)
 (SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS THAN (2147483646)
 (SUBPARTITION subpart31 , SUBPARTITION subpart32 )) ;
-ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '), PARTITION part3 VALUES LESS THAN (2147483646)
-(SUBPARTITION subpart31 , SUBPA' at line 7
+ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near 'SUBPARTITION subpart21 , SUBPARTITION subpart22 ), PARTITION part3 VALUES LESS T' at line 7
 CREATE TABLE t1 (  f_int1 INTEGER,
 f_int2 INTEGER,
 f_char1 CHAR(20),

=== modified file 'mysql-test/suite/rpl/r/rpl_innodb.result'
--- a/mysql-test/suite/rpl/r/rpl_innodb.result	2008-10-29 13:25:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_innodb.result	2009-07-02 09:40:40 +0000
@@ -82,3 +82,48 @@ FLUSH LOGS;
 FLUSH LOGS;
 DROP DATABASE mysqltest1;
 End of 5.1 tests
+#
+# Bug#39675 rename tables on innodb tables with pending 
+# transactions causes slave data issue.
+#
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+DROP TABLE IF EXISTS t3;
+CREATE TABLE t1 (
+id INT PRIMARY KEY auto_increment,
+b INT DEFAULT NULL
+) ENGINE=InnoDB;
+CREATE TABLE t2 (
+id INT PRIMARY KEY auto_increment,
+b INT DEFAULT NULL
+) ENGINE=InnoDB;
+INSERT INTO t1 (b) VALUES (1),(2),(3);
+BEGIN;
+INSERT INTO t1(b) VALUES (4);
+-------- switch to master1 --------
+RENAME TABLE t1 TO t3, t2 TO t1;;
+-------- switch to master --------
+COMMIT;
+-------- switch to master1 --------
+-------- switch to master --------
+SELECT * FROM t1;
+id	b
+SELECT * FROM t3;
+id	b
+1	1
+2	2
+3	3
+4	4
+-------- switch to slave --------
+SELECT * FROM t1;
+id	b
+SELECT * FROM t3;
+id	b
+1	1
+2	2
+3	3
+4	4
+-------- switch to master --------
+DROP TABLE t1;
+DROP TABLE t3;
+End of 6.0 tests

=== modified file 'mysql-test/suite/rpl/r/rpl_locktrans_innodb.result'
--- a/mysql-test/suite/rpl/r/rpl_locktrans_innodb.result	2009-06-04 14:08:54 +0000
+++ b/mysql-test/suite/rpl/r/rpl_locktrans_innodb.result	2009-07-31 17:53:36 +0000
@@ -101,12 +101,12 @@ ERROR 42000: You have an error in your S
 # Implicit lock method conversion due to mix in statement.
 LOCK TABLE t1 READ, t2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't2'
 UNLOCK TABLES;
 # Lock t1 share (converted to read), t2 write.
 LOCK TABLE t1 IN SHARE MODE, t2 WRITE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't1'
 # Show t1 is read locked, t2 write locked.
 INSERT INTO t1 SELECT * FROM t2;
 ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
@@ -117,8 +117,8 @@ INSERT INTO t2 SELECT * FROM t1;
 # Lock t1 exclusive (converted to write), t2 share (converted to read).
 LOCK TABLE t1 IN EXCLUSIVE MODE, t2 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 # Show t1 is write locked, t2 read locked.
 INSERT INTO t1 SELECT * FROM t2;
 INSERT INTO t2 SELECT * FROM t1;
@@ -142,8 +142,8 @@ ERROR HY000: Cannot convert to non-trans
 ## Error is reported on first table only. Show both errors:
 SHOW WARNINGS;
 Level	Code	Message
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't1'
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't2'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't1'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't2'
 UNLOCK TABLES;
 SET @@SQL_MODE= @wl3561_save_sql_mode;
 #
@@ -163,7 +163,7 @@ CREATE TABLE t4 (c4 INT) ENGINE= MyISAM;
 # Request a transactional lock, which is converted to non-transactional.
 LOCK TABLE t4 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Try a conflict with the existing non-transactional lock.
 INSERT INTO t4 VALUES(444);
 ERROR HY000: Table 't4' was locked with a READ lock and can't be updated
@@ -180,8 +180,8 @@ CREATE VIEW v1 AS SELECT * FROM t3, t4 W
 # Request a share lock on the view, which is converted to read locks.
 LOCK TABLE v1 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Show that read locks on the base tables prohibit writing ...
 INSERT INTO t3 SELECT * FROM t4;
 ERROR HY000: Table 't3' was locked with a READ lock and can't be updated
@@ -197,7 +197,7 @@ COUNT(*)
 ## Report conversion on view due to existing non-transactional locks.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'v1'
+Warning	1639	Converted to non-transactional lock on 'v1'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);
@@ -206,8 +206,8 @@ UNLOCK TABLES;
 ## Now report conversion on base table again.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);

=== modified file 'mysql-test/suite/rpl/r/rpl_locktrans_myisam.result'
--- a/mysql-test/suite/rpl/r/rpl_locktrans_myisam.result	2009-06-08 14:58:33 +0000
+++ b/mysql-test/suite/rpl/r/rpl_locktrans_myisam.result	2009-07-31 17:53:36 +0000
@@ -68,8 +68,8 @@ UNLOCK TABLES;
 # Valid syntax for transactional locks.
 LOCK TABLE t1 IN SHARE MODE, t2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 UNLOCK TABLES;
 #
 # Valid syntax for aliases with and without 'AS'.
@@ -77,19 +77,19 @@ LOCK TABLE t1 AS a1 READ, t2 a2 WRITE;
 UNLOCK TABLES;
 LOCK TABLE t1 AS a1 IN SHARE MODE, t2 a2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'a1'
-Warning	1637	Converted to non-transactional lock on 'a2'
+Warning	1639	Converted to non-transactional lock on 'a1'
+Warning	1639	Converted to non-transactional lock on 'a2'
 UNLOCK TABLES;
 #
 # Transactional locks taken on a view.
 CREATE VIEW v1 AS SELECT * FROM t1, t2 WHERE t1.c1 = t2.c2;
 LOCK TABLE v1 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'v1'
+Warning	1639	Converted to non-transactional lock on 'v1'
 UNLOCK TABLES;
 DROP VIEW v1;
 #
@@ -142,12 +142,12 @@ ERROR 42000: You have an error in your S
 # Implicit lock method conversion due to mix in statement.
 LOCK TABLE t1 READ, t2 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't2'
 UNLOCK TABLES;
 # Lock t1 share (converted to read), t2 write.
 LOCK TABLE t1 IN SHARE MODE, t2 WRITE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't1'
 # Show t1 is read locked, t2 write locked.
 INSERT INTO t1 SELECT * FROM t2;
 ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
@@ -158,8 +158,8 @@ INSERT INTO t2 SELECT * FROM t1;
 # Lock t1 exclusive (converted to write), t2 share (converted to read).
 LOCK TABLE t1 IN EXCLUSIVE MODE, t2 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't1'
-Warning	1637	Converted to non-transactional lock on 't2'
+Warning	1639	Converted to non-transactional lock on 't1'
+Warning	1639	Converted to non-transactional lock on 't2'
 # Show t1 is write locked, t2 read locked.
 INSERT INTO t1 SELECT * FROM t2;
 INSERT INTO t2 SELECT * FROM t1;
@@ -183,8 +183,8 @@ ERROR HY000: Cannot convert to non-trans
 ## Error is reported on first table only. Show both errors:
 SHOW WARNINGS;
 Level	Code	Message
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't1'
-Error	1638	Cannot convert to non-transactional lock in strict mode on 't2'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't1'
+Error	1640	Cannot convert to non-transactional lock in strict mode on 't2'
 UNLOCK TABLES;
 SET @@SQL_MODE= @wl3561_save_sql_mode;
 #
@@ -204,7 +204,7 @@ CREATE TABLE t4 (c4 INT) ENGINE= MyISAM;
 # Request a transactional lock, which is converted to non-transactional.
 LOCK TABLE t4 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Try a conflict with the existing non-transactional lock.
 INSERT INTO t4 VALUES(444);
 ERROR HY000: Table 't4' was locked with a READ lock and can't be updated
@@ -221,8 +221,8 @@ CREATE VIEW v1 AS SELECT * FROM t3, t4 W
 # Request a share lock on the view, which is converted to read locks.
 LOCK TABLE v1 IN SHARE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 # Show that read locks on the base tables prohibit writing ...
 INSERT INTO t3 SELECT * FROM t4;
 ERROR HY000: Table 't3' was locked with a READ lock and can't be updated
@@ -238,7 +238,7 @@ COUNT(*)
 ## Report conversion on view due to existing non-transactional locks.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 'v1'
+Warning	1639	Converted to non-transactional lock on 'v1'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);
@@ -247,8 +247,8 @@ UNLOCK TABLES;
 ## Now report conversion on base table again.
 LOCK TABLE v1 IN EXCLUSIVE MODE;
 Warnings:
-Warning	1637	Converted to non-transactional lock on 't3'
-Warning	1637	Converted to non-transactional lock on 't4'
+Warning	1639	Converted to non-transactional lock on 't3'
+Warning	1639	Converted to non-transactional lock on 't4'
 INSERT INTO t3 VALUES(333);
 INSERT INTO t4 VALUES(444);
 INSERT INTO t1 VALUES(111);

=== removed file 'mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result'
--- a/mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result	2008-07-10 16:09:39 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result	1970-01-01 00:00:00 +0000
@@ -1,17 +0,0 @@
-stop slave;
-drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
-reset master;
-reset slave;
-drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
-start slave;
-create table t1 (words varchar(20)) engine=myisam;
-load data infile '../../std_data/words.dat' into table t1 (words);
-select count(*) from t1;
-count(*)
-70
-select count(*) from t1;
-count(*)
-70
-drop table t1;
-include/stop_slave.inc
-drop table t1;

=== modified file 'mysql-test/suite/rpl/r/rpl_semi_sync.result'
--- a/mysql-test/suite/rpl/r/rpl_semi_sync.result	2009-06-17 10:37:04 +0000
+++ b/mysql-test/suite/rpl/r/rpl_semi_sync.result	2009-07-07 02:44:17 +0000
@@ -29,6 +29,33 @@ set global rpl_semi_sync_master_enabled 
 show variables like 'rpl_semi_sync_master_enabled';
 Variable_name	Value
 rpl_semi_sync_master_enabled	ON
+[ status of semi-sync on master should be OFF without any semi-sync slaves ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+#
+# BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
+# BUG#45673 Semisynch reports correct operation even if no slave is connected
+#
+[ status of semi-sync on master should be OFF ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+#
+# INSTALL PLUGIN semi-sync on slave
+#
 [ on slave ]
 [ default state of semi-sync on slave should be OFF ]
 show variables like 'rpl_semi_sync_slave_enabled';
@@ -213,6 +240,7 @@ a
 2
 3
 [ on master ]
+[ master semi-sync status should be ON ]
 show status like 'Rpl_semi_sync_master_status';
 Variable_name	Value
 Rpl_semi_sync_master_status	ON
@@ -225,10 +253,10 @@ Rpl_semi_sync_master_yes_tx	3
 #
 # Start semi-sync replication without SUPER privilege
 #
-reset master;
 include/stop_slave.inc
 reset slave;
 [ on master ]
+reset master;
 set sql_log_bin=0;
 grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl';
 flush privileges;
@@ -238,7 +266,14 @@ grant replication slave on *.* to rpl@12
 flush privileges;
 change master to master_user='rpl',master_password='rpl';
 include/start_slave.inc
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	ON
 [ on master ]
+[ master semi-sync should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
 show status like 'Rpl_semi_sync_master_status';
 Variable_name	Value
 Rpl_semi_sync_master_status	ON
@@ -250,6 +285,10 @@ Variable_name	Value
 Rpl_semi_sync_master_yes_tx	0
 insert into t1 values (4);
 insert into t1 values (5);
+[ master semi-sync should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
 show status like 'Rpl_semi_sync_master_status';
 Variable_name	Value
 Rpl_semi_sync_master_status	ON
@@ -268,6 +307,34 @@ SHOW STATUS LIKE 'Rpl_semi_sync_slave_st
 Variable_name	Value
 Rpl_semi_sync_slave_status	OFF
 [ on master ]
+[ Semi-sync status on master should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+set global rpl_semi_sync_master_enabled= 0;
+[ on slave ]
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name	Value
+rpl_semi_sync_slave_enabled	ON
+include/start_slave.inc
+[ on master ]
+insert into t1 values (8);
+[ master semi-sync clients should be 0, status should be OFF ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+[ on slave ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	OFF
+include/stop_slave.inc
+[ on master ]
 set sql_log_bin=0;
 UNINSTALL PLUGIN rpl_semi_sync_master;
 set sql_log_bin=1;

=== modified file 'mysql-test/suite/rpl/r/rpl_sf.result'
--- a/mysql-test/suite/rpl/r/rpl_sf.result	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/rpl/r/rpl_sf.result	2009-07-28 17:44:38 +0000
@@ -19,5 +19,50 @@ fn16456()
 timestamp
 set binlog_format=STATEMENT;
 select fn16456();
-ERROR HY000: Slave running with --log-slave-updates must use row-based binary logging to be able to replicate row-based binary log events
+ERROR HY000: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
+drop function fn16456;
+set global log_bin_trust_function_creators=0;
+create function fn16456()
+returns int deterministic
+begin
+return unix_timestamp();
+end|
+set binlog_format=ROW;
+select fn16456();
+fn16456()
+timestamp
+set binlog_format=STATEMENT;
+select fn16456();
+fn16456()
+timestamp
+drop function fn16456;
+set global log_bin_trust_function_creators=0;
+create function fn16456()
+returns int no sql
+begin
+return unix_timestamp();
+end|
+set binlog_format=ROW;
+select fn16456();
+fn16456()
+timestamp
+set binlog_format=STATEMENT;
+select fn16456();
+fn16456()
+timestamp
+drop function fn16456;
+set global log_bin_trust_function_creators=0;
+create function fn16456()
+returns int reads sql data
+begin
+return unix_timestamp();
+end|
+set binlog_format=ROW;
+select fn16456();
+fn16456()
+timestamp
+set binlog_format=STATEMENT;
+select fn16456();
+fn16456()
+timestamp
 drop function fn16456;

=== added file 'mysql-test/suite/rpl/r/rpl_stop_middle_group.result'
--- a/mysql-test/suite/rpl/r/rpl_stop_middle_group.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_stop_middle_group.result	2009-07-08 12:34:52 +0000
@@ -0,0 +1,61 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+create table tm (a int auto_increment primary key) engine=myisam;
+create table ti (a int auto_increment primary key) engine=innodb;
+set @@global.debug="+d,stop_slave_middle_group";
+begin;
+insert into ti set a=null;
+insert into tm set a=null;
+commit;
+SELECT "NO" AS Last_SQL_Error, @check as `true`;
+Last_SQL_Error	true
+NO	1
+select count(*) as one from tm;
+one
+1
+select count(*) as one from ti;
+one
+1
+set @@global.debug="-d";
+include/start_slave.inc
+truncate table tm;
+truncate table ti;
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+begin;
+insert into ti set a=null;
+insert into tm set a=null;
+commit;
+SELECT "Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details)." AS Last_SQL_Error, @check as `true`;
+Last_SQL_Error	true
+Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details).	1
+select count(*) as one  from tm;
+one
+1
+select count(*) as zero from ti;
+zero
+0
+set @@global.debug="-d";
+stop slave;
+truncate table tm;
+include/start_slave.inc
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+update tm as t1, ti as t2 set t1.a=t1.a * 2, t2.a=t2.a * 2;
+SELECT "Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details)." AS Last_SQL_Error, @check as `true`;
+Last_SQL_Error	true
+Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details).	1
+select max(a) as two from tm;
+two
+2
+select max(a) as one from ti;
+one
+1
+set @@global.debug="-d";
+drop table tm, ti;
+include/stop_slave.inc
+drop table tm, ti;

=== modified file 'mysql-test/suite/rpl/r/rpl_temp_table_mix_row.result'
--- a/mysql-test/suite/rpl/r/rpl_temp_table_mix_row.result	2009-02-23 03:26:38 +0000
+++ b/mysql-test/suite/rpl/r/rpl_temp_table_mix_row.result	2009-07-26 21:48:24 +0000
@@ -24,3 +24,48 @@ Slave_open_temp_tables	0
 [on master]
 DROP TABLE t1;
 [on slave]
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+CREATE TABLE t1 (a int);
+CREATE TABLE t2 ( i1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (i1) );
+CREATE TABLE t3 ( i1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (i1) );
+CREATE TRIGGER tr1 AFTER DELETE ON t2 FOR EACH ROW INSERT INTO t3 () VALUES ();
+CREATE TEMPORARY TABLE t1_tmp (i1 int);
+ALTER TABLE t1_tmp ADD COLUMN b INT;
+DELETE FROM t2;
+CREATE TEMPORARY TABLE t2_tmp (a int);
+ALTER TABLE t1_tmp ADD COLUMN c INT;
+### assertion: assert that there is one open temp table on slave
+SHOW STATUS LIKE 'Slave_open_temp_tables';
+Variable_name	Value
+Slave_open_temp_tables	1
+DROP TABLE t1_tmp, t2;
+INSERT INTO t1 VALUES (1);
+DROP TEMPORARY TABLE t2_tmp;
+INSERT INTO t1 VALUES (2);
+### assertion: assert that slave has no temporary tables opened
+SHOW STATUS LIKE 'Slave_open_temp_tables';
+Variable_name	Value
+Slave_open_temp_tables	0
+DROP TABLE t3, t1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a int)
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t2 ( i1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (i1) )
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t3 ( i1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (i1) )
+slave-bin.000001	#	Query	#	#	use `test`; CREATE DEFINER=`root`@`localhost` TRIGGER tr1 AFTER DELETE ON t2 FOR EACH ROW INSERT INTO t3 () VALUES ()
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TEMPORARY TABLE t1_tmp (i1 int)
+slave-bin.000001	#	Query	#	#	use `test`; ALTER TABLE t1_tmp ADD COLUMN b INT
+slave-bin.000001	#	Query	#	#	use `test`; DROP TABLE `t2` /* generated by server */
+slave-bin.000001	#	Query	#	#	use `test`; DROP TEMPORARY TABLE IF EXISTS `t1_tmp` /* generated by server */
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	use `test`; DROP TEMPORARY TABLE IF EXISTS `t2_tmp` /* generated by server */
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+slave-bin.000001	#	Query	#	#	use `test`; DROP TABLE t3, t1

=== modified file 'mysql-test/suite/rpl/r/rpl_udf.result'
--- a/mysql-test/suite/rpl/r/rpl_udf.result	2009-07-13 17:45:27 +0000
+++ b/mysql-test/suite/rpl/r/rpl_udf.result	2009-07-31 19:46:24 +0000
@@ -181,21 +181,21 @@ affected rows: 2
 CREATE TABLE t1(sum INT, price FLOAT(24)) ENGINE=MyISAM;
 affected rows: 0
 INSERT INTO t1 VALUES(myfunc_int(100), myfunc_double(50.00));
+affected rows: 1
 Warnings:
 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));
+affected rows: 1
 Warnings:
 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));
+affected rows: 1
 Warnings:
 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));
+affected rows: 1
 Warnings:
 Note	1592	Statement may not be safe to log in statement format.
-affected rows: 1
 SELECT * FROM t1 ORDER BY sum;
 sum	price
 1	48.5

=== modified file 'mysql-test/suite/rpl/t/disabled.def'
--- a/mysql-test/suite/rpl/t/disabled.def	2009-07-06 22:29:09 +0000
+++ b/mysql-test/suite/rpl/t/disabled.def	2009-07-31 19:46:24 +0000
@@ -17,5 +17,4 @@ rpl_heartbeat_basic        : Bug#43828 S
 rpl_heartbeat_2slaves      : Bug#43828 Sporadic failures (Serge.Kozlov@stripped)
 rpl_failed_optimize        : WL#4284: Can't optimize table used by a pending transaction (there is metadata lock on the table).
 rpl_read_only              : WL#4284: Setting Read only won't succeed until all metadata locks are released.
-rpl_init_slave         : Bug#44920 2009-07006 pcrews MTR2 is not processing master.opt input properly on Windows.  *Must be done this way due to the nature of the bug*
-
+rpl_init_slave             : Bug#43005

=== modified file 'mysql-test/suite/rpl/t/rpl_innodb.test'
--- a/mysql-test/suite/rpl/t/rpl_innodb.test	2008-10-29 13:25:03 +0000
+++ b/mysql-test/suite/rpl/t/rpl_innodb.test	2009-07-02 09:40:40 +0000
@@ -120,6 +120,71 @@ connection master;
 FLUSH LOGS;
 
 DROP DATABASE mysqltest1;
--- source include/master-slave-end.inc
 
 --echo End of 5.1 tests
+
+--echo #
+--echo # Bug#39675 rename tables on innodb tables with pending 
+--echo # transactions causes slave data issue.
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+DROP TABLE IF EXISTS t3;
+--enable_warnings
+
+CREATE TABLE t1 (
+  id INT PRIMARY KEY auto_increment,
+  b INT DEFAULT NULL
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+  id INT PRIMARY KEY auto_increment,
+  b INT DEFAULT NULL
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (b) VALUES (1),(2),(3);
+
+BEGIN;
+INSERT INTO t1(b) VALUES (4);
+
+--echo -------- switch to master1 --------
+connection master1;
+--send RENAME TABLE t1 TO t3, t2 TO t1;
+
+--echo -------- switch to master --------
+connection master;
+# Need to wait until RENAME is received
+let $wait_condition=
+  SELECT COUNT(*) = 1 FROM information_schema.processlist
+  WHERE info = "RENAME TABLE t1 TO t3, t2 TO t1" and
+  state = "Waiting for table";
+--source include/wait_condition.inc
+
+COMMIT;
+
+--echo -------- switch to master1 --------
+connection master1;
+--reap
+
+--echo -------- switch to master --------
+connection master;
+SELECT * FROM t1;
+SELECT * FROM t3;
+
+sync_slave_with_master;
+
+--echo -------- switch to slave --------
+connection slave;
+SELECT * FROM t1;
+SELECT * FROM t3;
+
+--echo -------- switch to master --------
+connection master;
+DROP TABLE t1;
+DROP TABLE t3;
+
+--echo End of 6.0 tests
+
+--source include/master-slave-end.inc

=== removed file 'mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt'
--- a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt	1970-01-01 00:00:00 +0000
@@ -1 +0,0 @@
---loose-binlog-row-event-max-size=256

=== removed file 'mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt'
--- a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt	1970-01-01 00:00:00 +0000
@@ -1 +0,0 @@
---loose-debug=d,STOP_SLAVE_after_first_Rows_event

=== modified file 'mysql-test/suite/rpl/t/rpl_semi_sync.test'
--- a/mysql-test/suite/rpl/t/rpl_semi_sync.test	2009-06-17 10:37:04 +0000
+++ b/mysql-test/suite/rpl/t/rpl_semi_sync.test	2009-07-07 02:44:17 +0000
@@ -58,6 +58,50 @@ echo [ enable semi-sync on master ];
 set global rpl_semi_sync_master_enabled = 1;
 show variables like 'rpl_semi_sync_master_enabled';
 
+echo [ status of semi-sync on master should be OFF without any semi-sync slaves ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+--echo #
+--echo # BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
+--echo # BUG#45673 Semisynch reports correct operation even if no slave is connected
+--echo #
+
+# BUG#45672 When semi-sync is enabled on master, it would allocate
+# transaction node even without semi-sync slave connected, and would
+# finally result in transaction node allocation error.
+#
+# Semi-sync master will pre-allocate 'max_connections' transaction
+# nodes, so here we do more than that much transactions to check if it
+# will fail or not.
+# select @@global.max_connections + 1;
+let $i= `select @@global.max_connections + 1`;
+disable_query_log;
+eval create table t1 (a int) engine=$engine_type;
+while ($i)
+{
+  eval insert into t1 values ($i);
+  dec $i;
+}
+drop table t1;
+enable_query_log;
+
+# BUG#45673
+echo [ status of semi-sync on master should be OFF ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+disable_query_log;
+# reset master to make sure the following test will start with a clean environment
+reset master;
+enable_query_log;
+
+--echo #
+--echo # INSTALL PLUGIN semi-sync on slave
+--echo #
+
 connection slave;
 echo [ on slave ];
 
@@ -237,11 +281,35 @@ echo [ on slave ];
 
 source include/stop_slave.inc;
 reset slave;
+
+# Kill the dump thread on master for previous slave connection and
+# wait for it to exit
+connection master;
+let $_tid= `select id from information_schema.processlist where command = 'Binlog Dump' limit 1`;
+if ($_tid)
+{
+  disable_query_log;
+  eval kill query $_tid;
+  enable_query_log;
+
+  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+  let $status_var= Rpl_semi_sync_master_clients;
+  let $status_var_value= 0;
+  source include/wait_for_status_var.inc;
+}
+
+connection slave;
 source include/start_slave.inc;
 
 connection master;
 echo [ on master ];
 
+# Wait for dump thread to start, Rpl_semi_sync_master_clients will be
+# 1 after dump thread started.
+let $status_var= Rpl_semi_sync_master_clients;
+let $status_var_value= 1;
+source include/wait_for_status_var.inc;
+
 replace_result $engine_type ENGINE_TYPE;
 eval create table t1 (a int) engine = $engine_type;
 insert into t1 values (1);
@@ -255,6 +323,7 @@ select * from t1;
 connection master;
 echo [ on master ];
 
+echo [ master semi-sync status should be ON ];
 show status like 'Rpl_semi_sync_master_status';
 show status like 'Rpl_semi_sync_master_no_tx';
 show status like 'Rpl_semi_sync_master_yes_tx';
@@ -262,13 +331,27 @@ show status like 'Rpl_semi_sync_master_y
 --echo #
 --echo # Start semi-sync replication without SUPER privilege
 --echo #
-connection master;
-reset master;
-sync_slave_with_master;
+connection slave;
 source include/stop_slave.inc;
 reset slave;
 connection master;
 echo [ on master ];
+reset master;
+
+# Kill the dump thread on master for previous slave connection and wait for it to exit
+let $_tid= `select id from information_schema.processlist where command = 'Binlog Dump' limit 1`;
+if ($_tid)
+{
+  disable_query_log;
+  eval kill query $_tid;
+  enable_query_log;
+
+  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+  let $status_var= Rpl_semi_sync_master_clients;
+  let $status_var_value= 0;
+  source include/wait_for_status_var.inc;
+}
+
 # Do not binlog the following statement because it will generate
 # different events for ROW and STATEMENT format
 set sql_log_bin=0;
@@ -281,13 +364,23 @@ grant replication slave on *.* to rpl@12
 flush privileges;
 change master to master_user='rpl',master_password='rpl';
 source include/start_slave.inc;
+show status like 'Rpl_semi_sync_slave_status';
 connection master;
 echo [ on master ];
+
+# Wait for the semi-sync binlog dump thread to start
+let $status_var= Rpl_semi_sync_master_clients;
+let $status_var_value= 1;
+source include/wait_for_status_var.inc;
+echo [ master semi-sync should be ON ];
+show status like 'Rpl_semi_sync_master_clients';
 show status like 'Rpl_semi_sync_master_status';
 show status like 'Rpl_semi_sync_master_no_tx';
 show status like 'Rpl_semi_sync_master_yes_tx';
 insert into t1 values (4);
 insert into t1 values (5);
+echo [ master semi-sync should be ON ];
+show status like 'Rpl_semi_sync_master_clients';
 show status like 'Rpl_semi_sync_master_status';
 show status like 'Rpl_semi_sync_master_no_tx';
 show status like 'Rpl_semi_sync_master_yes_tx';
@@ -296,6 +389,7 @@ show status like 'Rpl_semi_sync_master_y
 --echo # Test semi-sync slave connect to non-semi-sync master
 --echo #
 
+# Disable semi-sync on master
 connection slave;
 echo [ on slave ];
 source include/stop_slave.inc;
@@ -303,6 +397,45 @@ SHOW STATUS LIKE 'Rpl_semi_sync_slave_st
 
 connection master;
 echo [ on master ];
+
+# Kill the dump thread on master for previous slave connection and wait for it to exit
+let $_tid= `select id from information_schema.processlist where command = 'Binlog Dump' limit 1`;
+if ($_tid)
+{
+  disable_query_log;
+  eval kill query $_tid;
+  enable_query_log;
+
+  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+  let $status_var= Rpl_semi_sync_master_clients;
+  let $status_var_value= 0;
+  source include/wait_for_status_var.inc;
+}
+
+echo [ Semi-sync status on master should be ON ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+set global rpl_semi_sync_master_enabled= 0;
+
+connection slave;
+echo [ on slave ];
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+source include/start_slave.inc;
+connection master;
+echo [ on master ];
+insert into t1 values (8);
+echo [ master semi-sync clients should be 0, status should be OFF ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+sync_slave_with_master;
+echo [ on slave ];
+show status like 'Rpl_semi_sync_slave_status';
+
+# Uninstall semi-sync plugin on master
+connection slave;
+source include/stop_slave.inc;
+connection master;
+echo [ on master ];
 set sql_log_bin=0;
 UNINSTALL PLUGIN rpl_semi_sync_master;
 set sql_log_bin=1;

=== modified file 'mysql-test/suite/rpl/t/rpl_sf.test'
--- a/mysql-test/suite/rpl/t/rpl_sf.test	2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/rpl/t/rpl_sf.test	2009-07-28 17:44:38 +0000
@@ -1,6 +1,7 @@
 -- source include/have_log_bin.inc
 
 # Bug#16456 RBR: rpl_sp.test expects query to fail, but passes in RBR
+# BUG#41166 stored function requires "deterministic" if binlog_format is "statement"
 
 # save status
 
@@ -55,15 +56,131 @@ select fn16456();
 
 set binlog_format=STATEMENT;
 
---error ER_BINLOG_ROW_RBR_TO_SBR
+--error ER_BINLOG_UNSAFE_ROUTINE
 select fn16456();
 
 
 
-# restore status
+# clean
+
+drop function fn16456;
+
+
+
+# success in definition with deterministic
+
+set global log_bin_trust_function_creators=0;
+
+delimiter |;
+create function fn16456()
+       returns int deterministic
+begin
+       return unix_timestamp();
+end|
+delimiter ;|
+
+
+
+# allow funcall in RBR
+
+set binlog_format=ROW;
+
+--replace_column 1 timestamp
+select fn16456();
+
+
+
+# allow funcall in SBR
+
+set binlog_format=STATEMENT;
+
+--replace_column 1 timestamp
+select fn16456();
+
+
+
+# clean
+
+drop function fn16456;
+
+
+# success in definition with NO SQL
+
+set global log_bin_trust_function_creators=0;
+
+delimiter |;
+create function fn16456()
+       returns int no sql
+begin
+       return unix_timestamp();
+end|
+delimiter ;|
+
+
+
+# allow funcall in RBR
+
+set binlog_format=ROW;
+
+--replace_column 1 timestamp
+select fn16456();
+
+
+
+# allow funcall in SBR
+
+set binlog_format=STATEMENT;
+
+--replace_column 1 timestamp
+select fn16456();
+
+
+# clean
 
 drop function fn16456;
 
+
+
+# success in definition with reads sql data
+
+set global log_bin_trust_function_creators=0;
+
+delimiter |;
+create function fn16456()
+       returns int reads sql data
+begin
+       return unix_timestamp();
+end|
+delimiter ;|
+
+
+
+# allow funcall in RBR
+
+set binlog_format=ROW;
+
+--replace_column 1 timestamp
+select fn16456();
+
+
+
+# allow funcall in SBR
+
+set binlog_format=STATEMENT;
+
+--replace_column 1 timestamp
+select fn16456();
+
+
+
+# clean
+
+drop function fn16456;
+
+
+
+# restore status
+
 --disable_query_log
 eval set binlog_format=$oblf;
 eval set global log_bin_trust_function_creators=$otfc;

=== renamed file 'mysql-test/suite/rpl/t/rpl_row_stop_middle_update.test' => 'mysql-test/suite/rpl/t/rpl_stop_middle_group.test'
--- a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update.test	2008-08-04 14:30:50 +0000
+++ b/mysql-test/suite/rpl/t/rpl_stop_middle_group.test	2009-07-08 12:34:52 +0000
@@ -1,32 +1,149 @@
--- source include/have_binlog_format_row.inc
 -- source include/have_debug.inc
 -- source include/master-slave.inc
+-- source include/have_innodb.inc
 
-# master is asked to create small Rows events: if only one event is
-# created, stopping slave at the end of that one will show no bug, we
-# need at least two (and stop after first); in this test we use three.
+# Proving that stopping in the middle of applying a group of events
+# does not have immediate effect if a non-transaction table has been changed.
+# The slave sql thread has to try to finish applying first.
+# The tests rely on simulation of the killed status.
+# The matter of testing correlates to some of `rpl_start_stop_slave' that does
+# not require `have_debug'.
 
 connection master;
-create table t1 (words varchar(20)) engine=myisam;
 
-load data infile '../../std_data/words.dat' into table t1 (words);
-select count(*) from t1;
-save_master_pos;
+create table tm (a int auto_increment primary key) engine=myisam;
+create table ti (a int auto_increment primary key) engine=innodb;
+
+sync_slave_with_master;
+set @@global.debug="+d,stop_slave_middle_group";
+
+connection master;
+
+begin;
+insert into ti set a=null;
+insert into tm set a=null; # to simulate killed status on the slave 
+commit;
 
 connection slave;
 
-# slave will automatically stop the sql thread thanks to the .opt
-# file; it will initiate the stop request after the first
-# Rows_log_event (out of 3) but should wait until the last one is
-# executed before stopping.
+# slave will catch the killed status but won't shut down immediately
+# only after the whole group has done (commit)
 
 source include/wait_for_slave_sql_to_stop.inc;
 
-# check that we inserted all rows (waited until the last Rows event)
-select count(*) from t1;
+# checking: no error and the group is finished
+
+let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+let $read = query_get_value("SHOW SLAVE STATUS", Read_Master_Log_Pos, 1);
+let $exec = query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1);
+--disable_query_log
+eval SELECT $read = $exec into @check;
+--enable_query_log
+eval SELECT "NO$error" AS Last_SQL_Error, @check as `true`;
+select count(*) as one from tm;
+select count(*) as one from ti;
+
+set @@global.debug="-d";
+
+#
+# bug#45940 issues around rli->last_event_start_time
+# Testing of slave stopped after it had waited (in vain) for
+# the group be finished.
+# It could not be finished because of simulation of failure to
+# receive the terminal part
+# The test relay on simulation of the incomplete group in the relay log
+
+# Two cases are verified: a mixed transacton and a mixed multi-table update.
+#
+# The mixed transacton.
+#
+source include/start_slave.inc;
 
 connection master;
-drop table t1;
+
+truncate table tm; # cleanup of former tests
+truncate table ti;
+
+#connection slave;
+sync_slave_with_master;
+
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+
+connection master;
+
+begin;
+insert into ti set a=null;
+insert into tm set a=null;
+commit;
+
+connection slave;
+
+# slave will catch the killed status, won't shut down immediately
+# but does it eventually having the whole group unfinished (not committed)
+
+source include/wait_for_slave_sql_to_stop.inc;
+
+# checking: the error and group unfinished
+
+let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+let $read = query_get_value("SHOW SLAVE STATUS", Read_Master_Log_Pos, 1);
+let $exec = query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1);
+--disable_query_log
+eval SELECT $read - $exec > 0 into @check;
+--enable_query_log
+eval SELECT "$error" AS Last_SQL_Error, @check as `true`;
+select count(*) as one  from tm;
+select count(*) as zero from ti;
+
+set @@global.debug="-d";
+
+#
+# The mixed multi-table update
+#
+stop slave;
+truncate table tm;
+source include/start_slave.inc;
+
+connection master;
+
+#connection slave;
+sync_slave_with_master;
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+
+connection master;
+update tm as t1, ti as t2 set t1.a=t1.a * 2, t2.a=t2.a * 2;
+
+connection slave;
+
+# slave will catch the killed status, won't shut down immediately
+# but does it eventually having the whole group unfinished (not committed)
+# 
+
+source include/wait_for_slave_sql_to_stop.inc;
+
+# checking: the error and group unfinished 
+
+let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+let $read = query_get_value("SHOW SLAVE STATUS", Read_Master_Log_Pos, 1);
+let $exec = query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1);
+--disable_query_log
+eval SELECT $read - $exec > 0 into @check;
+--enable_query_log
+eval SELECT "$error" AS Last_SQL_Error, @check as `true`;
+select max(a) as two from tm;
+select max(a) as one from ti;
+
+set @@global.debug="-d";
+
+#
+# clean-up
+#
+
+connection master;
+drop table tm, ti;
+
 connection slave; # slave SQL thread is stopped
 source include/stop_slave.inc;
-drop table t1;
+drop table tm, ti;

=== modified file 'mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test'
--- a/mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test	2009-03-24 08:55:03 +0000
+++ b/mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test	2009-07-26 21:48:24 +0000
@@ -51,3 +51,98 @@ DROP TABLE t1;
 
 --echo [on slave]
 sync_slave_with_master;
+
+#
+# BUG#43046: mixed mode switch to row format with temp table lead to wrong
+# result
+#
+# NOTES
+# =====
+#  
+#  1. Temporary tables cannot be logged using the row-based
+#     format. Thus, once row-based logging is used, all subsequent
+#     statements using that table are unsafe, and we approximate this
+#     condition by treating all statements made by that client as
+#     unsafe until the client no longer holds any temporary tables.
+#
+#  2. Two different connections can use the same temporary table
+#     name without conflicting with each other or with an
+#     existing non-TEMPORARY table of the same name.
+#
+# DESCRIPTION
+# ===========
+#  
+#   The test is implemented as follows:
+#     1. create regular tables 
+#     2. create a temporary table t1_tmp: should be logged as statement
+#     3. issue an alter table: should be logged as statement
+#     4. issue statement that forces switch to RBR
+#     5. create another temporary table t2_tmp: should not be logged
+#     6. issue alter table on t1_tmp: should not be logged
+#     7. drop t1_tmp and regular table on same statement: should log both in
+#        statement format (but different statements)
+#     8. issue deterministic insert: logged as row (because t2_tmp still
+#        exists).
+#     9. drop t2_tmp and issue deterministic statement: should log drop and
+#        query in statement format (show switch back to STATEMENT format)
+#    10. in the end the slave should not have open temp tables.
+#  
+
+connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
+-- source include/master-slave-reset.inc
+-- connection master
+
+# action: setup environment
+CREATE TABLE t1 (a int);
+CREATE TABLE t2 ( i1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (i1) );
+CREATE TABLE t3 ( i1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (i1) );
+CREATE TRIGGER tr1 AFTER DELETE ON t2 FOR EACH ROW INSERT INTO t3 () VALUES ();
+
+# assertion: assert that CREATE is logged as STATEMENT
+CREATE TEMPORARY TABLE t1_tmp (i1 int);
+
+# assertion: assert that ALTER TABLE is logged as STATEMENT
+ALTER TABLE t1_tmp ADD COLUMN b INT;
+
+# action: force switch to RBR
+DELETE FROM t2;
+
+# assertion: assert that t2_tmp will not make into the binlog (RBR logging atm)
+CREATE TEMPORARY TABLE t2_tmp (a int);
+
+# assertion: assert that ALTER TABLE on t1_tmp will not make into the binlog
+ALTER TABLE t1_tmp ADD COLUMN c INT;
+
+-- echo ### assertion: assert that there is one open temp table on slave
+-- sync_slave_with_master
+SHOW STATUS LIKE 'Slave_open_temp_tables';
+
+-- connection master
+
+# assertion: assert that both drops are logged
+DROP TABLE t1_tmp, t2;
+
+# assertion: assert that statement is logged as row (master still has one
+#            opened temporary table - t2_tmp.
+INSERT INTO t1 VALUES (1);
+
+# assertion: assert that DROP TABLE *is* logged despite CREATE is not.
+DROP TEMPORARY TABLE t2_tmp;
+
+# assertion: assert that statement is now logged as STMT (mixed mode switches
+#            back to STATEMENT).
+INSERT INTO t1 VALUES (2);
+
+-- sync_slave_with_master
+
+-- echo ### assertion: assert that slave has no temporary tables opened
+SHOW STATUS LIKE 'Slave_open_temp_tables';
+
+-- connection master
+
+# action: drop remaining tables
+DROP TABLE t3, t1;
+
+-- sync_slave_with_master
+
+-- source include/show_binlog_events.inc

=== modified file 'mysql-test/t/create.test'
--- a/mysql-test/t/create.test	2009-05-28 21:29:31 +0000
+++ b/mysql-test/t/create.test	2009-07-29 10:25:07 +0000
@@ -1545,6 +1545,30 @@ DROP TABLE t1;
 create table `me:i`(id int);
 drop table `me:i`;
 
+###########################################################################
+
+#
+# Bug#45829 CREATE TABLE TRANSACTIONAL PAGE_CHECKSUM ROW_FORMAT=PAGE accepted, does nothing
+#
+
+--echo
+--echo # --
+--echo # -- Bug#45829: CREATE TABLE TRANSACTIONAL PAGE_CHECKSUM ROW_FORMAT=PAGE accepted, does nothing
+--echo # --
+--echo
+
+--disable_warnings
+drop table if exists t1,t2,t3;
+--enable_warnings
+--error ER_PARSE_ERROR
+create table t1 (a int) transactional=0;
+--error ER_PARSE_ERROR
+create table t2 (a int) page_checksum=1;
+--error ER_PARSE_ERROR
+create table t3 (a int) row_format=page;
+--echo
+--echo # -- End of Bug#45829
+
 --echo
 --echo End of 5.1 tests
 

=== modified file 'mysql-test/t/disabled.def'
--- a/mysql-test/t/disabled.def	2009-07-11 20:13:14 +0000
+++ b/mysql-test/t/disabled.def	2009-07-23 10:22:21 +0000
@@ -14,5 +14,5 @@ innodb_bug39438      : Bug#42383 2009-01
 query_cache_28249    : Bug#43861 2009-03-25 main.query_cache_28249 fails sporadically
 information_schema   : Bug#42893 2009-03-26 alik main.information_schema times out sporadically
 skip_name_resolve    : Bug#43006 2009-06-25 alik main.skip_name_resolve fails on Windows in PB2
-init_connect         : Bug#44920 2009-07-06 pcrews MTR not processing master.opt input properly on Windows.  *Must be done this way due to the nature of the bug*
+init_connect         : Bug#43005
 mysql_locale_posix   : Bug#46131 2009-07-11 alik main.mysql_locale_posix fais, thus disabled

=== modified file 'mysql-test/t/innodb_mysql.test'
--- a/mysql-test/t/innodb_mysql.test	2009-07-09 16:11:01 +0000
+++ b/mysql-test/t/innodb_mysql.test	2009-07-28 12:56:22 +0000
@@ -463,6 +463,25 @@ DROP TABLE t1;
 
 --echo End of 5.1 tests
 
+
+--echo #
+--echo # Test for bug #39932 "create table fails if column for FK is in different
+--echo #                      case than in corr index".
+--echo #
+--disable_warnings
+drop tables if exists t1, t2;
+--enable_warnings
+create table t1 (pk int primary key) engine=InnoDB;
+--echo # Even although the below statement uses uppercased field names in
+--echo # foreign key definition it still should be able to find explicitly
+--echo # created supporting index. So it should succeed and should not
+--echo # create any additional supporting indexes.
+create table t2 (fk int, key x (fk),
+                 constraint x foreign key (FK) references t1 (PK)) engine=InnoDB;
+show create table t2;
+drop table t2, t1;
+
+
 --echo #
 --echo # BUG#42744: Crash when using a join buffer to join a table with a blob
 --echo # column and an additional column used for duplicate elimination.

=== added file 'mysql-test/t/innodb_mysql_lock-master.opt'
--- a/mysql-test/t/innodb_mysql_lock-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_mysql_lock-master.opt	2009-07-08 12:09:38 +0000
@@ -0,0 +1 @@
+--innodb_lock_wait_timeout=300

=== added file 'mysql-test/t/innodb_mysql_lock.test'
--- a/mysql-test/t/innodb_mysql_lock.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_mysql_lock.test	2009-07-08 12:09:38 +0000
@@ -0,0 +1,58 @@
+-- source include/have_innodb.inc
+
+--echo #
+--echo # Bug #22876 Four-way deadlock
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+connect (con1,localhost,root,,);
+connect (con2,localhost,root,,);
+connect (con3,localhost,root,,);
+
+--echo # Connection 1
+connection con1;
+set @@autocommit=0;
+CREATE TABLE t1(s1 INT UNIQUE) ENGINE=innodb;
+INSERT INTO t1 VALUES (1);
+
+--echo # Connection 2
+connection con2;
+set @@autocommit=0;
+INSERT INTO t1 VALUES (2);
+--send INSERT INTO t1 VALUES (1)
+
+--echo # Connection 3
+connection con3;
+set @@autocommit=0;
+--send DROP TABLE t1
+
+--echo # Connection 1
+connection con1;
+let $wait_condition=
+  SELECT COUNT(*) = 1 FROM information_schema.processlist
+  WHERE info = "INSERT INTO t1 VALUES (1)" and 
+  state = "update";
+--source include/wait_condition.inc
+let $wait_condition=
+  SELECT COUNT(*) = 1 FROM information_schema.processlist
+  WHERE info = "DROP TABLE t1" and 
+  state = "Waiting for table";
+--source include/wait_condition.inc
+--echo # Connection 1 is now holding the lock.
+--echo # Issuing insert from connection 1 while connection 2&3 
+--echo # is waiting for the lock should give a deadlock error.
+--error ER_LOCK_DEADLOCK
+INSERT INTO t1 VALUES (2);
+
+--echo # Cleanup
+connection con2;
+--reap
+commit;
+connection con1;
+commit;
+connection con3;
+--reap
+connection default;

=== modified file 'mysql-test/t/innodb_notembedded.test'
--- a/mysql-test/t/innodb_notembedded.test	2008-07-10 16:09:39 +0000
+++ b/mysql-test/t/innodb_notembedded.test	2009-07-30 14:31:45 +0000
@@ -36,9 +36,15 @@ rollback;
 connection b;
 reap;
 rollback;
+
+# Cleanup
+connection a;
+disconnect a;
+--source include/wait_until_disconnected.inc
+connection b;
+disconnect b;
+--source include/wait_until_disconnected.inc
 connection default;
 drop table t1;
 drop function f1;
-disconnect a;
-disconnect b;
 SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators;

=== modified file 'mysql-test/t/insert.test'
--- a/mysql-test/t/insert.test	2009-07-13 17:45:27 +0000
+++ b/mysql-test/t/insert.test	2009-07-31 19:46:24 +0000
@@ -493,3 +493,33 @@ DROP TABLE t1, t2;
 
 --echo End of 5.0 tests.
 
+--echo #
+--echo # Bug#34898 "mysql_info() reports 0 warnings while
+--echo # mysql_warning_count() reports 1"
+--echo # Check that the number of warnings reported by
+--echo # mysql_info() is correct.
+--echo #
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+create table t1 (data varchar(4) not null);
+
+set sql_mode='error_for_division_by_zero';
+--echo #
+--echo # Demonstrate that the number of warnings matches
+--echo # the information in mysql_info().
+--echo #
+--enable_info
+insert t1 (data) values ('letter'), (1/0);
+update t1 set data='envelope' where 1/0 or 1;
+insert t1 (data) values (default), (1/0), ('dead beef');
+--disable_info
+
+set sql_mode=default;
+drop table t1;
+
+--echo #
+--echo # End of 5.4 tests
+--echo #

=== modified file 'mysql-test/t/insert_select.test'
--- a/mysql-test/t/insert_select.test	2009-05-04 12:45:36 +0000
+++ b/mysql-test/t/insert_select.test	2009-07-24 12:09:35 +0000
@@ -394,3 +394,24 @@ check table t2 extended;
 drop table t1,t2;
 --echo ##################################################################
 
+--echo #
+--echo # Bug #46075: Assertion failed: 0, file .\protocol.cc, line 416
+--echo #
+
+CREATE TABLE t1(a INT);
+# To force MyISAM temp. table in the following INSERT ... SELECT.
+SET max_heap_table_size = 16384;
+# To overflow the temp. table.
+SET @old_myisam_data_pointer_size = @@myisam_data_pointer_size;
+SET GLOBAL myisam_data_pointer_size = 2;
+
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+
+--error ER_RECORD_FILE_FULL,ER_RECORD_FILE_FULL
+INSERT IGNORE INTO t1 SELECT t1.a FROM t1,t1 t2,t1 t3,t1 t4,t1 t5,t1 t6,t1 t7;
+
+# Cleanup
+SET GLOBAL myisam_data_pointer_size = @old_myisam_data_pointer_size;
+DROP TABLE t1;
+
+--echo End of 5.0 tests

=== modified file 'mysql-test/t/loadxml.test'
--- a/mysql-test/t/loadxml.test	2008-10-29 08:45:14 +0000
+++ b/mysql-test/t/loadxml.test	2009-07-30 11:32:37 +0000
@@ -48,3 +48,16 @@ select 1 as xml;
 remove_file $MYSQLTEST_VARDIR/tmp/loadxml-dump.xml;
 drop table t1;
 
+#
+# Bug #36750    LOAD XML doesn't understand new line (feed) characters in multi line text fields
+#
+
+create table t1 (
+  id int(11) not null,
+  text text,
+  primary key (id)
+) engine=MyISAM default charset=latin1;
+load xml infile '../../std_data/loadxml2.dat' into table t1;
+select * from t1;
+drop table t1;
+

=== modified file 'mysql-test/t/lock.test'
--- a/mysql-test/t/lock.test	2009-03-27 22:06:26 +0000
+++ b/mysql-test/t/lock.test	2009-07-02 14:24:05 +0000
@@ -345,5 +345,37 @@ connection default;
 drop table t1;
 
 --echo #
+--echo # Bug#45066 FLUSH TABLES WITH READ LOCK deadlocks against 
+--echo #           LOCK TABLE 
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1(a INT);
+
+LOCK TABLE t1 READ;
+--error ER_TABLE_NOT_LOCKED_FOR_WRITE
+FLUSH TABLES;
+
+LOCK TABLE t1 WRITE;
+FLUSH TABLES;
+
+--echo #
+--echo # If you allow the next combination, you reintroduce bug Bug#45066
+--echo # 
+LOCK TABLE t1 READ;
+--error ER_LOCK_OR_ACTIVE_TRANSACTION
+FLUSH TABLES WITH READ LOCK;
+
+LOCK TABLE t1 WRITE;
+--error ER_LOCK_OR_ACTIVE_TRANSACTION
+FLUSH TABLES WITH READ LOCK;
+
+UNLOCK TABLES;
+DROP TABLE t1;
+
+--echo #
 --echo # End of 6.0 tests.
 --echo #

=== modified file 'mysql-test/t/merge.test'
--- a/mysql-test/t/merge.test	2009-07-16 08:00:34 +0000
+++ b/mysql-test/t/merge.test	2009-07-31 04:03:41 +0000
@@ -1377,6 +1377,49 @@ insert into m1 (col1) values (1);
 
 drop table m1, t1;
 
+--echo #
+--echo # Bug#45800 crash when replacing into a merge table and there is a duplicate
+--echo #
+
+--echo # Replace duplicate value in child table when merge table doesn't have key
+CREATE TABLE t1 (c1 INT PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE m1 (c1 INT NOT NULL) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+INSERT INTO m1  VALUES (666);
+SELECT * FROM m1;
+--echo # insert the duplicate value into the merge table
+REPLACE INTO m1 VALUES (666);
+SELECT * FROM m1;
+DROP TABLE m1, t1;
+
+--echo # Insert... on duplicate key update (with duplicate values in the table)
+CREATE TABLE t1 (c1 INT PRIMARY KEY) ENGINE=MyISAM;
+CREATE TABLE m1 (c1 INT NOT NULL) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+INSERT INTO m1  VALUES (666);
+SELECT * FROM m1;
+--echo # insert the duplicate value into the merge table
+INSERT INTO m1 VALUES (666) ON DUPLICATE KEY UPDATE c1=c1+1;
+SELECT * FROM m1;
+DROP TABLE m1, t1;
+
+--echo # Insert duplicate value on MERGE table, where, MERGE has a key but MyISAM has more keys
+CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE (c1), UNIQUE (c2));
+CREATE TABLE m1 (c1 INT, c2 INT, UNIQUE (c1)) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+INSERT INTO m1 VALUES (1,2);
+--echo # insert the duplicate value into the merge table
+--error ER_DUP_ENTRY
+INSERT INTO m1 VALUES (3,2);
+DROP TABLE m1,t1;
+
+--echo # Try to define MERGE and MyISAM with keys on different columns
+CREATE TABLE t1 (c1 INT, c2 INT, UNIQUE (c1));
+CREATE TABLE m1 (c1 INT, c2 INT, UNIQUE (c2)) ENGINE=MRG_MyISAM INSERT_METHOD=LAST UNION=(t1);
+--echo # Try accessing the merge table for inserts (error occurs)
+--error ER_WRONG_MRG_TABLE
+INSERT INTO m1 VALUES (1,2);
+--error ER_WRONG_MRG_TABLE
+INSERT INTO m1 VALUES (1,4);
+DROP TABLE m1,t1;
+
 #
 #Bug #44040   MySQL allows creating a MERGE table upon VIEWs but crashes 
 #when using it

=== modified file 'mysql-test/t/myisam.test'
--- a/mysql-test/t/myisam.test	2009-04-30 10:27:29 +0000
+++ b/mysql-test/t/myisam.test	2009-07-29 10:25:07 +0000
@@ -1495,12 +1495,6 @@ let $MYSQLD_DATADIR= `select @@datadir`;
 --exec $MYISAMCHK -d $MYSQLD_DATADIR/test/t1
 DROP TABLE t1;
 
-# Test warnings with transactional=1 with MyISAM
-#
-create table t1 (n int not null, c char(1)) transactional=1;
-show create table t1;
-drop table t1;
-
 #
 # Test of BUG#35570 CHECKSUM TABLE unreliable if LINESTRING field
 # (same content / differen checksum)

=== modified file 'mysql-test/t/mysql.test'
--- a/mysql-test/t/mysql.test	2009-07-10 12:31:32 +0000
+++ b/mysql-test/t/mysql.test	2009-07-31 01:24:46 +0000
@@ -400,5 +400,19 @@ drop tables t1, t2;
 # 
 --exec $MYSQL --html test -e "select '< & >' as '<'"
 
+#
+# Bug #27884: mysql client + null byte
+# 
+create table t1 (a char(5));
+insert into t1 values ('\0b\0');
+--exec $MYSQL test -e "select a from t1"
+--exec $MYSQL -r test -e "select a from t1"
+--exec $MYSQL -s test -e "select a from t1"
+--exec $MYSQL --table test -e "select a from t1"
+--exec $MYSQL --vertical test -e "select a from t1"
+--exec $MYSQL --html test -e "select a from t1"
+--exec $MYSQL --xml test -e "select a from t1"
+drop table t1;
+
 --echo
 --echo End of tests

=== modified file 'mysql-test/t/mysql_upgrade.test'
--- a/mysql-test/t/mysql_upgrade.test	2009-06-26 09:10:20 +0000
+++ b/mysql-test/t/mysql_upgrade.test	2009-07-28 20:33:08 +0000
@@ -8,6 +8,26 @@ select LENGTH("$MYSQL_UPGRADE")>0 as hav
 --enable_query_log
 
 #
+# Hack:
+#
+# If running with Valgrind ($VALGRIND_TEST <> 0) then the resource
+# consumption (CPU) for upgrading a large log table will be intense.
+# Therefore, truncate the log table in advance and issue a statement
+# that should be logged.
+#
+if (`SELECT $VALGRIND_TEST`)
+{
+  --disable_query_log
+  --disable_result_log
+  --disable_abort_on_error
+  TRUNCATE TABLE mysql.general_log;
+  SELECT 1;
+  --enable_abort_on_error
+  --enable_result_log
+  --enable_query_log
+}
+
+#
 # Basic test that we can run mysql_upgrde and that it finds the
 # expected binaries it uses.
 #

=== modified file 'mysql-test/t/mysqldump.test'
--- a/mysql-test/t/mysqldump.test	2009-07-14 17:16:51 +0000
+++ b/mysql-test/t/mysqldump.test	2009-07-31 17:53:36 +0000
@@ -1496,8 +1496,11 @@ INSERT INTO t1 VALUES (1), (2);
 --exec $MYSQL_DUMP --tab=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa test 2>&1
 
 --exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ --fields-terminated-by=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa test
+--error 2
 --exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ --fields-enclosed-by=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa test
+--error 2
 --exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ --fields-optionally-enclosed-by=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa test
+--error 2
 --exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ --fields-escaped-by=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa test
 --exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ --lines-terminated-by=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa test
 
@@ -2050,6 +2053,88 @@ DROP TABLE IF EXISTS t1;
 ###########################################################################
 
 --echo #
+--echo # Bug #30946: mysqldump silently ignores --default-character-set
+--echo #             when used with --tab
+--echo #
+--echo # Also see outfile_loaddata.test
+--echo #
+
+SET NAMES utf8;
+CREATE TABLE t1 (a INT, b CHAR(10) CHARSET koi8r, c CHAR(10) CHARSET latin1);
+CREATE TABLE t2 LIKE t1;
+INSERT INTO t1 VALUES (1, 'ABC-АБВ', 'DEF-ÂÃÄ'), (2, NULL, NULL);
+
+--let $file=$MYSQLTEST_VARDIR/tmp/t1.txt
+
+
+--echo # error on multi-character ENCLOSED/ESCAPED BY
+
+--error 2
+--exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ --fields-enclosed-by='12345' test t1
+--remove_file $file
+
+--error 2
+--exec $MYSQL_DUMP --tab=$MYSQLTEST_VARDIR/tmp/ --fields-escaped-by='12345' test t1
+--remove_file $file
+
+--echo # default '--default-charset' (binary):
+
+--exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --tab=$MYSQLTEST_VARDIR/tmp/ test t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET binary
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+--echo # utf8:
+
+--exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --default-character-set=utf8 --tab=$MYSQLTEST_VARDIR/tmp/ test t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET utf8
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+--echo # latin1 (data corruption is expected):
+
+--exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --default-character-set=latin1 --tab=$MYSQLTEST_VARDIR/tmp/ test t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET latin1 
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+--echo # koi8r (data corruption is expected):
+
+--exec $MYSQL_DUMP --character-sets-dir=$CHARSETSDIR --default-character-set=koi8r --tab=$MYSQLTEST_VARDIR/tmp/ test t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET koi8r
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+SET NAMES default;
+
+DROP TABLE t1, t2;
+
+###########################################################################
+--echo #
 --echo # End of 5.1 tests
 --echo #
 

=== modified file 'mysql-test/t/outfile_loaddata.test'
--- a/mysql-test/t/outfile_loaddata.test	2007-11-20 16:15:20 +0000
+++ b/mysql-test/t/outfile_loaddata.test	2009-07-31 17:14:52 +0000
@@ -111,3 +111,146 @@ SELECT HEX(c1) FROM t1;
 DROP TABLE t1;
 
 --echo # End of 5.0 tests.
+
+###########################################################################
+
+--echo #
+--echo # Bug #30946: mysqldump silently ignores --default-character-set
+--echo #             when used with --tab
+--echo #
+--echo # Also see mysqldump.test
+--echo #
+
+SET NAMES utf8;
+CREATE TABLE t1 (a INT, b CHAR(10) CHARSET koi8r, c CHAR(10) CHARSET latin1);
+CREATE TABLE t2 LIKE t1;
+INSERT INTO t1 VALUES (1, 'ABC-АБВ', 'DEF-ÂÃÄ'), (2, NULL, NULL);
+
+--let $file=$MYSQLTEST_VARDIR/tmp/t1.txt
+
+
+--echo # Error on multi-character ENCLOSED/ESCAPED BY
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--error 1083
+--eval SELECT * FROM t1 INTO OUTFILE '$file' FIELDS ENCLOSED BY '12345'
+--remove_file $file
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--error 1083
+--eval SELECT * FROM t1 INTO OUTFILE '$file' FIELDS ESCAPED BY '12345'
+--remove_file $file
+
+
+--echo # "Not implemented" warning on multibyte  ENCLOSED/ESCAPED BY character,
+--echo # LOAD DATA rises error or has unpredictable result -- to be fixed later
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * FROM t1 INTO OUTFILE '$file' FIELDS ENCLOSED BY 'ъ'
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--error 1083 # backward compatibility
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET binary FIELDS ENCLOSED BY 'ъ'
+--remove_file $file
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * FROM t1 INTO OUTFILE '$file' FIELDS ESCAPED BY 'ъ'
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--error 1083 # backward compatibility
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET binary FIELDS ESCAPED BY 'ъ'
+--remove_file $file
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * FROM t1 INTO OUTFILE '$file' FIELDS TERMINATED BY 'ъ'
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET binary FIELDS TERMINATED BY 'ъ'
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * FROM t1 INTO OUTFILE '$file' LINES STARTING BY 'ъ'
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET binary LINES STARTING BY 'ъ'
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * FROM t1 INTO OUTFILE '$file' LINES TERMINATED BY 'ъ'
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET binary LINES TERMINATED BY 'ъ'
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+--echo # Default (binary) charset:
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * INTO OUTFILE '$file' FROM t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET binary
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+--echo # latin1 charset (INTO OUTFILE warning is expected):
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * INTO OUTFILE '$file' CHARACTER SET latin1 FROM t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET latin1 
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+--echo # KOI8-R charset (INTO OUTFILE warning is expected):
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * INTO OUTFILE '$file' CHARACTER SET koi8r FROM t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET koi8r
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+--echo # UTF-8 charset:
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval SELECT * INTO OUTFILE '$file' CHARACTER SET utf8 FROM t1
+--echo ##################################################
+--cat_file $file
+--echo ##################################################
+TRUNCATE t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$file' INTO TABLE t2 CHARACTER SET utf8
+--remove_file $file
+SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
+
+
+SET NAMES default;
+
+DROP TABLE t1, t2;
+
+###########################################################################
+--echo # End of 5.1 tests.

=== modified file 'mysql-test/t/partition.test'
--- a/mysql-test/t/partition.test	2009-07-02 15:51:04 +0000
+++ b/mysql-test/t/partition.test	2009-08-06 12:41:22 +0000
@@ -10,13 +10,47 @@
 #
 --source include/have_partition.inc
 
-SET @old_general_log= @@global.general_log;
-
 --disable_warnings
 drop table if exists t1, t2;
 --enable_warnings
 
 #
+# Bug#45904: Error when CHARSET=utf8 and subpartitioning
+#
+create table t1 (a int NOT NULL, b varchar(5) NOT NULL)
+default charset=utf8
+partition by list (a)
+subpartition by key (b)
+(partition p0 values in (1),
+ partition p1 values in (2));
+drop table t1;
+#
+# Bug#44059: rec_per_key on empty partition gives weird optimiser results
+#
+create table t1 (a int, b int, key(a))
+partition by list (a)
+subpartition by key (b)
+(partition p0 values in (1),
+ partition p1 values in (2));
+insert into t1 values (1,1),(2,1),(2,2),(2,3);
+show indexes from t1;
+analyze table t1;
+show indexes from t1;
+drop table t1;
+#
+# Bug#40181: hang if create index
+#
+create table t1 (a int)
+partition by hash (a);
+create index i on t1 (a);
+insert into t1 values (1);
+insert into t1 select * from t1;
+--error ER_DUP_KEYNAME
+create index i on t1 (a);
+create index i2 on t1 (a);
+drop table t1;
+
+#
 # Bug#36001: Partitions: spelling and using some error messages
 #
 --error ER_FOREIGN_KEY_ON_PARTITIONED
@@ -1067,6 +1101,17 @@ subpartition by hash(a)
  partition p1 values less than (1) (subpartition sp0));
 
 #
+# Bug 46354 Crash with subpartition
+#
+--error ER_PARSE_ERROR
+create table t1 (a int, b int)
+partition by list (a)
+subpartition by hash(a)
+(partition p0 values in (0),
+ partition p1 values in (1) (subpartition sp0));
+
+
+#
 # BUG 15961 No error when subpartition defined without subpartition by clause
 #
 --error ER_SUBPARTITION_ERROR
@@ -1687,23 +1732,6 @@ insert into t values (1);
 drop table t;
 
 #
-# Bug #27816: Log tables ran with partitions crashes the server when logging
-# is enabled.
-#
-
-USE mysql;
-TRUNCATE TABLE general_log;
-SET @old_general_log_state = @@global.general_log;
-SET GLOBAL general_log = 0;
-ALTER TABLE general_log ENGINE = MyISAM;
---error ER_WRONG_USAGE
-ALTER TABLE general_log PARTITION BY RANGE (TO_DAYS(event_time))
-  (PARTITION p0 VALUES LESS THAN (733144), PARTITION p1 VALUES LESS THAN (3000000));
-ALTER TABLE general_log ENGINE = CSV;
-SET GLOBAL general_log = @old_general_log_state;
-use test;
-
-#
 # Bug #27084 partitioning by list seems failing when using case 
 # BUG #18198: Case no longer supported, test case removed
 #
@@ -2033,6 +2061,23 @@ CREATE TABLE t1(id INT,KEY(id)) ENGINE=M
 DROP TABLE t1;
 SET SESSION SQL_MODE=DEFAULT;
 
---echo End of 5.1 tests
 
-SET @@global.general_log= @old_general_log;
+--echo #
+--echo # BUG#45816 - assertion failure with index containing double 
+--echo #             column on partitioned table
+--echo #
+
+CREATE TABLE t1 (
+  a INT DEFAULT NULL,
+  b DOUBLE DEFAULT NULL,
+  c INT DEFAULT NULL,
+  KEY idx2(b,a)
+) PARTITION BY HASH(c) PARTITIONS 3;
+
+INSERT INTO t1 VALUES (6,8,9);
+INSERT INTO t1 VALUES (6,8,10);
+
+SELECT  1 FROM t1 JOIN t1 AS t2 USING (a) FOR UPDATE;
+
+DROP TABLE t1;
+--echo End of 5.1 tests

=== modified file 'mysql-test/t/partition_csv.test'
--- a/mysql-test/t/partition_csv.test	2007-10-22 18:10:51 +0000
+++ b/mysql-test/t/partition_csv.test	2009-07-31 23:39:26 +0000
@@ -24,15 +24,68 @@ partition by list (a)
 (partition p0 values in (null));
 
 #
-# Bug#27816: Log tables ran with partitions crashes the server when logging
-#            is enabled.
+# Bug #27816: Log tables ran with partitions crashes the server when logging
+#             is enabled.
 #
+
 USE mysql;
+TRUNCATE TABLE general_log;
+SET @old_general_log_state = @@global.general_log;
 SET GLOBAL general_log = 0;
 ALTER TABLE general_log ENGINE = MyISAM;
 --error ER_WRONG_USAGE
 ALTER TABLE general_log PARTITION BY RANGE (TO_DAYS(event_time))
-  (PARTITION p0 VALUES LESS THAN (733144),
-   PARTITION p1 VALUES LESS THAN (3000000));
+  (PARTITION p0 VALUES LESS THAN (733144), PARTITION p1 VALUES LESS THAN (3000000));
 ALTER TABLE general_log ENGINE = CSV;
+SET GLOBAL general_log = @old_general_log_state;
+use test;
+
+--echo #
+--echo # Bug#40281: partitioning the general log table crashes the server
+--echo #
+
+--echo # set up partitioned log, and switch to it
+
+USE mysql;
+SET @old_general_log_state = @@global.general_log;
+SET GLOBAL general_log = 0;
+CREATE TABLE gl_partitioned LIKE general_log;
+ALTER TABLE gl_partitioned ENGINE=myisam;
+ALTER TABLE gl_partitioned PARTITION BY HASH (thread_id) PARTITIONS 10;
+ALTER TABLE general_log RENAME TO gl_nonpartitioned;
+ALTER TABLE gl_partitioned RENAME TO general_log;
+
+SELECT @@global.log_output INTO @old_glo;
+SET GLOBAL log_output='table';
+SET GLOBAL general_log =1;
+
+--echo # do some things to be logged to partitioned log, should fail
+USE /* 1 */ test;
+
+CREATE TABLE t1 (i INT);
+
+connect (con1,localhost,root,,);
+INSERT INTO t1 VALUES (1);
+SELECT * FROM t1;
+disconnect con1;
+
+connection default;
+USE mysql;
+SET GLOBAL general_log =0;
+ALTER TABLE general_log RENAME TO gl_partitioned;
+ALTER TABLE gl_nonpartitioned RENAME TO general_log;
+
+--echo # show whether we actually logged anything (no) to general_log
+SELECT COUNT(argument) FROM gl_partitioned;
+
+DROP TABLE gl_partitioned;
+
+SET GLOBAL log_output = @old_glo;
 SET GLOBAL general_log = 1;
+
+USE /* 2 */ test;
+DROP TABLE t1;
+
+SET GLOBAL general_log = @old_general_log_state;
+
+--echo End of 5.1 tests

=== modified file 'mysql-test/t/partition_error.test'
--- a/mysql-test/t/partition_error.test	2009-02-20 12:37:37 +0000
+++ b/mysql-test/t/partition_error.test	2009-07-23 15:41:27 +0000
@@ -7,7 +7,17 @@
 --disable_warnings
 drop table if exists t1;
 --enable_warnings
- 
+
+#
+# Bug#44108: Assertion bitmap_is_set in ha_partition::end_bulk_insert
+#
+CREATE TABLE t1 (a int, b int) PARTITION BY HASH (a) PARTITIONS 2;
+INSERT INTO t1 VALUES (1,2);
+--error ER_WRONG_VALUE_COUNT_ON_ROW
+INSERT INTO t1 (a) SELECT * FROM t1;
+DROP TABLE t1;
+
+#
 #
 # Bug#38719: Partitioning returns a different error code for a
 # duplicate key error

=== added file 'mysql-test/t/partition_not_embedded.test'
--- a/mysql-test/t/partition_not_embedded.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/partition_not_embedded.test	2009-07-27 11:20:43 +0000
@@ -0,0 +1,53 @@
+-- source include/have_partition.inc
+-- source include/not_embedded.inc
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+
+#
+# Bug#30102: rename table does corrupt tables with partition files on failure
+#
+--echo # Bug#30102 test
+CREATE TABLE t1 (a INT)
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (6),
+ PARTITION `p1....................` VALUES LESS THAN (9),
+ PARTITION p2 VALUES LESS THAN MAXVALUE);
+# partition p1 is 't1#P#p1' + @002e * 20 = 107 characters + file ending
+# total path lenght of './test/t1#P#p1@002e@002e<...>@002e.MY[ID]' is 118 chars
+--echo # List of files in database `test`, all original t1-files here
+--list_files $MYSQLD_DATADIR/test t1*
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
+--echo # Renaming to a file name where the first partition is 250 chars
+--echo # and the second partition is 350 chars
+# 7,7 avoids the error message, which is not deterministic.
+--error 7,7
+RENAME TABLE t1 TO `t2_new..............................................end`;
+#                         1234567890123456789012345678901234567890123456
+--echo # List of files in database `test`, should not be any t2-files here
+--list_files $MYSQLD_DATADIR/test t2*
+--echo # List of files in database `test`, should be all t1-files here
+--list_files $MYSQLD_DATADIR/test t1*
+--sorted_result
+SELECT * FROM t1;
+--echo # List of files in database `test`, should be all t1-files here
+--list_files $MYSQLD_DATADIR/test t1*
+--echo # Renaming to a file name where the first partition is 156 chars
+--echo # and the second partition is 256 chars
+# 7,7 avoids the error message, which is not deterministic.
+--error 7,7
+RENAME TABLE t1 TO `t2_............................_end`;
+#                      1234567890123456789012345678
+# 7 + 4 + 5 + 28 * 5 = 16 + 140 = 156
+--echo # List of files in database `test`, should not be any t2-files here
+--list_files $MYSQLD_DATADIR/test t2*
+--echo # List of files in database `test`, should be all t1-files here
+--list_files $MYSQLD_DATADIR/test t1*
+--sorted_result
+SELECT * FROM t1;
+DROP TABLE t1;
+--echo # Should not be any files left here
+--list_files $MYSQLD_DATADIR/test t1*
+--list_files $MYSQLD_DATADIR/test t2*
+--echo # End of bug#30102 test.

=== added file 'mysql-test/t/partition_rename_longfilename.test'
--- a/mysql-test/t/partition_rename_longfilename.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/partition_rename_longfilename.test	2009-07-27 11:20:43 +0000
@@ -0,0 +1,50 @@
+-- source include/not_windows.inc
+-- source include/have_partition.inc
+-- source include/not_embedded.inc
+--disable_warnings
+DROP TABLE IF EXISTS t1, t2;
+--enable_warnings
+let $MYSQLD_DATADIR= `SELECT @@datadir`;
+
+#
+# Bug#30102: rename table does corrupt tables with partition files on failure
+# This test case renames the table such that the partition file name 
+# is 255 chars long. Due the restriction of 260 char path name (including drive label)
+# this will fail in windows.
+# Other tests related to this bug can be found in partition_not_embedded.test
+#
+CREATE TABLE t1 (a INT)
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (6),
+ PARTITION `p1....................` VALUES LESS THAN (9),
+ PARTITION p2 VALUES LESS THAN MAXVALUE);
+# partition p1 is 't1#P#p1' + @002e * 20 = 107 characters + file ending
+# total path lenght of './test/t1#P#p1@002e@002e<...>@002e.MY[ID]' is 118 chars
+--echo # List of files in database `test`, all original t1-files here
+--list_files $MYSQLD_DATADIR/test t1*
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
+--echo # Renaming to a file name where the first partition is 155 chars
+--echo # and the second partition is 255 chars
+RENAME TABLE t1 TO `t2_............................end`;
+#                      1234567890123456789012345678
+# t2_ + end
+#     .MY[ID] or .frm
+#         #P#p[012]
+#             28 * @002e
+# 6 + 4 + 5 + 28 * 5 = 155
+--echo # List of files in database `test`, should not be any t1-files here
+--list_files $MYSQLD_DATADIR/test t1*
+--echo # List of files in database `test`, should be all t2-files here
+--list_files $MYSQLD_DATADIR/test t2*
+--sorted_result
+SELECT * FROM `t2_............................end`;
+RENAME TABLE `t2_............................end` to t1;
+--echo # List of files in database `test`, should be all t1-files here
+--list_files $MYSQLD_DATADIR/test t1*
+--sorted_result
+SELECT * FROM t1;
+DROP TABLE t1;
+--echo # Should not be any files left here
+--list_files $MYSQLD_DATADIR/test t1*
+--list_files $MYSQLD_DATADIR/test t2*
+--echo # End of bug#30102 test.

=== modified file 'mysql-test/t/show_check.test'
--- a/mysql-test/t/show_check.test	2009-06-24 19:39:33 +0000
+++ b/mysql-test/t/show_check.test	2009-07-27 15:57:53 +0000
@@ -1198,6 +1198,13 @@ DROP USER test_u@localhost;
 
 --echo End of 5.1 tests
 
+#
+# Maria removal: check that deadlock% variables are not present in the SHOW
+# VARIABLES output.
+#
+
+SHOW VARIABLES LIKE 'deadlock%';
+
 # Wait till all disconnects are completed
 --source include/wait_until_count_sessions.inc
 

=== modified file 'mysql-test/t/sp_notembedded.test'
--- a/mysql-test/t/sp_notembedded.test	2009-06-04 06:27:44 +0000
+++ b/mysql-test/t/sp_notembedded.test	2009-07-30 16:22:41 +0000
@@ -379,3 +379,39 @@ set @@global.concurrent_insert= @old_con
 # Wait till all disconnects are completed
 --source include/wait_until_count_sessions.inc
 
+
+--echo #
+--echo # Bug#44521 Prepared Statement: CALL p() - crashes: `! thd->main_da.is_sent' failed et.al.
+--echo #
+SELECT GET_LOCK('Bug44521', 0);
+--connect (con1,localhost,root,,)
+--echo ** Connection con1
+delimiter $;
+CREATE PROCEDURE p()
+BEGIN
+  SELECT 1;
+  SELECT GET_LOCK('Bug44521', 100);
+  SELECT 2;
+END$
+delimiter ;$
+--send CALL p();
+--connection default
+--echo ** Default connection
+let $wait_condition=
+  SELECT count(*) = 1 FROM information_schema.processlist
+  WHERE state = "User lock" AND info = "SELECT GET_LOCK('Bug44521', 100)";
+--source include/wait_condition.inc
+let $conid =
+  `SELECT id FROM information_schema.processlist
+   WHERE state = "User lock" AND info = "SELECT GET_LOCK('Bug44521', 100)"`;
+dirty_close con1;
+SELECT RELEASE_LOCK('Bug44521');
+let $wait_condition=
+  SELECT count(*) = 0 FROM information_schema.processlist
+  WHERE id = $conid;
+--source include/wait_condition.inc 
+DROP PROCEDURE p;
+
+--echo # ------------------------------------------------------------------
+--echo # -- End of 5.1 tests
+--echo # ------------------------------------------------------------------

=== modified file 'mysql-test/t/sp_trans.test'
--- a/mysql-test/t/sp_trans.test	2007-06-20 15:20:58 +0000
+++ b/mysql-test/t/sp_trans.test	2009-07-29 08:27:59 +0000
@@ -592,6 +592,47 @@ select distinct f1, bug13575(f1) from t3
 drop function bug13575|
 drop table t3|
 
+--echo #
+--echo # End of 5.1 tests
+--echo #
+
+--echo # 
+--echo # Bug #35877 Update .. WHERE with function, constraint violation, crash 
+--echo #           
+
+--disable_warnings
+DROP TABLE IF EXISTS t1_aux|
+DROP TABLE IF EXISTS t1_not_null|
+DROP FUNCTION IF EXISTS f1_two_inserts|
+--enable_warnings
+
+-- echo # MyISAM test
+CREATE TABLE t1_not_null (f1 BIGINT, f2 BIGINT NOT NULL)|
+CREATE TABLE t1_aux (f1 BIGINT, f2 BIGINT)|
+INSERT INTO t1_aux VALUES (1,1)|
+
+CREATE FUNCTION f1_two_inserts() returns INTEGER
+BEGIN
+   INSERT INTO t1_not_null SET f1 = 10, f2 = NULL;
+   RETURN 1;
+END|
+
+-- error ER_BAD_NULL_ERROR
+UPDATE t1_aux SET f2 = 2 WHERE f1 = f1_two_inserts()|
+
+-- echo # InnoDB test
+ALTER TABLE t1_not_null ENGINE = InnoDB|
+ALTER TABLE t1_aux ENGINE = InnoDB|
+
+-- error ER_BAD_NULL_ERROR
+UPDATE t1_aux SET f2 = 2 WHERE f1 = f1_two_inserts()|
+
+DROP TABLE t1_aux, t1_not_null|
+DROP FUNCTION f1_two_inserts|
+
+-- echo #
+-- echo # End of 5.4 tests
+-- echo #
 
 #
 # BUG#NNNN: New bug synopsis

=== modified file 'mysql-test/valgrind.supp'
--- a/mysql-test/valgrind.supp	2009-03-11 07:19:41 +0000
+++ b/mysql-test/valgrind.supp	2009-08-06 05:18:44 +0000
@@ -622,3 +622,28 @@
   fun:deflate_slow
   fun:deflate
 }
+
+# BUG#45630
+# Suppress valgrind failures within nptl_pthread_exit_hack_handler on Ubuntu 9.04, x86 (but not amd64)
+#
+
+{
+   Mem loss within nptl_pthread_exit_hack_handler
+   Memcheck:Leak
+   fun:malloc
+   obj:*/ld-*.so
+   obj:*/ld-*.so
+   obj:*/ld-*.so
+   obj:*/ld-*.so
+   obj:*/libc-*.so
+   obj:*/ld-*.so
+   fun:__libc_dlopen_mode
+   fun:pthread_cancel_init
+   fun:_Unwind_ForcedUnwind
+   fun:__pthread_unwind
+   fun:pthread_exit
+   fun:nptl_pthread_exit_hack_handler
+   fun:start_thread
+   fun:clone
+}
+

=== modified file 'mysys/Makefile.am'
--- a/mysys/Makefile.am	2009-02-07 15:47:14 +0000
+++ b/mysys/Makefile.am	2009-07-31 20:21:25 +0000
@@ -80,7 +80,7 @@ EXTRA_DIST =		CMakeLists.txt mf_soundex.
 			my_conio.c my_wincond.c my_winthread.c my_winerr.c my_winfile.c
 
 DEFS =			-DDEFAULT_BASEDIR=\"$(prefix)\" \
-			-DDATADIR="\"$(MYSQLDATAdir)\"" \
+			-DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \
 			-DDEFAULT_CHARSET_HOME="\"$(MYSQLBASEdir)\"" \
 			-DSHAREDIR="\"$(MYSQLSHAREdir)\"" \
 			-DDEFAULT_HOME_ENV=MYSQL_HOME \

=== modified file 'mysys/array.c'
--- a/mysys/array.c	2009-03-17 20:07:27 +0000
+++ b/mysys/array.c	2009-07-24 08:27:14 +0000
@@ -32,11 +32,11 @@
   DESCRIPTION
     init_dynamic_array() initiates array and allocate space for
     init_alloc eilements.
-    Array is usable even if space allocation failed.
+    Array is usable even if space allocation failed, hence, the
+    function never returns TRUE.
     Static buffers must begin immediately after the array structure.
 
   RETURN VALUE
-    TRUE	my_malloc_ci() failed
     FALSE	Ok
 */
 
@@ -57,13 +57,14 @@ my_bool init_dynamic_array2(DYNAMIC_ARRA
   array->size_of_element=element_size;
   if ((array->buffer= init_buffer))
     DBUG_RETURN(FALSE);
+  /* 
+    Since the dynamic array is usable even if allocation fails here malloc
+    should not throw an error
+  */
   if (init_alloc &&
       !(array->buffer=(uchar*) my_malloc_ci(element_size*init_alloc,
-                                            MYF(MY_WME))))
-  {
+                                            MYF(0))))
     array->max_element=0;
-    DBUG_RETURN(TRUE);
-  }
   DBUG_RETURN(FALSE);
 }
 

=== modified file 'mysys/my_handler_errors.h'
--- a/mysys/my_handler_errors.h	2008-07-22 14:16:22 +0000
+++ b/mysys/my_handler_errors.h	2009-07-24 12:37:26 +0000
@@ -132,6 +132,8 @@ static const char *handler_error_message
   /* HA_ERR_TABLESPACE_DATAFILE_EXIST */
   "Tablespace data file already exists", /* TODO: get a better message */
   /* HA_ERR_ROW_NOT_VISIBLE */
-  "Row is not visible by the current transaction"
+  "Row is not visible by the current transaction",
+  /* HA_ERR_TOO_MANY_CONCURRENT_TRXS */
+  "Too many active concurrent transactions"
 };
 

=== modified file 'netware/BUILD/compile-netware-START'
--- a/netware/BUILD/compile-netware-START	2006-10-12 16:25:27 +0000
+++ b/netware/BUILD/compile-netware-START	2009-07-20 16:51:21 +0000
@@ -22,6 +22,5 @@ base_configs=" \
 	--enable-local-infile \
 	--with-extra-charsets=all \
 	--prefix=N:/mysql \
-	--without-mysqlmanager \
 	--without-man \
 	"

=== modified file 'plugin/semisync/semisync_master.cc'
--- a/plugin/semisync/semisync_master.cc	2009-06-17 10:37:04 +0000
+++ b/plugin/semisync/semisync_master.cc	2009-07-16 09:03:48 +0000
@@ -90,7 +90,7 @@ ActiveTranx::~ActiveTranx()
 {
   for (int idx = 0; idx < num_transactions_; ++idx)
   {
-    delete node_array_[idx].log_name_;
+    delete [] node_array_[idx].log_name_;
     node_array_[idx].log_name_ = NULL;
   }
 
@@ -138,6 +138,16 @@ ActiveTranx::TranxNode* ActiveTranx::all
     ptr->next_ = NULL;
     ptr->hash_next_ = NULL;
   }
+  else
+  {
+    /*
+      free_pool should never be NULL here, because we have
+      max_connections number of pre-allocated nodes.
+    */
+    sql_print_error("You have encountered a semi-sync bug (free_pool == NULL), "
+                    "please report to http://bugs.mysql.com");
+    assert(free_pool_);
+  }
 
   return ptr;
 }
@@ -438,7 +448,7 @@ int ReplSemiSyncMaster::enableMaster()
     }
     else
     {
-      sql_print_information("Semi-sync replication not able to allocate memory.");
+      sql_print_error("Cannot allocate memory to enable semi-sync on the master.");
       result = -1;
     }
   }
@@ -764,17 +774,11 @@ int ReplSemiSyncMaster::commitTrx(const 
 
         if (wait_result != 0)
 	{
-          if (trace_level_ & kTraceGeneral)
-	  {
-            /* This is a real wait timeout. */
-            sql_print_warning("Replication semi-sync not sent binlog to "
-                            "slave within the timeout %lu ms - OFF.",
-                            wait_timeout_);
-            sql_print_warning("          semi-sync up to file %s, position %lu",
+          /* This is a real wait timeout. */
+          sql_print_warning("Timeout waiting for reply of binlog (file: %s, pos: %lu), "
+                            "semi-sync up to file %s, position %lu.",
+                            trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos,
                             reply_file_name_, (unsigned long)reply_file_pos_);
-            sql_print_warning("          transaction needs file %s, position %lu",
-                            trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos);
-          }
           total_wait_timeouts_++;
 
           /* switch semi-sync off */
@@ -821,7 +825,7 @@ int ReplSemiSyncMaster::commitTrx(const 
 
   l_end:
     /* Update the status counter. */
-    if (is_on())
+    if (is_on() && rpl_semi_sync_master_clients)
       enabled_transactions_++;
     else
       disabled_transactions_++;
@@ -867,7 +871,7 @@ int ReplSemiSyncMaster::switch_off()
   switched_off_times_++;
   wait_file_name_inited_   = false;
   reply_file_name_inited_  = false;
-  commit_file_name_inited_ = false;
+  sql_print_information("Semi-sync replication switched OFF.");
   cond_broadcast();                            /* wake up all waiting threads */
 
   return function_exit(kWho, result);
@@ -904,11 +908,10 @@ int ReplSemiSyncMaster::try_switch_on(in
     /* Switch semi-sync replication on. */
     state_ = true;
 
-    if (trace_level_ & kTraceGeneral)
-      sql_print_information("%s switch semi-sync ON with server(%d) "
-                            "at (%s, %lu), repl(%d)",
-                            kWho, server_id, log_file_name,
-                            (unsigned long)log_file_pos, (int)is_on());
+    sql_print_information("Semi-sync replication switched ON with slave (server_id: %d) "
+                          "at (%s, %lu)",
+                          server_id, log_file_name,
+                          (unsigned long)log_file_pos);
   }
 
   return function_exit(kWho, 0);
@@ -930,6 +933,9 @@ int ReplSemiSyncMaster::reserveSyncHeade
     /* No enough space for the extra header, disable semi-sync master */
     if (sizeof(kSyncHeader) > size)
     {
+      sql_print_warning("No enough space in the packet "
+                        "for semi-sync extra header, "
+                        "semi-sync replication disabled");
       disableMaster();
       return 0;
     }
@@ -1083,10 +1089,19 @@ int ReplSemiSyncMaster::writeTranxInBinl
     commit_file_name_inited_ = true;
   }
 
-  if (is_on())
+  if (is_on() && rpl_semi_sync_master_clients)
   {
     assert(active_tranxs_ != NULL);
-    result = active_tranxs_->insert_tranx_node(log_file_name, log_file_pos);
+    if(active_tranxs_->insert_tranx_node(log_file_name, log_file_pos))
+    {
+      /*
+        if insert tranx_node failed, print a warning message
+        and turn off semi-sync
+      */
+      sql_print_warning("Semi-sync failed to insert tranx_node for binlog file: %s, position: %ul",
+                        log_file_name, log_file_pos);
+      switch_off();
+    }
   }
 
  l_end:
@@ -1131,7 +1146,7 @@ void ReplSemiSyncMaster::setExportStats(
 {
   lock();
 
-  rpl_semi_sync_master_status           = state_ ? 1 : 0;
+  rpl_semi_sync_master_status           = state_ && rpl_semi_sync_master_clients;
   rpl_semi_sync_master_yes_transactions = enabled_transactions_;
   rpl_semi_sync_master_no_transactions  = disabled_transactions_;
   rpl_semi_sync_master_off_times        = switched_off_times_;

=== modified file 'plugin/semisync/semisync_master_plugin.cc'
--- a/plugin/semisync/semisync_master_plugin.cc	2009-06-17 10:37:04 +0000
+++ b/plugin/semisync/semisync_master_plugin.cc	2009-07-16 08:59:59 +0000
@@ -159,7 +159,7 @@ static MYSQL_SYSVAR_ULONG(timeout, rpl_s
  "The timeout value (in ms) for semi-synchronous replication in the master",
   NULL, 			// check
   fix_rpl_semi_sync_master_timeout,	// update
-  10, 0, ~0L, 1);
+  10000, 0, ~0L, 1);
 
 static MYSQL_SYSVAR_ULONG(trace_level, rpl_semi_sync_master_trace_level,
   PLUGIN_VAR_OPCMDARG,

=== modified file 'plugin/semisync/semisync_slave_plugin.cc'
--- a/plugin/semisync/semisync_slave_plugin.cc	2009-06-17 10:37:04 +0000
+++ b/plugin/semisync/semisync_slave_plugin.cc	2009-07-07 02:44:17 +0000
@@ -63,7 +63,7 @@ int repl_semi_slave_request_dump(Binlog_
   }
 
   row= mysql_fetch_row(res);
-  if (!row)
+  if (!row || strcmp(row[1], "ON"))
   {
     /* Master does not support or not configured semi-sync */
     sql_print_warning("Master server does not support or not configured semi-sync replication, fallback to asynchronous");

=== modified file 'scripts/make_binary_distribution.sh'
--- a/scripts/make_binary_distribution.sh	2009-04-14 21:07:28 +0000
+++ b/scripts/make_binary_distribution.sh	2009-07-21 14:35:04 +0000
@@ -56,6 +56,12 @@ SOURCE=`pwd`
 CP="cp -p"
 MV="mv"
 
+# There are platforms, notably OS X on Intel (x86 + x86_64),
+# for which "uname" does not provide sufficient information.
+# The value of CFLAGS as used during compilation is the most exact info
+# we can get - after all, we care about _what_ we built, not _where_ we did it.
+cflags="@CFLAGS@"
+
 STRIP=1				# Option ignored
 SILENT=0
 PLATFORM=""
@@ -104,7 +110,50 @@ if [ x"$PLATFORM" = x"" ] ; then
   system=`echo $system | sed -e 's/linux-gnu/linux/g'`
   system=`echo $system | sed -e 's/solaris2.\([0-9]*\)/solaris\1/g'`
   system=`echo $system | sed -e 's/sco3.2v\(.*\)/openserver\1/g'`
+fi
+
+# Get the "machine", which really is the CPU architecture (including the size).
+# The precedence is:
+# 1) use an explicit argument, if given;
+# 2) use platform-specific fixes, if there are any (see bug#37808);
+# 3) stay with the default (determined during "configure", using predefined macros).
+
+if [ x"$MACHINE" != x"" ] ; then
+  machine=$MACHINE
+else
+  case $system in
+    osx* )
+      # Extract "XYZ" from CFLAGS "... -arch XYZ ...", or empty!
+      cflag_arch=`echo "$cflags" | sed -n -e 's=.* -arch \([^ ]*\) .*=\1=p'`
+      case "$cflag_arch" in
+        i386 )    case $system in
+                    osx10.4 )  machine=i686 ;; # Used a different naming
+                    * )        machine=x86 ;;
+                  esac ;;
+        x86_64 )  machine=x86_64 ;;
+        ppc )     ;;  # No treatment needed with PPC
+        ppc64 )   ;;
+        * ) # No matching compiler flag? "--platform" is needed
+            if [ x"$PLATFORM" != x"" ] ; then
+              :  # See below: "$PLATFORM" will take precedence anyway
+            elif [ "$system" = "osx10.3" -a -z "$cflag_arch" ] ; then
+              :  # Special case of OS X 10.3, which is PPC-32 only and doesn't use "-arch"
+            else
+              echo "On system '$system' only specific '-arch' values are expected."
+              echo "It is taken from the 'CFLAGS' whose value is:"
+              echo "$cflags"
+              echo "'-arch $cflag_arch' is unexpected, and no '--platform' was given: ABORT"
+              exit 1
+            fi ;;
+      esac  # "$cflag_arch"
+      ;;
+  esac  # $system
+fi
 
+# Combine OS and CPU to the "platform". Again, an explicit argument takes precedence.
+if [ x"$PLATFORM" != x"" ] ; then
+  :  
+else
   PLATFORM="$system-$machine"
 fi
 
@@ -153,10 +202,10 @@ which_1 ()
     do
       for file in $d/$cmd
       do
-	if [ -x $file -a ! -d $file ] ; then
-	  echo $file
-	  exit 0
-	fi
+        if [ -x $file -a ! -d $file ] ; then
+          echo $file
+          exit 0
+        fi
       done
     done
   done
@@ -342,7 +391,6 @@ BIN_FILES="extra/comp_err$BS extra/repla
   storage/myisam/myisamlog$BS storage/myisam/myisam_ftdump$BS \
   sql/mysqld$BS sql/mysqld-debug$BS \
   sql/mysql_tzinfo_to_sql$BS \
-  server-tools/instance-manager/mysqlmanager$BS \
   client/mysql$BS client/mysqlshow$BS client/mysqladmin$BS \
   client/mysqlslap$BS \
   client/mysqldump$BS client/mysqlimport$BS \
@@ -460,7 +508,7 @@ rm -f   $BASE/support-files/magic \
         $BASE/support-files/mysql-log-rotate \
         $BASE/support-files/binary-configure \
         $BASE/support-files/build-tags \
-	$BASE/support-files/MySQL-shared-compat.spec \
+        $BASE/support-files/MySQL-shared-compat.spec \
         $BASE/INSTALL-BINARY
 
 # Clean up if we did this from a bk tree

=== modified file 'sql-bench/README' (properties changed: +x to -x)
=== modified file 'sql-common/client.c'
--- a/sql-common/client.c	2009-07-08 07:30:40 +0000
+++ b/sql-common/client.c	2009-08-04 12:53:39 +0000
@@ -2378,6 +2378,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     struct addrinfo *res_lst, hints, *t_res;
     int gai_errno;
     char port_buf[NI_MAXSERV];
+    my_socket sock= SOCKET_ERROR;
+    int saved_error, status= -1;
 
     unix_socket=0;				/* This is not used */
 
@@ -2422,44 +2424,58 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       goto error;
     }
 
-    /* We only look at the first item (something to think about changing in the future) */
-    t_res= res_lst; 
+    /*
+      A hostname might map to multiple IP addresses (IPv4/IPv6). Go over the
+      list of IP addresses until a successful connection can be established.
+    */
+    for (t_res= res_lst; t_res; t_res= t_res->ai_next)
     {
-      my_socket sock= socket(t_res->ai_family, t_res->ai_socktype,
-                             t_res->ai_protocol);
+      sock= socket(t_res->ai_family, t_res->ai_socktype, t_res->ai_protocol);
       if (sock == SOCKET_ERROR)
       {
-        set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
-                                 ER(CR_IPSOCK_ERROR), socket_errno);
-        freeaddrinfo(res_lst);
-        goto error;
+        saved_error= socket_errno;
+        continue;
       }
 
-      net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ);
-      if (! net->vio )
-      {
-        DBUG_PRINT("error",("Unknow protocol %d ", mysql->options.protocol));
-        set_mysql_error(mysql, CR_CONN_UNKNOW_PROTOCOL, unknown_sqlstate);
-        closesocket(sock);
-        freeaddrinfo(res_lst);
-        goto error;
-      }
+      status= my_connect(sock, t_res->ai_addr, t_res->ai_addrlen,
+                         mysql->options.connect_timeout);
+      if (!status)
+        break;
 
-      if (my_connect(sock, t_res->ai_addr, t_res->ai_addrlen,
-                     mysql->options.connect_timeout))
-      {
-        DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno,
-                            host));
-        set_mysql_extended_error(mysql, CR_CONN_HOST_ERROR, unknown_sqlstate,
-                                 ER(CR_CONN_HOST_ERROR), host, socket_errno);
-        vio_delete(net->vio);
-        net->vio= 0;
-        freeaddrinfo(res_lst);
-        goto error;
-      }
+      /*
+        Save value as socket errno might be overwritten due to
+        calling a socket function below.
+      */
+      saved_error= socket_errno;
+
+      closesocket(sock);
     }
 
     freeaddrinfo(res_lst);
+
+    if (sock == SOCKET_ERROR)
+    {
+      set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
+                                ER(CR_IPSOCK_ERROR), saved_error);
+      goto error;
+    }
+
+    if (status)
+    {
+      DBUG_PRINT("error",("Got error %d on connect to '%s'", saved_error, host));
+      set_mysql_extended_error(mysql, CR_CONN_HOST_ERROR, unknown_sqlstate,
+                                ER(CR_CONN_HOST_ERROR), host, saved_error);
+      goto error;
+    }
+
+    net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ);
+    if (! net->vio )
+    {
+      DBUG_PRINT("error",("Unknow protocol %d ", mysql->options.protocol));
+      set_mysql_error(mysql, CR_CONN_UNKNOW_PROTOCOL, unknown_sqlstate);
+      closesocket(sock);
+      goto error;
+    }
   }
 
   if (!net->vio)

=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am	2009-06-08 14:58:33 +0000
+++ b/sql/Makefile.am	2009-07-31 20:21:25 +0000
@@ -177,7 +177,7 @@ mysql_tzinfo_to_sql_CXXFLAGS= -DTZINFO2S
 
 DEFS =			-DMYSQL_SERVER \
 			-DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \
-			-DDATADIR="\"$(MYSQLDATAdir)\"" \
+			-DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \
 			-DSHAREDIR="\"$(MYSQLSHAREdir)\"" \
 			-DPLUGINDIR="\"$(pkgplugindir)\"" \
 			-DHAVE_EVENT_SCHEDULER \

=== modified file 'sql/backup/be_thread.cc'
--- a/sql/backup/be_thread.cc	2009-03-16 14:38:05 +0000
+++ b/sql/backup/be_thread.cc	2009-07-24 16:14:20 +0000
@@ -124,8 +124,7 @@ pthread_handler_t backup_thread_for_lock
   }
 
   THD_SET_PROC_INFO(thd, "Locking thread started");
-  thd->query= locking_thd->thd_name.c_ptr();
-  thd->query_length= locking_thd->thd_name.length();
+  thd->set_query(locking_thd->thd_name.c_ptr(), locking_thd->thd_name.length());
 
   pthread_detach_this_thread();
   locking_thd->lock_thd= thd;
@@ -319,9 +318,9 @@ void Locking_thread_st::kill_locking_thr
   if (lock_thd && (lock_state != LOCK_DONE) && (lock_state != LOCK_SIGNAL))
   {
     lock_state= LOCK_SIGNAL;
-    pthread_mutex_lock(&lock_thd->LOCK_delete);
+    pthread_mutex_lock(&lock_thd->LOCK_thd_data);
     lock_thd->awake(THD::KILL_CONNECTION);
-    pthread_mutex_unlock(&lock_thd->LOCK_delete);
+    pthread_mutex_unlock(&lock_thd->LOCK_thd_data);
     pthread_cond_signal(&COND_thread_wait);
   }
   pthread_mutex_unlock(&THR_LOCK_caller);

=== modified file 'sql/derror.cc'
--- a/sql/derror.cc	2009-07-03 05:54:09 +0000
+++ b/sql/derror.cc	2009-07-21 08:37:50 +0000
@@ -111,7 +111,20 @@ bool read_texts(const char *file_name, c
                               lang_path, "", 4),
 		    O_RDONLY | O_SHARE | O_BINARY,
 		    MYF(0))) < 0)
-    goto err; /* purecov: inspected */
+  {
+    /*
+      Trying pre-5.4 sematics of the --language parameter.
+      It included the language-specific part, e.g.:
+      
+      --language=/path/to/english/
+    */
+    if ((file= my_open(fn_format(name, file_name, lc_messages_dir, "", 4),
+                       O_RDONLY | O_SHARE | O_BINARY,
+                       MYF(0))) < 0)
+      goto err;
+    sql_print_error("An old style --language value with language specific part detected: %s", lc_messages_dir);
+    sql_print_error("Use --lc-messages-dir without language specific part instead.");
+  }
 
   funktpos=1;
   if (my_read(file,(uchar*) head,32,MYF(MY_NABP))) goto err;

=== modified file 'sql/event_data_objects.cc'
--- a/sql/event_data_objects.cc	2009-08-07 09:26:33 +0000
+++ b/sql/event_data_objects.cc	2009-08-07 16:25:06 +0000
@@ -1431,13 +1431,7 @@ Event_job_data::execute(THD *thd, bool d
   thd->variables.sql_mode= sql_mode;
   thd->variables.time_zone= time_zone;
 
-  /*
-    Peculiar initialization order is a crutch to avoid races in SHOW
-    PROCESSLIST which reads thd->{query/query_length} without a mutex.
-  */
-  thd->query_length= 0;
-  thd->query= sp_sql.c_ptr_safe();
-  thd->query_length= sp_sql.length();
+  thd->set_query(sp_sql.c_ptr_safe(), sp_sql.length());
 
   {
     Parser_state parser_state(thd, thd->query, thd->query_length);
@@ -1498,13 +1492,8 @@ end_no_parse:
     else
     {
       ulong saved_master_access;
-      /*
-        Peculiar initialization order is a crutch to avoid races in SHOW
-        PROCESSLIST which reads thd->{query/query_length} without a mutex.
-      */
-      thd->query_length= 0;
-      thd->query= sp_sql.c_ptr_safe();
-      thd->query_length= sp_sql.length();
+
+      thd->set_query(sp_sql.c_ptr_safe(), sp_sql.length());
 
       /*
         NOTE: even if we run in read-only mode, we should be able to lock
@@ -1529,8 +1518,7 @@ end_no_parse:
   thd->end_statement();
   thd->cleanup_after_query();
   /* Avoid races with SHOW PROCESSLIST */
-  thd->query_length= 0;
-  thd->query= NULL;
+  thd->set_query(NULL, 0);
 
   DBUG_PRINT("info", ("EXECUTED %s.%s  ret: %d", dbname.str, name.str, ret));
 

=== modified file 'sql/event_scheduler.cc'
--- a/sql/event_scheduler.cc	2009-01-07 17:37:52 +0000
+++ b/sql/event_scheduler.cc	2009-07-24 19:09:00 +0000
@@ -158,6 +158,7 @@ deinit_event_thread(THD *thd)
   thread_count--;
   thread_running--;
   delete thd;
+  pthread_cond_broadcast(&COND_thread_count);
   pthread_mutex_unlock(&LOCK_thread_count);
 }
 
@@ -426,6 +427,7 @@ Event_scheduler::start()
     thread_count--;
     thread_running--;
     delete new_thd;
+    pthread_cond_broadcast(&COND_thread_count);
     pthread_mutex_unlock(&LOCK_thread_count);
   }
 end:
@@ -558,6 +560,7 @@ error:
     thread_count--;
     thread_running--;
     delete new_thd;
+    pthread_cond_broadcast(&COND_thread_count);
     pthread_mutex_unlock(&LOCK_thread_count);
   }
   delete event_name;
@@ -638,13 +641,13 @@ Event_scheduler::stop()
     DBUG_PRINT("info", ("Scheduler thread has id %lu",
                         scheduler_thd->thread_id));
     /* Lock from delete */
-    pthread_mutex_lock(&scheduler_thd->LOCK_delete);
+    pthread_mutex_lock(&scheduler_thd->LOCK_thd_data);
     /* This will wake up the thread if it waits on Queue's conditional */
     sql_print_information("Event Scheduler: Killing the scheduler thread, "
                           "thread id %lu",
                           scheduler_thd->thread_id);
     scheduler_thd->awake(THD::KILL_CONNECTION);
-    pthread_mutex_unlock(&scheduler_thd->LOCK_delete);
+    pthread_mutex_unlock(&scheduler_thd->LOCK_thd_data);
 
     /* thd could be 0x0, when shutting down */
     sql_print_information("Event Scheduler: "

=== modified file 'sql/events.cc'
--- a/sql/events.cc	2009-04-09 06:24:18 +0000
+++ b/sql/events.cc	2009-07-24 19:09:00 +0000
@@ -821,22 +821,23 @@ Events::fill_schema_events(THD *thd, TAB
 }
 
 
-/*
-  Inits the scheduler's structures.
-
-  SYNOPSIS
-    Events::init()
-
-  NOTES
-    This function is not synchronized.
+/**
+  Initializes the scheduler's structures.
 
-  RETURN VALUE
-    FALSE  OK
-    TRUE   Error in case the scheduler can't start
+  @param  opt_noacl_or_bootstrap
+                     TRUE if there is --skip-grant-tables or --bootstrap
+                     option. In that case we disable the event scheduler.
+
+  @note   This function is not synchronized.
+
+  @retval  FALSE   Perhaps there was an error, and the event scheduler
+                   is disabled. But the error is not fatal and the 
+                   server start up can continue.
+  @retval  TRUE    Fatal error. Startup must terminate (call unireg_abort()).
 */
 
 bool
-Events::init(my_bool opt_noacl)
+Events::init(my_bool opt_noacl_or_bootstrap)
 {
 
   THD *thd;
@@ -844,11 +845,6 @@ Events::init(my_bool opt_noacl)
 
   DBUG_ENTER("Events::init");
 
-  /* Disable the scheduler if running with --skip-grant-tables */
-  if (opt_noacl)
-    opt_event_scheduler= EVENTS_DISABLED;
-
-
   /* We need a temporary THD during boot */
   if (!(thd= new THD()))
   {
@@ -876,23 +872,30 @@ Events::init(my_bool opt_noacl)
   /*
     Since we allow event DDL even if the scheduler is disabled,
     check the system tables, as we might need them.
+
+    If run with --skip-grant-tables or --bootstrap, don't try to do the
+    check of system tables and don't complain: in these modes the tables
+    are most likely not there and we're going to disable the event
+    scheduler anyway.
   */
-  if (Event_db_repository::check_system_tables(thd))
+  if (opt_noacl_or_bootstrap || Event_db_repository::check_system_tables(thd))
   {
-    sql_print_error("Event Scheduler: An error occurred when initializing "
-                    "system tables.%s",
-                    opt_event_scheduler == EVENTS_DISABLED ?
-                    "" : " Disabling the Event Scheduler.");
+    if (! opt_noacl_or_bootstrap)
+    {
+      sql_print_error("Event Scheduler: An error occurred when initializing "
+                      "system tables. Disabling the Event Scheduler.");
+      check_system_tables_error= TRUE;
+    }
 
     /* Disable the scheduler since the system tables are not up to date */
     opt_event_scheduler= EVENTS_DISABLED;
-    check_system_tables_error= TRUE;
     goto end;
   }
 
   /*
     Was disabled explicitly from the command line, or because we're running
-    with --skip-grant-tables, or because we have no system tables.
+    with --skip-grant-tables, or --bootstrap, or because we have no system
+    tables.
   */
   if (opt_event_scheduler == Events::EVENTS_DISABLED)
     goto end;
@@ -909,7 +912,7 @@ Events::init(my_bool opt_noacl)
   }
 
   if (event_queue->init_queue(thd) || load_events_from_db(thd) ||
-      opt_event_scheduler == EVENTS_ON && scheduler->start())
+      (opt_event_scheduler == EVENTS_ON && scheduler->start()))
   {
     sql_print_error("Event Scheduler: Error while loading from disk.");
     res= TRUE; /* fatal error: request unireg_abort */

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2009-07-13 17:45:27 +0000
+++ b/sql/field.cc	2009-08-06 12:41:22 +0000
@@ -4517,7 +4517,6 @@ bool Field_double::send_binary(Protocol 
 
 int Field_double::cmp(const uchar *a_ptr, const uchar *b_ptr)
 {
-  ASSERT_COLUMN_MARKED_FOR_READ;
   double a,b;
 #ifdef WORDS_BIGENDIAN
   if (table->s->db_low_byte_first)
@@ -6188,50 +6187,19 @@ check_string_copy_error(Field_str *field
                         const char *end,
                         CHARSET_INFO *cs)
 {
-  const char *pos, *end_orig;
-  char tmp[64], *t;
+  const char *pos;
+  char tmp[32];
   THD *thd= field->table->in_use;
   
   if (!(pos= well_formed_error_pos) &&
       !(pos= cannot_convert_error_pos))
     return FALSE;
 
-  end_orig= end;
-  set_if_smaller(end, pos + 6);
+  convert_to_printable(tmp, sizeof(tmp), pos, (end - pos), cs, 6);
 
-  for (t= tmp; pos < end; pos++)
-  {
-    /*
-      If the source string is ASCII compatible (mbminlen==1)
-      and the source character is in ASCII printable range (0x20..0x7F),
-      then display the character as is.
-      
-      Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
-      or the source character is not in the printable range,
-      then print the character using HEX notation.
-    */
-    if (((unsigned char) *pos) >= 0x20 &&
-        ((unsigned char) *pos) <= 0x7F &&
-        cs->mbminlen == 1)
-    {
-      *t++= *pos;
-    }
-    else
-    {
-      *t++= '\\';
-      *t++= 'x';
-      *t++= _dig_vec_upper[((unsigned char) *pos) >> 4];
-      *t++= _dig_vec_upper[((unsigned char) *pos) & 15];
-    }
-  }
-  if (end_orig > end)
-  {
-    *t++= '.';
-    *t++= '.';
-    *t++= '.';
-  }
-  *t= '\0';
   push_warning_printf(thd,
+                      field->table->in_use->abort_on_warning ?
+                      MYSQL_ERROR::WARN_LEVEL_ERROR :
                       MYSQL_ERROR::WARN_LEVEL_WARN,
                       ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
                       ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2009-07-08 12:46:36 +0000
+++ b/sql/ha_partition.cc	2009-08-06 12:41:22 +0000
@@ -424,12 +424,9 @@ bool ha_partition::initialize_partition(
 
 int ha_partition::delete_table(const char *name)
 {
-  int error;
   DBUG_ENTER("ha_partition::delete_table");
 
-  if ((error= del_ren_cre_table(name, NULL, NULL, NULL)))
-    DBUG_RETURN(error);
-  DBUG_RETURN(handler::delete_table(name));
+  DBUG_RETURN(del_ren_cre_table(name, NULL, NULL, NULL));
 }
 
 
@@ -457,12 +454,9 @@ int ha_partition::delete_table(const cha
 
 int ha_partition::rename_table(const char *from, const char *to)
 {
-  int error;
   DBUG_ENTER("ha_partition::rename_table");
 
-  if ((error= del_ren_cre_table(from, to, NULL, NULL)))
-    DBUG_RETURN(error);
-  DBUG_RETURN(handler::rename_table(from, to));
+  DBUG_RETURN(del_ren_cre_table(from, to, NULL, NULL));
 }
 
 
@@ -1823,6 +1817,15 @@ uint ha_partition::del_ren_cre_table(con
   DBUG_PRINT("enter", ("from: (%s) to: (%s)", from, to));
   name_buffer_ptr= m_name_buffer_ptr;
   file= m_file;
+  if (to == NULL && table_arg == NULL)
+  {
+    /*
+      Delete table, start by delete the .par file. If error, break, otherwise
+      delete as much as possible.
+    */
+    if ((error= handler::delete_table(from)))
+      DBUG_RETURN(error);
+  }
   /*
     Since ha_partition has HA_FILE_BASED, it must alter underlying table names
     if they do not have HA_FILE_BASED and lower_case_table_names == 2.
@@ -1844,6 +1847,8 @@ uint ha_partition::del_ren_cre_table(con
       create_partition_name(to_buff, to_path, name_buffer_ptr,
                             NORMAL_PART_NAME, FALSE);
       error= (*file)->ha_rename_table(from_buff, to_buff);
+      if (error)
+        goto rename_error;
     }
     else if (table_arg == NULL)			// delete branch
       error= (*file)->ha_delete_table(from_buff);
@@ -1859,6 +1864,15 @@ uint ha_partition::del_ren_cre_table(con
       save_error= error;
     i++;
   } while (*(++file));
+  if (to != NULL)
+  {
+    if ((error= handler::rename_table(from, to)))
+    {
+      /* Try to revert everything, ignore errors */
+      (void) handler::rename_table(to, from);
+      goto rename_error;
+    }
+  }
   DBUG_RETURN(save_error);
 create_error:
   name_buffer_ptr= m_name_buffer_ptr;
@@ -1870,6 +1884,20 @@ create_error:
     name_buffer_ptr= strend(name_buffer_ptr) + 1;
   }
   DBUG_RETURN(error);
+rename_error:
+  name_buffer_ptr= m_name_buffer_ptr;
+  for (abort_file= file, file= m_file; file < abort_file; file++)
+  {
+    /* Revert the rename, back from 'to' to the original 'from' */
+    create_partition_name(from_buff, from_path, name_buffer_ptr,
+                          NORMAL_PART_NAME, FALSE);
+    create_partition_name(to_buff, to_path, name_buffer_ptr,
+                          NORMAL_PART_NAME, FALSE);
+    /* Ignore error here */
+    (void) (*file)->ha_rename_table(to_buff, from_buff);
+    name_buffer_ptr= strend(name_buffer_ptr) + 1;
+  }
+  DBUG_RETURN(error);
 }
 
 /*
@@ -2470,6 +2498,7 @@ int ha_partition::open(const char *name,
   /* Initialize the bitmap we use to minimize ha_start_bulk_insert calls */
   if (bitmap_init(&m_bulk_insert_started, NULL, m_tot_parts + 1, FALSE))
     DBUG_RETURN(1);
+  bitmap_clear_all(&m_bulk_insert_started);
   /* Initialize the bitmap we use to determine what partitions are used */
   if (!is_clone)
   {
@@ -3336,6 +3365,10 @@ ha_rows ha_partition::guess_bulk_insert_
   RETURN VALUE
     >0                      Error code
     0                       Success
+
+  Note: end_bulk_insert can be called without start_bulk_insert
+        being called, see bug¤44108.
+
 */
 
 int ha_partition::end_bulk_insert(bool abort)
@@ -3344,7 +3377,9 @@ int ha_partition::end_bulk_insert(bool a
   uint i;
   DBUG_ENTER("ha_partition::end_bulk_insert");
 
-  DBUG_ASSERT(bitmap_is_set(&m_bulk_insert_started, m_tot_parts));
+  if (!bitmap_is_set(&m_bulk_insert_started, m_tot_parts))
+    DBUG_RETURN(error);
+
   for (i= 0; i < m_tot_parts; i++)
   {
     int tmp;
@@ -3796,7 +3831,7 @@ int ha_partition::index_init(uint inx, b
   */
   if (m_lock_type == F_WRLCK)
     bitmap_union(table->read_set, &m_part_info->full_part_field_set);
-  else if (sorted)
+  if (sorted)
   {
     /*
       An ordered scan is requested. We must make sure all fields of the 
@@ -5008,14 +5043,32 @@ int ha_partition::info(uint flag)
       ref_length:               We set this to the value calculated
       and stored in local object
       create_time:              Creation time of table
-      Set by first handler
+      Set by handler with most rows
 
       So we calculate these constants by using the variables on the first
       handler.
     */
-    handler *file;
+    handler *file, **file_array;
+    ulonglong max_records= 0;
+    uint32 i= 0;
+    uint32 handler_instance= 0;
+
+    file_array= m_file;
+    do
+    {
+      file= *file_array;
+      /* Get variables if not already done */
+      if (!(flag & HA_STATUS_VARIABLE))
+        file->info(HA_STATUS_VARIABLE);
+      if (file->stats.records > max_records)
+      {
+        max_records= file->stats.records;
+        handler_instance= i;
+      }
+      i++;
+    } while (*(++file_array));
 
-    file= m_file[0];
+    file= m_file[handler_instance];
     file->info(HA_STATUS_CONST);
     stats.create_time= file->stats.create_time;
     ref_length= m_ref_length;
@@ -5504,6 +5557,13 @@ int ha_partition::extra(enum ha_extra_fu
     /* Special actions for MERGE tables. Ignore. */
     break;
   }
+  /*
+    http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations.html
+    says we no longer support logging to partitioned tables, so we fail
+    here.
+  */
+  case HA_EXTRA_MARK_AS_LOG_TABLE:
+    DBUG_RETURN(ER_UNSUPORTED_LOG_ENGINE);
   default:
   {
     /* Temporary crash to discover what is wrong */

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2009-07-10 12:31:32 +0000
+++ b/sql/handler.cc	2009-07-29 10:25:07 +0000
@@ -66,7 +66,9 @@ static const LEX_STRING sys_table_aliase
 };
 
 const char *ha_row_type[] = {
-  "", "FIXED", "DYNAMIC", "COMPRESSED", "REDUNDANT", "COMPACT", "PAGE", "?","?","?"
+  "", "FIXED", "DYNAMIC", "COMPRESSED", "REDUNDANT", "COMPACT",
+  /* Reserved to be "PAGE" in future versions */ "?",
+  "?","?","?"
 };
 
 const char *tx_isolation_names[] =
@@ -351,6 +353,7 @@ int ha_init_errors(void)
   SETMSG(HA_ERR_TABLE_READONLY,         ER_DEFAULT(ER_OPEN_AS_READONLY));
   SETMSG(HA_ERR_AUTOINC_READ_FAILED,    ER_DEFAULT(ER_AUTOINC_READ_FAILED));
   SETMSG(HA_ERR_AUTOINC_ERANGE,         ER_DEFAULT(ER_WARN_DATA_OUT_OF_RANGE));
+  SETMSG(HA_ERR_TOO_MANY_CONCURRENT_TRXS, ER_DEFAULT(ER_TOO_MANY_CONCURRENT_TRXS));
 
   /* Register the error messages for use with my_error(). */
   return my_error_register(get_handler_errmsgs, HA_ERR_FIRST, HA_ERR_LAST);
@@ -2783,6 +2786,8 @@ void handler::print_error(int error, myf
     my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
                ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
     DBUG_VOID_RETURN;
+  case HA_ERR_TOO_MANY_CONCURRENT_TRXS:
+    textno= ER_TOO_MANY_CONCURRENT_TRXS;
     break;
   default:
     {
@@ -3010,6 +3015,7 @@ uint handler::get_dup_key(int error)
 */
 int handler::delete_table(const char *name)
 {
+  int saved_error= 0;
   int error= 0;
   int enoent_or_zero= ENOENT;                   // Error if no file was deleted
   char buff[FN_REFLEN];
@@ -3019,21 +3025,31 @@ int handler::delete_table(const char *na
     fn_format(buff, name, "", *ext, MY_UNPACK_FILENAME|MY_APPEND_EXT);
     if (my_delete_with_symlink(buff, MYF(0)))
     {
-      if ((error= my_errno) != ENOENT)
-	break;
+      if (my_errno != ENOENT)
+      {
+        /*
+          If error on the first existing file, return the error.
+          Otherwise delete as much as possible.
+        */
+        if (enoent_or_zero)
+          return my_errno;
+	saved_error= my_errno;
+      }
     }
     else
       enoent_or_zero= 0;                        // No error for ENOENT
     error= enoent_or_zero;
   }
-  return error;
+  return saved_error ? saved_error : error;
 }
 
 
 int handler::rename_table(const char * from, const char * to)
 {
   int error= 0;
-  for (const char **ext= bas_ext(); *ext ; ext++)
+  const char **ext, **start_ext;
+  start_ext= bas_ext();
+  for (ext= start_ext; *ext ; ext++)
   {
     if (rename_file_ext(from, to, *ext))
     {
@@ -3042,6 +3058,12 @@ int handler::rename_table(const char * f
       error= 0;
     }
   }
+  if (error)
+  {
+    /* Try to revert the rename. Ignore errors. */
+    for (; ext >= start_ext; ext--)
+      rename_file_ext(to, from, *ext);
+  }
   return error;
 }
 

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2009-05-25 10:10:18 +0000
+++ b/sql/handler.h	2009-07-29 10:25:07 +0000
@@ -350,7 +350,9 @@ enum legacy_db_type
 
 enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
 		ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
-		ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, ROW_TYPE_PAGE };
+		ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT,
+                /** Unused. Reserved for future versions. */
+                ROW_TYPE_PAGE };
 
 enum column_format_type { COLUMN_FORMAT_TYPE_NOT_USED= -1,
                           COLUMN_FORMAT_TYPE_DEFAULT=   0,
@@ -400,7 +402,9 @@ enum enum_binlog_command {
 #define HA_CREATE_USED_PASSWORD         (1L << 17)
 #define HA_CREATE_USED_CONNECTION       (1L << 18)
 #define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
+/** Unused. Reserved for future versions. */
 #define HA_CREATE_USED_TRANSACTIONAL    (1L << 20)
+/** Unused. Reserved for future versions. */
 #define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
 
 typedef ulonglong my_xid; // this line is the same as in log_event.h
@@ -1041,13 +1045,14 @@ typedef struct st_ha_create_information
   uint options;				/* OR of HA_CREATE_ options */
   uint merge_insert_method;
   uint extra_size;                      /* length of extra data segment */
-  /* 0 not used, 1 if not transactional, 2 if transactional */
+  /** Transactional or not. Unused; reserved for future versions. */
   enum ha_choice transactional;
   bool table_existed;			/* 1 in create if table existed */
   bool frm_only;                        /* 1 if no ha_create_table() */
   bool varchar;                         /* 1 if table has a VARCHAR */
   enum ha_storage_media default_storage_media;  /* DEFAULT, DISK or MEMORY */
-  enum ha_choice page_checksum;         /* If we have page_checksums */
+  /** Per-page checksums or not. Unused; reserved for future versions. */
+  enum ha_choice page_checksum;
 } HA_CREATE_INFO;
 
 typedef struct st_ha_alter_information

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2009-07-03 10:39:01 +0000
+++ b/sql/item_func.cc	2009-07-28 22:45:02 +0000
@@ -6110,6 +6110,9 @@ Item_func_sp::execute_impl(THD *thd)
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
   Security_context *save_security_ctx= thd->security_ctx;
 #endif
+  enum enum_sp_data_access access=
+    (m_sp->m_chistics->daccess == SP_DEFAULT_ACCESS) ?
+     SP_DEFAULT_ACCESS_MAPPING : m_sp->m_chistics->daccess;
 
   DBUG_ENTER("Item_func_sp::execute_impl");
 
@@ -6127,11 +6130,13 @@ Item_func_sp::execute_impl(THD *thd)
     Throw an error if a non-deterministic function is called while
     statement-based replication (SBR) is active.
   */
+
   if (!m_sp->m_chistics->detistic && !trust_function_creators &&
+      (access == SP_CONTAINS_SQL || access == SP_MODIFIES_SQL_DATA) &&
       (mysql_bin_log.is_open() &&
        thd->variables.binlog_format == BINLOG_FORMAT_STMT))
   {
-    my_error(ER_BINLOG_ROW_RBR_TO_SBR, MYF(0));
+    my_error(ER_BINLOG_UNSAFE_ROUTINE, MYF(0));
     goto error;
   }
 

=== modified file 'sql/lex.h'
--- a/sql/lex.h	2009-05-13 11:04:33 +0000
+++ b/sql/lex.h	2009-07-29 10:25:07 +0000
@@ -404,7 +404,6 @@ static SYMBOL symbols[] = {
   { "PACK_KEYS",	SYM(PACK_KEYS_SYM)},
   { "PARSER",           SYM(PARSER_SYM)},
   { "PAGE",	        SYM(PAGE_SYM)},
-  { "PAGE_CHECKSUM",    SYM(PAGE_CHECKSUM_SYM)},
   { "PARTIAL",		SYM(PARTIAL)},
   { "PARTITION",        SYM(PARTITION_SYM)},
   { "PARTITIONING",     SYM(PARTITIONING_SYM)},
@@ -568,7 +567,6 @@ static SYMBOL symbols[] = {
   { "TO",		SYM(TO_SYM)},
   { "TRAILING",		SYM(TRAILING)},
   { "TRANSACTION",	SYM(TRANSACTION_SYM)},
-  { "TRANSACTIONAL",	SYM(TRANSACTIONAL_SYM)},
   { "TRIGGER",          SYM(TRIGGER_SYM)},
   { "TRIGGERS",         SYM(TRIGGERS_SYM)},
   { "TRUE",		SYM(TRUE_SYM)},

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2009-07-18 20:10:35 +0000
+++ b/sql/log.cc	2009-07-28 14:16:37 +0000
@@ -6081,7 +6081,6 @@ bool MYSQL_BIN_LOG::write(Log_event *eve
         DBUG_EVALUATE_IF("injecting_fault_writing", 1, 0))
       goto err;
 
-    error=0;
     if (file == &log_file) // we are writing to the real log (disk)
     {
       bool synced;
@@ -6090,12 +6089,14 @@ bool MYSQL_BIN_LOG::write(Log_event *eve
 
       if (RUN_HOOK(binlog_storage, after_flush,
                    (thd, log_file_name, file->pos_in_file, synced))) {
+        sql_print_error("Failed to run 'after_flush' hooks");
         goto err;
       }
 
       signal_update();
       rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
     }
+    error=0;
 
 err:
     if (error)
@@ -6499,7 +6500,11 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_C
 
       if (RUN_HOOK(binlog_storage, after_flush,
                    (thd, log_file_name, log_file.pos_in_file, synced)))
+      {
+        sql_print_error("Failed to run 'after_flush' hooks");
+        write_error=1;
         goto err;
+      }
 
       signal_update();
     }

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-07-06 08:12:12 +0000
+++ b/sql/log_event.cc	2009-07-28 14:16:37 +0000
@@ -3045,8 +3045,7 @@ int Query_log_event::do_apply_event(Rela
       rpl_filter->db_ok(thd->db))
   {
     thd->set_time((time_t)when);
-    thd->query_length= q_len_arg;
-    thd->query= (char*)query_arg;
+    thd->set_query((char*)query_arg, q_len_arg);
     pthread_mutex_lock(&LOCK_thread_count);
     thd->query_id = next_query_id();
     pthread_mutex_unlock(&LOCK_thread_count);
@@ -3250,8 +3249,22 @@ Default database: '%s'. Query: '%s'",
     */
   } /* End of if (db_ok(... */
 
+  {/**
+      The following failure injecion works in cooperation with tests 
+      setting @@global.debug= 'd,stop_slave_middle_group'.
+      The sql thread receives the killed status and will proceed 
+      to shutdown trying to finish incomplete events group.
+   */
+    DBUG_EXECUTE_IF("stop_slave_middle_group",
+                    if (strcmp("COMMIT", query) != 0 &&
+                        strcmp("BEGIN", query) != 0)
+                    {
+                      if (thd->transaction.all.modified_non_trans_table)
+                        const_cast<Relay_log_info*>(rli)->abort_slave= 1;
+                    };);
+  }
+
 end:
-  pthread_mutex_lock(&LOCK_thread_count);
   /*
     Probably we have set thd->query, thd->db, thd->catalog to point to places
     in the data_buf of this event. Now the event is going to be deleted
@@ -3264,10 +3277,8 @@ end:
   */
   thd->catalog= 0;
   thd->set_db(NULL, 0);                 /* will free the current database */
+  thd->set_query(NULL, 0);
   DBUG_PRINT("info", ("end: query= 0"));
-  thd->query= 0;			// just to be sure
-  thd->query_length= 0;
-  pthread_mutex_unlock(&LOCK_thread_count);
   close_thread_tables(thd);      
   /*
     As a disk space optimization, future masters will not log an event for
@@ -4571,8 +4582,7 @@ int Load_log_event::do_apply_event(NET* 
       print_query(FALSE, load_data_query, &end, (char **)&thd->lex->fname_start,
                   (char **)&thd->lex->fname_end);
       *end= 0;
-      thd->query_length= end - load_data_query;
-      thd->query= load_data_query;
+      thd->set_query(load_data_query, (uint) (end - load_data_query));
 
       if (sql_ex.opt_flags & REPLACE_FLAG)
       {
@@ -4678,12 +4688,9 @@ int Load_log_event::do_apply_event(NET* 
 error:
   thd->net.vio = 0; 
   const char *remember_db= thd->db;
-  pthread_mutex_lock(&LOCK_thread_count);
   thd->catalog= 0;
   thd->set_db(NULL, 0);                   /* will free the current database */
-  thd->query= 0;
-  thd->query_length= 0;
-  pthread_mutex_unlock(&LOCK_thread_count);
+  thd->set_query(NULL, 0);
   close_thread_tables(thd);
 
   DBUG_EXECUTE_IF("LOAD_DATA_INFILE_has_fatal_error",
@@ -7497,8 +7504,16 @@ int Rows_log_event::do_apply_event(Relay
           thd->transaction.stmt.modified_non_trans_table= TRUE;
     } // row processing loop
 
-    DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
-                    const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
+    {/**
+         The following failure injecion works in cooperation with tests 
+         setting @@global.debug= 'd,stop_slave_middle_group'.
+         The sql thread receives the killed status and will proceed 
+         to shutdown trying to finish incomplete events group.
+     */
+      DBUG_EXECUTE_IF("stop_slave_middle_group",
+                      if (thd->transaction.all.modified_non_trans_table)
+                        const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
+    }
 
     if ((error= do_after_row_operations(rli, error)) &&
         ignored_error_code(convert_handler_error(error, thd, table)))
@@ -7531,32 +7546,6 @@ int Rows_log_event::do_apply_event(Relay
     const_cast<Relay_log_info*>(rli)->cleanup_context(thd, error);
     thd->is_slave_error= 1;
   }
-  /*
-    This code would ideally be placed in do_update_pos() instead, but
-    since we have no access to table there, we do the setting of
-    last_event_start_time here instead.
-  */
-  else if (table && (table->s->primary_key == MAX_KEY) &&
-           !cache_stmt && get_flags(STMT_END_F) == RLE_NO_FLAGS)
-  {
-    /*
-      ------------ Temporary fix until WL#2975 is implemented ---------
-
-      This event is not the last one (no STMT_END_F). If we stop now
-      (in case of terminate_slave_thread()), how will we restart? We
-      have to restart from Table_map_log_event, but as this table is
-      not transactional, the rows already inserted will still be
-      present, and idempotency is not guaranteed (no PK) so we risk
-      that repeating leads to double insert. So we desperately try to
-      continue, hope we'll eventually leave this buggy situation (by
-      executing the final Rows_log_event). If we are in a hopeless
-      wait (reached end of last relay log and nothing gets appended
-      there), we timeout after one minute, and notify DBA about the
-      problem.  When WL#2975 is implemented, just remove the member
-      Relay_log_info::last_event_start_time and all its occurrences.
-    */
-    const_cast<Relay_log_info*>(rli)->last_event_start_time= my_time(0);
-  }
 
   DBUG_RETURN(error);
 }

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	2009-04-29 16:48:59 +0000
+++ b/sql/log_event_old.cc	2009-07-06 13:46:31 +0000
@@ -224,7 +224,7 @@ Old_rows_log_event::do_apply_event(Old_r
 
       row_start= row_end;
     }
-    DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
+    DBUG_EXECUTE_IF("stop_slave_middle_group",
                     const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
     error= do_after_row_operations(table, error);
     if (!ev->cache_stmt)
@@ -260,34 +260,6 @@ Old_rows_log_event::do_apply_event(Old_r
     DBUG_RETURN(error);
   }
 
-  /*
-    This code would ideally be placed in do_update_pos() instead, but
-    since we have no access to table there, we do the setting of
-    last_event_start_time here instead.
-  */
-  if (table && (table->s->primary_key == MAX_KEY) &&
-      !ev->cache_stmt && 
-      ev->get_flags(Old_rows_log_event::STMT_END_F) == Old_rows_log_event::RLE_NO_FLAGS)
-  {
-    /*
-      ------------ Temporary fix until WL#2975 is implemented ---------
-
-      This event is not the last one (no STMT_END_F). If we stop now
-      (in case of terminate_slave_thread()), how will we restart? We
-      have to restart from Table_map_log_event, but as this table is
-      not transactional, the rows already inserted will still be
-      present, and idempotency is not guaranteed (no PK) so we risk
-      that repeating leads to double insert. So we desperately try to
-      continue, hope we'll eventually leave this buggy situation (by
-      executing the final Old_rows_log_event). If we are in a hopeless
-      wait (reached end of last relay log and nothing gets appended
-      there), we timeout after one minute, and notify DBA about the
-      problem.  When WL#2975 is implemented, just remove the member
-      st_relay_log_info::last_event_start_time and all its occurences.
-    */
-    const_cast<Relay_log_info*>(rli)->last_event_start_time= my_time(0);
-  }
-
   DBUG_RETURN(0);
 }
 #endif
@@ -1743,7 +1715,7 @@ int Old_rows_log_event::do_apply_event(R
  
     } // row processing loop
 
-    DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
+    DBUG_EXECUTE_IF("stop_slave_middle_group",
                     const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
     error= do_after_row_operations(rli, error);
     if (!cache_stmt)
@@ -1779,33 +1751,6 @@ int Old_rows_log_event::do_apply_event(R
     DBUG_RETURN(error);
   }
 
-  /*
-    This code would ideally be placed in do_update_pos() instead, but
-    since we have no access to table there, we do the setting of
-    last_event_start_time here instead.
-  */
-  if (table && (table->s->primary_key == MAX_KEY) &&
-      !cache_stmt && get_flags(STMT_END_F) == RLE_NO_FLAGS)
-  {
-    /*
-      ------------ Temporary fix until WL#2975 is implemented ---------
-
-      This event is not the last one (no STMT_END_F). If we stop now
-      (in case of terminate_slave_thread()), how will we restart? We
-      have to restart from Table_map_log_event, but as this table is
-      not transactional, the rows already inserted will still be
-      present, and idempotency is not guaranteed (no PK) so we risk
-      that repeating leads to double insert. So we desperately try to
-      continue, hope we'll eventually leave this buggy situation (by
-      executing the final Old_rows_log_event). If we are in a hopeless
-      wait (reached end of last relay log and nothing gets appended
-      there), we timeout after one minute, and notify DBA about the
-      problem.  When WL#2975 is implemented, just remove the member
-      Relay_log_info::last_event_start_time and all its occurrences.
-    */
-    const_cast<Relay_log_info*>(rli)->last_event_start_time= my_time(0);
-  }
-
   DBUG_RETURN(0);
 }
 

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2009-07-07 11:33:10 +0000
+++ b/sql/mysql_priv.h	2009-07-31 19:46:24 +0000
@@ -1067,6 +1067,7 @@ bool compare_record(TABLE *table);
 bool append_file_to_dir(THD *thd, const char **filename_ptr, 
                         const char *table_name);
 bool table_def_init(void);
+void table_def_start_shutdown(void);
 void table_def_free(void);
 void assign_new_table_id(TABLE_SHARE *share);
 uint cached_open_tables(void);
@@ -1967,6 +1968,7 @@ extern bool opt_disable_networking, opt_
 extern bool opt_ignore_builtin_innodb;
 extern my_bool opt_character_set_client_handshake;
 extern bool volatile abort_loop, shutdown_in_progress;
+extern bool in_bootstrap;
 extern uint volatile thread_count, thread_running, global_read_lock;
 extern ulong thread_created;
 extern uint connection_count;

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-07-23 13:07:41 +0000
+++ b/sql/mysqld.cc	2009-08-06 14:59:03 +0000
@@ -464,6 +464,21 @@ my_bool locked_in_memory;
 bool opt_using_transactions;
 bool volatile abort_loop;
 bool volatile shutdown_in_progress;
+/*
+  True if the bootstrap thread is running. Protected by LOCK_thread_count,
+  just like thread_count.
+  Used in bootstrap() function to determine if the bootstrap thread
+  has completed. Note, that we can't use 'thread_count' instead,
+  since in 5.1, in presence of the Event Scheduler, there may be
+  event threads running in parallel, so it's impossible to know
+  what value of 'thread_count' is a sign of completion of the
+  bootstrap thread.
+
+  At the same time, we can't start the event scheduler after
+  bootstrap either, since we want to be able to process event-related
+  SQL commands in the init file and in --bootstrap mode.
+*/
+bool in_bootstrap= FALSE;
 /**
    @brief 'grant_option' is used to indicate if privileges needs
    to be checked, in which case the lock, LOCK_grant, is used
@@ -1031,7 +1046,7 @@ static void close_connections(void)
 
     tmp->killed= THD::KILL_CONNECTION;
     thread_scheduler.post_kill_notification(tmp);
-    pthread_mutex_lock(&tmp->LOCK_delete);
+    pthread_mutex_lock(&tmp->LOCK_thd_data);
     if (tmp->mysys_var)
     {
       tmp->mysys_var->abort=1;
@@ -1054,7 +1069,7 @@ static void close_connections(void)
       }
       pthread_mutex_unlock(&tmp->mysys_var->mutex);
     }
-    pthread_mutex_unlock(&tmp->LOCK_delete);
+    pthread_mutex_unlock(&tmp->LOCK_thd_data);
   }
   (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
 
@@ -1380,9 +1395,7 @@ void clean_up(bool print_message)
   grant_free();
 #endif
   query_cache_destroy();
-  table_def_free();
   hostname_cache_free();
-  mdl_destroy();
   item_user_lock_free();
   lex_free();				/* Free some memory */
   item_create_cleanup();
@@ -1397,6 +1410,7 @@ void clean_up(bool print_message)
 #ifndef EMBEDDED_LIBRARY
   backup_shutdown();
 #endif
+  table_def_start_shutdown();
   plugin_shutdown();
   ha_end();
   if (tc_log)
@@ -1404,6 +1418,8 @@ void clean_up(bool print_message)
   delegates_destroy();
   xid_cache_free();
   wt_end();
+  table_def_free();
+  mdl_destroy();
   delete_elements(&key_caches, (void (*)(const char*, uchar*)) free_key_cache);
   multi_keycache_free();
   sp_cache_end();
@@ -3719,7 +3735,7 @@ static int init_thread_environment()
 {
   (void) pthread_mutex_init(&LOCK_mysql_create_db,MY_MUTEX_INIT_SLOW);
   (void) pthread_mutex_init(&LOCK_lock_db,MY_MUTEX_INIT_SLOW);
-  (void) pthread_mutex_init(&LOCK_open, NULL);
+  (void) pthread_mutex_init(&LOCK_open, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&LOCK_mapped_file,MY_MUTEX_INIT_SLOW);
   (void) pthread_mutex_init(&LOCK_status,MY_MUTEX_INIT_FAST);
@@ -4179,6 +4195,10 @@ will be ignored as the --log-bin option 
     }
   }
 
+  /* if the errmsg.sys is not loaded, terminate to maintain behaviour */
+  if (!DEFAULT_ERRMSGS[0][0])
+    unireg_abort(1);
+  
   /* We have to initialize the storage engines before CSV logging */
   if (ha_init())
   {
@@ -4700,6 +4720,11 @@ int main(int argc, char **argv)
     unireg_abort(1);
   }
 
+  execute_ddl_log_recovery();
+
+  if (Events::init(opt_noacl || opt_bootstrap))
+    unireg_abort(1);
+
   if (opt_bootstrap)
   {
     select_thread_in_use= 0;                    // Allow 'kill' to work
@@ -4711,14 +4736,10 @@ int main(int argc, char **argv)
     if (read_init_file(opt_init_file))
       unireg_abort(1);
   }
-  execute_ddl_log_recovery();
 
   create_shutdown_thread();
   start_handle_manager();
 
-  if (Events::init(opt_noacl))
-    unireg_abort(1);
-
   sql_print_information(ER_DEFAULT(ER_STARTUP),my_progname,server_version,
                         ((unix_sock == INVALID_SOCKET) ? (char*) ""
                                                        : mysqld_unix_port),
@@ -4835,15 +4856,28 @@ default_service_handling(char **argv,
 			 const char *account_name)
 {
   char path_and_service[FN_REFLEN+FN_REFLEN+32], *pos, *end;
+  const char *opt_delim;
   end= path_and_service + sizeof(path_and_service)-3;
 
   /* We have to quote filename if it contains spaces */
   pos= add_quoted_string(path_and_service, file_path, end);
   if (*extra_opt)
   {
-    /* Add (possible quoted) option after file_path */
+    /* 
+     Add option after file_path. There will be zero or one extra option.  It's 
+     assumed to be --defaults-file=file but isn't checked.  The variable (not
+     the option name) should be quoted if it contains a string.  
+    */
     *pos++= ' ';
-    pos= add_quoted_string(pos, extra_opt, end);
+    if (opt_delim= strchr(extra_opt, '='))
+    {
+      size_t length= ++opt_delim - extra_opt;
+      strnmov(pos, extra_opt, length);
+    }
+    else
+      opt_delim= extra_opt;
+    
+    pos= add_quoted_string(pos, opt_delim, end);
   }
   /* We must have servicename last */
   *pos++= ' ';
@@ -4989,6 +5023,7 @@ static void bootstrap(FILE *file)
   thd->security_ctx->master_access= ~(ulong)0;
   thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
   thread_count++;
+  in_bootstrap= TRUE;
 
   bootstrap_file=file;
 #ifndef EMBEDDED_LIBRARY			// TODO:  Enable this
@@ -5001,7 +5036,7 @@ static void bootstrap(FILE *file)
   }
   /* Wait for thread to die */
   (void) pthread_mutex_lock(&LOCK_thread_count);
-  while (thread_count)
+  while (in_bootstrap)
   {
     (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
     DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
@@ -6053,26 +6088,6 @@ struct my_option my_long_options[] =
    NO_ARG, 0, 0, 0, 0, 0, 0},
   {"datadir", 'h', "Path to the database root.", (uchar**) &mysql_data_home,
    (uchar**) &mysql_data_home, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"deadlock-search-depth-short", OPT_DEADLOCK_SEARCH_DEPTH_SHORT,
-   "Short search depth for the two-step deadlock detection",
-   (uchar**) &global_system_variables.wt_deadlock_search_depth_short,
-   (uchar**) &max_system_variables.wt_deadlock_search_depth_short,
-   0, GET_ULONG, REQUIRED_ARG, 4, 0, 32, 0, 0, 0},
-  {"deadlock-search-depth-long", OPT_DEADLOCK_SEARCH_DEPTH_LONG,
-   "Long search depth for the two-step deadlock detection",
-   (uchar**) &global_system_variables.wt_deadlock_search_depth_long,
-   (uchar**) &max_system_variables.wt_deadlock_search_depth_long,
-   0, GET_ULONG, REQUIRED_ARG, 15, 0, 33, 0, 0, 0},
-  {"deadlock-timeout-short", OPT_DEADLOCK_TIMEOUT_SHORT,
-   "Short timeout for the two-step deadlock detection (in microseconds)",
-   (uchar**) &global_system_variables.wt_timeout_short,
-   (uchar**) &max_system_variables.wt_timeout_short,
-   0, GET_ULONG, REQUIRED_ARG, 10000, 0, ULONG_MAX, 0, 0, 0},
-  {"deadlock-timeout-long", OPT_DEADLOCK_TIMEOUT_LONG,
-   "Long timeout for the two-step deadlock detection (in microseconds)",
-   (uchar**) &global_system_variables.wt_timeout_long,
-   (uchar**) &max_system_variables.wt_timeout_long,
-   0, GET_ULONG, REQUIRED_ARG, 50000000, 0, ULONG_MAX, 0, 0, 0},
 #ifndef DBUG_OFF
   {"debug", '#', "Debug log.", (uchar**) &default_dbug_option,
    (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
@@ -6173,6 +6188,11 @@ Disable with --skip-large-pages.",
   {"init-slave", OPT_INIT_SLAVE, "Command(s) that are executed when a slave connects to this master",
    (uchar**) &opt_init_slave, (uchar**) &opt_init_slave, 0, GET_STR_ALLOC,
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"language", 'L',
+   "Client error messages in given language. May be given as a full path. "
+   "Deprecated. Use --lc-messages-dir instead.",
+   (uchar**) &lc_messages_dir_ptr, (uchar**) &lc_messages_dir_ptr, 0,
+   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"lc-messages-dir", 'L',
    "Directory where error messages are.", (uchar**) &lc_messages_dir_ptr,
    (uchar**) &lc_messages_dir_ptr, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -7880,10 +7900,7 @@ SHOW_VAR status_vars[]= {
 static void print_version(void)
 {
   set_server_version();
-  /*
-    Note: the instance manager keys off the string 'Ver' so it can find the
-    version from the output of 'mysqld --version', so don't change it!
-  */
+
   printf("%s  Ver %s for %s on %s (%s)\n",my_progname,
 	 server_version,SYSTEM_TYPE,MACHINE_TYPE, MYSQL_COMPILATION_COMMENT);
 }
@@ -8061,7 +8078,7 @@ static int mysql_init_variables(void)
 
   /* Set directory paths */
   mysql_real_data_home_len=
-    strmake(mysql_real_data_home, get_relative_path(DATADIR),
+    strmake(mysql_real_data_home, get_relative_path(MYSQL_DATADIR),
             sizeof(mysql_real_data_home) - 1) - mysql_real_data_home;
   mysql_data_home_buff[0]=FN_CURLIB;	// all paths are relative from here
   mysql_data_home_buff[1]=0;

=== modified file 'sql/net_serv.cc'
--- a/sql/net_serv.cc	2009-03-17 20:07:27 +0000
+++ b/sql/net_serv.cc	2009-07-28 19:11:30 +0000
@@ -188,10 +188,12 @@ my_bool net_realloc(NET *net, size_t len
   pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); 
   /*
     We must allocate some extra bytes for the end 0 and to be able to
-    read big compressed blocks
+    read big compressed blocks + 1 safety byte since uint3korr() in
+    my_real_read() may actually read 4 bytes depending on build flags and
+    platform.
   */
   if (!(buff= (uchar*) my_realloc((char*) net->buff, pkt_length +
-                                  NET_HEADER_SIZE + COMP_HEADER_SIZE,
+                                  NET_HEADER_SIZE + COMP_HEADER_SIZE + 1,
                                   MYF(MY_WME))))
   {
     /* @todo: 1 and 2 codes are identical. */
@@ -943,6 +945,13 @@ my_real_read(NET *net, size_t *complen)
 #ifdef HAVE_COMPRESS
 	if (net->compress)
 	{
+          /*
+            The following uint3korr() may read 4 bytes, so make sure we don't
+            read unallocated or uninitialized memory. The right-hand expression
+            must match the size of the buffer allocated in net_realloc().
+          */
+          DBUG_ASSERT(net->where_b + NET_HEADER_SIZE + sizeof(uint32) <=
+                      net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1);
 	  /*
 	    If the packet is compressed then complen > 0 and contains the
 	    number of bytes in the uncompressed packet

=== modified file 'sql/protocol.cc'
--- a/sql/protocol.cc	2009-07-03 05:54:09 +0000
+++ b/sql/protocol.cc	2009-07-30 16:22:41 +0000
@@ -28,13 +28,13 @@
 #include <stdarg.h>
 
 static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
-void net_send_error_packet(THD *, uint, const char *, const char *);
+bool net_send_error_packet(THD *, uint, const char *, const char *);
 /* Declared non-static only because of the embedded library. */
-void net_send_ok(THD *, uint, uint, ulonglong, ulonglong, const char *);
+bool net_send_ok(THD *, uint, uint, ulonglong, ulonglong, const char *);
 /* Declared non-static only because of the embedded library. */
-void net_send_eof(THD *thd, uint server_status, uint statement_warn_count);
+bool net_send_eof(THD *thd, uint server_status, uint statement_warn_count);
 #ifndef EMBEDDED_LIBRARY
-static void write_eof_packet(THD *, NET *, uint, uint);
+static bool write_eof_packet(THD *, NET *, uint, uint);
 #endif
 
 #ifndef EMBEDDED_LIBRARY
@@ -180,19 +180,20 @@ void net_send_error(THD *thd, uint sql_e
 */
 
 #ifndef EMBEDDED_LIBRARY
-void
+bool
 net_send_ok(THD *thd,
             uint server_status, uint statement_warn_count,
             ulonglong affected_rows, ulonglong id, const char *message)
 {
   NET *net= &thd->net;
   uchar buff[MYSQL_ERRMSG_SIZE+10],*pos;
+  bool error= FALSE;
   DBUG_ENTER("my_ok");
 
   if (! net->vio)	// hack for re-parsing queries
   {
     DBUG_PRINT("info", ("vio present: NO"));
-    DBUG_VOID_RETURN;
+    DBUG_RETURN(FALSE);
   }
 
   buff[0]=0;					// No fields
@@ -223,13 +224,15 @@ net_send_ok(THD *thd,
 
   if (message && message[0])
     pos= net_store_data(pos, (uchar*) message, strlen(message));
-  (void) my_net_write(net, buff, (size_t) (pos-buff));
-  (void) net_flush(net);
+  error= my_net_write(net, buff, (size_t) (pos-buff));
+  if (!error)
+    error= net_flush(net);
+
 
   thd->stmt_da->can_overwrite_status= FALSE;
   DBUG_PRINT("info", ("OK sent, so no more error sending allowed"));
 
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(error);
 }
 
 static uchar eof_buff[1]= { (uchar) 254 };      /* Marker for end of fields */
@@ -253,21 +256,23 @@ static uchar eof_buff[1]= { (uchar) 254 
                         like in send_result_set_metadata().
 */    
 
-void
+bool
 net_send_eof(THD *thd, uint server_status, uint statement_warn_count)
 {
-  NET *net= &thd->net;
   DBUG_ENTER("net_send_eof");
+  bool error= FALSE;
+  NET *net= &thd->net;
   /* Set to TRUE if no active vio, to work well in case of --init-file */
   if (net->vio != 0)
   {
     thd->stmt_da->can_overwrite_status= TRUE;
-    write_eof_packet(thd, net, server_status, statement_warn_count);
-    (void) net_flush(net);
+    error= write_eof_packet(thd, net, server_status, statement_warn_count);
+    if (!error)
+      error= net_flush(net);
     thd->stmt_da->can_overwrite_status= FALSE;
     DBUG_PRINT("info", ("EOF sent, so no more error sending allowed"));
   }
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(error);
 }
 
 
@@ -276,7 +281,7 @@ net_send_eof(THD *thd, uint server_statu
   write it to the network output buffer.
 */
 
-static void write_eof_packet(THD *thd, NET *net,
+static bool write_eof_packet(THD *thd, NET *net,
                              uint server_status,
                              uint statement_warn_count)
 {
@@ -298,10 +303,10 @@ static void write_eof_packet(THD *thd, N
     if (thd->is_fatal_error)
       server_status&= ~SERVER_MORE_RESULTS_EXISTS;
     int2store(buff + 3, server_status);
-    (void) my_net_write(net, buff, 5);
+    return(my_net_write(net, buff, 5));
   }
   else
-    (void) my_net_write(net, eof_buff, 1);
+    return(my_net_write(net, eof_buff, 1));
 }
 
 /**
@@ -322,7 +327,7 @@ bool send_old_password_request(THD *thd)
 }
 
 
-void net_send_error_packet(THD *thd, uint sql_errno, const char *err,
+bool net_send_error_packet(THD *thd, uint sql_errno, const char *err,
                            const char* sqlstate)
 {
   NET *net= &thd->net;
@@ -344,7 +349,7 @@ void net_send_error_packet(THD *thd, uin
       /* In bootstrap it's ok to print on stderr */
       fprintf(stderr,"ERROR: %d  %s\n",sql_errno,err);
     }
-    DBUG_VOID_RETURN;
+    DBUG_RETURN(FALSE);
   }
 
   int2store(buff,sql_errno);
@@ -365,9 +370,8 @@ void net_send_error_packet(THD *thd, uin
                   (char*) buff);
   err= (char*) buff;
 
-  (void) net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) err,
-                           length);
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) err,
+                                length));
 }
 
 #endif /* EMBEDDED_LIBRARY */
@@ -455,6 +459,7 @@ void Protocol::end_statement()
 {
   DBUG_ENTER("Protocol::end_statement");
   DBUG_ASSERT(! thd->stmt_da->is_sent);
+  bool error= FALSE;
 
   /* Can not be true, but do not take chances in production. */
   if (thd->stmt_da->is_sent)
@@ -463,30 +468,31 @@ void Protocol::end_statement()
   switch (thd->stmt_da->status()) {
   case Diagnostics_area::DA_ERROR:
     /* The query failed, send error to log and abort bootstrap. */
-    send_error(thd->stmt_da->sql_errno(),
-               thd->stmt_da->message(),
-               thd->stmt_da->get_sqlstate());
+    error= send_error(thd->stmt_da->sql_errno(),
+                      thd->stmt_da->message(),
+                      thd->stmt_da->get_sqlstate());
     break;
   case Diagnostics_area::DA_EOF:
-    send_eof(thd->stmt_da->server_status(),
-             thd->stmt_da->statement_warn_count());
+    error= send_eof(thd->stmt_da->server_status(),
+                    thd->stmt_da->statement_warn_count());
     break;
   case Diagnostics_area::DA_OK:
-    send_ok(thd->stmt_da->server_status(),
-            thd->stmt_da->statement_warn_count(),
-            thd->stmt_da->affected_rows(),
-            thd->stmt_da->last_insert_id(),
-            thd->stmt_da->message());
+    error= send_ok(thd->stmt_da->server_status(),
+                   thd->stmt_da->statement_warn_count(),
+                   thd->stmt_da->affected_rows(),
+                   thd->stmt_da->last_insert_id(),
+                   thd->stmt_da->message());
     break;
   case Diagnostics_area::DA_DISABLED:
     break;
   case Diagnostics_area::DA_EMPTY:
   default:
     DBUG_ASSERT(0);
-    send_ok(thd->server_status, 0, 0, 0, NULL);
+    error= send_ok(thd->server_status, 0, 0, 0, NULL);
     break;
   }
-  thd->stmt_da->is_sent= TRUE;
+  if (!error)
+    thd->stmt_da->is_sent= TRUE;
   DBUG_VOID_RETURN;
 }
 
@@ -500,16 +506,14 @@ void Protocol::end_statement()
   on client side.
 */
 
-void Protocol::send_ok(uint server_status, uint statement_warn_count,
+bool Protocol::send_ok(uint server_status, uint statement_warn_count,
                        ulonglong affected_rows, ulonglong last_insert_id,
                        const char *message)
 {
   DBUG_ENTER("Protocol::send_ok");
 
-  net_send_ok(thd, server_status, statement_warn_count, affected_rows,
-              last_insert_id, message);
-
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(net_send_ok(thd, server_status, statement_warn_count,
+                          affected_rows, last_insert_id, message));
 }
 
 
@@ -519,13 +523,11 @@ void Protocol::send_ok(uint server_statu
   Binary and text protocol do not differ in their EOF packet format.
 */
 
-void Protocol::send_eof(uint server_status, uint statement_warn_count)
+bool Protocol::send_eof(uint server_status, uint statement_warn_count)
 {
   DBUG_ENTER("Protocol::send_eof");
 
-  net_send_eof(thd, server_status, statement_warn_count);
-
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(net_send_eof(thd, server_status, statement_warn_count));
 }
 
 
@@ -535,13 +537,12 @@ void Protocol::send_eof(uint server_stat
   Binary and text protocol do not differ in ERROR packet format.
 */
 
-void Protocol::send_error(uint sql_errno, const char *err_msg, const char *sql_state)
+bool Protocol::send_error(uint sql_errno, const char *err_msg,
+                          const char *sql_state)
 {
   DBUG_ENTER("Protocol::send_error");
 
-  net_send_error_packet(thd, sql_errno, err_msg, sql_state);
-
-  DBUG_VOID_RETURN;
+  DBUG_RETURN(net_send_error_packet(thd, sql_errno, err_msg, sql_state));
 }
 
 

=== modified file 'sql/protocol.h'
--- a/sql/protocol.h	2009-01-17 02:29:30 +0000
+++ b/sql/protocol.h	2009-07-30 16:22:41 +0000
@@ -49,13 +49,14 @@ protected:
   bool store_string_aux(const char *from, size_t length,
                         CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
 
-  virtual void send_ok(uint server_status, uint statement_warn_count,
+  virtual bool send_ok(uint server_status, uint statement_warn_count,
                        ulonglong affected_rows, ulonglong last_insert_id,
                        const char *message);
 
-  virtual void send_eof(uint server_status, uint statement_warn_count);
+  virtual bool send_eof(uint server_status, uint statement_warn_count);
 
-  virtual void send_error(uint sql_errno, const char *err_msg, const char *sql_state);
+  virtual bool send_error(uint sql_errno, const char *err_msg,
+                          const char *sql_state);
 
 public:
   Protocol() {}

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2009-07-09 11:54:09 +0000
+++ b/sql/rpl_rli.cc	2009-07-20 16:29:15 +0000
@@ -930,7 +930,6 @@ void Relay_log_info::cleanup_context(THD
   */
   thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
   thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
-  last_event_start_time= 0;
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/rpl_rli.h'
--- a/sql/rpl_rli.h	2009-04-02 16:14:14 +0000
+++ b/sql/rpl_rli.h	2009-07-06 13:46:31 +0000
@@ -316,12 +316,10 @@ public:
   void clear_tables_to_lock();
 
   /*
-    Used by row-based replication to detect that it should not stop at
-    this event, but give it a chance to send more events. The time
-    where the last event inside a group started is stored here. If the
-    variable is zero, we are not in a group (but may be in a
-    transaction).
-   */
+    Used to defer stopping the SQL thread to give it a chance
+    to finish up the current group of events.
+    The timestamp is set and reset in @c sql_slave_killed().
+  */
   time_t last_event_start_time;
 
   /**

=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc	2009-07-16 12:51:04 +0000
+++ b/sql/set_var.cc	2009-07-31 19:46:24 +0000
@@ -244,18 +244,6 @@ static sys_var_long_ptr	sys_connect_time
 					    &connect_timeout);
 static sys_var_const_os_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
 static sys_var_backup_wait_timeout sys_backup_wait_timeout(&vars, "backup_wait_timeout");
-static sys_var_thd_ulong sys_deadlock_search_depth_short(&vars,
-                                "deadlock_search_depth_short",
-                                 &SV::wt_deadlock_search_depth_short);
-static sys_var_thd_ulong sys_deadlock_search_depth_long(&vars,
-                                "deadlock_search_depth_long",
-                                 &SV::wt_deadlock_search_depth_long);
-static sys_var_thd_ulong sys_deadlock_timeout_short(&vars,
-                                "deadlock_timeout_short",
-                                 &SV::wt_timeout_short);
-static sys_var_thd_ulong sys_deadlock_timeout_long(&vars,
-                                "deadlock_timeout_long",
-                                 &SV::wt_timeout_long);
 #ifndef DBUG_OFF
 static sys_var_thd_dbug        sys_dbug(&vars, "debug");
 #endif

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2009-07-13 17:48:36 +0000
+++ b/sql/share/errmsg-utf8.txt	2009-07-31 17:53:36 +0000
@@ -6196,6 +6196,12 @@ ER_RENAMED_NAME
   eng "Renamed"
   swe "Namnändrad"
 
+ER_TOO_MANY_CONCURRENT_TRXS
+  eng  "Too many active concurrent transactions"
+
+WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED
+  eng "Non-ASCII separator arguments are not fully supported"
+
 ER_WARN_AUTO_CONVERT_LOCK
         eng "Converted to non-transactional lock on '%-.64s'"
         ger "Umgewandelt zu nicht-transaktionalen Sperren auf '%-.64s'"

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2009-07-06 07:29:06 +0000
+++ b/sql/share/errmsg.txt	2009-07-31 17:53:36 +0000
@@ -6196,6 +6196,12 @@ ER_RENAMED_NAME
   eng "Renamed"
   swe "Namn�rad"
 
+ER_TOO_MANY_CONCURRENT_TRXS
+  eng  "Too many active concurrent transactions"
+
+WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED
+  eng "Non-ASCII separator arguments are not fully supported"
+
 ER_WARN_AUTO_CONVERT_LOCK
         eng "Converted to non-transactional lock on '%-.64s'"
         ger "Umgewandelt zu nicht-transaktionalen Sperren auf '%-.64s'"

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2009-08-07 09:26:33 +0000
+++ b/sql/slave.cc	2009-08-07 16:25:06 +0000
@@ -53,6 +53,10 @@
 #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
 
 #define MAX_SLAVE_RETRY_PAUSE 5
+/*
+  a parameter of sql_slave_killed() to defer the killed status
+*/
+#define SLAVE_WAIT_GROUP_DONE 60
 bool use_slave_mask = 0;
 MY_BITMAP slave_error_mask;
 char slave_skip_error_names[SHOW_VAR_FUNC_BUFF_SIZE];
@@ -674,7 +678,7 @@ terminate_slave_thread(THD *thd,
     int error;
     DBUG_PRINT("loop", ("killing slave thread"));
 
-    pthread_mutex_lock(&thd->LOCK_delete);
+    pthread_mutex_lock(&thd->LOCK_thd_data);
 #ifndef DONT_USE_THR_ALARM
     /*
       Error codes from pthread_kill are:
@@ -685,7 +689,7 @@ terminate_slave_thread(THD *thd,
     DBUG_ASSERT(err != EINVAL);
 #endif
     thd->awake(THD::NOT_KILLED);
-    pthread_mutex_unlock(&thd->LOCK_delete);
+    pthread_mutex_unlock(&thd->LOCK_thd_data);
 
     /*
       There is a small chance that slave thread might miss the first
@@ -894,44 +898,92 @@ static bool io_slave_killed(THD* thd, Ma
   DBUG_RETURN(mi->abort_slave || abort_loop || thd->killed);
 }
 
+/**
+   The function analyzes a possible killed status and makes
+   a decision whether to accept it or not.
+   Normally upon accepting the sql thread goes to shutdown.
+   In the event of deffering decision @rli->last_event_start_time waiting
+   timer is set to force the killed status be accepted upon its expiration.
+
+   @param thd   pointer to a THD instance
+   @param rli   pointer to Relay_log_info instance
 
+   @return TRUE the killed status is recognized, FALSE a possible killed
+           status is deferred.
+*/
 static bool sql_slave_killed(THD* thd, Relay_log_info* rli)
 {
+  bool ret= FALSE;
   DBUG_ENTER("sql_slave_killed");
 
   DBUG_ASSERT(rli->info_thd == thd);
   DBUG_ASSERT(rli->slave_running == 1);// tracking buffer overrun
   if (abort_loop || thd->killed || rli->abort_slave)
   {
-    if (rli->abort_slave && rli->is_in_group() &&
-        thd->transaction.all.modified_non_trans_table)
-      DBUG_RETURN(0);
-    /*
-      If we are in an unsafe situation (stopping could corrupt replication),
-      we give one minute to the slave SQL thread of grace before really
-      terminating, in the hope that it will be able to read more events and
-      the unsafe situation will soon be left. Note that this one minute starts
-      from the last time anything happened in the slave SQL thread. So it's
-      really one minute of idleness, we don't timeout if the slave SQL thread
-      is actively working.
-    */
-    if (rli->last_event_start_time == 0)
-      DBUG_RETURN(1);
-    DBUG_PRINT("info", ("Slave SQL thread is in an unsafe situation, giving "
-                        "it some grace period"));
-    if (difftime(time(0), rli->last_event_start_time) > 60)
-    {
-      rli->report(ERROR_LEVEL, 0,
-                  "SQL thread had to stop in an unsafe situation, in "
-                  "the middle of applying updates to a "
-                  "non-transactional table without any primary key. "
-                  "There is a risk of duplicate updates when the slave "
-                  "SQL thread is restarted. Please check your tables' "
-                  "contents after restart.");
-      DBUG_RETURN(1);
+    if (thd->transaction.all.modified_non_trans_table && rli->is_in_group())
+    {
+      char msg_stopped[]=
+        "... The slave SQL is stopped, leaving the current group "
+        "of events unfinished with a non-transaction table changed. "
+        "If the group consists solely of Row-based events, you can try "
+        "restarting the slave with --slave-exec-mode=IDEMPOTENT, which "
+        "ignores duplicate key, key not found, and similar errors (see "
+        "documentation for details).";
+
+      if (rli->abort_slave)
+      {
+        DBUG_PRINT("info", ("Slave SQL thread is being stopped in the middle of"
+                            " a group having updated a non-trans table, giving"
+                            " it some grace period"));
+
+        /*
+          Slave sql thread shutdown in face of unfinished group modified 
+          Non-trans table is handled via a timer. The slave may eventually
+          give out to complete the current group and in that case there
+          might be issues at consequent slave restart, see the error message.
+          WL#2975 offers a robust solution requiring to store the last exectuted
+          event's coordinates along with the group's coordianates
+          instead of waiting with @c last_event_start_time the timer.
+        */
+
+        if (rli->last_event_start_time == 0)
+          rli->last_event_start_time= my_time(0);
+        ret= difftime(my_time(0), rli->last_event_start_time) <=
+          SLAVE_WAIT_GROUP_DONE ? FALSE : TRUE;
+
+        DBUG_EXECUTE_IF("stop_slave_middle_group", 
+                        DBUG_EXECUTE_IF("incomplete_group_in_relay_log",
+                                        ret= TRUE;);); // time is over
+
+        if (ret == 0)
+        {
+          rli->report(WARNING_LEVEL, 0,
+                      "slave SQL thread is being stopped in the middle "
+                      "of applying of a group having updated a non-transaction "
+                      "table; waiting for the group completion ... ");
+        }
+        else
+        {
+          rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
+                      ER(ER_SLAVE_FATAL_ERROR), msg_stopped);
+        }
+      }
+      else
+      {
+        ret= TRUE;
+        rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, ER(ER_SLAVE_FATAL_ERROR),
+                    msg_stopped);
+      }
+    }
+    else
+    {
+      ret= TRUE;
     }
   }
-  DBUG_RETURN(0);
+  if (ret)
+    rli->last_event_start_time= 0;
+  
+  DBUG_RETURN(ret);
 }
 
 
@@ -2426,6 +2478,27 @@ static int exec_relay_log_event(THD* thd
       delete ev;
       DBUG_RETURN(1);
     }
+
+    { /**
+         The following failure injecion works in cooperation with tests 
+         setting @@global.debug= 'd,incomplete_group_in_relay_log'.
+         Xid or Commit events are not executed to force the slave sql
+         read hanging if the realy log does not have any more events.
+      */
+      DBUG_EXECUTE_IF("incomplete_group_in_relay_log",
+                      if ((ev->get_type_code() == XID_EVENT) ||
+                          ((ev->get_type_code() == QUERY_EVENT) &&
+                           strcmp("COMMIT", ((Query_log_event *) ev)->query) == 0))
+                      {
+                        DBUG_ASSERT(thd->transaction.all.modified_non_trans_table);
+                        rli->abort_slave= 1;
+                        pthread_mutex_unlock(&rli->data_lock);
+                        delete ev;
+                        rli->inc_event_relay_log_pos();
+                        DBUG_RETURN(0);
+                      };);
+    }
+
     exec_res= apply_event_and_update_pos(ev, thd, rli, TRUE);
 
     /*
@@ -2925,9 +2998,9 @@ err:
                   IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
   pthread_mutex_lock(&LOCK_thread_count);
   RUN_HOOK(binlog_relay_io, thread_stop, (thd, mi));
-  thd->query = thd->db = 0; // extra safety
-  thd->query_length= thd->db_length= 0;
   pthread_mutex_unlock(&LOCK_thread_count);
+  thd->set_query(NULL, 0);
+  thd->reset_db(NULL, 0);
   if (mysql)
   {
     /*
@@ -3285,15 +3358,14 @@ the slave SQL thread with \"SLAVE START\
     must "proactively" clear playgrounds:
   */
   rli->cleanup_context(thd, 1);
-  pthread_mutex_lock(&LOCK_thread_count);
   /*
     Some extra safety, which should not been needed (normally, event deletion
     should already have done these assignments (each event which sets these
     variables is supposed to set them to 0 before terminating)).
   */
-  thd->query= thd->db= thd->catalog= 0;
-  thd->query_length= thd->db_length= 0;
-  pthread_mutex_unlock(&LOCK_thread_count);
+  thd->catalog= 0;
+  thd->set_query(NULL, 0);
+  thd->reset_db(NULL, 0);
   thd_proc_info(thd, "Waiting for slave mutex on exit");
   pthread_mutex_lock(&rli->run_lock);
   /* We need data_lock, at least to wake up any waiting master_pos_wait() */
@@ -3866,7 +3938,7 @@ static int queue_event(Master_info* mi,c
     goto skip_relay_logging;
   }
   break;
-    
+
   default:
     inc_pos= event_len;
     break;

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2009-07-16 12:51:04 +0000
+++ b/sql/sp.cc	2009-07-28 22:45:02 +0000
@@ -41,9 +41,6 @@ db_load_routine(THD *thd, int type, sp_n
                 const char *definer, longlong created, longlong modified,
                 Stored_program_creation_ctx *creation_ctx);
 
-/* Tells what SP_DEFAULT_ACCESS should be mapped to */
-#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
-
 /*************************************************************************/
 
 /**

=== modified file 'sql/sp.h'
--- a/sql/sp.h	2009-05-29 15:06:21 +0000
+++ b/sql/sp.h	2009-07-28 22:45:02 +0000
@@ -17,6 +17,9 @@
 #ifndef _SP_H_
 #define _SP_H_
 
+/* Tells what SP_DEFAULT_ACCESS should be mapped to */
+#define SP_DEFAULT_ACCESS_MAPPING SP_CONTAINS_SQL
+
 // Return codes from sp_create_*, sp_drop_*, and sp_show_*:
 #define SP_OK                 0
 #define SP_KEY_NOT_FOUND     -1

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2009-06-12 02:01:08 +0000
+++ b/sql/sp_head.cc	2009-07-30 16:22:41 +0000
@@ -1004,8 +1004,7 @@ subst_spvars(THD *thd, sp_instr *instr, 
   else
     DBUG_RETURN(TRUE);
 
-  thd->query= pbuf;
-  thd->query_length= qbuf.length();
+  thd->set_query(pbuf, qbuf.length());
 
   DBUG_RETURN(FALSE);
 }
@@ -2877,13 +2876,12 @@ sp_instr_stmt::execute(THD *thd, uint *n
     }
     else
       *nextp= m_ip+1;
-    thd->query= query;
-    thd->query_length= query_length;
+    thd->set_query(query, query_length);
 
     if (!thd->is_error())
       thd->stmt_da->reset_diagnostics_area();
   }
-  DBUG_RETURN(res);
+  DBUG_RETURN(res || thd->is_error());
 }
 
 

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-07-16 13:22:38 +0000
+++ b/sql/sql_base.cc	2009-07-31 19:46:24 +0000
@@ -113,6 +113,7 @@ TABLE *unused_tables;
 HASH table_def_cache;
 static TABLE_SHARE *oldest_unused_share, end_of_unused_share;
 static bool table_def_inited= 0;
+static bool table_def_shutdown_in_progress= 0;
 
 static bool check_and_update_table_version(THD *thd, TABLE_LIST *tables,
                                            TABLE_SHARE *table_share);
@@ -274,13 +275,36 @@ bool table_def_init(void)
 }
 
 
+/**
+  Notify table definition cache that process of shutting down server
+  has started so it has to keep number of TABLE and TABLE_SHARE objects
+  minimal in order to reduce number of references to pluggable engines.
+*/
+
+void table_def_start_shutdown(void)
+{
+  if (table_def_inited)
+  {
+    pthread_mutex_lock(&LOCK_open);
+    /* Free all cached but unused TABLEs and TABLE_SHAREs first. */
+    close_cached_tables(NULL, NULL, TRUE, FALSE);
+    /*
+      Ensure that TABLE and TABLE_SHARE objects which are created for
+      tables that are open during process of plugins' shutdown are
+      immediately released. This keeps number of references to engine
+      plugins minimal and allows shutdown to proceed smoothly.
+    */
+    table_def_shutdown_in_progress= TRUE;
+    pthread_mutex_unlock(&LOCK_open);
+  }
+}
+
+
 void table_def_free(void)
 {
   DBUG_ENTER("table_def_free");
   if (table_def_inited)
   {
-    /* Free all open TABLEs first. */
-    close_cached_tables(NULL, NULL, FALSE, FALSE);
     table_def_inited= 0;
     /* Free table definitions. */
     my_hash_free(&table_def_cache);
@@ -640,7 +664,8 @@ void release_table_share(TABLE_SHARE *sh
 
   if (!--share->ref_count)
   {
-    if (share->version != refresh_version)
+    if (share->version != refresh_version ||
+        table_def_shutdown_in_progress)
       to_be_deleted=1;
     else
     {
@@ -1511,7 +1536,8 @@ bool close_thread_table(THD *thd, TABLE 
 
   table->mdl_ticket= NULL;
   if (table->needs_reopen() ||
-      thd->version != refresh_version || !table->db_stat)
+      thd->version != refresh_version || !table->db_stat ||
+      table_def_shutdown_in_progress)
   {
     free_cache_entry(table);
     found_old_table=1;

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-07-13 17:45:27 +0000
+++ b/sql/sql_class.cc	2009-07-31 19:46:24 +0000
@@ -95,7 +95,8 @@ bool Key_part_spec::operator==(const Key
 {
   return length == other.length &&
          field_name.length == other.field_name.length &&
-         !strcmp(field_name.str, other.field_name.str);
+         !my_strcasecmp(system_charset_info, field_name.str,
+                        other.field_name.str);
 }
 
 /**
@@ -543,7 +544,7 @@ THD::THD()
 #ifdef SIGNAL_WITH_VIO_CLOSE
   active_vio = 0;
 #endif
-  pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST);
+  pthread_mutex_init(&LOCK_thd_data, MY_MUTEX_INIT_FAST);
 
   /* Variables with default values */
   proc_info="login";
@@ -1074,14 +1075,14 @@ THD::~THD()
   THD_CHECK_SENTRY(this);
   DBUG_ENTER("~THD()");
   /* Ensure that no one is using THD */
-  pthread_mutex_lock(&LOCK_delete);
+  pthread_mutex_lock(&LOCK_thd_data);
   /*
-    resetting mysys_var is guarded by LOCK_delete
+    resetting mysys_var is guarded by LOCK_thd_data
     the same mutex as a killer thread acquires in order to get access
     to the victim's mysys_var
   */
   mysys_var= NULL;
-  pthread_mutex_unlock(&LOCK_delete);
+  pthread_mutex_unlock(&LOCK_thd_data);
   add_to_status(&global_status_var, &status_var);
 
   /* Close connection */
@@ -1108,7 +1109,7 @@ THD::~THD()
   safeFree(db);
   free_root(&transaction.mem_root,MYF(0));
   mysys_var=0;					// Safety (shouldn't be needed)
-  pthread_mutex_destroy(&LOCK_delete);
+  pthread_mutex_destroy(&LOCK_thd_data);
 #ifndef DBUG_OFF
   dbug_sentry= THD_SENTRY_GONE;
 #endif  
@@ -1191,7 +1192,7 @@ void THD::awake(THD::killed_state state_
   DBUG_ENTER("THD::awake");
   DBUG_PRINT("enter", ("this: %p", this));
   THD_CHECK_SENTRY(this);
-  safe_mutex_assert_owner(&LOCK_delete); 
+  safe_mutex_assert_owner(&LOCK_thd_data);
 
   killed= state_to_set;
   if (state_to_set != THD::KILL_QUERY)
@@ -1245,7 +1246,7 @@ void THD::awake(THD::killed_state state_
       pthread_mutex_lock(), we can cause a deadlock as we are here locking
       the mysys_var->mutex and mysys_var->current_mutex in a different order
       than in the thread we are trying to kill.
-      We only sleep for 2 seconds as we don't want to have LOCK_delete
+      We only sleep for 2 seconds as we don't want to have LOCK_thd_data
       locked too long time.
 
       There is a small change we may not succeed in aborting a thread that
@@ -1295,7 +1296,7 @@ bool THD::store_globals()
 #ifndef EMBEDDED_LIBRARY
   /*
     mysys_var is concurrently readable by a killer thread.
-    LOCK_delete is not needed to lock while the pointer is
+    LOCK_thd_data is not needed to lock while the pointer is
     changing from NULL not non-NULL.
   */
   DBUG_ASSERT(mysys_var == NULL);
@@ -1318,11 +1319,11 @@ bool THD::store_globals()
 
 #ifdef SAFE_MUTEX
   /* Register order of mutex for wrong mutex deadlock detector */
-  pthread_mutex_lock(&LOCK_delete);
+  pthread_mutex_lock(&LOCK_thd_data);
   pthread_mutex_lock(&mysys_var->mutex);
 
   pthread_mutex_unlock(&mysys_var->mutex);
-  pthread_mutex_unlock(&LOCK_delete);
+  pthread_mutex_unlock(&LOCK_thd_data);
 #endif
   DBUG_RETURN(0);
 }
@@ -1634,7 +1635,7 @@ int THD::send_explain_fields(select_resu
 void THD::close_active_vio()
 {
   DBUG_ENTER("close_active_vio");
-  safe_mutex_assert_owner(&LOCK_delete); 
+  safe_mutex_assert_owner(&LOCK_thd_data);
 #ifndef EMBEDDED_LIBRARY
   if (active_vio)
   {
@@ -2001,6 +2002,8 @@ select_export::prepare(List<Item> &list,
   if ((uint) strlen(exchange->file_name) + NAME_LEN >= FN_REFLEN)
     strmake(path,exchange->file_name,FN_REFLEN-1);
 
+  write_cs= exchange->cs ? exchange->cs : &my_charset_bin;
+
   if ((file= create_file(thd, path, exchange, &cache)) < 0)
     return 1;
   /* Check if there is any blobs in data */
@@ -2020,6 +2023,31 @@ select_export::prepare(List<Item> &list,
         non_string_results= TRUE;
     }
   }
+  if (exchange->escaped->numchars() > 1 || exchange->enclosed->numchars() > 1)
+  {
+    my_error(ER_WRONG_FIELD_TERMINATORS, MYF(0));
+    return TRUE;
+  }
+  if (exchange->escaped->length() > 1 || exchange->enclosed->length() > 1 ||
+      !my_isascii(exchange->escaped->ptr()[0]) ||
+      !my_isascii(exchange->enclosed->ptr()[0]) ||
+      !exchange->field_term->is_ascii() || !exchange->line_term->is_ascii() ||
+      !exchange->line_start->is_ascii())
+  {
+    /*
+      Current LOAD DATA INFILE recognizes field/line separators "as is" without
+      converting from client charset to data file charset. So, it is supposed,
+      that input file of LOAD DATA INFILE consists of data in one charset and
+      separators in other charset. For the compatibility with that [buggy]
+      behaviour SELECT INTO OUTFILE implementation has been saved "as is" too,
+      but the new warning message has been added:
+
+        Non-ASCII separator arguments are not fully supported
+    */
+    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                 WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED,
+                 ER(WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED));
+  }
   field_term_length=exchange->field_term->length();
   field_term_char= field_term_length ?
                    (int) (uchar) (*exchange->field_term)[0] : INT_MAX;
@@ -2069,6 +2097,8 @@ bool select_export::send_data(List<Item>
 
   DBUG_ENTER("select_export::send_data");
   char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH];
+  char cvt_buff[MAX_FIELD_WIDTH];
+  String cvt_str(cvt_buff, sizeof(cvt_buff), write_cs);
   bool space_inited=0;
   String tmp(buff,sizeof(buff),&my_charset_bin),*res;
   tmp.length(0);
@@ -2092,6 +2122,37 @@ bool select_export::send_data(List<Item>
     bool enclosed = (exchange->enclosed->length() &&
                      (!exchange->opt_enclosed || result_type == STRING_RESULT));
     res=item->str_result(&tmp);
+    if (res && !my_charset_same(write_cs, res->charset()) &&
+        !my_charset_same(write_cs, &my_charset_bin))
+    {
+      const char *well_formed_error_pos;
+      const char *cannot_convert_error_pos;
+      const char *from_end_pos;
+      const char *error_pos;
+      uint32 bytes;
+      bytes= well_formed_copy_nchars(write_cs, cvt_buff, sizeof(cvt_buff),
+                                     res->charset(), res->ptr(), res->length(),
+                                     sizeof(cvt_buff),
+                                     &well_formed_error_pos,
+                                     &cannot_convert_error_pos,
+                                     &from_end_pos);
+      error_pos= well_formed_error_pos ? well_formed_error_pos
+                                       : cannot_convert_error_pos;
+      if (error_pos)
+      {
+        char printable_buff[32];
+        convert_to_printable(printable_buff, sizeof(printable_buff),
+                             error_pos, res->ptr() + res->length() - error_pos,
+                             res->charset(), 6);
+        push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                            ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
+                            ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
+                            "string", printable_buff,
+                            item->name, row_count);
+      }
+      cvt_str.length(bytes);
+      res= &cvt_str;
+    }
     if (res && enclosed)
     {
       if (my_b_write(&cache,(uchar*) exchange->enclosed->ptr(),
@@ -3272,6 +3333,25 @@ void THD::restore_sub_statement_state(Su
 }
 
 
+void THD::set_statement(Statement *stmt)
+{
+  pthread_mutex_lock(&LOCK_thd_data);
+  Statement::set_statement(stmt);
+  pthread_mutex_unlock(&LOCK_thd_data);
+}
+
+
+/** Assign a new value to thd->query.  */
+
+void THD::set_query(char *query_arg, uint32 query_length_arg)
+{
+  pthread_mutex_lock(&LOCK_thd_data);
+  query= query_arg;
+  query_length= query_length_arg;
+  pthread_mutex_unlock(&LOCK_thd_data);
+}
+
+
 /**
   Mark transaction to rollback and mark error as fatal to a sub-statement.
 
@@ -3847,7 +3927,8 @@ int THD::binlog_query(THD::enum_binlog_q
     push_warning(this, MYSQL_ERROR::WARN_LEVEL_NOTE,
                  ER_BINLOG_UNSAFE_STATEMENT,
                  ER(ER_BINLOG_UNSAFE_STATEMENT));
-    if (!(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED))
+    if (global_system_variables.log_warnings &&
+        !(binlog_flags & BINLOG_FLAG_UNSAFE_STMT_PRINTED))
     {
       sql_print_warning("%s Statement: %.*s",
                         ER(ER_BINLOG_UNSAFE_STATEMENT),

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2009-07-23 13:07:41 +0000
+++ b/sql/sql_class.h	2009-07-31 19:46:24 +0000
@@ -685,22 +685,16 @@ public:
     we need to declare it char * because all table handlers are written
     in C and need to point to it.
 
-    Note that (A) if we set query = NULL, we must at the same time set
-    query_length = 0, and protect the whole operation with the
-    LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a
-    non-NULL value if its previous value is NULL. We do not need to protect
-    operation (B) with any mutex. To avoid crashes in races, if we do not
-    know that thd->query cannot change at the moment, one should print
+    Note that if we set query = NULL, we must at the same time set
+    query_length = 0, and protect the whole operation with
+    LOCK_thd_data mutex. To avoid crashes in races, if we do not
+    know that thd->query cannot change at the moment, we should print
     thd->query like this:
-      (1) reserve the LOCK_thread_count mutex;
-      (2) check if thd->query is NULL;
-      (3) if not NULL, then print at most thd->query_length characters from
-      it. We will see the query_length field as either 0, or the right value
-      for it.
-    Assuming that the write and read of an n-bit memory field in an n-bit
-    computer is atomic, we can avoid races in the above way.
-    This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB
-    STATUS.
+      (1) reserve the LOCK_thd_data mutex;
+      (2) print or copy the value of query and query_length
+      (3) release LOCK_thd_data mutex.
+    This printing is needed at least in SHOW PROCESSLIST and SHOW
+    ENGINE INNODB STATUS.
   */
   char *query;
   uint32 query_length;                          // current query length
@@ -732,7 +726,7 @@ public:
   virtual ~Statement();
 
   /* Assign execution context (note: not all members) of given stmt to self */
-  void set_statement(Statement *stmt);
+  virtual void set_statement(Statement *stmt);
   void set_n_backup_statement(Statement *stmt, Statement *backup);
   void restore_backup_statement(Statement *stmt, Statement *backup);
   /* return class type */
@@ -1342,7 +1336,15 @@ public:
   THR_LOCK_OWNER main_lock_id;          // To use for conventional queries
   THR_LOCK_OWNER *lock_id;              // If not main_lock_id, points to
                                         // the lock_id of a cursor.
-  pthread_mutex_t LOCK_delete;		// Locked before thd is deleted
+  /**
+    Protects THD data accessed from other threads:
+    - thd->query and thd->query_length (used by SHOW ENGINE
+      INNODB STATUS and SHOW PROCESSLIST
+    - thd->mysys_var (used by KILL statement and shutdown).
+    Is locked when THD is deleted.
+  */
+  pthread_mutex_t LOCK_thd_data;
+
   /* all prepared statements and cursors of this connection */
   Statement_map stmt_map;
   /*
@@ -1972,15 +1974,15 @@ public:
 #ifdef SIGNAL_WITH_VIO_CLOSE
   inline void set_active_vio(Vio* vio)
   {
-    pthread_mutex_lock(&LOCK_delete);
+    pthread_mutex_lock(&LOCK_thd_data);
     active_vio = vio;
-    pthread_mutex_unlock(&LOCK_delete);
+    pthread_mutex_unlock(&LOCK_thd_data);
   }
   inline void clear_active_vio()
   {
-    pthread_mutex_lock(&LOCK_delete);
+    pthread_mutex_lock(&LOCK_thd_data);
     active_vio = 0;
-    pthread_mutex_unlock(&LOCK_delete);
+    pthread_mutex_unlock(&LOCK_thd_data);
   }
   void close_active_vio();
 #endif
@@ -2145,7 +2147,7 @@ public:
   */
   inline void fatal_error()
   {
-    DBUG_ASSERT(stmt_da->is_error());
+    DBUG_ASSERT(stmt_da->is_error() || killed);
     is_fatal_error= 1;
     DBUG_PRINT("error",("Fatal error set"));
   }
@@ -2424,9 +2426,9 @@ private:
     To raise a SQL condition, the code should use the public
     raise_error() or raise_warning() methods provided by class THD.
   */
-  friend class Abstract_signal;
-  friend class SQLCOM_signal;
-  friend class SQLCOM_resignal;
+  friend class Signal_common;
+  friend class Signal_statement;
+  friend class Resignal_statement;
   friend void push_warning(THD*, MYSQL_ERROR::enum_warning_level, uint, const char*);
   friend void my_message_sql(uint, const char *, myf);
 
@@ -2461,6 +2463,15 @@ private:
                              MYSQL_ERROR::enum_warning_level level,
                              const char* msg);
 
+public:
+  /** Overloaded to guard query/query_length fields */
+  virtual void set_statement(Statement *stmt);
+
+  /**
+    Assign a new value to thd->query.
+    Protected with LOCK_thd_data mutex.
+  */
+  void set_query(char *query_arg, uint32 query_length_arg);
 private:
   /** The current internal error handler for this thread, or NULL. */
   Internal_error_handler *m_internal_handler;
@@ -2670,6 +2681,7 @@ class select_export :public select_to_fi
   */
   bool is_unsafe_field_sep;
   bool fixed_row_size;
+  CHARSET_INFO *write_cs; // output charset
 public:
   select_export(sql_exchange *ex) :select_to_file(ex) {}
   ~select_export();

=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc	2009-07-03 05:54:09 +0000
+++ b/sql/sql_error.cc	2009-07-30 09:41:30 +0000
@@ -153,7 +153,7 @@ This file contains the implementation of
   This is implemented by using 'String MYSQL_ERROR::m_message_text'.
 
   The UTF8 -> error_message_charset_info conversion is implemented in
-  Abstract_signal::eval_signal_informations() (for path #B and #C).
+  Signal_common::eval_signal_informations() (for path #B and #C).
 
   Future work
   -----------

=== modified file 'sql/sql_error.h'
--- a/sql/sql_error.h	2009-07-03 05:54:09 +0000
+++ b/sql/sql_error.h	2009-07-30 09:41:30 +0000
@@ -213,9 +213,9 @@ private:
   */
   friend class THD;
   friend class Warning_info;
-  friend class Abstract_signal;
-  friend class SQLCOM_signal;
-  friend class SQLCOM_resignal;
+  friend class Signal_common;
+  friend class Signal_statement;
+  friend class Resignal_statement;
   friend class sp_rcontext;
 
   /**
@@ -512,7 +512,7 @@ private:
   /** Read only status. */
   bool m_read_only;
 
-  friend class SQLCOM_resignal;
+  friend class Resignal_statement;
 };
 
 ///////////////////////////////////////////////////////////////////////////

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2009-08-07 09:26:33 +0000
+++ b/sql/sql_insert.cc	2009-08-07 16:25:06 +0000
@@ -973,10 +973,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
     if (ignore)
       sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
 	      (lock_type == TL_WRITE_DELAYED) ? (ulong) 0 :
-	      (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
+	      (ulong) (info.records - info.copied),
+              (ulong) thd->warning_info->statement_warn_count());
     else
       sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
-	      (ulong) (info.deleted + updated), (ulong) thd->cuted_fields);
+	      (ulong) (info.deleted + updated),
+              (ulong) thd->warning_info->statement_warn_count());
     thd->row_count_func= info.copied + info.deleted + updated;
     ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
   }
@@ -1951,7 +1953,8 @@ bool delayed_get_table(THD *thd, TABLE_L
       thread_count++;
       pthread_mutex_unlock(&LOCK_thread_count);
       di->thd.set_db(table_list->db, strlen(table_list->db));
-      di->thd.query= my_strdup(table_list->table_name, MYF(MY_WME | ME_FATALERROR));
+      di->thd.set_query(my_strdup(table_list->table_name,
+                                  MYF(MY_WME | ME_FATALERROR)), 0);
       if (di->thd.db == NULL || di->thd.query == NULL)
       {
         /* The error is reported */
@@ -3324,10 +3327,12 @@ bool select_insert::send_eof()
   char buff[160];
   if (info.ignore)
     sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
-	    (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
+	    (ulong) (info.records - info.copied),
+            (ulong) thd->warning_info->statement_warn_count());
   else
     sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
-	    (ulong) (info.deleted+info.updated), (ulong) thd->cuted_fields);
+	    (ulong) (info.deleted+info.updated),
+            (ulong) thd->warning_info->statement_warn_count());
   thd->row_count_func= info.copied + info.deleted +
                        ((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
                         info.touched : info.updated);

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2009-07-13 17:45:27 +0000
+++ b/sql/sql_lex.h	2009-07-31 19:46:24 +0000
@@ -1549,18 +1549,18 @@ public:
 /**
   Abstract representation of a statement.
   This class is an interface between the parser and the runtime.
-  The parser builds the appropriate sub classes of SQLCOM_statement
+  The parser builds the appropriate sub classes of Sql_statement
   to represent a SQL statement in the parsed tree.
   The execute() method in the sub classes contain the runtime implementation.
   Note that this interface is used for SQL statement recently implemented,
   the code for older statements tend to load the LEX structure with more
   attributes instead.
   The recommended way to implement new statements is to sub-class
-  SQLCOM_statement, as this improves code modularity (see the 'big switch' in
+  Sql_statement, as this improves code modularity (see the 'big switch' in
   dispatch_command()), and decrease the total size of the LEX structure
   (therefore saving memory in stored programs).
 */
-class SQLCOM_statement : public Sql_alloc
+class Sql_statement : public Sql_alloc
 {
 public:
   /**
@@ -1568,22 +1568,22 @@ public:
     @param thd the current thread.
     @return 0 on success.
   */
-  virtual int execute(THD *thd) = 0;
+  virtual bool execute(THD *thd) = 0;
 
 protected:
   /**
     Constructor.
     @param lex the LEX structure that represents parts of this statement.
   */
-  SQLCOM_statement(struct LEX *lex)
+  Sql_statement(struct LEX *lex)
     : m_lex(lex)
   {}
 
   /** Destructor. */
-  virtual ~SQLCOM_statement()
+  virtual ~Sql_statement()
   {
     /*
-      SQLCOM_statement objects are allocated in thd->mem_root.
+      Sql_statement objects are allocated in thd->mem_root.
       In MySQL, the C++ destructor is never called, the underlying MEM_ROOT is
       simply destroyed instead.
       Do not rely on the destructor for any cleanup.
@@ -1596,7 +1596,7 @@ protected:
     The legacy LEX structure for this statement.
     The LEX structure contains the existing properties of the parsed tree.
     TODO: with time, attributes from LEX should move to sub classes of
-    SQLCOM_statement, so that the parser only builds SQLCOM_statement objects
+    Sql_statement, so that the parser only builds Sql_statement objects
     with the minimum set of attributes, instead of a LEX structure that
     contains the collection of every possible attribute.
   */
@@ -1707,7 +1707,7 @@ struct LEX: public Query_tables_list
   nesting_map allow_sum_func;
   enum_sql_command sql_command;
 
-  SQLCOM_statement *m_stmt;
+  Sql_statement *m_stmt;
 
   /*
     Usually `expr` rule of yacc is quite reused but some commands better

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2009-06-17 15:26:50 +0000
+++ b/sql/sql_load.cc	2009-07-31 19:46:24 +0000
@@ -181,6 +181,17 @@ int mysql_load(THD *thd,sql_exchange *ex
 	       MYF(0));
     DBUG_RETURN(TRUE);
   }
+
+  /* Report problems with non-ascii separators */
+  if (!escaped->is_ascii() || !enclosed->is_ascii() ||
+      !field_term->is_ascii() ||
+      !ex->line_term->is_ascii() || !ex->line_start->is_ascii())
+  {
+    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                 WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED,
+                 ER(WARN_NON_ASCII_SEPARATOR_NOT_IMPLEMENTED));
+  } 
+
   if (open_and_lock_tables(thd, table_list))
     DBUG_RETURN(TRUE);
   if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context,
@@ -541,7 +552,8 @@ int mysql_load(THD *thd,sql_exchange *ex
     goto err;
   }
   sprintf(name, ER(ER_LOAD_INFO), (ulong) info.records, (ulong) info.deleted,
-	  (ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
+	  (ulong) (info.records - info.copied),
+          (ulong) thd->warning_info->statement_warn_count());
 
   if (thd->transaction.stmt.modified_non_trans_table)
     thd->transaction.all.modified_non_trans_table= TRUE;
@@ -1631,7 +1643,7 @@ int READ_INFO::read_value(int delim, Str
   int chr;
   String tmp;
 
-  for (chr= my_tospace(GET); chr != delim && chr != my_b_EOF; )
+  for (chr= GET; my_tospace(chr) != delim && chr != my_b_EOF;)
   {
 #ifdef USE_MB
     if (my_mbcharlen(read_charset, chr) > 1)
@@ -1671,9 +1683,9 @@ int READ_INFO::read_value(int delim, Str
     }
     else
       val->append(chr);
-    chr= my_tospace(GET);
+    chr= GET;
   }            
-  return chr;
+  return my_tospace(chr);
 }
 
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-07-16 12:51:04 +0000
+++ b/sql/sql_parse.cc	2009-07-28 14:16:37 +0000
@@ -493,6 +493,7 @@ pthread_handler_t handle_bootstrap(void 
   thd->init_for_queries();
   while (fgets(buff, thd->net.max_packet, file))
   {
+    char *query;
     /* strlen() can't be deleted because fgets() doesn't return length */
     ulong length= (ulong) strlen(buff);
     while (buff[length-1] != '\n' && !feof(file))
@@ -525,11 +526,10 @@ pthread_handler_t handle_bootstrap(void 
     if (strncmp(buff, STRING_WITH_LEN("delimiter")) == 0)
       continue;
 
-    thd->query_length=length;
-    thd->query= (char*) thd->memdup_w_gap(buff, length+1, 
-                                          thd->db_length+1+
-                                          QUERY_CACHE_FLAGS_SIZE);
-    thd->query[length] = '\0';
+    query= (char *) thd->memdup_w_gap(buff, length + 1,
+                                      thd->db_length + 1 +
+                                      QUERY_CACHE_FLAGS_SIZE);
+    thd->set_query(query, length);
     DBUG_PRINT("query",("%-.4096s",thd->query));
 #if defined(ENABLED_PROFILING)
     thd->profiling.start_new_query();
@@ -567,8 +567,9 @@ end:
 #ifndef EMBEDDED_LIBRARY
   (void) pthread_mutex_lock(&LOCK_thread_count);
   thread_count--;
-  (void) pthread_mutex_unlock(&LOCK_thread_count);
+  in_bootstrap= FALSE;
   (void) pthread_cond_broadcast(&COND_thread_count);
+  (void) pthread_mutex_unlock(&LOCK_thread_count);
   my_thread_end();
   pthread_exit(0);
 #endif
@@ -1097,9 +1098,8 @@ bool dispatch_command(enum enum_server_c
                         thd->security_ctx->priv_user,
                         (char *) thd->security_ctx->host_or_ip);
       
+      thd->set_query(beginning_of_next_stmt, length);
       pthread_mutex_lock(&LOCK_thread_count);
-      thd->query_length= length;
-      thd->query= beginning_of_next_stmt;
       /*
         Count each statement from the client.
       */
@@ -1150,9 +1150,10 @@ bool dispatch_command(enum enum_server_c
         table_list.schema_table= schema_table;
     }
 
-    thd->query_length= (uint) (packet_end - packet); // Don't count end \0
-    if (!(thd->query=fields= (char*) thd->memdup(packet,thd->query_length+1)))
+    uint query_length= (uint) (packet_end - packet); // Don't count end \0
+    if (!(fields= (char *) thd->memdup(packet, query_length + 1)))
       break;
+    thd->set_query(fields, query_length);
     general_log_print(thd, command, "%s %s", table_list.table_name, fields);
     if (lower_case_table_names)
       my_casedn_str(files_charset_info, table_list.table_name);
@@ -1416,13 +1417,12 @@ bool dispatch_command(enum enum_server_c
   log_slow_statement(thd);
 
   thd_proc_info(thd, "cleaning up");
-  pthread_mutex_lock(&LOCK_thread_count); // For process list
-  thd_proc_info(thd, 0);
+  thd->set_query(NULL, 0);
   thd->command=COM_SLEEP;
-  thd->query=0;
-  thd->query_length=0;
+  pthread_mutex_lock(&LOCK_thread_count); // For process list
   thread_running--;
   pthread_mutex_unlock(&LOCK_thread_count);
+  thd_proc_info(thd, 0);
   thd->packet.shrink(thd->variables.net_buffer_length);	// Reclaim some memory
   free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
 
@@ -1630,6 +1630,7 @@ int prepare_schema_table(THD *thd, LEX *
 
 bool alloc_query(THD *thd, const char *packet, uint packet_length)
 {
+  char *query;
   /* Remove garbage at start and end of query */
   while (packet_length > 0 && my_isspace(thd->charset(), packet[0]))
   {
@@ -1644,14 +1645,13 @@ bool alloc_query(THD *thd, const char *p
     packet_length--;
   }
   /* We must allocate some extra memory for query cache */
-  thd->query_length= 0;                        // Extra safety: Avoid races
-  if (!(thd->query= (char*) thd->memdup_w_gap((uchar*) (packet),
-					      packet_length,
-					      thd->db_length+ 1 +
-					      QUERY_CACHE_FLAGS_SIZE)))
-    return TRUE;
-  thd->query[packet_length]=0;
-  thd->query_length= packet_length;
+  if (! (query= (char*) thd->memdup_w_gap(packet,
+                                          packet_length,
+                                          1 + thd->db_length +
+                                          QUERY_CACHE_FLAGS_SIZE)))
+      return TRUE;
+  query[packet_length]= '\0';
+  thd->set_query(query, packet_length);
 
   /* Reclaim some memory */
   thd->packet.shrink(thd->variables.net_buffer_length);
@@ -6999,7 +6999,7 @@ uint kill_one_thread(THD *thd, ulong id,
       continue;
     if (tmp->thread_id == id)
     {
-      pthread_mutex_lock(&tmp->LOCK_delete);	// Lock from delete
+      pthread_mutex_lock(&tmp->LOCK_thd_data);	// Lock from delete
       break;
     }
   }
@@ -7032,7 +7032,7 @@ uint kill_one_thread(THD *thd, ulong id,
     }
     else
       error=ER_KILL_DENIED_ERROR;
-    pthread_mutex_unlock(&tmp->LOCK_delete);
+    pthread_mutex_unlock(&tmp->LOCK_thd_data);
   }
   DBUG_PRINT("exit", ("%d", error));
   DBUG_RETURN(error);

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2009-08-07 09:26:33 +0000
+++ b/sql/sql_partition.cc	2009-08-07 16:25:06 +0000
@@ -1718,7 +1718,7 @@ bool fix_partition_func(THD *thd, TABLE 
   if (((part_info->part_type != HASH_PARTITION ||
       part_info->list_of_part_fields == FALSE) &&
       check_part_func_fields(part_info->part_field_array, TRUE)) ||
-      (part_info->list_of_part_fields == FALSE &&
+      (part_info->list_of_subpart_fields == FALSE &&
        part_info->is_sub_partitioned() &&
        check_part_func_fields(part_info->subpart_field_array, TRUE)))
   {
@@ -3920,7 +3920,9 @@ bool mysql_unpack_partition(THD *thd,
       */
       thd->free_items();
       part_info= thd->work_part_info;
-      table->s->version= 0UL;
+      tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
+                       table->s->db.str,
+                       table->s->table_name.str);
       *work_part_info_used= true;
     }
   }
@@ -4212,12 +4214,17 @@ uint prep_alter_part_table(THD *thd, TAB
 
   /*
     We are going to manipulate the partition info on the table object
-    so we need to ensure that the data structure of the table object
-    is freed by setting version to 0. table->s->version= 0 forces a
-    flush of the table object in close_thread_tables().
+    so we need to ensure that the table instances cached and all other
+    instances are properly closed.
   */
   if (table->part_info)
-    table->s->version= 0L;
+  {
+    pthread_mutex_lock(&LOCK_open);
+    tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
+                     table->s->db.str,
+                     table->s->table_name.str);
+    pthread_mutex_unlock(&LOCK_open);
+  }
 
   thd->work_part_info= thd->lex->part_info;
   if (thd->work_part_info &&
@@ -5883,7 +5890,9 @@ static int alter_close_tables(ALTER_PART
         alter_partition_lock_handling() and the table is closed
         by close_thread_tables() instead.
       */
-      table->s->version= 0;
+      tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
+                       table->s->db.str,
+                       table->s->table_name.str);
     }
   }
   pthread_mutex_unlock(&LOCK_open);

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2009-07-15 18:31:27 +0000
+++ b/sql/sql_prepare.cc	2009-07-30 16:22:41 +0000
@@ -236,12 +236,12 @@ protected:
 #endif
   virtual enum enum_protocol_type type() { return PROTOCOL_LOCAL; };
 
-  virtual void send_ok(uint server_status, uint statement_warn_count,
+  virtual bool send_ok(uint server_status, uint statement_warn_count,
                        ulonglong affected_rows, ulonglong last_insert_id,
                        const char *message);
 
-  virtual void send_eof(uint server_status, uint statement_warn_count);
-  virtual void send_error(uint sql_errno, const char *err_msg, const char* sqlstate);
+  virtual bool send_eof(uint server_status, uint statement_warn_count);
+  virtual bool send_error(uint sql_errno, const char *err_msg, const char* sqlstate);
 private:
   bool store_string(const char *str, size_t length,
                     CHARSET_INFO *src_cs, CHARSET_INFO *dst_cs);
@@ -4342,7 +4342,7 @@ bool Protocol_local::send_out_parameters
 
 /** Called for statements that don't have a result set, at statement end. */
 
-void
+bool
 Protocol_local::send_ok(uint server_status, uint statement_warn_count,
                         ulonglong affected_rows, ulonglong last_insert_id,
                         const char *message)
@@ -4351,6 +4351,7 @@ Protocol_local::send_ok(uint server_stat
     Just make sure nothing is sent to the client, we have grabbed
     the status information in the connection diagnostics area.
   */
+  return FALSE;
 }
 
 
@@ -4362,7 +4363,7 @@ Protocol_local::send_ok(uint server_stat
   building of the result set at hand.
 */
 
-void Protocol_local::send_eof(uint server_status, uint statement_warn_count)
+bool Protocol_local::send_eof(uint server_status, uint statement_warn_count)
 {
   Ed_result_set *ed_result_set;
 
@@ -4377,7 +4378,7 @@ void Protocol_local::send_eof(uint serve
   m_rset= NULL;
 
   if (! ed_result_set)
-    return;
+    return TRUE;
 
   /* In case of successful allocation memory ownership was transferred. */
   DBUG_ASSERT(!alloc_root_inited(&m_rset_root));
@@ -4387,18 +4388,20 @@ void Protocol_local::send_eof(uint serve
     result sets. Never fails.
   */
   m_connection->add_result_set(ed_result_set);
+  return FALSE;
 }
 
 
 /** Called to send an error to the client at the end of a statement. */
 
-void
+bool
 Protocol_local::send_error(uint sql_errno, const char *err_msg, const char*)
 {
   /*
     Just make sure that nothing is sent to the client (default
     implementation).
   */
+  return FALSE;
 }
 
 

=== modified file 'sql/sql_repl.cc'
--- a/sql/sql_repl.cc	2009-06-29 14:56:06 +0000
+++ b/sql/sql_repl.cc	2009-07-24 16:14:20 +0000
@@ -1341,7 +1341,7 @@ void kill_zombie_dump_threads(uint32 sla
     if (tmp->command == COM_BINLOG_DUMP &&
        tmp->server_id == slave_server_id)
     {
-      pthread_mutex_lock(&tmp->LOCK_delete);	// Lock from delete
+      pthread_mutex_lock(&tmp->LOCK_thd_data);	// Lock from delete
       break;
     }
   }
@@ -1354,7 +1354,7 @@ void kill_zombie_dump_threads(uint32 sla
       again. We just to do kill the thread ourselves.
     */
     tmp->awake(THD::KILL_QUERY);
-    pthread_mutex_unlock(&tmp->LOCK_delete);
+    pthread_mutex_unlock(&tmp->LOCK_thd_data);
   }
 }
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2009-07-16 13:22:38 +0000
+++ b/sql/sql_select.cc	2009-07-28 14:16:37 +0000
@@ -15531,7 +15531,11 @@ create_internal_tmp_table_from_heap2(THD
   if (table->s->db_type() != heap_hton || 
       error != HA_ERR_RECORD_FILE_FULL)
   {
-    table->file->print_error(error,MYF(0));
+    /*
+      We don't want this error to be converted to a warning, e.g. in case of
+      INSERT IGNORE ... SELECT.
+    */
+    table->file->print_error(error, MYF(ME_FATALERROR));
     DBUG_RETURN(1);
   }
 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2009-07-16 12:51:04 +0000
+++ b/sql/sql_show.cc	2009-07-29 15:07:02 +0000
@@ -75,9 +75,6 @@ static TYPELIB grant_types = { sizeof(gr
                                grant_names, NULL};
 #endif
 
-/* Match the values of enum ha_choice */
-static const char *ha_choice_values[] = {"", "0", "1"};
-
 static void store_key_options(THD *thd, String *packet, TABLE *table,
                               KEY *key_info);
 
@@ -1378,11 +1375,6 @@ int store_create_info(THD *thd, TABLE_LI
     /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
     if (create_info.options & HA_OPTION_CHECKSUM)
       packet->append(STRING_WITH_LEN(" CHECKSUM=1"));
-    if (create_info.page_checksum != HA_CHOICE_UNDEF)
-    {
-      packet->append(STRING_WITH_LEN(" PAGE_CHECKSUM="));
-      packet->append(ha_choice_values[create_info.page_checksum], 1);
-    }
     if (create_info.options & HA_OPTION_DELAY_KEY_WRITE)
       packet->append(STRING_WITH_LEN(" DELAY_KEY_WRITE=1"));
     if (create_info.row_type != ROW_TYPE_DEFAULT)
@@ -1390,11 +1382,6 @@ int store_create_info(THD *thd, TABLE_LI
       packet->append(STRING_WITH_LEN(" ROW_FORMAT="));
       packet->append(ha_row_type[(uint) create_info.row_type]);
     }
-    if (share->transactional != HA_CHOICE_UNDEF)
-    {
-      packet->append(STRING_WITH_LEN(" TRANSACTIONAL="));
-      packet->append(ha_choice_values[(uint) share->transactional], 1);
-    }
     if (table->s->key_block_size)
     {
       char *end;
@@ -1797,26 +1784,24 @@ void mysqld_list_processes(THD *thd,cons
         if ((thd_info->db=tmp->db))             // Safe test
           thd_info->db=thd->strdup(thd_info->db);
         thd_info->command=(int) tmp->command;
-        pthread_mutex_lock(&tmp->LOCK_delete);
+        pthread_mutex_lock(&tmp->LOCK_thd_data);
         if ((mysys_var= tmp->mysys_var))
           pthread_mutex_lock(&mysys_var->mutex);
         thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
         thd_info->state_info= thread_state_info(tmp);
         if (mysys_var)
           pthread_mutex_unlock(&mysys_var->mutex);
-        pthread_mutex_unlock(&tmp->LOCK_delete);
+        pthread_mutex_unlock(&tmp->LOCK_thd_data);
         thd_info->start_time= tmp->start_time;
         thd_info->query=0;
+        /* Lock THD mutex that protects its data when looking at it. */
+        pthread_mutex_lock(&tmp->LOCK_thd_data);
         if (tmp->query)
         {
-	  /*
-            query_length is always set to 0 when we set query = NULL; see
-	    the comment in sql_class.h why this prevents crashes in possible
-            races with query_length
-          */
           uint length= min(max_query_length, tmp->query_length);
           thd_info->query=(char*) thd->strmake(tmp->query,length);
         }
+        pthread_mutex_unlock(&tmp->LOCK_thd_data);
         thread_infos.append(thd_info);
       }
     }
@@ -1903,7 +1888,7 @@ int fill_schema_processlist(THD* thd, TA
         table->field[3]->set_notnull();
       }
 
-      pthread_mutex_lock(&tmp->LOCK_delete);
+      pthread_mutex_lock(&tmp->LOCK_thd_data);
       if ((mysys_var= tmp->mysys_var))
         pthread_mutex_lock(&mysys_var->mutex);
       /* COMMAND */
@@ -1924,7 +1909,7 @@ int fill_schema_processlist(THD* thd, TA
 
       if (mysys_var)
         pthread_mutex_unlock(&mysys_var->mutex);
-      pthread_mutex_unlock(&tmp->LOCK_delete);
+      pthread_mutex_unlock(&tmp->LOCK_thd_data);
 
       /* INFO */
       if (tmp->query)
@@ -3735,9 +3720,6 @@ static int get_schema_tables_record(THD 
     /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
     if (share->db_create_options & HA_OPTION_CHECKSUM)
       ptr=strmov(ptr," checksum=1");
-    if (share->page_checksum != HA_CHOICE_UNDEF)
-      ptr= strxmov(ptr, " page_checksum=",
-                   ha_choice_values[(uint) share->page_checksum], NullS);
     if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
       ptr=strmov(ptr," delay_key_write=1");
     if (share->row_type != ROW_TYPE_DEFAULT)
@@ -3748,9 +3730,6 @@ static int get_schema_tables_record(THD 
     if (is_partitioned)
       ptr= strmov(ptr, " partitioned");
 #endif
-    if (share->transactional != HA_CHOICE_UNDEF)
-      ptr= strxmov(ptr, " transactional=",
-                   ha_choice_values[(uint) share->transactional], NullS);
     if (share->key_block_size)
     {
       ptr= strmov(ptr, " KEY_BLOCK_SIZE=");

=== modified file 'sql/sql_signal.cc'
--- a/sql/sql_signal.cc	2009-02-06 03:25:50 +0000
+++ b/sql/sql_signal.cc	2009-07-30 09:41:30 +0000
@@ -91,10 +91,10 @@ void Set_signal_information::clear()
   memset(m_item, 0, sizeof(m_item));
 }
 
-void Abstract_signal::assign_defaults(MYSQL_ERROR *cond,
-                                      bool set_level_code,
-                                      MYSQL_ERROR::enum_warning_level level,
-                                      int sqlcode)
+void Signal_common::assign_defaults(MYSQL_ERROR *cond,
+                                    bool set_level_code,
+                                    MYSQL_ERROR::enum_warning_level level,
+                                    int sqlcode)
 {
   if (set_level_code)
   {
@@ -105,7 +105,7 @@ void Abstract_signal::assign_defaults(MY
     cond->set_builtin_message_text(ER(sqlcode));
 }
 
-void Abstract_signal::eval_defaults(THD *thd, MYSQL_ERROR *cond)
+void Signal_common::eval_defaults(THD *thd, MYSQL_ERROR *cond)
 {
   DBUG_ASSERT(cond);
 
@@ -260,7 +260,7 @@ static int assign_condition_item(MEM_ROO
 }
 
 
-int Abstract_signal::eval_signal_informations(THD *thd, MYSQL_ERROR *cond)
+int Signal_common::eval_signal_informations(THD *thd, MYSQL_ERROR *cond)
 {
   struct cond_item_map
   {
@@ -292,7 +292,7 @@ int Abstract_signal::eval_signal_informa
   String *member;
   const LEX_STRING *name;
 
-  DBUG_ENTER("Abstract_signal::eval_signal_informations");
+  DBUG_ENTER("Signal_common::eval_signal_informations");
 
   for (i= FIRST_DIAG_SET_PROPERTY;
        i <= LAST_DIAG_SET_PROPERTY;
@@ -418,11 +418,11 @@ end:
   DBUG_RETURN(result);
 }
 
-int Abstract_signal::raise_condition(THD *thd, MYSQL_ERROR *cond)
+bool Signal_common::raise_condition(THD *thd, MYSQL_ERROR *cond)
 {
-  int result= 1;
+  bool result= TRUE;
 
-  DBUG_ENTER("Abstract_signal::raise_condition");
+  DBUG_ENTER("Signal_common::raise_condition");
 
   DBUG_ASSERT(m_lex->query_tables == NULL);
 
@@ -445,18 +445,18 @@ int Abstract_signal::raise_condition(THD
   if (cond->m_level == MYSQL_ERROR::WARN_LEVEL_WARN)
   {
     my_ok(thd);
-    result= 0;
+    result= FALSE;
   }
 
   DBUG_RETURN(result);
 }
 
-int SQLCOM_signal::execute(THD *thd)
+bool Signal_statement::execute(THD *thd)
 {
-  int result= 1;
+  bool result= TRUE;
   MYSQL_ERROR cond(thd->mem_root);
 
-  DBUG_ENTER("SQLCOM_signal::execute");
+  DBUG_ENTER("Signal_statement::execute");
 
   thd->stmt_da->reset_diagnostics_area();
   thd->row_count_func= 0;
@@ -468,12 +468,12 @@ int SQLCOM_signal::execute(THD *thd)
 }
 
 
-int SQLCOM_resignal::execute(THD *thd)
+bool Resignal_statement::execute(THD *thd)
 {
   MYSQL_ERROR *signaled;
-  int result= 1;
+  int result= TRUE;
 
-  DBUG_ENTER("SQLCOM_resignal::execute");
+  DBUG_ENTER("Resignal_statement::execute");
 
   thd->warning_info->m_warn_id= thd->query_id;
 

=== modified file 'sql/sql_signal.h'
--- a/sql/sql_signal.h	2009-01-16 01:27:22 +0000
+++ b/sql/sql_signal.h	2009-07-30 09:41:30 +0000
@@ -17,10 +17,10 @@
 #define SQL_SIGNAL_H
 
 /**
-  Abstract_signal represents the common properties of the SIGNAL and RESIGNAL
+  Signal_common represents the common properties of the SIGNAL and RESIGNAL
   statements.
 */
-class Abstract_signal : public SQLCOM_statement
+class Signal_common : public Sql_statement
 {
 protected:
   /**
@@ -29,15 +29,15 @@ protected:
     @param cond the condition signaled if any, or NULL.
     @param set collection of signal condition item assignments.
   */
-  Abstract_signal(LEX *lex,
-                  const sp_cond_type_t *cond,
-                  const Set_signal_information& set)
-    : SQLCOM_statement(lex),
+  Signal_common(LEX *lex,
+                const sp_cond_type_t *cond,
+                const Set_signal_information& set)
+    : Sql_statement(lex),
       m_cond(cond),
       m_set_signal_information(set)
   {}
 
-  virtual ~Abstract_signal()
+  virtual ~Signal_common()
   {}
 
   /**
@@ -73,9 +73,9 @@ protected:
     Raise a SQL condition.
     @param thd the current thread.
     @param cond the condition to raise.
-    @return 0 on success.
+    @return false on success.
   */
-  int raise_condition(THD *thd, MYSQL_ERROR *cond);
+  bool raise_condition(THD *thd, MYSQL_ERROR *cond);
 
   /**
     The condition to signal or resignal.
@@ -91,9 +91,9 @@ protected:
 };
 
 /**
-  SQLCOM_signal represents a SIGNAL statement.
+  Signal_statement represents a SIGNAL statement.
 */
-class SQLCOM_signal : public Abstract_signal
+class Signal_statement : public Signal_common
 {
 public:
   /**
@@ -102,27 +102,27 @@ public:
     @param cond the SQL condition to signal (required).
     @param set the collection of signal informations to signal.
   */
-  SQLCOM_signal(LEX *lex,
+  Signal_statement(LEX *lex,
                 const sp_cond_type_t *cond,
                 const Set_signal_information& set)
-    : Abstract_signal(lex, cond, set)
+    : Signal_common(lex, cond, set)
   {}
 
-  virtual ~SQLCOM_signal()
+  virtual ~Signal_statement()
   {}
 
   /**
     Execute a SIGNAL statement at runtime.
     @param thd the current thread.
-    @return 0 on success.
+    @return false on success.
   */
-  virtual int execute(THD *thd);
+  virtual bool execute(THD *thd);
 };
 
 /**
-  SQLCOM_resignal represents a RESIGNAL statement.
+  Resignal_statement represents a RESIGNAL statement.
 */
-class SQLCOM_resignal : public Abstract_signal
+class Resignal_statement : public Signal_common
 {
 public:
   /**
@@ -131,13 +131,13 @@ public:
     @param cond the SQL condition to resignal (optional, may be NULL).
     @param set the collection of signal informations to resignal.
   */
-  SQLCOM_resignal(LEX *lex,
-                  const sp_cond_type_t *cond,
-                  const Set_signal_information& set)
-    : Abstract_signal(lex, cond, set)
+  Resignal_statement(LEX *lex,
+                     const sp_cond_type_t *cond,
+                     const Set_signal_information& set)
+    : Signal_common(lex, cond, set)
   {}
 
-  virtual ~SQLCOM_resignal()
+  virtual ~Resignal_statement()
   {}
 
   /**
@@ -145,7 +145,7 @@ public:
     @param thd the current thread.
     @return 0 on success.
   */
-  virtual int execute(THD *thd);
+  virtual bool execute(THD *thd);
 };
 
 #endif

=== modified file 'sql/sql_string.cc'
--- a/sql/sql_string.cc	2009-06-26 12:46:24 +0000
+++ b/sql/sql_string.cc	2009-07-31 17:53:36 +0000
@@ -1132,3 +1132,76 @@ void String::swap(String &s)
   swap_variables(bool, alloced, s.alloced);
   swap_variables(CHARSET_INFO*, str_charset, s.str_charset);
 }
+
+
+/**
+  Convert string to printable ASCII string
+
+  @details This function converts input string "from" replacing non-ASCII bytes
+  with hexadecimal sequences ("\xXX") optionally appending "..." to the end of
+  the resulting string.
+  This function used in the ER_TRUNCATED_WRONG_VALUE_FOR_FIELD error messages,
+  e.g. when a string cannot be converted to a result charset.
+
+
+  @param    to          output buffer
+  @param    to_len      size of the output buffer (8 bytes or greater)
+  @param    from        input string
+  @param    from_len    size of the input string
+  @param    from_cs     input charset
+  @param    nbytes      maximal number of bytes to convert (from_len if 0)
+
+  @return   number of bytes in the output string
+*/
+
+uint convert_to_printable(char *to, size_t to_len,
+                          const char *from, size_t from_len,
+                          CHARSET_INFO *from_cs, size_t nbytes /*= 0*/)
+{
+  /* needs at least 8 bytes for '\xXX...' and zero byte */
+  DBUG_ASSERT(to_len >= 8);
+
+  char *t= to;
+  char *t_end= to + to_len - 1; // '- 1' is for the '\0' at the end
+  const char *f= from;
+  const char *f_end= from + (nbytes ? min(from_len, nbytes) : from_len);
+  char *dots= to; // last safe place to append '...'
+
+  if (!f || t == t_end)
+    return 0;
+
+  for (; t < t_end && f < f_end; f++)
+  {
+    /*
+      If the source string is ASCII compatible (mbminlen==1)
+      and the source character is in ASCII printable range (0x20..0x7F),
+      then display the character as is.
+      
+      Otherwise, if the source string is not ASCII compatible (e.g. UCS2),
+      or the source character is not in the printable range,
+      then print the character using HEX notation.
+    */
+    if (((unsigned char) *f) >= 0x20 &&
+        ((unsigned char) *f) <= 0x7F &&
+        from_cs->mbminlen == 1)
+    {
+      *t++= *f;
+    }
+    else
+    {
+      if (t_end - t < 4) // \xXX
+        break;
+      *t++= '\\';
+      *t++= 'x';
+      *t++= _dig_vec_upper[((unsigned char) *f) >> 4];
+      *t++= _dig_vec_upper[((unsigned char) *f) & 0x0F];
+    }
+    if (t_end - t >= 3) // '...'
+      dots= t;
+  }
+  if (f < from + from_len)
+    memcpy(dots, STRING_WITH_LEN("...\0"));
+  else
+    *t= '\0';
+  return t - to;
+}

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2009-01-26 16:03:39 +0000
+++ b/sql/sql_string.h	2009-07-31 17:53:36 +0000
@@ -36,6 +36,9 @@ uint32 well_formed_copy_nchars(CHARSET_I
 size_t my_copy_with_hex_escaping(CHARSET_INFO *cs,
                                  char *dst, size_t dstlen,
                                  const char *src, size_t srclen);
+uint convert_to_printable(char *to, size_t to_len,
+                          const char *from, size_t from_len,
+                          CHARSET_INFO *from_cs, size_t nbytes= 0);
 
 class String
 {
@@ -367,6 +370,19 @@ public:
   {
     return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
   }
+  bool is_ascii() const
+  {
+    if (length() == 0)
+      return TRUE;
+    if (charset()->mbminlen > 1)
+      return FALSE;
+    for (const char *c= ptr(), *end= c + length(); c < end; c++)
+    {
+      if (!my_isascii(*c))
+        return FALSE;
+    }
+    return TRUE;
+  }
 };
 
 static inline bool check_if_only_end_space(CHARSET_INFO *cs, char *str, 

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-07-10 12:31:32 +0000
+++ b/sql/sql_table.cc	2009-07-31 19:46:24 +0000
@@ -1797,6 +1797,7 @@ int mysql_rm_table_part2(THD *thd, TABLE
   int non_temp_tables_count= 0;
   bool some_tables_deleted=0, tmp_table_deleted=0, foreign_key_error=0;
   String built_query;
+  String built_tmp_query;
   DBUG_ENTER("mysql_rm_table_part2");
 
   LINT_INIT(alias);
@@ -1900,6 +1901,25 @@ int mysql_rm_table_part2(THD *thd, TABLE
     case  0:
       // removed temporary table
       tmp_table_deleted= 1;
+      if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED &&
+          thd->current_stmt_binlog_row_based)
+      {
+        if (built_tmp_query.is_empty()) 
+        {
+          built_tmp_query.set_charset(system_charset_info);
+          built_tmp_query.append("DROP TEMPORARY TABLE IF EXISTS ");
+        }
+
+        built_tmp_query.append("`");
+        if (thd->db == NULL || strcmp(db,thd->db) != 0)
+        {
+          built_tmp_query.append(db);
+          built_tmp_query.append("`.`");
+        }
+        built_tmp_query.append(table->table_name);
+        built_tmp_query.append("`,");
+      }
+
       continue;
     case -1:
       DBUG_ASSERT(thd->in_sub_stmt);
@@ -2066,29 +2086,52 @@ int mysql_rm_table_part2(THD *thd, TABLE
         write_bin_log(thd, !error, thd->query, thd->query_length);
       }
       else if (thd->current_stmt_binlog_row_based &&
-               non_temp_tables_count > 0 &&
                tmp_table_deleted)
       {
-        /*
-          In this case we have deleted both temporary and
-          non-temporary tables, so:
-          - since we have deleted a non-temporary table we have to
-            binlog the statement, but
-          - since we have deleted a temporary table we cannot binlog
-            the statement (since the table has not been created on the
-            slave, this might cause the slave to stop).
+        if (non_temp_tables_count > 0)
+        {
+          /*
+            In this case we have deleted both temporary and
+            non-temporary tables, so:
+            - since we have deleted a non-temporary table we have to
+              binlog the statement, but
+            - since we have deleted a temporary table we cannot binlog
+              the statement (since the table may have not been created on the
+              slave - check "if" branch below, this might cause the slave to 
+              stop).
 
-          Instead, we write a built statement, only containing the
-          non-temporary tables, to the binary log
+            Instead, we write a built statement, only containing the
+            non-temporary tables, to the binary log
+          */
+          built_query.chop();                  // Chop of the last comma
+          built_query.append(" /* generated by server */");
+          write_bin_log(thd, !error, built_query.ptr(), built_query.length());
+        }
+
+        /*
+          One needs to always log any temporary table drop, if:
+            1. thread logging format is mixed mode; AND
+            2. current statement logging format is set to row.
         */
-        built_query.chop();                  // Chop of the last comma
-        built_query.append(" /* generated by server */");
-        write_bin_log(thd, !error, built_query.ptr(), built_query.length());
+        if (thd->variables.binlog_format == BINLOG_FORMAT_MIXED)
+        {
+          /*
+            In this case we have deleted some temporary tables but we are using
+            row based logging for the statement. However, thread uses mixed mode
+            format, thence we need to log the dropping as we cannot tell for
+            sure whether the create was logged as statement previously or not, ie,
+            before switching to row mode.
+          */
+          built_tmp_query.chop();                  // Chop of the last comma
+          built_tmp_query.append(" /* generated by server */");
+          write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length());
+        }
       }
+
       /*
         The remaining cases are:
-        - no tables where deleted and
-        - only temporary tables where deleted and row-based
+        - no tables were deleted and
+        - only temporary tables were deleted and row-based
           replication is used.
         In both these cases, nothing should be written to the binary
         log.
@@ -6445,8 +6488,6 @@ mysql_prepare_alter_table(THD *thd, TABL
   }
   if (!(used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE))
     create_info->key_block_size= table->s->key_block_size;
-  if (!(used_fields & HA_CREATE_USED_TRANSACTIONAL))
-    create_info->transactional= table->s->transactional;
 
   restore_record(table, s->default_values);     // Empty record for DEFAULT
 
@@ -7693,7 +7734,7 @@ end_online:
 end_temporary:
   my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
 	      (ulong) (copied + deleted), (ulong) deleted,
-	      (ulong) thd->cuted_fields);
+	      (ulong) thd->warning_info->statement_warn_count());
   my_ok(thd, copied + deleted, 0L, tmp_name);
   thd->some_tables_deleted=0;
   DBUG_RETURN(FALSE);

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2009-07-14 09:21:56 +0000
+++ b/sql/sql_update.cc	2009-07-31 19:46:24 +0000
@@ -842,8 +842,9 @@ int mysql_update(THD *thd,
   if (error < 0)
   {
     char buff[STRING_BUFFER_USUAL_SIZE];
-    my_snprintf(buff, sizeof(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->warning_info->statement_warn_count());
     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/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2009-07-16 12:51:04 +0000
+++ b/sql/sql_yacc.yy	2009-07-31 19:46:24 +0000
@@ -999,7 +999,6 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %token  OWNER_SYM
 %token  PACK_KEYS_SYM
 %token  PAGE_SYM
-%token  PAGE_CHECKSUM_SYM
 %token  PARAM_MARKER
 %token  PARSER_SYM
 %token  PARTIAL                       /* SQL-2003-N */
@@ -1166,7 +1165,6 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %token  TO_SYM                        /* SQL-2003-R */
 %token  TRAILING                      /* SQL-2003-R */
 %token  TRANSACTION_SYM
-%token  TRANSACTIONAL_SYM
 %token  TRIGGERS_SYM
 %token  TRIGGER_SYM                   /* SQL-2003-R */
 %token  TRIM                          /* SQL-2003-N */
@@ -2770,9 +2768,8 @@ signal_stmt:
             Yacc_state *state= & thd->m_parser_state->m_yacc;
 
             lex->sql_command= SQLCOM_SIGNAL;
-            lex->m_stmt= new (thd->mem_root) SQLCOM_signal(lex, 
-                                                           $2,
-                                                           state->m_set_signal_info);
+            lex->m_stmt= new (thd->mem_root) Signal_statement(lex, $2,
+                                                      state->m_set_signal_info);
             if (lex->m_stmt == NULL)
               MYSQL_YYABORT;
           }
@@ -2910,9 +2907,8 @@ resignal_stmt:
             Yacc_state *state= & thd->m_parser_state->m_yacc;
 
             lex->sql_command= SQLCOM_RESIGNAL;
-            lex->m_stmt= new (thd->mem_root) SQLCOM_resignal(lex, 
-                                                             $2,
-                                                             state->m_set_signal_info);
+            lex->m_stmt= new (thd->mem_root) Resignal_statement(lex, $2,
+                                                      state->m_set_signal_info);
             if (lex->m_stmt == NULL)
               MYSQL_YYABORT;
           }
@@ -4575,6 +4571,10 @@ opt_sub_partition:
             if (Lex->part_info->no_subparts != 0 &&
                 !Lex->part_info->use_default_subpartitions)
             {
+              /*
+                We come here when we have defined subpartitions on the first
+                partition but not on all the subsequent partitions. 
+              */
               my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR));
               MYSQL_YYABORT;
             }
@@ -4617,6 +4617,23 @@ sub_part_definition:
             partition_info *part_info= lex->part_info;
             partition_element *curr_part= part_info->current_partition;
             partition_element *sub_p_elem= new partition_element(curr_part);
+            if (part_info->use_default_subpartitions &&
+                part_info->partitions.elements >= 2)
+            {
+              /*
+                create table t1 (a int)
+                partition by list (a) subpartition by hash (a)
+                (partition p0 values in (1),
+                 partition p1 values in (2) subpartition sp11);
+                causes use to arrive since we are on the second
+                partition, but still use_default_subpartitions
+                is set. When we come here we're processing at least
+                the second partition (the current partition processed
+                have already been put into the partitions list.
+              */
+              my_parse_error(ER(ER_PARTITION_WRONG_NO_SUBPART_ERROR));
+              MYSQL_YYABORT;
+            }
             if (!sub_p_elem ||
              curr_part->subpartitions.push_back(sub_p_elem))
             {
@@ -4827,11 +4844,6 @@ create_table_option:
              Lex->create_info.table_options|= $3 ? HA_OPTION_CHECKSUM : HA_OPTION_NO_CHECKSUM;
              Lex->create_info.used_fields|= HA_CREATE_USED_CHECKSUM;
           }
-        | PAGE_CHECKSUM_SYM opt_equal choice
-          {
-            Lex->create_info.used_fields|= HA_CREATE_USED_PAGE_CHECKSUM;
-            Lex->create_info.page_checksum= $3;
-          }
         | DELAY_KEY_WRITE_SYM opt_equal ulong_num
           {
             Lex->create_info.table_options|= $3 ? HA_OPTION_DELAY_KEY_WRITE : HA_OPTION_NO_DELAY_KEY_WRITE;
@@ -4903,11 +4915,6 @@ create_table_option:
             Lex->create_info.used_fields|= HA_CREATE_USED_KEY_BLOCK_SIZE;
             Lex->create_info.key_block_size= $3;
           }
-        | TRANSACTIONAL_SYM opt_equal choice
-          {
-	    Lex->create_info.used_fields|= HA_CREATE_USED_TRANSACTIONAL;
-            Lex->create_info.transactional= $3;
-          }
         ;
 
 default_charset:
@@ -4994,7 +5001,6 @@ row_types:
         | COMPRESSED_SYM { $$= ROW_TYPE_COMPRESSED; }
         | REDUNDANT_SYM  { $$= ROW_TYPE_REDUNDANT; }
         | COMPACT_SYM    { $$= ROW_TYPE_COMPACT; }
-        | PAGE_SYM       { $$= ROW_TYPE_PAGE; }
         ;
 
 merge_insert_types:
@@ -10017,6 +10023,8 @@ into_destination:
                 !(lex->result= new select_export(lex->exchange)))
               MYSQL_YYABORT;
           }
+          opt_load_data_charset
+          { Lex->exchange->cs= $4; }
           opt_field_term opt_line_term
         | DUMPFILE TEXT_STRING_filesystem
           {
@@ -12366,7 +12374,6 @@ keyword_sp:
         | ONLINE_SYM               {}
         | PACK_KEYS_SYM            {}
         | PAGE_SYM                 {}
-        | PAGE_CHECKSUM_SYM	   {}
         | PARTIAL                  {}
         | PARTITIONING_SYM         {}
         | PARTITIONS_SYM           {}
@@ -12448,7 +12455,6 @@ keyword_sp:
         | TEXT_SYM                 {}
         | THAN_SYM                 {}
         | TRANSACTION_SYM          {}
-        | TRANSACTIONAL_SYM        {}
         | TRIGGERS_SYM             {}
         | TIMESTAMP                {}
         | TIMESTAMP_ADD            {}

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2009-07-29 18:01:49 +0000
+++ b/sql/table.cc	2009-08-07 16:25:06 +0000
@@ -783,8 +783,6 @@ static int open_binary_frm(THD *thd, TAB
   if (!head[32])				// New frm file in 3.23
   {
     share->avg_row_length= uint4korr(head+34);
-    share->transactional= (ha_choice) (head[39] & 3);
-    share->page_checksum= (ha_choice) ((head[39] >> 2) & 3);
     share->row_type= (row_type) head[40];
     share->table_charset= get_charset((((uint) head[41]) << 8) + 
                                         (uint) head[38],MYF(0));
@@ -2653,8 +2651,11 @@ File create_frm(THD *thd, const char *na
     csid= (create_info->default_table_charset ?
            create_info->default_table_charset->number : 0);
     fileinfo[38]= (uchar) csid;
-    fileinfo[39]= (uchar) ((uint) create_info->transactional |
-                           ((uint) create_info->page_checksum << 2));
+    /*
+      In future versions, we will store in fileinfo[39] the values of the
+      TRANSACTIONAL and PAGE_CHECKSUM clauses of CREATE TABLE.
+    */
+    fileinfo[39]= 0;
     fileinfo[40]= (uchar) create_info->row_type;
     /* Next few bytes where for RAID support */
     fileinfo[41]= (uchar) (csid >> 8);

=== modified file 'sql/table.h'
--- a/sql/table.h	2009-06-17 15:26:50 +0000
+++ b/sql/table.h	2009-07-29 10:25:07 +0000
@@ -372,7 +372,9 @@ struct TABLE_SHARE
   enum ha_storage_media default_storage_media;
   char *tablespace;
   enum tmp_table_type tmp_table;
+  /** Transactional or not. Unused; reserved for future versions. */
   enum ha_choice transactional;
+  /** Per-page checksums or not. Unused; reserved for future versions. */
   enum ha_choice page_checksum;
 
   uint ref_count;                       /* How many TABLE objects uses this */

=== modified file 'sql/unireg.h'
--- a/sql/unireg.h	2009-07-03 05:54:09 +0000
+++ b/sql/unireg.h	2009-07-31 20:21:25 +0000
@@ -29,8 +29,8 @@
 #define TEMP_PREFIX	"MY"
 #define LOG_PREFIX	"ML"
 #define PROGDIR		"bin/"
-#ifndef DATADIR
-#define DATADIR		"data/"
+#ifndef MYSQL_DATADIR
+#define MYSQL_DATADIR		"data/"
 #endif
 #ifndef SHAREDIR
 #define SHAREDIR	"share/"

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2009-07-10 11:44:11 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2009-07-24 12:37:26 +0000
@@ -693,17 +693,7 @@ convert_error_code_to_mysql(
     		return(HA_ERR_LOCK_TABLE_FULL);
 	} else if (error == DB_TOO_MANY_CONCURRENT_TRXS) {
 
-		/* Once MySQL add the appropriate code to errmsg.txt then
-		we can get rid of this #ifdef. NOTE: The code checked by
-		the #ifdef is the suggested name for the error condition
-		and the actual error code name could very well be different.
-		This will require some monitoring, ie. the status
-		of this request on our part.*/
-#ifdef ER_TOO_MANY_CONCURRENT_TRXS
-		return(ER_TOO_MANY_CONCURRENT_TRXS);
-#else
-		return(HA_ERR_RECORD_FILE_FULL);
-#endif
+		return(HA_ERR_TOO_MANY_CONCURRENT_TRXS);
 
 	} else if (error == DB_UNSUPPORTED) {
 

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2009-07-08 12:46:36 +0000
+++ b/storage/myisam/ha_myisam.cc	2009-07-24 16:14:20 +0000
@@ -1477,10 +1477,7 @@ bool ha_myisam::check_and_repair(THD *th
 
   old_query= thd->query;
   old_query_length= thd->query_length;
-  pthread_mutex_lock(&LOCK_thread_count);
-  thd->query=        table->s->table_name.str;
-  thd->query_length= table->s->table_name.length;
-  pthread_mutex_unlock(&LOCK_thread_count);
+  thd->set_query(table->s->table_name.str, table->s->table_name.length);
 
   if ((marked_crashed= mi_is_crashed(file)) || check(thd, &check_opt))
   {
@@ -1493,10 +1490,7 @@ bool ha_myisam::check_and_repair(THD *th
     if (repair(thd, &check_opt))
       error=1;
   }
-  pthread_mutex_lock(&LOCK_thread_count);
-  thd->query= old_query;
-  thd->query_length= old_query_length;
-  pthread_mutex_unlock(&LOCK_thread_count);
+  thd->set_query(old_query, old_query_length);
   DBUG_RETURN(error);
 }
 

=== modified file 'storage/myisam/myisam_backup_engine.cc'
--- a/storage/myisam/myisam_backup_engine.cc	2009-05-14 21:49:53 +0000
+++ b/storage/myisam/myisam_backup_engine.cc	2009-07-24 16:14:20 +0000
@@ -435,11 +435,11 @@ retry:
       To do that we will use lock_thd, but how to be sure that lock_thd is not
       being deleted now? One way would be to hold THR_LOCK_myisam but
       THD::awake() can't bear it (same mutex locked twice).
-      Another way is to take lock_thd->LOCK_delete (THD::awake() requires it
+      Another way is to take lock_thd->LOCK_thd_data (THD::awake() requires it
       anyway), but again that requires that lock_thd is not deleted while we
-      access the mutex. We cannot hold THR_LOCK_myisam to get LOCK_delete,
+      access the mutex. We cannot hold THR_LOCK_myisam to get LOCK_thd_data,
       because that could deadlock if a some other thread is doing a KILL on
-      the locking thread (it would indeed take LOCK_delete and then
+      the locking thread (it would indeed take LOCK_thd_data and then
       THR_LOCK_myisam to wake up the locking thread).
       So So we set a flag:
     */
@@ -450,9 +450,9 @@ retry:
       We kill the thread (which will in particular work if it is waiting for
       some table locks).
     */
-    pthread_mutex_lock(&lock_thd->LOCK_delete);
+    pthread_mutex_lock(&lock_thd->LOCK_thd_data);
     lock_thd->awake(THD::KILL_CONNECTION);
-    pthread_mutex_unlock(&lock_thd->LOCK_delete);
+    pthread_mutex_unlock(&lock_thd->LOCK_thd_data);
     /* won't look at lock_thd anymore, allow its deletion */
     pthread_mutex_lock(&THR_LOCK_myisam);
     cannot_delete_lock_thd= FALSE;
@@ -835,8 +835,7 @@ void Backup::lock_tables_TL_READ_NO_INSE
   /*
     Set info for the process list. Used in test cases.
   */
-  thd->query= (char*) thread_name;
-  thd->query_length= sizeof(thread_name) - 1;
+  thd->set_query((char*) thread_name, sizeof(thread_name) - 1);
 
   lex_start(thd);
   mysql_reset_thd_for_next_command(thd);

=== modified file 'storage/myisammrg/ha_myisammrg.cc'
--- a/storage/myisammrg/ha_myisammrg.cc	2009-07-12 14:58:09 +0000
+++ b/storage/myisammrg/ha_myisammrg.cc	2009-07-31 04:03:41 +0000
@@ -1086,7 +1086,6 @@ int ha_myisammrg::info(uint flag)
     */
     mrg_info.errkey= MAX_KEY;
   }
-  errkey= mrg_info.errkey;
   table->s->keys_in_use.set_prefix(table->s->keys);
   stats.mean_rec_length= mrg_info.reclength;
   
@@ -1136,6 +1135,11 @@ int ha_myisammrg::info(uint flag)
              min(file->keys, table->s->key_parts));
     }
   }
+  if (flag & HA_STATUS_ERRKEY)
+  {
+    errkey= mrg_info.errkey;
+    my_store_ptr(dup_ref, ref_length, mrg_info.dupp_key_pos);
+  }
   return 0;
 }
 

=== modified file 'storage/myisammrg/ha_myisammrg.h'
--- a/storage/myisammrg/ha_myisammrg.h	2009-04-01 21:36:07 +0000
+++ b/storage/myisammrg/ha_myisammrg.h	2009-07-31 04:03:41 +0000
@@ -47,7 +47,8 @@ class ha_myisammrg: public handler
 	    HA_NULL_IN_KEY | HA_CAN_INDEX_BLOBS | HA_FILE_BASED |
             HA_ANY_INDEX_MAY_BE_UNIQUE | HA_CAN_BIT_FIELD |
             HA_HAS_RECORDS |
-            HA_NO_COPY_ON_ALTER);
+            HA_NO_COPY_ON_ALTER |
+            HA_DUPLICATE_POS);
   }
   ulong index_flags(uint inx, uint part, bool all_parts) const
   {

=== modified file 'storage/myisammrg/myrg_info.c'
--- a/storage/myisammrg/myrg_info.c	2008-05-09 10:27:23 +0000
+++ b/storage/myisammrg/myrg_info.c	2009-07-31 04:03:41 +0000
@@ -59,9 +59,27 @@ int myrg_status(MYRG_INFO *info,register
     x->reclength= info->reclength;
     x->options= info->options;
     if (current_table)
+    {
+      /*
+        errkey is set to the index number of the myisam tables. But
+        since the MERGE table can have less keys than the MyISAM
+        tables, errkey cannot be be used as an index into the key_info
+        on the server. This value will be overwritten with MAX_KEY by
+        the MERGE engine.
+      */
       x->errkey= current_table->table->errkey;
+      /*
+        Calculate the position of the duplicate key to be the sum of the
+        offset of the myisam file and the offset into the file at which
+        the duplicate key is located.
+      */
+      x->dupp_key_pos= current_table->file_offset + current_table->table->dupp_key_pos;
+    }
     else
+    {
       x->errkey= 0;
+      x->dupp_key_pos= 0;
+    }
     x->rec_per_key = info->rec_per_key_part;
   }
   DBUG_RETURN(0);

=== modified file 'storage/ndb/src/mgmsrv/Makefile.am'
--- a/storage/ndb/src/mgmsrv/Makefile.am	2009-01-07 10:58:33 +0000
+++ b/storage/ndb/src/mgmsrv/Makefile.am	2009-07-31 20:21:25 +0000
@@ -48,7 +48,7 @@ LDADD_LOC = $(top_builddir)/storage/ndb/
 	    @TERMCAP_LIB@
 
 DEFS_LOC =		-DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \
-			-DDATADIR="\"$(MYSQLDATAdir)\"" \
+			-DMYSQL_DATADIR="\"$(MYSQLDATAdir)\"" \
 			-DSHAREDIR="\"$(MYSQLSHAREdir)\"" \
 			-DMYSQLCLUSTERDIR="\"$(MYSQLCLUSTERdir)\""
 

=== modified file 'support-files/mysql.server.sh'
--- a/support-files/mysql.server.sh	2008-03-26 16:40:41 +0000
+++ b/support-files/mysql.server.sh	2009-07-21 14:57:51 +0000
@@ -53,13 +53,14 @@ datadir=
 # Negative numbers mean to wait indefinitely
 service_startup_timeout=900
 
+# Lock directory for RedHat / SuSE.
+lockdir='/var/lock/subsys'
+lock_file_path="$lockdir/mysql"
+
 # The following variables are only set for letting mysql.server find things.
 
 # Set some defaults
-pid_file=
-server_pid_file=
-use_mysqld_safe=1
-user=@MYSQLD_USER@
+mysqld_pid_file_path=
 if test -z "$basedir"
 then
   basedir=@prefix@
@@ -101,11 +102,14 @@ else
   }
 fi
 
-PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
+PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
 export PATH
 
 mode=$1    # start or stop
-shift
+
+[ $# -ge 1 ] && shift
+
+
 other_args="$*"   # uncommon, but needed when called from an RPM upgrade action
            # Expected: "--skip-networking --skip-grant-tables"
            # They are not checked here, intentionally, as it is the resposibility
@@ -131,59 +135,50 @@ parse_server_arguments() {
       --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
 		    datadir_set=1
 	;;
-      --user=*)  user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
-      --pid-file=*) server_pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
+      --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
       --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
-      --use-mysqld_safe) use_mysqld_safe=1;;
-      --use-manager)     use_mysqld_safe=0;;
-    esac
-  done
-}
-
-parse_manager_arguments() {
-  for arg do
-    case "$arg" in
-      --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
-      --user=*)  user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
     esac
   done
 }
 
 wait_for_pid () {
-  verb="$1"
-  manager_pid="$2"  # process ID of the program operating on the pid-file
+  verb="$1"           # created | removed
+  pid="$2"            # process ID of the program operating on the pid-file
+  pid_file_path="$3" # path to the PID file.
+
   i=0
   avoid_race_condition="by checking again"
+
   while test $i -ne $service_startup_timeout ; do
 
     case "$verb" in
       'created')
         # wait for a PID-file to pop into existence.
-        test -s $pid_file && i='' && break
+        test -s "$pid_file_path" && i='' && break
         ;;
       'removed')
         # wait for this PID-file to disappear
-        test ! -s $pid_file && i='' && break
+        test ! -s "$pid_file_path" && i='' && break
         ;;
       *)
-        echo "wait_for_pid () usage: wait_for_pid created|removed manager_pid"
+        echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"
         exit 1
         ;;
     esac
 
-    # if manager isn't running, then pid-file will never be updated
-    if test -n "$manager_pid"; then
-      if kill -0 "$manager_pid" 2>/dev/null; then
-        :  # the manager still runs
+    # if server isn't running, then pid-file will never be updated
+    if test -n "$pid"; then
+      if kill -0 "$pid" 2>/dev/null; then
+        :  # the server still runs
       else
-        # The manager may have exited between the last pid-file check and now.  
+        # The server may have exited between the last pid-file check and now.  
         if test -n "$avoid_race_condition"; then
           avoid_race_condition=""
           continue  # Check again.
         fi
 
         # there's nothing that will affect the file.
-        log_failure_msg "Manager of pid-file quit without updating file."
+        log_failure_msg "The server quit without updating PID file ($pid_file_path)."
         return 1  # not waiting any more.
       fi
     fi
@@ -191,6 +186,7 @@ wait_for_pid () {
     echo $echo_n ".$echo_c"
     i=`expr $i + 1`
     sleep 1
+
   done
 
   if test -z "$i" ; then
@@ -259,28 +255,16 @@ fi
 
 parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`
 
-# Look for the pidfile 
-parse_manager_arguments `$print_defaults $extra_args manager`
-
 #
 # Set pid file if not given
 #
-if test -z "$pid_file"
-then
-  pid_file=$datadir/mysqlmanager-`@HOSTNAME@`.pid
-else
-  case "$pid_file" in
-    /* ) ;;
-    * )  pid_file="$datadir/$pid_file" ;;
-  esac
-fi
-if test -z "$server_pid_file"
+if test -z "$mysqld_pid_file_path"
 then
-  server_pid_file=$datadir/`@HOSTNAME@`.pid
+  mysqld_pid_file_path=$datadir/`@HOSTNAME@`.pid
 else
-  case "$server_pid_file" in
+  case "$mysqld_pid_file_path" in
     /* ) ;;
-    * )  server_pid_file="$datadir/$server_pid_file" ;;
+    * )  mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
   esac
 fi
 
@@ -291,53 +275,23 @@ case "$mode" in
     # Safeguard (relative paths, core dumps..)
     cd $basedir
 
-    manager=$bindir/mysqlmanager
-    if test -x $libexecdir/mysqlmanager
-    then
-      manager=$libexecdir/mysqlmanager
-    elif test -x $sbindir/mysqlmanager
-    then
-      manager=$sbindir/mysqlmanager
-    fi
-
     echo $echo_n "Starting MySQL"
-    if test -x $manager -a "$use_mysqld_safe" = "0"
-    then
-      if test -n "$other_args"
-      then
-        log_failure_msg "MySQL manager does not support options '$other_args'"
-        exit 1
-      fi
-      # Give extra arguments to mysqld with the my.cnf file. This script may
-      # be overwritten at next upgrade.
-      "$manager" \
-        --mysqld-safe-compatible \
-        --user="$user" \
-        --pid-file="$pid_file" >/dev/null 2>&1 &
-      wait_for_pid created $!; return_value=$?
-
-      # Make lock for RedHat / SuSE
-      if test -w /var/lock/subsys
-      then
-        touch /var/lock/subsys/mysqlmanager
-      fi
-      exit $return_value
-    elif test -x $bindir/mysqld_safe
+    if test -x $bindir/mysqld_safe
     then
       # Give extra arguments to mysqld with the my.cnf file. This script
       # may be overwritten at next upgrade.
-      pid_file=$server_pid_file
-      $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
-      wait_for_pid created $!; return_value=$?
+      $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
+      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
 
       # Make lock for RedHat / SuSE
-      if test -w /var/lock/subsys
+      if test -w "$lockdir"
       then
-        touch /var/lock/subsys/mysql
+        touch "$lock_file_path"
       fi
+
       exit $return_value
     else
-      log_failure_msg "Couldn't find MySQL manager ($manager) or server ($bindir/mysqld_safe)"
+      log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
     fi
     ;;
 
@@ -345,32 +299,22 @@ case "$mode" in
     # Stop daemon. We use a signal here to avoid having to know the
     # root password.
 
-    # The RedHat / SuSE lock directory to remove
-    lock_dir=/var/lock/subsys/mysqlmanager
-
-    # If the manager pid_file doesn't exist, try the server's
-    if test ! -s "$pid_file"
+    if test -s "$mysqld_pid_file_path"
     then
-      pid_file=$server_pid_file
-      lock_dir=/var/lock/subsys/mysql
-    fi
-
-    if test -s "$pid_file"
-    then
-      mysqlmanager_pid=`cat $pid_file`
+      mysqld_pid=`cat "$mysqld_pid_file_path"`
       echo $echo_n "Shutting down MySQL"
-      kill $mysqlmanager_pid
-      # mysqlmanager should remove the pid_file when it exits, so wait for it.
-      wait_for_pid removed "$mysqlmanager_pid"; return_value=$?
+      kill $mysqld_pid
+      # mysqld should remove the pid file when it exits, so wait for it.
+      wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?
 
-      # delete lock for RedHat / SuSE
-      if test -f $lock_dir
+      # Delete lock for RedHat / SuSE
+      if test -f "$lock_file_path"
       then
-        rm -f $lock_dir
+        rm -f "$lock_file_path"
       fi
       exit $return_value
     else
-      log_failure_msg "MySQL manager or server PID file could not be found!"
+      log_failure_msg "MySQL server PID file could not be found!"
     fi
     ;;
 
@@ -386,10 +330,10 @@ case "$mode" in
     ;;
 
   'reload'|'force-reload')
-    if test -s "$server_pid_file" ; then
-      read mysqld_pid <  $server_pid_file
+    if test -s "$mysqld_pid_file_path" ; then
+      read mysqld_pid <  "$mysqld_pid_file_path"
       kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
-      touch $server_pid_file
+      touch "$mysqld_pid_file_path"
     else
       log_failure_msg "MySQL PID file could not be found!"
       exit 1
@@ -397,8 +341,8 @@ case "$mode" in
     ;;
   'status')
     # First, check to see if pid file exists
-    if test -s "$server_pid_file" ; then 
-      read mysqld_pid < $server_pid_file
+    if test -s "$mysqld_pid_file_path" ; then 
+      read mysqld_pid < "$mysqld_pid_file_path"
       if kill -0 $mysqld_pid 2>/dev/null ; then 
         log_success_msg "MySQL running ($mysqld_pid)"
         exit 0
@@ -410,13 +354,8 @@ case "$mode" in
       # Try to find appropriate mysqld process
       mysqld_pid=`pidof $libexecdir/mysqld`
       if test -z $mysqld_pid ; then 
-        if test "$use_mysqld_safe" = "0" ; then 
-          lockfile=/var/lock/subsys/mysqlmanager
-        else
-          lockfile=/var/lock/subsys/mysql
-        fi 
-        if test -f $lockfile ; then 
-          log_failure_msg "MySQL is not running, but lock exists"
+        if test -f "$lock_file_path" ; then 
+          log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"
           exit 2
         fi 
         log_failure_msg "MySQL is not running"
@@ -429,7 +368,8 @@ case "$mode" in
     ;;
     *)
       # usage
-      echo "Usage: $0  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"
+      basename=`basename "$0"`
+      echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"
       exit 1
     ;;
 esac

=== modified file 'tests/grant.pl' (properties changed: -x to +x)
=== modified file 'tests/mysql_client_test.c'
--- a/tests/mysql_client_test.c	2009-07-16 12:51:04 +0000
+++ b/tests/mysql_client_test.c	2009-07-27 19:15:46 +0000
@@ -17550,9 +17550,10 @@ static void bug20023_change_user(MYSQL *
                            opt_db ? opt_db : "test"));
 }
 
-static my_bool query_int_variable(MYSQL *con,
+static my_bool query_str_variable(MYSQL *con,
                                   const char *var_name,
-                                  int *var_value)
+                                  char *str,
+                                  size_t len)
 {
   MYSQL_RES *rs;
   MYSQL_ROW row;
@@ -17561,10 +17562,8 @@ static my_bool query_int_variable(MYSQL 
 
   my_bool is_null;
 
-  my_snprintf(query_buffer,
-          sizeof (query_buffer),
-          "SELECT %s",
-          (const char *) var_name);
+  my_snprintf(query_buffer, sizeof (query_buffer),
+              "SELECT %s", var_name);
 
   DIE_IF(mysql_query(con, query_buffer));
   DIE_UNLESS(rs= mysql_store_result(con));
@@ -17573,28 +17572,44 @@ static my_bool query_int_variable(MYSQL 
   is_null= row[0] == NULL;
 
   if (!is_null)
-    *var_value= atoi(row[0]);
+    my_snprintf(str, len, "%s", row[0]);
 
   mysql_free_result(rs);
 
   return is_null;
 }
 
+static my_bool query_int_variable(MYSQL *con,
+                                  const char *var_name,
+                                  int *var_value)
+{
+  char str[32];
+  my_bool is_null= query_str_variable(con, var_name, str, sizeof(str));
+
+  if (!is_null)
+    *var_value= atoi(str);
+
+  return is_null;
+}
+
 static void test_bug20023()
 {
   MYSQL con;
 
   int sql_big_selects_orig;
-  int max_join_size_orig;
+  /*
+    Type of max_join_size is ha_rows, which might be ulong or off_t
+    depending on the platform or configure options. Preserve the string
+    to avoid type overflow pitfalls.
+  */
+  char max_join_size_orig[32];
 
   int sql_big_selects_2;
   int sql_big_selects_3;
   int sql_big_selects_4;
   int sql_big_selects_5;
 
-#if NOT_USED
   char query_buffer[MAX_TEST_QUERY_LENGTH];
-#endif
 
   /* Create a new connection. */
 
@@ -17617,9 +17632,10 @@ static void test_bug20023()
                      "@@session.sql_big_selects",
                      &sql_big_selects_orig);
 
-  query_int_variable(&con,
+  query_str_variable(&con,
                      "@@global.max_join_size",
-                     &max_join_size_orig);
+                     max_join_size_orig,
+                     sizeof(max_join_size_orig));
 
   /***********************************************************************
     Test that COM_CHANGE_USER resets the SQL_BIG_SELECTS to the initial value.
@@ -17692,25 +17708,16 @@ static void test_bug20023()
     Check that SQL_BIG_SELECTS will be the original one.
   ***********************************************************************/
 
-#if NOT_USED
-  /*
-    max_join_size is a ulong or better.
-    my_snprintf() only goes up to ul.
-  */
-
   /* Restore MAX_JOIN_SIZE. */
 
   my_snprintf(query_buffer,
            sizeof (query_buffer),
-           "SET @@global.max_join_size = %d",
-           (int) max_join_size_orig);
+           "SET @@global.max_join_size = %s",
+           max_join_size_orig);
 
   DIE_IF(mysql_query(&con, query_buffer));
 
-#else
   DIE_IF(mysql_query(&con, "SET @@global.max_join_size = -1"));
-#endif
-
   DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default"));
 
   /* Issue COM_CHANGE_USER. */

Thread
bzr commit into mysql-pe branch (mikael:3482) Bug#40281Mikael Ronstrom7 Aug