List:Commits« Previous MessageNext Message »
From:magnus.blaudd Date:November 18 2011 11:49am
Subject:bzr push into mysql-5.5 branch (magnus.blaudd:3242 to 3244)
View as plain text  
 3244 magnus.blaudd@stripped	2011-11-18
      ndb
       - update 5.5-cluster-base with latest compile-cluster script

    modified:
      storage/ndb/compile-cluster
 3243 magnus.blaudd@stripped	2011-11-18 [merge]
      Merge 5.5.17 into 5.5-cluster-base

    removed:
      mysql-test/std_data/bug57108.cnf
      scripts/make_binary_distribution.sh
      scripts/make_win_bin_dist
    added:
      mysql-test/r/auth_rpl.result
      mysql-test/suite/innodb/r/innodb_bug59733.result
      mysql-test/suite/innodb/r/innodb_corrupt_bit.result
      mysql-test/suite/innodb/t/innodb_bug59733.test
      mysql-test/suite/innodb/t/innodb_corrupt_bit.test
      mysql-test/suite/stress/t/wrapper.test
      mysql-test/suite/sys_vars/r/innodb_force_load_corrupted_basic.result
      mysql-test/suite/sys_vars/r/innodb_large_prefix_basic.result
      mysql-test/suite/sys_vars/t/innodb_force_load_corrupted_basic.test
      mysql-test/suite/sys_vars/t/innodb_large_prefix_basic.test
      mysql-test/suite/sys_vars/t/plugin_dir_basic-master.opt
      mysql-test/t/auth_rpl-master.opt
      mysql-test/t/auth_rpl-slave.opt
      mysql-test/t/auth_rpl.test
    modified:
      .bzr-mysql/default.conf
      VERSION
      client/mysqltest.cc
      cmake/mysql_version.cmake
      extra/innochecksum.c
      include/decimal.h
      include/heap.h
      include/my_base.h
      libmysql/authentication_win/handshake_client.cc
      libmysql/client_settings.h
      man/CMakeLists.txt
      mysql-test/include/mtr_check.sql
      mysql-test/include/mysqld--help.inc
      mysql-test/lib/mtr_cases.pm
      mysql-test/mysql-stress-test.pl
      mysql-test/mysql-test-run.pl
      mysql-test/r/execution_constants.result
      mysql-test/r/func_str.result
      mysql-test/r/group_by.result
      mysql-test/r/heap.result
      mysql-test/r/myisampack.result
      mysql-test/r/mysqltest.result
      mysql-test/r/show_check.result
      mysql-test/r/sp_trans.result
      mysql-test/r/type_newdecimal.result
      mysql-test/suite/federated/federated_plugin-master.opt
      mysql-test/suite/federated/federated_plugin.result
      mysql-test/suite/federated/federated_plugin.test
      mysql-test/suite/innodb/r/innodb-index.result
      mysql-test/suite/innodb/t/innodb-index.test
      mysql-test/suite/sys_vars/r/all_vars.result
      mysql-test/suite/sys_vars/r/innodb_file_per_table_basic.result
      mysql-test/suite/sys_vars/r/innodb_lock_wait_timeout_basic.result
      mysql-test/suite/sys_vars/r/plugin_dir_basic.result
      mysql-test/suite/sys_vars/t/innodb_autoinc_lock_mode_basic.test
      mysql-test/suite/sys_vars/t/innodb_fast_shutdown_basic.test
      mysql-test/suite/sys_vars/t/innodb_file_per_table_basic.test
      mysql-test/suite/sys_vars/t/innodb_io_capacity_basic.test
      mysql-test/suite/sys_vars/t/innodb_lock_wait_timeout_basic.test
      mysql-test/suite/sys_vars/t/innodb_max_dirty_pages_pct_basic.test
      mysql-test/suite/sys_vars/t/plugin_dir_basic.test
      mysql-test/t/execution_constants.test
      mysql-test/t/func_str.test
      mysql-test/t/group_by.test
      mysql-test/t/heap.test
      mysql-test/t/myisampack.test
      mysql-test/t/mysql_plugin.test
      mysql-test/t/mysqld--defaults-file.test
      mysql-test/t/mysqltest.test
      mysql-test/t/show_check.test
      mysql-test/t/sp_trans.test
      mysql-test/t/type_newdecimal.test
      mysql-test/valgrind.supp
      mysys/my_handler_errors.h
      plugin/semisync/semisync_master.cc
      scripts/CMakeLists.txt
      scripts/mysql_install_db.pl.in
      scripts/mysql_install_db.sh
      sql/client_settings.h
      sql/filesort.cc
      sql/handler.cc
      sql/my_decimal.h
      sql/share/errmsg-utf8.txt
      sql/slave.cc
      sql/sql_lex.cc
      sql/sql_parse.cc
      sql/sql_yacc.yy
      storage/heap/ha_heap.cc
      storage/heap/hp_create.c
      storage/heap/hp_info.c
      storage/innobase/btr/btr0btr.c
      storage/innobase/btr/btr0cur.c
      storage/innobase/btr/btr0pcur.c
      storage/innobase/btr/btr0sea.c
      storage/innobase/buf/buf0buddy.c
      storage/innobase/buf/buf0buf.c
      storage/innobase/buf/buf0lru.c
      storage/innobase/dict/dict0crea.c
      storage/innobase/dict/dict0dict.c
      storage/innobase/dict/dict0load.c
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/ibuf/ibuf0ibuf.c
      storage/innobase/include/btr0btr.h
      storage/innobase/include/btr0btr.ic
      storage/innobase/include/btr0cur.h
      storage/innobase/include/btr0cur.ic
      storage/innobase/include/buf0buf.h
      storage/innobase/include/buf0buf.ic
      storage/innobase/include/buf0lru.h
      storage/innobase/include/db0err.h
      storage/innobase/include/dict0boot.h
      storage/innobase/include/dict0dict.h
      storage/innobase/include/dict0dict.ic
      storage/innobase/include/dict0mem.h
      storage/innobase/include/dict0types.h
      storage/innobase/include/mtr0mtr.h
      storage/innobase/include/page0cur.ic
      storage/innobase/include/page0page.h
      storage/innobase/include/page0page.ic
      storage/innobase/include/rem0rec.h
      storage/innobase/include/rem0rec.ic
      storage/innobase/include/row0upd.ic
      storage/innobase/include/srv0srv.h
      storage/innobase/include/sync0rw.ic
      storage/innobase/include/sync0sync.h
      storage/innobase/include/sync0sync.ic
      storage/innobase/include/trx0undo.h
      storage/innobase/include/univ.i
      storage/innobase/mtr/mtr0mtr.c
      storage/innobase/page/page0cur.c
      storage/innobase/page/page0page.c
      storage/innobase/pars/pars0opt.c
      storage/innobase/row/row0ins.c
      storage/innobase/row/row0merge.c
      storage/innobase/row/row0mysql.c
      storage/innobase/row/row0purge.c
      storage/innobase/row/row0row.c
      storage/innobase/row/row0sel.c
      storage/innobase/row/row0uins.c
      storage/innobase/row/row0umod.c
      storage/innobase/row/row0upd.c
      storage/innobase/row/row0vers.c
      storage/innobase/sync/sync0rw.c
      storage/innobase/sync/sync0sync.c
      storage/innobase/trx/trx0rec.c
      storage/innobase/trx/trx0undo.c
      storage/innobase/ut/ut0ut.c
      storage/myisam/ft_boolean_search.c
      storage/myisam/ft_nlq_search.c
      storage/myisam/mi_check.c
      storage/myisam/mi_write.c
      strings/decimal.c
      strings/dtoa.c
      support-files/mysql.spec.sh
 3242 magnus.blaudd@stripped	2011-09-27
      Cherry pick fix for bug#12585902

    modified:
      mysql-test/t/disabled.def
=== modified file '.bzr-mysql/default.conf'
--- a/.bzr-mysql/default.conf	2011-08-09 08:50:55 +0000
+++ b/.bzr-mysql/default.conf	2011-09-26 10:46:18 +0000
@@ -1,4 +1,4 @@
 [MYSQL]
-post_commit_to = "dbg_mysql_security@stripped"
-post_push_to = "dbg_mysql_security@sun.com"
-tree_name = "mysql-5.5-security"
+post_commit_to = "commits@stripped"
+post_push_to = "commits@lists.mysql.com"
+tree_name = "mysql-5.5"

=== modified file 'VERSION'
--- a/VERSION	2011-08-09 08:03:29 +0000
+++ b/VERSION	2011-09-21 10:40:41 +0000
@@ -1,4 +1,4 @@
 MYSQL_VERSION_MAJOR=5
 MYSQL_VERSION_MINOR=5
-MYSQL_VERSION_PATCH=16
+MYSQL_VERSION_PATCH=17
 MYSQL_VERSION_EXTRA=

=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2011-07-22 07:50:44 +0000
+++ b/client/mysqltest.cc	2011-09-15 11:09:24 +0000
@@ -118,6 +118,41 @@ static char **default_argv;
 static const char *load_default_groups[]= { "mysqltest", "client", 0 };
 static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
 
+/* Info on properties that can be set with --enable_X and --disable_X */
+
+struct property {
+  my_bool *var;			/* Actual variable */
+  my_bool set;			/* Has been set for ONE command */
+  my_bool old;			/* If set, thus is the old value */
+  my_bool reverse;		/* Varible is true if disabled */
+  const char *env_name;		/* Env. variable name */
+};
+
+static struct property prop_list[] = {
+  { &abort_on_error, 0, 1, 0, "$ENABLED_ABORT_ON_ERROR" },
+  { &disable_connect_log, 0, 1, 1, "$ENABLED_CONNECT_LOG" },
+  { &disable_info, 0, 1, 1, "$ENABLED_INFO" },
+  { &display_metadata, 0, 0, 0, "$ENABLED_METADATA" },
+  { &ps_protocol_enabled, 0, 0, 0, "$ENABLED_PS_PROTOCOL" },
+  { &disable_query_log, 0, 0, 1, "$ENABLED_QUERY_LOG" },
+  { &disable_result_log, 0, 0, 1, "$ENABLED_RESULT_LOG" },
+  { &disable_warnings, 0, 0, 1, "$ENABLED_WARNINGS" }
+};
+
+static my_bool once_property= FALSE;
+
+enum enum_prop {
+  P_ABORT= 0,
+  P_CONNECT,
+  P_INFO,
+  P_META,
+  P_PS,
+  P_QUERY,
+  P_RESULT,
+  P_WARN,
+  P_MAX
+};
+
 static uint start_lineno= 0; /* Start line of current command */
 static uint my_end_arg= 0;
 
@@ -463,6 +498,7 @@ TYPELIB command_typelib= {array_elements
 DYNAMIC_STRING ds_res;
 /* Points to ds_warning in run_query, so it can be freed */
 DYNAMIC_STRING *ds_warn= 0;
+struct st_command *curr_command= 0;
 
 char builtin_echo[FN_REFLEN];
 
@@ -494,6 +530,7 @@ void str_to_file(const char *fname, char
 void str_to_file2(const char *fname, char *str, int size, my_bool append);
 
 void fix_win_paths(const char *val, int len);
+const char *get_errname_from_code (uint error_code);
 
 #ifdef __WIN__
 void free_tmp_sh_file();
@@ -711,6 +748,7 @@ void handle_error(struct st_command*,
                   unsigned int err_errno, const char *err_error,
                   const char *err_sqlstate, DYNAMIC_STRING *ds);
 void handle_no_error(struct st_command*);
+void revert_properties();
 
 #ifdef EMBEDDED_LIBRARY
 
@@ -1173,6 +1211,7 @@ void handle_command_error(struct st_comm
     {
       DBUG_PRINT("info", ("command \"%.*s\" failed with expected error: %d",
                           command->first_word_len, command->query, error));
+      revert_properties();
       DBUG_VOID_RETURN;
     }
     if (command->expected_errors.count > 0)
@@ -1187,6 +1226,7 @@ void handle_command_error(struct st_comm
         command->first_word_len, command->query,
         command->expected_errors.err[0].code.errnum);
   }
+  revert_properties();
   DBUG_VOID_RETURN;
 }
 
@@ -2263,6 +2303,51 @@ void var_set_int(const char* name, int v
 void var_set_errno(int sql_errno)
 {
   var_set_int("$mysql_errno", sql_errno);
+  var_set_string("$mysql_errname", get_errname_from_code(sql_errno));
+}
+
+/* Functions to handle --disable and --enable properties */
+
+void set_once_property(enum_prop prop, my_bool val)
+{
+  property &pr= prop_list[prop];
+  pr.set= 1;
+  pr.old= *pr.var;
+  *pr.var= val;
+  var_set_int(pr.env_name, (val != pr.reverse));
+  once_property= TRUE;
+}
+
+void set_property(st_command *command, enum_prop prop, my_bool val)
+{
+  char* p= command->first_argument;
+  if (p && !strcmp (p, "ONCE")) 
+  {
+    command->last_argument= p + 4;
+    set_once_property(prop, val);
+    return;
+  }
+  property &pr= prop_list[prop];
+  *pr.var= val;
+  pr.set= 0;
+  var_set_int(pr.env_name, (val != pr.reverse));
+}
+
+void revert_properties()
+{
+  if (! once_property)
+    return;
+  for (int i= 0; i < (int) P_MAX; i++) 
+  {
+    property &pr= prop_list[i];
+    if (pr.set) 
+    {
+      *pr.var= pr.old;
+      pr.set= 0;
+      var_set_int(pr.env_name, (pr.old != pr.reverse));
+    }
+  }
+  once_property=FALSE;
 }
 
 
@@ -2316,9 +2401,16 @@ void var_query_set(VAR *var, const char 
   init_dynamic_string(&ds_query, 0, (end - query) + 32, 256);
   do_eval(&ds_query, query, end, FALSE);
 
-  if (mysql_real_query(mysql, ds_query.str, ds_query.length))
-    die("Error running query '%s': %d %s", ds_query.str,
-	mysql_errno(mysql), mysql_error(mysql));
+  if (mysql_real_query(mysql, ds_query.str, ds_query.length)) 
+  {
+    handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql),
+                  mysql_sqlstate(mysql), &ds_res);
+    /* If error was acceptable, return empty string */
+    dynstr_free(&ds_query);
+    eval_expr(var, "", 0);
+    DBUG_VOID_RETURN;
+  }
+  
   if (!(res= mysql_store_result(mysql)))
     die("Query '%s' didn't return a result set", ds_query.str);
   dynstr_free(&ds_query);
@@ -2472,8 +2564,15 @@ void var_set_query_get_value(struct st_c
 
   /* Run the query */
   if (mysql_real_query(mysql, ds_query.str, ds_query.length))
-    die("Error running query '%s': %d %s", ds_query.str,
-	mysql_errno(mysql), mysql_error(mysql));
+  {
+    handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql),
+                  mysql_sqlstate(mysql), &ds_res);
+    /* If error was acceptable, return empty string */
+    dynstr_free(&ds_query);
+    eval_expr(var, "", 0);
+    DBUG_VOID_RETURN;
+  }
+
   if (!(res= mysql_store_result(mysql)))
     die("Query '%s' didn't return a result set", ds_query.str);
 
@@ -4424,6 +4523,7 @@ void do_let(struct st_command *command)
   var_set(var_name, var_name_end, let_rhs_expr.str,
           (let_rhs_expr.str + let_rhs_expr.length));
   dynstr_free(&let_rhs_expr);
+  revert_properties();
   DBUG_VOID_RETURN;
 }
 
@@ -4670,8 +4770,7 @@ void do_shutdown_server(struct st_comman
 }
 
 
-#if MYSQL_VERSION_ID >= 50000
-/* List of error names to error codes, available from 5.0 */
+/* List of error names to error codes */
 typedef struct
 {
   const char *name;
@@ -4681,6 +4780,7 @@ typedef struct
 
 static st_error global_error_names[] =
 {
+  { "<No error>", -1, "" },
 #include <mysqld_ername.h>
   { 0, 0, 0 }
 };
@@ -4711,16 +4811,28 @@ uint get_errcode_from_name(char *error_n
     die("Unknown SQL error name '%s'", error_name);
   DBUG_RETURN(0);
 }
-#else
-uint get_errcode_from_name(char *error_name __attribute__((unused)),
-                           char *error_end __attribute__((unused)))
+
+const char *get_errname_from_code (uint error_code)
 {
-  abort_not_in_this_version();
-  return 0; /* Never reached */
-}
-#endif
+   st_error *e= global_error_names;
 
+   DBUG_ENTER("get_errname_from_code");
+   DBUG_PRINT("enter", ("error_code: %d", error_code));
 
+   if (! error_code)
+   {
+     DBUG_RETURN("");
+   }
+   for (; e->name; e++)
+   {
+     if (e->code == error_code)
+     {
+       DBUG_RETURN(e->name);
+     }
+   }
+   /* Apparently, errors without known names may occur */
+   DBUG_RETURN("<Unknown>");
+} 
 
 void do_get_errcodes(struct st_command *command)
 {
@@ -7340,6 +7452,7 @@ void handle_error(struct st_command *com
         dynstr_append(ds,"Got one of the listed errors\n");
     }
     /* OK */
+    revert_properties();
     DBUG_VOID_RETURN;
   }
 
@@ -7367,6 +7480,7 @@ void handle_error(struct st_command *com
 	  command->expected_errors.err[0].code.sqlstate);
   }
 
+  revert_properties();
   DBUG_VOID_RETURN;
 }
 
@@ -7401,6 +7515,7 @@ void handle_no_error(struct st_command *
         command->query, command->expected_errors.err[0].code.sqlstate);
   }
 
+  revert_properties();
   DBUG_VOID_RETURN;
 }
 
@@ -7431,6 +7546,9 @@ void run_query_stmt(MYSQL *mysql, struct
   DBUG_ENTER("run_query_stmt");
   DBUG_PRINT("query", ("'%-.60s'", query));
 
+  /* Remember disable_result_log since handle_no_error() may reset it */
+  my_bool dis_res= disable_result_log;
+  
   /*
     Init a new stmt if it's not already one created for this connection
   */
@@ -7526,7 +7644,7 @@ void run_query_stmt(MYSQL *mysql, struct
 
   /* If we got here the statement was both executed and read successfully */
   handle_no_error(command);
-  if (!disable_result_log)
+  if (!dis_res)
   {
     /*
       Not all statements creates a result set. If there is one we can
@@ -8452,6 +8570,8 @@ int main(int argc, char **argv)
     {
       command->last_argument= command->first_argument;
       processed = 1;
+      /* Need to remember this for handle_error() */
+      curr_command= command;
       switch (command->type) {
       case Q_CONNECT:
         do_connect(command);
@@ -8461,60 +8581,46 @@ int main(int argc, char **argv)
       case Q_DIRTY_CLOSE:
 	do_close_connection(command); break;
       case Q_ENABLE_QUERY_LOG:
-        disable_query_log= 0;
-        var_set_int("$ENABLED_QUERY_LOG", 1);
+        set_property(command, P_QUERY, 0);
         break;
       case Q_DISABLE_QUERY_LOG:
-        disable_query_log= 1;
-        var_set_int("$ENABLED_QUERY_LOG", 0);
+        set_property(command, P_QUERY, 1);
         break;
       case Q_ENABLE_ABORT_ON_ERROR:
-        abort_on_error= 1;
-        var_set_int("$ENABLED_ABORT_ON_ERROR", 1);
+        set_property(command, P_ABORT, 1);
         break;
       case Q_DISABLE_ABORT_ON_ERROR:
-        abort_on_error= 0;
-        var_set_int("$ENABLED_ABORT_ON_ERROR", 0);
+        set_property(command, P_ABORT, 0);
         break;
       case Q_ENABLE_RESULT_LOG:
-        disable_result_log= 0;
-        var_set_int("$ENABLED_RESULT_LOG", 1);
+        set_property(command, P_RESULT, 0);
         break;
       case Q_DISABLE_RESULT_LOG:
-        disable_result_log=1;
-        var_set_int("$ENABLED_RESULT_LOG", 0);
+        set_property(command, P_RESULT, 1);
         break;
       case Q_ENABLE_CONNECT_LOG:
-        disable_connect_log=0;
-        var_set_int("$ENABLED_CONNECT_LOG", 1);
+        set_property(command, P_CONNECT, 0);
         break;
       case Q_DISABLE_CONNECT_LOG:
-        disable_connect_log=1;
-        var_set_int("$ENABLED_CONNECT_LOG", 0);
+        set_property(command, P_CONNECT, 1);
         break;
       case Q_ENABLE_WARNINGS:
-        disable_warnings= 0;
-        var_set_int("$ENABLED_WARNINGS", 1);
+        set_property(command, P_WARN, 0);
         break;
       case Q_DISABLE_WARNINGS:
-        disable_warnings= 1;
-        var_set_int("$ENABLED_WARNINGS", 0);
+        set_property(command, P_WARN, 1);
         break;
       case Q_ENABLE_INFO:
-        disable_info= 0;
-        var_set_int("$ENABLED_INFO", 1);
+        set_property(command, P_INFO, 0);
         break;
       case Q_DISABLE_INFO:
-        disable_info= 1;
-        var_set_int("$ENABLED_INFO", 0);
+        set_property(command, P_INFO, 1);
         break;
       case Q_ENABLE_METADATA:
-        display_metadata= 1;
-        var_set_int("$ENABLED_METADATA", 1);
+        set_property(command, P_META, 1);
         break;
       case Q_DISABLE_METADATA:
-        display_metadata= 0;
-        var_set_int("$ENABLED_METADATA", 0);
+        set_property(command, P_META, 0);
         break;
       case Q_SOURCE: do_source(command); break;
       case Q_SLEEP: do_sleep(command, 0); break;
@@ -8730,12 +8836,12 @@ int main(int argc, char **argv)
 	do_set_charset(command);
 	break;
       case Q_DISABLE_PS_PROTOCOL:
-        ps_protocol_enabled= 0;
+        set_property(command, P_PS, 0);
         /* Close any open statements */
         close_statements();
         break;
       case Q_ENABLE_PS_PROTOCOL:
-        ps_protocol_enabled= ps_protocol;
+        set_property(command, P_PS, ps_protocol);
         break;
       case Q_DISABLE_RECONNECT:
         set_reconnect(&cur_con->mysql, 0);

=== modified file 'cmake/mysql_version.cmake'
--- a/cmake/mysql_version.cmake	2011-06-30 15:46:53 +0000
+++ b/cmake/mysql_version.cmake	2011-09-20 15:47:53 +0000
@@ -94,8 +94,8 @@ ENDIF()
 IF(NOT CPACK_SOURCE_PACKAGE_FILE_NAME)
   SET(CPACK_SOURCE_PACKAGE_FILE_NAME "mysql-${VERSION}")
 ENDIF()
-SET(CPACK_PACKAGE_CONTACT "MySQL Build Team <build@mysql.com>")
-SET(CPACK_PACKAGE_VENDOR "Sun Microsystems, Inc")
+SET(CPACK_PACKAGE_CONTACT "MySQL Release Engineering <mysql-build@stripped>")
+SET(CPACK_PACKAGE_VENDOR "Oracle Corporation")
 SET(CPACK_SOURCE_GENERATOR "TGZ")
 INCLUDE(cpack_source_ignore_files)
 

=== modified file 'extra/innochecksum.c'
--- a/extra/innochecksum.c	2011-07-03 23:48:19 +0000
+++ b/extra/innochecksum.c	2011-08-22 14:12:27 +0000
@@ -25,12 +25,7 @@
   Published with a permission.
 */
 
-/* needed to have access to 64 bit file functions */
-#define _LARGEFILE_SOURCE
-#define _LARGEFILE64_SOURCE
-
-#define _XOPEN_SOURCE 500 /* needed to include getopt.h on some platforms. */
-
+#include <my_global.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
@@ -53,7 +48,6 @@
 /* another argument to specify page ranges... seek to right spot and go from there */
 
 typedef unsigned long int ulint;
-typedef unsigned char uchar;
 
 /* innodb function in name; modified slightly to not have the ASM version (lots of #ifs that didn't apply) */
 ulint mach_read_from_4(uchar *b)

=== modified file 'include/decimal.h'
--- a/include/decimal.h	2011-06-30 15:46:53 +0000
+++ b/include/decimal.h	2011-08-29 09:34:48 +0000
@@ -21,6 +21,15 @@ typedef enum
   decimal_round_mode;
 typedef int32 decimal_digit_t;
 
+/**
+    intg is the number of *decimal* digits (NOT number of decimal_digit_t's !)
+         before the point
+    frac is the number of decimal digits after the point
+    len  is the length of buf (length of allocated space) in decimal_digit_t's,
+         not in bytes
+    sign false means positive, true means negative
+    buf  is an array of decimal_digit_t's
+ */
 typedef struct st_decimal_t {
   int    intg, frac, len;
   my_bool sign;

=== modified file 'include/heap.h'
--- a/include/heap.h	2011-07-03 23:48:19 +0000
+++ b/include/heap.h	2011-09-27 12:14:31 +0000
@@ -51,6 +51,7 @@ typedef struct st_heapinfo		/* Struct fr
   uint reclength;			/* Length of one record */
   int errkey;
   ulonglong auto_increment;
+  time_t create_time;
 } HEAPINFO;
 
 
@@ -147,6 +148,7 @@ typedef struct st_heap_share
   uint open_count;
   uchar *del_link;			/* Link to next block with del. rec */
   char * name;			/* Name of "memory-file" */
+  time_t create_time;
   THR_LOCK lock;
   mysql_mutex_t intern_lock;            /* Locking for use with _locking */
   my_bool delete_on_close;

=== modified file 'include/my_base.h'
--- a/include/my_base.h	2011-06-30 15:46:53 +0000
+++ b/include/my_base.h	2011-09-01 18:48:04 +0000
@@ -446,8 +446,10 @@ enum ha_base_keytype {
 #define HA_ERR_FILE_TOO_SHORT	  175	 /* File too short */
 #define HA_ERR_WRONG_CRC	  176	 /* Wrong CRC on page */
 #define HA_ERR_TOO_MANY_CONCURRENT_TRXS 177 /*Too many active concurrent transactions */
-#define HA_ERR_INDEX_COL_TOO_LONG 178	/* Index column length exceeds limit */
-#define HA_ERR_LAST               178    /* Copy of last error nr */
+#define HA_ERR_INDEX_COL_TOO_LONG 178	 /* Index column length exceeds limit */
+#define HA_ERR_INDEX_CORRUPT      179	 /* Index corrupted */
+#define HA_ERR_UNDO_REC_TOO_BIG   180    /* Undo log record too big */
+#define HA_ERR_LAST               180    /* Copy of last error nr */
 
 /* Number of different errors */
 #define HA_ERR_ERRORS            (HA_ERR_LAST - HA_ERR_FIRST + 1)

=== modified file 'libmysql/authentication_win/handshake_client.cc'
--- a/libmysql/authentication_win/handshake_client.cc	2011-09-07 18:02:35 +0000
+++ b/libmysql/authentication_win/handshake_client.cc	2011-09-30 11:27:29 +0000
@@ -161,6 +161,21 @@ int Handshake_client::write_packet(Blob 
       keep all the data.
     */
     unsigned block_count= data.len()/512 + ((data.len() % 512) ? 1 : 0);
+
+#if !defined(DBUG_OFF) && defined(WINAUTH_USE_DBUG_LIB)
+
+    /*
+      For testing purposes, use wrong block count to see how server
+      handles this.
+    */
+    DBUG_EXECUTE_IF("winauth_first_packet_test",{
+      block_count= data.len() == 601 ? 0 :
+                   data.len() == 602 ? 1 : 
+                   block_count;
+    });
+
+#endif
+
     DBUG_ASSERT(block_count < (unsigned)0x100);
     saved_byte= data[254];
     data[254] = block_count;

=== modified file 'libmysql/client_settings.h'
--- a/libmysql/client_settings.h	2011-06-30 15:46:53 +0000
+++ b/libmysql/client_settings.h	2011-09-14 14:10:18 +0000
@@ -22,6 +22,11 @@
 extern uint		mysql_port;
 extern char *	mysql_unix_port;
 
+/*
+ Note: CLIENT_CAPABILITIES is also defined in sql/client_settings.h.
+ When adding capabilities here, consider if they should be also added to
+ the server's version.
+*/
 #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | \
                              CLIENT_LONG_FLAG |     \
                              CLIENT_TRANSACTIONS |  \

=== modified file 'man/CMakeLists.txt'
--- a/man/CMakeLists.txt	2010-11-13 22:16:52 +0000
+++ b/man/CMakeLists.txt	2011-10-04 10:28:30 +0000
@@ -1,4 +1,4 @@
-# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -16,15 +16,23 @@
 # Copy man pages
 FILE(GLOB MAN1_FILES *.1)
 FILE(GLOB MAN1_EXCLUDE make_win_bin_dist.1)
+FILE(GLOB MAN1_NDB ndb*.1)
 FILE(GLOB MAN8_FILES *.8)
+FILE(GLOB MAN8_NDB ndb*.8)
 IF(MAN1_FILES)
   IF(MAN1_EXCLUDE)
     LIST(REMOVE_ITEM MAN1_FILES ${MAN1_EXCLUDE})
   ENDIF()
+  IF(MAN1_NDB)
+    LIST(REMOVE_ITEM MAN1_FILES ${MAN1_NDB})
+  ENDIF()
   INSTALL(FILES ${MAN1_FILES} DESTINATION ${INSTALL_MANDIR}/man1
   COMPONENT ManPages)
 ENDIF()
 IF(MAN8_FILES)
+  IF(MAN8_NDB)
+    LIST(REMOVE_ITEM MAN8_FILES ${MAN8_NDB})
+  ENDIF()
   INSTALL(FILES ${MAN8_FILES} DESTINATION ${INSTALL_MANDIR}/man8
   COMPONENT ManPages)
 ENDIF()

=== modified file 'mysql-test/include/mtr_check.sql'
--- a/mysql-test/include/mtr_check.sql	2011-07-04 07:33:16 +0000
+++ b/mysql-test/include/mtr_check.sql	2011-08-17 12:42:18 +0000
@@ -72,3 +72,13 @@ BEGIN
     mysql.user;
 
 END||
+
+--
+-- Procedure used by test case used to force all
+-- servers to restart after testcase and thus skipping
+-- check test case after test
+--
+CREATE DEFINER=root@localhost PROCEDURE force_restart()
+BEGIN
+  SELECT 1 INTO OUTFILE 'force_restart';
+END||

=== modified file 'mysql-test/include/mysqld--help.inc'
--- a/mysql-test/include/mysqld--help.inc	2010-09-30 13:52:39 +0000
+++ b/mysql-test/include/mysqld--help.inc	2011-08-16 09:08:10 +0000
@@ -26,7 +26,7 @@ perl;
 
   # And substitute the content some environment variables with their
   # names:
-  @env=qw/MYSQLTEST_VARDIR MYSQL_TEST_DIR MYSQL_LIBDIR MYSQL_CHARSETSDIR MYSQL_SHAREDIR/;
+  @env=qw/MYSQLTEST_VARDIR MYSQL_TEST_DIR MYSQL_CHARSETSDIR MYSQL_SHAREDIR/;
 
   $re1=join('|', @skipvars, @plugins);
   $re2=join('|', @plugins);

=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	2011-06-30 14:51:02 +0000
+++ b/mysql-test/lib/mtr_cases.pm	2011-07-28 11:18:52 +0000
@@ -337,17 +337,41 @@ sub collect_one_suite($)
   for my $skip (@disabled_collection)
     {
       if ( open(DISABLED, $skip ) )
-      {
-        while ( <DISABLED> )
-          {
-            chomp;
-            if ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )
-              {
-                $disabled{$1}= $2 if not exists $disabled{$1};
-              }
-          }
-        close DISABLED;
-      }
+	{
+	  # $^O on Windows considered not generic enough
+	  my $plat= (IS_WINDOWS) ? 'windows' : $^O;
+
+	  while ( <DISABLED> )
+	    {
+	      chomp;
+	      #diasble the test case if platform matches
+	      if ( /\@/ )
+		{
+		  if ( /\@$plat/ )
+		    {
+		      /^\s*(\S+)\s*\@$plat.*:\s*(.*?)\s*$/ ;
+		      $disabled{$1}= $2 if not exists $disabled{$1};
+		    }
+		  elsif ( /\@!(\S*)/ )
+		    {
+		      if ( $1 ne $plat)
+			{
+			  /^\s*(\S+)\s*\@!.*:\s*(.*?)\s*$/ ;
+			  $disabled{$1}= $2 if not exists $disabled{$1};
+			}
+		    }
+		}
+	      elsif ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )
+		{
+		  chomp;
+		  if ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )
+		    {
+		      $disabled{$1}= $2 if not exists $disabled{$1};
+		    }
+		}
+	    }
+	  close DISABLED;
+	}
     }
 
   # Read suite.opt file

=== modified file 'mysql-test/mysql-stress-test.pl'
--- a/mysql-test/mysql-stress-test.pl	2011-01-18 10:21:37 +0000
+++ b/mysql-test/mysql-stress-test.pl	2011-09-15 10:34:32 +0000
@@ -238,9 +238,9 @@ GetOptions("server-host=s", "server-logs
            "test-duration=i", "test-suffix=s", "check-tests-file", 
            "verbose", "log-error-details", "cleanup", "mysqltest=s", 
            # OBN: (changing 'abort-on-error' to numberic for WL-4626/4685) 
-           "abort-on-error=i" => \$opt_abort_on_error, "help") || usage();
+           "abort-on-error=i" => \$opt_abort_on_error, "help") || usage(1);
 
-usage() if ($opt_help);
+usage(0) if ($opt_help);
 
 #$opt_abort_on_error=1;
 
@@ -1131,6 +1131,7 @@ sub sig_TERM_handler
 
 sub usage
 {
+  my $retcode= shift;
   print <<EOF;
 
 The MySQL Stress suite Ver $stress_suite_version
@@ -1234,7 +1235,7 @@ perl mysql-stress-test.pl \
 --cleanup \
 
 EOF
-exit(0);
+exit($retcode);
 }
 
 

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2011-08-24 13:16:24 +0000
+++ b/mysql-test/mysql-test-run.pl	2011-09-26 08:27:54 +0000
@@ -181,6 +181,8 @@ our @opt_combinations;
 our @opt_extra_mysqld_opt;
 our @opt_mysqld_envs;
 
+my $opt_stress;
+
 my $opt_compress;
 my $opt_ssl;
 my $opt_skip_ssl;
@@ -222,10 +224,13 @@ our %gprof_dirs;
 our $glob_debugger= 0;
 our $opt_gdb;
 our $opt_client_gdb;
+my $opt_boot_gdb;
 our $opt_dbx;
 our $opt_client_dbx;
+my $opt_boot_dbx;
 our $opt_ddd;
 our $opt_client_ddd;
+my $opt_boot_ddd;
 our $opt_manual_gdb;
 our $opt_manual_dbx;
 our $opt_manual_ddd;
@@ -423,8 +428,8 @@ sub main {
   }
   $ENV{MTR_PARALLEL} = $opt_parallel;
 
-  if ($opt_parallel > 1 && $opt_start_exit) {
-    mtr_warning("Parallel and --start-and-exit cannot be combined\n" .
+  if ($opt_parallel > 1 && ($opt_start_exit || $opt_stress)) {
+    mtr_warning("Parallel cannot be used with --start-and-exit or --stress\n" .
                "Setting parallel to 1");
     $opt_parallel= 1;
   }
@@ -654,8 +659,9 @@ sub run_test_server ($$$) {
 			 my $core_file= $File::Find::name;
 			 my $core_name= basename($core_file);
 
-			 if ($core_name =~ /^core/ or  # Starting with core
-			     (IS_WINDOWS and $core_name =~ /\.dmp$/)){
+			 # Name beginning with core, not ending in .gz
+			 if (($core_name =~ /^core/ and $core_name !~ /\.gz$/)
+			     or (IS_WINDOWS and $core_name =~ /\.dmp$/)){
                                                        # Ending with .dmp
 			   mtr_report(" - found '$core_name'",
 				      "($num_saved_cores/$opt_max_save_core)");
@@ -1098,14 +1104,17 @@ sub command_line_setup {
              'gdb'                      => \$opt_gdb,
              'client-gdb'               => \$opt_client_gdb,
              'manual-gdb'               => \$opt_manual_gdb,
+	     'boot-gdb'                 => \$opt_boot_gdb,
              'manual-debug'             => \$opt_manual_debug,
              'ddd'                      => \$opt_ddd,
              'client-ddd'               => \$opt_client_ddd,
              'manual-ddd'               => \$opt_manual_ddd,
+	     'boot-ddd'                 => \$opt_boot_ddd,
              'dbx'                      => \$opt_dbx,
 	     'client-dbx'               => \$opt_client_dbx,
 	     'manual-dbx'               => \$opt_manual_dbx,
 	     'debugger=s'               => \$opt_debugger,
+	     'boot-dbx'                 => \$opt_boot_dbx,
 	     'client-debugger=s'        => \$opt_client_debugger,
              'strace-client:s'          => \$opt_strace_client,
              'max-save-core=i'          => \$opt_max_save_core,
@@ -1174,6 +1183,7 @@ sub command_line_setup {
 	     'report-times'             => \$opt_report_times,
 	     'result-file'              => \$opt_resfile,
 	     'unit-tests!'              => \$opt_ctest,
+	     'stress=s'                 => \$opt_stress,
 
              'help|h'                   => \$opt_usage,
 	     # list-options is internal, not listed in help
@@ -1628,6 +1638,22 @@ sub command_line_setup {
   }
 
   # --------------------------------------------------------------------------
+  # Gather stress-test options and modify behavior
+  # --------------------------------------------------------------------------
+
+  if ($opt_stress)
+  {
+    $opt_stress=~ s/,/ /g;
+    $opt_user_args= 1;
+    mtr_error("--stress cannot be combined with named ordinary suites or tests")
+      if $opt_suites || @opt_cases;
+    $opt_suites="stress";
+    @opt_cases= ("wrapper");
+    $ENV{MST_OPTIONS}= $opt_stress;
+    $opt_ctest= 0;
+  }
+
+  # --------------------------------------------------------------------------
   # Check timeout arguments
   # --------------------------------------------------------------------------
 
@@ -2298,12 +2324,6 @@ sub environment_setup {
   $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'port'};
   $ENV{'MYSQL_TMP_DIR'}=      $opt_tmpdir;
   $ENV{'MYSQLTEST_VARDIR'}=   $opt_vardir;
-  # Used for guessing default plugin dir, we can't really know for sure
-  $ENV{'MYSQL_LIBDIR'}=       "$basedir/lib";
-  # Override if this does not exist, but lib64 does (best effort)
-  if (! -d "$basedir/lib" && -d "$basedir/lib64") {
-    $ENV{'MYSQL_LIBDIR'}=     "$basedir/lib64";
-  }
   $ENV{'MYSQL_BINDIR'}=       "$bindir";
   $ENV{'MYSQL_SHAREDIR'}=     $path_language;
   $ENV{'MYSQL_CHARSETSDIR'}=  $path_charsetsdir;
@@ -2365,6 +2385,12 @@ sub environment_setup {
   $ENV{'MYSQL_PLUGIN'}=             $exe_mysql_plugin;
   $ENV{'MYSQL_EMBEDDED'}=           $exe_mysql_embedded;
 
+  my $exe_mysqld= find_mysqld($basedir);
+  $ENV{'MYSQLD'}= $exe_mysqld;
+  my $extra_opts= join (" ", @opt_extra_mysqld_opt);
+  $ENV{'MYSQLD_CMD'}= "$exe_mysqld --defaults-group-suffix=.1 ".
+    "--defaults-file=$path_config_file $extra_opts";
+
   # ----------------------------------------------------
   # bug25714 executable may _not_ exist in
   # some versions, test using it should be skipped
@@ -3240,6 +3266,19 @@ sub mysql_install_db {
   # ----------------------------------------------------------------------
   my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql";
 
+  if ($opt_boot_gdb) {
+    gdb_arguments(\$args, \$exe_mysqld_bootstrap, $mysqld->name(),
+		  $bootstrap_sql_file);
+  }
+  if ($opt_boot_dbx) {
+    dbx_arguments(\$args, \$exe_mysqld_bootstrap, $mysqld->name(),
+		  $bootstrap_sql_file);
+  }
+  if ($opt_boot_ddd) {
+    ddd_arguments(\$args, \$exe_mysqld_bootstrap, $mysqld->name(),
+		  $bootstrap_sql_file);
+  }
+
   my $path_sql= my_find_file($install_basedir,
 			     ["mysql", "sql/share", "share/mysql",
 			      "share", "scripts"],
@@ -4158,6 +4197,11 @@ sub extract_server_log ($$) {
       else
       {
 	push(@lines, $line);
+	if (scalar(@lines) > 1000000) {
+	  $Ferr = undef;
+	  mtr_warning("Too much log from test, bailing out from extracting");
+	  return ();
+	}
       }
     }
     else
@@ -5562,19 +5606,21 @@ sub gdb_arguments {
   my $args= shift;
   my $exe=  shift;
   my $type= shift;
+  my $input= shift;
 
-  # Write $args to gdb init file
-  my $str= join " ", map { s/"/\\"/g; "\"$_\""; } @$$args;
   my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
 
   # Remove the old gdbinit file
   unlink($gdb_init_file);
 
+  # Put $args into a single string
+  my $str= join(" ", @$$args);
+  my $runline= $input ? "run $str < $input" : "run $str";
+
   # write init file for mysqld or client
   mtr_tofile($gdb_init_file,
-	     "set args $str\n" .
 	     "break main\n" .
-	     "run");
+	     $runline);
 
   if ( $opt_manual_gdb )
   {
@@ -5613,20 +5659,22 @@ sub ddd_arguments {
   my $args= shift;
   my $exe=  shift;
   my $type= shift;
+  my $input= shift;
 
-  # Write $args to ddd init file
-  my $str= join " ", map { s/"/\\"/g; "\"$_\""; } @$$args;
   my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
 
   # Remove the old gdbinit file
   unlink($gdb_init_file);
 
+  # Put $args into a single string
+  my $str= join(" ", @$$args);
+  my $runline= $input ? "run $str < $input" : "run $str";
+
   # write init file for mysqld or client
   mtr_tofile($gdb_init_file,
 	     "file $$exe\n" .
-	     "set args $str\n" .
 	     "break main\n" .
-	     "run");
+	     $runline);
 
   if ( $opt_manual_ddd )
   {
@@ -5662,14 +5710,16 @@ sub dbx_arguments {
   my $args= shift;
   my $exe=  shift;
   my $type= shift;
+  my $input= shift;
 
   # Put $args into a single string
   my $str= join " ", @$$args;
+  my $runline= $input ? "run $str < $input" : "run $str";
 
   if ( $opt_manual_dbx ) {
     print "\nTo start dbx for $type, type in another window:\n";
     print "cd $glob_mysql_test_dir; dbx -c \"stop in main; " .
-          "run $str\" $$exe\n";
+          "$runline\" $$exe\n";
 
     # Indicate the exe should not be started
     $$exe= undef;
@@ -5688,7 +5738,7 @@ sub dbx_arguments {
 
   mtr_add_arg($$args, "dbx");
   mtr_add_arg($$args, "-c");
-  mtr_add_arg($$args, "stop in main; run $str");
+  mtr_add_arg($$args, "stop in main; $runline");
   mtr_add_arg($$args, "$$exe");
 
   $$exe= "xterm";
@@ -6134,6 +6184,8 @@ Misc options
   nounit-tests          Do not run unit tests. Normally run if configured
                         and if not running named tests/suites
   unit-tests            Run unit tests even if they would otherwise not be run
+  stress=ARGS           Run stress test, providing options to
+                        mysql-stress-test.pl. Options are separated by comma.
 
 Some options that control enabling a feature for normal test runs,
 can be turned off by prepending 'no' to the option, e.g. --notimer.

=== added file 'mysql-test/r/auth_rpl.result'
--- a/mysql-test/r/auth_rpl.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/auth_rpl.result	2011-09-16 12:35:25 +0000
@@ -0,0 +1,24 @@
+include/master-slave.inc
+[connection master]
+[connection slave]
+include/stop_slave.inc
+[connection master]
+CREATE USER 'plug_user' IDENTIFIED WITH 'test_plugin_server' AS 'plug_user';
+GRANT REPLICATION SLAVE ON *.* TO plug_user;
+FLUSH PRIVILEGES;
+[connection slave]
+CHANGE MASTER TO 
+MASTER_USER=     'plug_user',
+MASTER_PASSWORD= 'plug_user';
+include/start_slave.inc
+# Slave in-sync with master now.
+SELECT user, plugin, authentication_string FROM mysql.user WHERE user LIKE 'plug_user';
+user	plugin	authentication_string
+plug_user	test_plugin_server	plug_user
+# Cleanup (on slave).
+include/stop_slave.inc
+CHANGE MASTER TO MASTER_USER='root';
+DROP USER 'plug_user';
+# Cleanup (on master).
+DROP USER 'plug_user';
+include/rpl_end.inc

=== modified file 'mysql-test/r/execution_constants.result'
--- a/mysql-test/r/execution_constants.result	2006-09-27 18:42:56 +0000
+++ b/mysql-test/r/execution_constants.result	2011-08-22 11:58:49 +0000
@@ -7,6 +7,6 @@ PRIMARY KEY  (`ID_MEMBER`,`ID_BOARD`),
 KEY `logTime` (`logTime`)
 ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_bulgarian_ci;
 INSERT INTO `t_bug21476` VALUES (2,2,1154870939,0),(1,2,1154870957,0),(2,183,1154941362,0),(2,84,1154904301,0),(1,84,1154905867,0),(2,13,1154947484,10271),(3,84,1154880549,0),(1,6,1154892183,0),(2,25,1154947581,10271),(3,25,1154904760,0),(1,25,1154947373,10271),(1,179,1154899992,0),(2,179,1154899410,0),(5,25,1154901666,0),(2,329,1154902026,0),(3,329,1154902040,0),(1,329,1154902058,0),(1,13,1154930841,0),(3,85,1154904987,0),(1,183,1154929665,0),(3,13,1154931268,0),(1,85,1154936888,0),(1,169,1154937959,0),(2,169,1154941717,0),(3,183,1154939810,0),(3,169,1154941734,0);
-Assertion: mysql_errno 1436 == 1436
+Assertion: mysql_errname ER_STACK_OVERRUN_NEED_MORE == ER_STACK_OVERRUN_NEED_MORE
 DROP TABLE `t_bug21476`;
 End of 5.0 tests.

=== modified file 'mysql-test/r/func_str.result'
--- a/mysql-test/r/func_str.result	2011-01-13 08:07:21 +0000
+++ b/mysql-test/r/func_str.result	2011-09-26 12:21:28 +0000
@@ -2785,5 +2785,40 @@ format(123,2,'no_NO')
 123,00
 DROP TABLE t1;
 #
+# Bug#12985030 SIMPLE QUERY WITH DECIMAL NUMBERS LEAKS MEMORY
+#
+SELECT (rpad(1.0,2048,1)) IS NOT FALSE;
+(rpad(1.0,2048,1)) IS NOT FALSE
+1
+SELECT ((+0) IN
+((0b111111111111111111111111111111111111111111111111111),(rpad(1.0,2048,1)),
+(32767.1)));
+((+0) IN
+((0b111111111111111111111111111111111111111111111111111),(rpad(1.0,2048,1)),
+(32767.1)))
+0
+SELECT ((rpad(1.0,2048,1)) = ('4(') ^ (0.1));
+((rpad(1.0,2048,1)) = ('4(') ^ (0.1))
+0
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: '4('
+SELECT
+pow((rpad(10.0,2048,1)),(b'1111111111111111111111111111111111111111111'));
+ERROR 22003: DOUBLE value is out of range in 'pow(rpad(10.0,2048,1),0x07ffffffffff)'
+SELECT ((rpad(1.0,2048,1)) + (0) ^ ('../'));
+((rpad(1.0,2048,1)) + (0) ^ ('../'))
+1.011111111111111
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: '../'
+SELECT stddev_samp(rpad(1.0,2048,1));
+stddev_samp(rpad(1.0,2048,1))
+NULL
+SELECT ((127.1) not in ((rpad(1.0,2048,1)),(''),(-1.1)));
+((127.1) not in ((rpad(1.0,2048,1)),(''),(-1.1)))
+1
+SELECT ((0xf3) * (rpad(1.0,2048,1)) << (0xcc));
+((0xf3) * (rpad(1.0,2048,1)) << (0xcc))
+0
+#
 # End of 5.5 tests
 #

=== modified file 'mysql-test/r/group_by.result'
--- a/mysql-test/r/group_by.result	2011-02-18 10:55:24 +0000
+++ b/mysql-test/r/group_by.result	2011-08-30 08:16:23 +0000
@@ -1892,6 +1892,38 @@ a	AVG(t1.b)	t11c	t12c
 1	4.0000	6	6
 2	2.0000	7	7
 DROP TABLE t1;
+#
+# Bug#11765254 (58200): Assertion failed: param.sort_length when grouping
+# by functions
+#
+SET SQL_BIG_TABLES=1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0),(0);
+SELECT 1 FROM t1 GROUP BY IF(`a`,'','');
+1
+1
+SELECT 1 FROM t1 GROUP BY TRIM(LEADING RAND() FROM '');
+1
+1
+SELECT 1 FROM t1 GROUP BY SUBSTRING('',SLEEP(0),'');
+1
+1
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: ''
+Warning	1292	Truncated incorrect INTEGER value: ''
+Warning	1292	Truncated incorrect INTEGER value: ''
+SELECT 1 FROM t1 GROUP BY SUBSTRING(SYSDATE() FROM 'K' FOR 'jxW<');
+1
+1
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: 'K'
+Warning	1292	Truncated incorrect INTEGER value: 'jxW<'
+Warning	1292	Truncated incorrect INTEGER value: 'K'
+Warning	1292	Truncated incorrect INTEGER value: 'jxW<'
+Warning	1292	Truncated incorrect INTEGER value: 'K'
+Warning	1292	Truncated incorrect INTEGER value: 'jxW<'
+DROP TABLE t1;
+SET SQL_BIG_TABLES=0;
 # End of 5.1 tests
 #
 # Bug#49771: Incorrect MIN (date) when minimum value is 0000-00-00

=== modified file 'mysql-test/r/heap.result'
--- a/mysql-test/r/heap.result	2010-02-20 10:07:32 +0000
+++ b/mysql-test/r/heap.result	2011-09-27 12:14:31 +0000
@@ -715,8 +715,8 @@ create table t1 (c char(10)) engine=memo
 create table t2 (c varchar(10)) engine=memory;
 show table status like 't_';
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	0	11	0	#	0	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	0	12	0	#	0	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	0	11	0	#	0	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	0	12	0	#	0	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 drop table t1, t2;
 CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
 KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;

=== modified file 'mysql-test/r/myisampack.result'
--- a/mysql-test/r/myisampack.result	2010-09-22 08:15:41 +0000
+++ b/mysql-test/r/myisampack.result	2011-09-16 12:21:05 +0000
@@ -118,3 +118,35 @@ Aborted: file is not compressed
 DROP TABLE t1,t2,t3;
 DROP TABLE mysql_db1.t1;
 DROP DATABASE mysql_db1;
+#
+# BUG#11761180 - 53646: MYISAMPACK CORRUPTS TABLES WITH FULLTEXT INDEXES
+#
+CREATE TABLE t1(a CHAR(4), FULLTEXT(a));
+INSERT INTO t1 VALUES('aaaa'),('bbbb'),('cccc');
+FLUSH TABLE t1;
+CHECK TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+SELECT * FROM t1 WHERE MATCH(a) AGAINST('aaaa' IN BOOLEAN MODE);
+a
+aaaa
+SELECT * FROM t1 WHERE MATCH(a) AGAINST('aaaa');
+a
+aaaa
+DROP TABLE t1;
+# Test table with key_reflength > rec_reflength
+CREATE TABLE t1(a CHAR(30), FULLTEXT(a));
+# Populating a table, so it's index file exceeds 65K
+# Populating a table, so index file has second level fulltext tree
+FLUSH TABLE t1;
+# Compressing table
+# Fixing index (repair by sort)
+CHECK TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+FLUSH TABLE t1;
+# Fixing index (repair with keycache)
+CHECK TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+DROP TABLE t1;

=== modified file 'mysql-test/r/mysqltest.result'
--- a/mysql-test/r/mysqltest.result	2011-01-11 14:15:25 +0000
+++ b/mysql-test/r/mysqltest.result	2011-09-15 11:09:24 +0000
@@ -1,6 +1,5 @@
-select 0 as "before_use_test" ;
-before_use_test
-0
+-1 before test
+<No error> before test
 select otto from (select 1 as otto) as t1;
 otto
 1
@@ -21,27 +20,32 @@ mysqltest: At line 1: query 'select frie
 select otto from (select 1 as otto) as t1;
 otto
 1
+
 select 0 as "after_successful_stmt_errno" ;
 after_successful_stmt_errno
 0
 garbage ;
 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 'garbage' at line 1
+ER_PARSE_ERROR
 select 1064 as "after_wrong_syntax_errno" ;
 after_wrong_syntax_errno
 1064
 garbage ;
 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 'garbage' at line 1
+ER_PARSE_ERROR
 select 1064 as "after_let_var_equal_value" ;
 after_let_var_equal_value
 1064
 garbage ;
 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 'garbage' at line 1
 set @my_var= 'abc' ;
+
 select 0 as "after_set_var_equal_value" ;
 after_set_var_equal_value
 0
 garbage ;
 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 'garbage' at line 1
+ER_PARSE_ERROR
 select 1064 as "after_disable_warnings_command" ;
 after_disable_warnings_command
 1064
@@ -49,6 +53,7 @@ drop table if exists t1 ;
 garbage ;
 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 'garbage' at line 1
 drop table if exists t1 ;
+
 select 0 as "after_disable_warnings" ;
 after_disable_warnings
 0
@@ -56,6 +61,7 @@ garbage ;
 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 'garbage' at line 1
 select 3 from t1 ;
 ERROR 42S02: Table 'test.t1' doesn't exist
+ER_NO_SUCH_TABLE
 select 1146 as "after_minus_masked" ;
 after_minus_masked
 1146
@@ -63,6 +69,7 @@ garbage ;
 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 'garbage' at line 1
 select 3 from t1 ;
 ERROR 42S02: Table 'test.t1' doesn't exist
+ER_NO_SUCH_TABLE
 select 1146 as "after_!_masked" ;
 after_!_masked
 1146
@@ -75,6 +82,7 @@ garbage ;
 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 'garbage' at line 1
 prepare stmt from "select 3 from t1" ;
 ERROR 42S02: Table 'test.t1' doesn't exist
+ER_NO_SUCH_TABLE
 select 1146 as "after_failing_prepare" ;
 after_failing_prepare
 1146
@@ -82,6 +90,7 @@ create table t1 ( f1 char(10));
 garbage ;
 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 'garbage' at line 1
 prepare stmt from "select 3 from t1" ;
+
 select 0 as "after_successful_prepare" ;
 after_successful_prepare
 0
@@ -89,6 +98,7 @@ garbage ;
 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 'garbage' at line 1
 execute stmt;
 3
+
 select 0 as "after_successful_execute" ;
 after_successful_execute
 0
@@ -97,6 +107,7 @@ garbage ;
 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 'garbage' at line 1
 execute stmt;
 ERROR 42S02: Table 'test.t1' doesn't exist
+ER_NO_SUCH_TABLE
 select 1146 as "after_failing_execute" ;
 after_failing_execute
 1146
@@ -104,12 +115,14 @@ garbage ;
 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 'garbage' at line 1
 execute __stmt_;
 ERROR HY000: Unknown prepared statement handler (__stmt_) given to EXECUTE
+ER_UNKNOWN_STMT_HANDLER
 select 1243 as "after_failing_execute" ;
 after_failing_execute
 1243
 garbage ;
 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 'garbage' at line 1
 deallocate prepare stmt;
+
 select 0 as "after_successful_deallocate" ;
 after_successful_deallocate
 0
@@ -117,11 +130,13 @@ garbage ;
 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 'garbage' at line 1
 deallocate prepare __stmt_;
 ERROR HY000: Unknown prepared statement handler (__stmt_) given to DEALLOCATE PREPARE
+ER_UNKNOWN_STMT_HANDLER
 select 1243 as "after_failing_deallocate" ;
 after_failing_deallocate
 1243
 garbage ;
 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 'garbage' at line 1
+ER_PARSE_ERROR
 select 1064 as "after_--disable_abort_on_error" ;
 after_--disable_abort_on_error
 1064
@@ -131,18 +146,46 @@ select 3 from t1 ;
 ERROR 42S02: Table 'test.t1' doesn't exist
 select 3 from t1 ;
 ERROR 42S02: Table 'test.t1' doesn't exist
+ER_NO_SUCH_TABLE
 select 1146 as "after_!errno_masked_error" ;
 after_!errno_masked_error
 1146
 mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146: 'Table 'test.t1' doesn't exist', instead of 1000...
+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 'garbage' at line 1
+ is empty
+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 'nonsense' at line 1
+ is empty
 garbage ;
 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 'garbage' at line 1
+ER_PARSE_ERROR
 select 1064 as "after_--enable_abort_on_error" ;
 after_--enable_abort_on_error
 1064
 select 3 from t1 ;
 ERROR 42S02: Table 'test.t1' doesn't exist
 mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146: 'Table 'test.t1' doesn't exist', instead of 1064...
+garbage;
+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 'garbage' at line 1
+select 2;
+select 3;
+3
+3
+select 5;
+ERROR 42S02: Table 'test.t1' doesn't exist
+select 7;
+7
+7
+mysqltest: At line 1: End of line junk detected: "OCNE"
+connect  con1,localhost,root,,;
+select 5 from t1;
+lower
+case
+name
+abc
+xyz
+ is empty
+ is empty
+"Yes it's empty"
 hello
 hello
 ;;;;;;;;
@@ -315,7 +358,7 @@ insert into t1 values ('$dollar');
 $dollar
 `select 42`
 drop table t1;
-mysqltest: At line 1: Error running query 'failing query': 1064 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 'failing query' at line 1
+mysqltest: At line 1: query 'let $var2= `failing query`' failed: 1064: 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 'failing query' at line 1
 mysqltest: At line 1: Missing required argument 'filename' to command 'source'
 mysqltest: At line 1: Could not open './non_existingFile' for reading, errno: 2
 mysqltest: In included file "MYSQLTEST_VARDIR/tmp/recursive.sql": 
@@ -847,7 +890,7 @@ mysqltest: At line 1: Could not find col
 mysqltest: At line 1: Query 'SET @A = 1' didn't return a result set
 mysqltest: At line 1: Could not find column '1 AS B' in the result of 'SELECT 1 AS A'
 value= No such row
-mysqltest: At line 1: Error running query 'SHOW COLNS FROM t1': 1064 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 'COLNS FROM t1' at line 1
+mysqltest: At line 1: query 'let $value= query_get_value(SHOW COLNS FROM t1, Field, 1)' failed: 1064: 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 'COLNS FROM t1' at line 1
 
 Field Type Null Key Default Extra
 a int(11) YES -><- NULL 

=== modified file 'mysql-test/r/show_check.result'
--- a/mysql-test/r/show_check.result	2011-03-30 12:55:53 +0000
+++ b/mysql-test/r/show_check.result	2011-09-27 12:14:31 +0000
@@ -460,57 +460,57 @@ insert into t2 values (1),(2);
 insert into t3 values (1,1),(2,2);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	2	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	2	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t3	MEMORY	10	Fixed	2	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	2	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	2	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t3	MEMORY	10	Fixed	2	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 insert into t1 values (3),(4);
 insert into t2 values (3),(4);
 insert into t3 values (3,3),(4,4);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	4	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	4	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t3	MEMORY	10	Fixed	4	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	4	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	4	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t3	MEMORY	10	Fixed	4	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 insert into t1 values (5);
 insert into t2 values (5);
 insert into t3 values (5,5);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	5	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	5	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t3	MEMORY	10	Fixed	5	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	5	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	5	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t3	MEMORY	10	Fixed	5	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 delete from t1 where a=3;
 delete from t2 where b=3;
 delete from t3 where a=3;
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	4	#	#	#	#	#	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	4	#	#	#	#	#	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t3	MEMORY	10	Fixed	4	#	#	#	#	#	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	4	#	#	#	#	#	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	4	#	#	#	#	#	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t3	MEMORY	10	Fixed	4	#	#	#	#	#	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 truncate table t1;
 truncate table t2;
 truncate table t3;
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	0	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	0	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t3	MEMORY	10	Fixed	0	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	0	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	0	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t3	MEMORY	10	Fixed	0	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 insert into t1 values (5);
 insert into t2 values (5);
 insert into t3 values (5,5);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	1	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	1	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t3	MEMORY	10	Fixed	1	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	1	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	1	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t3	MEMORY	10	Fixed	1	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 delete from t1 where a=5;
 delete from t2 where b=5;
 delete from t3 where a=5;
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	MEMORY	10	Fixed	0	#	#	#	#	#	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t2	MEMORY	10	Fixed	0	#	#	#	#	#	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
-t3	MEMORY	10	Fixed	0	#	#	#	#	#	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+t1	MEMORY	10	Fixed	0	#	#	#	#	#	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t2	MEMORY	10	Fixed	0	#	#	#	#	#	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
+t3	MEMORY	10	Fixed	0	#	#	#	#	#	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 drop table t1, t2, t3;
 create database mysqltest;
 show create database mysqltest;
@@ -662,7 +662,7 @@ DROP TABLE t1;
 flush tables;
 SHOW TABLE STATUS like 't1';
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	NULL	NULL	NULL	NULL	#	#	#	#	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Incorrect information in file: './test/t1.frm'
+t1	NULL	NULL	NULL	NULL	#	#	#	#	NULL	NULL	#	NULL	NULL	NULL	NULL	NULL	Incorrect information in file: './test/t1.frm'
 Warnings:
 Warning	1033	Incorrect information in file: './test/t1.frm'
 show create table t1;
@@ -1334,7 +1334,7 @@ CREATE DATABASE `�
 CREATE TABLE `�`�(a int) ENGINE=Memory;
 SHOW TABLE STATUS FROM `�LIKE '�
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-�EMORY	10	Fixed	0	#	#	#	#	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL		
+�EMORY	10	Fixed	0	#	#	#	#	0	NULL	#	NULL	NULL	latin1_swedish_ci	NULL		
 DROP DATABASE `�
 show columns from `#mysql50#????????`;
 Got one of the listed errors

=== modified file 'mysql-test/r/sp_trans.result'
--- a/mysql-test/r/sp_trans.result	2010-10-06 14:34:28 +0000
+++ b/mysql-test/r/sp_trans.result	2011-08-08 16:45:43 +0000
@@ -558,6 +558,52 @@ f1	bug13575(f1)
 3	ccc
 drop function bug13575|
 drop table t3|
+SELECT @@GLOBAL.storage_engine INTO @old_engine|
+SET @@GLOBAL.storage_engine=InnoDB|
+SET @@SESSION.storage_engine=InnoDB|
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+Variable_name	Value
+storage_engine	InnoDB
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+Variable_name	Value
+storage_engine	InnoDB
+CREATE PROCEDURE bug11758414()
+BEGIN
+SET @@GLOBAL.storage_engine="MyISAM";
+SET @@SESSION.storage_engine="MyISAM"; 
+# show defaults at execution time / that setting them worked
+SHOW GLOBAL VARIABLES LIKE 'storage_engine';
+SHOW SESSION VARIABLES LIKE 'storage_engine';
+CREATE TABLE t1 (id int);
+CREATE TABLE t2 (id int) ENGINE=InnoDB;
+# show we're heeding the default (at run-time, not parse-time!)
+ SHOW CREATE TABLE t1;
+ # show that we didn't break explicit override with ENGINE=...
+SHOW CREATE TABLE t2;
+END;
+|
+CALL bug11758414|
+Variable_name	Value
+storage_engine	MyISAM
+Variable_name	Value
+storage_engine	MyISAM
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `id` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `id` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+Variable_name	Value
+storage_engine	MyISAM
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+Variable_name	Value
+storage_engine	MyISAM
+DROP PROCEDURE bug11758414|
+DROP TABLE t1, t2|
+SET @@GLOBAL.storage_engine=@old_engine|
 #
 # End of 5.1 tests
 #

=== modified file 'mysql-test/r/type_newdecimal.result'
--- a/mysql-test/r/type_newdecimal.result	2011-05-12 03:05:12 +0000
+++ b/mysql-test/r/type_newdecimal.result	2011-08-29 09:34:48 +0000
@@ -1934,3 +1934,14 @@ f1
 0.000000000000000000000000
 DROP TABLE IF EXISTS t1;
 End of 5.1 tests
+#
+# BUG#12911710 - VALGRIND FAILURE IN 
+# ROW-DEBUG:PERFSCHEMA.SOCKET_SUMMARY_BY_INSTANCE_FUNC 
+#
+CREATE TABLE t1(d1 DECIMAL(60,0) NOT NULL,
+d2 DECIMAL(60,0) NOT NULL);
+INSERT INTO t1 (d1, d2) VALUES(0.0, 0.0);
+SELECT d1 * d2 FROM t1;
+d1 * d2
+0
+DROP TABLE t1;

=== removed file 'mysql-test/std_data/bug57108.cnf'
--- a/mysql-test/std_data/bug57108.cnf	2010-11-04 10:00:59 +0000
+++ b/mysql-test/std_data/bug57108.cnf	1970-01-01 00:00:00 +0000
@@ -1,95 +0,0 @@
-[mysqld]
-open-files-limit=1024
-character-set-server=latin1
-connect-timeout=4711
-log-bin-trust-function-creators=1
-key_buffer_size=1M
-sort_buffer=256K
-max_heap_table_size=1M
-loose-innodb_data_file_path=ibdata1:10M:autoextend
-loose-innodb_buffer_pool_size=8M
-loose-innodb_write_io_threads=2
-loose-innodb_read_io_threads=2
-loose-innodb_log_buffer_size=1M
-loose-innodb_log_file_size=5M
-loose-innodb_additional_mem_pool_size=1M
-loose-innodb_log_files_in_group=2
-slave-net-timeout=120
-log-bin=mysqld-bin
-loose-enable-performance-schema
-loose-performance-schema-max-mutex-instances=10000
-loose-performance-schema-max-rwlock-instances=10000
-loose-performance-schema-max-table-instances=500
-loose-performance-schema-max-table-handles=1000
-binlog-direct-non-transactional-updates
-
-[mysql]
-default-character-set=latin1
-
-[mysqlshow]
-default-character-set=latin1
-
-[mysqlimport]
-default-character-set=latin1
-
-[mysqlcheck]
-default-character-set=latin1
-
-[mysql_upgrade]
-default-character-set=latin1
-tmpdir=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/tmp
-
-[mysqld.1]
-#!run-master-sh
-log-bin=master-bin
-loose-enable-performance-schema
-basedir=/home/bzr/bugs/b57108-5.5-bugteam
-tmpdir=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/tmp/mysqld.1
-character-sets-dir=/home/bzr/bugs/b57108-5.5-bugteam/sql/share/charsets
-lc-messages-dir=/home/bzr/bugs/b57108-5.5-bugteam/sql/share/
-datadir=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/mysqld.1/data
-pid-file=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/run/mysqld.1.pid
-#host=localhost
-port=13000
-socket=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/tmp/mysqld.1.sock
-#log-error=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/log/mysqld.1.err
-general_log=1
-general_log_file=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/mysqld.1/mysqld.log
-slow_query_log=1
-slow_query_log_file=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/mysqld.1/mysqld-slow.log
-#user=root
-#password=
-server-id=1
-secure-file-priv=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var
-ssl-ca=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/std_data/cacert.pem
-ssl-cert=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/std_data/server-cert.pem
-ssl-key=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/std_data/server-key.pem
-
-[mysqlbinlog]
-disable-force-if-open
-character-sets-dir=/home/bzr/bugs/b57108-5.5-bugteam/sql/share/charsets
-
-[ENV]
-MASTER_MYPORT=13000
-MASTER_MYSOCK=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/tmp/mysqld.1.sock
-
-[client]
-password=
-user=root
-port=13000
-host=localhost
-socket=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/tmp/mysqld.1.sock
-
-[mysqltest]
-ssl-ca=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/std_data/cacert.pem
-ssl-cert=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/std_data/client-cert.pem
-ssl-key=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/std_data/client-key.pem
-skip-ssl=1
-
-[client.1]
-password=
-user=root
-port=13000
-host=localhost
-socket=/home/bzr/bugs/b57108-5.5-bugteam/mysql-test/var/tmp/mysqld.1.sock
-

=== modified file 'mysql-test/suite/federated/federated_plugin-master.opt'
--- a/mysql-test/suite/federated/federated_plugin-master.opt	2010-06-14 09:23:49 +0000
+++ b/mysql-test/suite/federated/federated_plugin-master.opt	2011-09-05 12:57:48 +0000
@@ -1 +1,2 @@
 --plugin_dir=$FEDERATED_PLUGIN_DIR
+--loose-federated=ON

=== modified file 'mysql-test/suite/federated/federated_plugin.result'
--- a/mysql-test/suite/federated/federated_plugin.result	2010-05-05 07:35:38 +0000
+++ b/mysql-test/suite/federated/federated_plugin.result	2011-09-05 12:57:48 +0000
@@ -0,0 +1,19 @@
+CREATE TABLE t2(a int);
+CREATE TABLE t1(a int) ENGINE=FEDERATED
+CONNECTION='mysql://root@localhost:$MASTER_MYPORT/test/t2';
+Warnings:
+Warning	1286	Unknown storage engine 'FEDERATED'
+Warning	1266	Using storage engine MyISAM for table 't1'
+DROP TABLE t1;
+INSTALL PLUGIN federated SONAME 'FEDERATED_PLUGIN';
+INSTALL PLUGIN FEDERATED SONAME 'FEDERATED_PLUGIN';
+ERROR HY000: Function 'FEDERATED' already exists
+UNINSTALL PLUGIN federated;
+INSTALL PLUGIN federated SONAME 'FEDERATED_PLUGIN';
+CREATE TABLE t1(a int) ENGINE=FEDERATED
+CONNECTION='mysql://root@localhost:$MASTER_MYPORT/test/t2';
+DROP TABLE t1;
+UNINSTALL PLUGIN federated;
+UNINSTALL PLUGIN federated;
+ERROR 42000: PLUGIN federated does not exist
+DROP TABLE t2;

=== modified file 'mysql-test/suite/federated/federated_plugin.test'
--- a/mysql-test/suite/federated/federated_plugin.test	2010-06-14 09:23:49 +0000
+++ b/mysql-test/suite/federated/federated_plugin.test	2011-09-15 11:09:24 +0000
@@ -1,24 +1,37 @@
---source include/not_windows.inc
 --source include/have_federated_plugin.inc
 
---skip federated plugin is disabled
+# Uninstall will not uninstall if ps has been used
+--disable_ps_protocol
 
-CREATE TABLE t1(a int) ENGINE=FEDERATED;
+connect (master,localhost,root,,test,$MASTER_MYPORT,);
+connect (slave,localhost,root,,test,$SLAVE_MYPORT,);
+
+connection master;
+CREATE TABLE t2(a int);
+
+connection slave;
+CREATE TABLE t1(a int) ENGINE=FEDERATED
+  CONNECTION='mysql://root@localhost:$MASTER_MYPORT/test/t2';
 DROP TABLE t1;
 
-INSTALL PLUGIN federated SONAME 'ha_federated.so';
---error 1125
-INSTALL PLUGIN FEDERATED SONAME 'ha_federated.so';
+--replace_result $FEDERATED_PLUGIN FEDERATED_PLUGIN
+eval INSTALL PLUGIN federated SONAME '$FEDERATED_PLUGIN';
+--replace_result $FEDERATED_PLUGIN FEDERATED_PLUGIN
+--error ER_UDF_EXISTS
+eval INSTALL PLUGIN FEDERATED SONAME '$FEDERATED_PLUGIN';
 
 UNINSTALL PLUGIN federated;
 
-INSTALL PLUGIN federated SONAME 'ha_federated.so';
-
-CREATE TABLE t1(a int) ENGINE=FEDERATED;
+--replace_result $FEDERATED_PLUGIN FEDERATED_PLUGIN
+eval INSTALL PLUGIN federated SONAME '$FEDERATED_PLUGIN';
 
+CREATE TABLE t1(a int) ENGINE=FEDERATED
+  CONNECTION='mysql://root@localhost:$MASTER_MYPORT/test/t2';
 DROP TABLE t1;
 
 UNINSTALL PLUGIN federated;
 --error ER_SP_DOES_NOT_EXIST
 UNINSTALL PLUGIN federated;
 
+connection master;
+DROP TABLE t2;

=== modified file 'mysql-test/suite/innodb/r/innodb-index.result'
--- a/mysql-test/suite/innodb/r/innodb-index.result	2011-07-08 13:16:23 +0000
+++ b/mysql-test/suite/innodb/r/innodb-index.result	2011-09-26 07:08:42 +0000
@@ -39,6 +39,81 @@ DELETE FROM t1_purge;
 DELETE FROM t2_purge;
 DELETE FROM t3_purge;
 DELETE FROM t4_purge;
+SET @r=REPEAT('a',500);
+CREATE TABLE t12637786(a INT,
+v1 VARCHAR(500), v2 VARCHAR(500), v3 VARCHAR(500),
+v4 VARCHAR(500), v5 VARCHAR(500), v6 VARCHAR(500),
+v7 VARCHAR(500), v8 VARCHAR(500), v9 VARCHAR(500),
+v10 VARCHAR(500), v11 VARCHAR(500), v12 VARCHAR(500),
+v13 VARCHAR(500), v14 VARCHAR(500), v15 VARCHAR(500),
+v16 VARCHAR(500), v17 VARCHAR(500), v18 VARCHAR(500)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+CREATE INDEX idx1 ON t12637786(a,v1);
+INSERT INTO t12637786 VALUES(9,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r);
+UPDATE t12637786 SET a=1000;
+DELETE FROM t12637786;
+create table t12963823(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
+i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob)
+engine=innodb row_format=dynamic;
+SET @r = repeat('a', 767);
+insert into t12963823 values (@r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r);
+create index ndx_a on t12963823 (a(500));
+create index ndx_b on t12963823 (b(500));
+create index ndx_c on t12963823 (c(500));
+create index ndx_d on t12963823 (d(500));
+create index ndx_e on t12963823 (e(500));
+create index ndx_f on t12963823 (f(500));
+create index ndx_k on t12963823 (k(500));
+create index ndx_l on t12963823 (l(500));
+SET @r = repeat('b', 500);
+update t12963823 set a=@r,b=@r,c=@r,d=@r;
+update t12963823 set e=@r,f=@r,g=@r,h=@r;
+update t12963823 set i=@r,j=@r,k=@r,l=@r;
+update t12963823 set m=@r,n=@r,o=@r,p=@r;
+alter table t12963823 drop index ndx_a;
+alter table t12963823 drop index ndx_b;
+create index ndx_g on t12963823 (g(500));
+create index ndx_h on t12963823 (h(500));
+create index ndx_i on t12963823 (i(500));
+create index ndx_j on t12963823 (j(500));
+create index ndx_m on t12963823 (m(500));
+create index ndx_n on t12963823 (n(500));
+create index ndx_o on t12963823 (o(500));
+create index ndx_p on t12963823 (p(500));
+show create table t12963823;
+Table	Create Table
+t12963823	CREATE TABLE `t12963823` (
+  `a` blob,
+  `b` blob,
+  `c` blob,
+  `d` blob,
+  `e` blob,
+  `f` blob,
+  `g` blob,
+  `h` blob,
+  `i` blob,
+  `j` blob,
+  `k` blob,
+  `l` blob,
+  `m` blob,
+  `n` blob,
+  `o` blob,
+  `p` blob,
+  KEY `ndx_c` (`c`(500)),
+  KEY `ndx_d` (`d`(500)),
+  KEY `ndx_e` (`e`(500)),
+  KEY `ndx_f` (`f`(500)),
+  KEY `ndx_k` (`k`(500)),
+  KEY `ndx_l` (`l`(500)),
+  KEY `ndx_g` (`g`(500)),
+  KEY `ndx_h` (`h`(500)),
+  KEY `ndx_i` (`i`(500)),
+  KEY `ndx_j` (`j`(500)),
+  KEY `ndx_m` (`m`(500)),
+  KEY `ndx_n` (`n`(500)),
+  KEY `ndx_o` (`o`(500)),
+  KEY `ndx_p` (`p`(500))
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
 set global innodb_file_per_table=0;
 set global innodb_file_format=Antelope;
 create table t1(a int not null, b int, c char(10) not null, d varchar(20)) engine = innodb;
@@ -961,20 +1036,15 @@ ERROR HY000: Too big row
 alter table t1 row_format=compact;
 create index t1u on t1 (u(767));
 drop table t1;
-SET @r=REPEAT('a',500);
-CREATE TABLE t1(a INT,
-v1 VARCHAR(500), v2 VARCHAR(500), v3 VARCHAR(500),
-v4 VARCHAR(500), v5 VARCHAR(500), v6 VARCHAR(500),
-v7 VARCHAR(500), v8 VARCHAR(500), v9 VARCHAR(500),
-v10 VARCHAR(500), v11 VARCHAR(500), v12 VARCHAR(500),
-v13 VARCHAR(500), v14 VARCHAR(500), v15 VARCHAR(500),
-v16 VARCHAR(500), v17 VARCHAR(500), v18 VARCHAR(500)
+CREATE TABLE bug12547647(
+a INT NOT NULL, b BLOB NOT NULL, c TEXT,
+PRIMARY KEY (b(10), a), INDEX (c(767)), INDEX(b(767))
 ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
-CREATE INDEX idx1 ON t1(a,v1);
-INSERT INTO t1 VALUES(9,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r);
-UPDATE t1 SET a=1000;
-DELETE FROM t1;
-DROP TABLE t1;
+INSERT INTO bug12547647 VALUES (5,repeat('khdfo5AlOq',1900),repeat('g',7751));
+COMMIT;
+UPDATE bug12547647 SET c = REPEAT('b',16928);
+ERROR HY000: Undo log record is too big.
+DROP TABLE bug12547647;
 set global innodb_file_per_table=0;
 set global innodb_file_format=Antelope;
 set global innodb_file_format_max=Antelope;
@@ -1146,3 +1216,5 @@ SELECT SLEEP(10);
 SLEEP(10)
 0
 DROP TABLE t1_purge, t2_purge, t3_purge, t4_purge;
+DROP TABLE t12637786;
+DROP TABLE t12963823;

=== added file 'mysql-test/suite/innodb/r/innodb_bug59733.result'
--- a/mysql-test/suite/innodb/r/innodb_bug59733.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/r/innodb_bug59733.result	2011-08-15 09:18:34 +0000
@@ -0,0 +1,18 @@
+CREATE TABLE bug59733(a INT AUTO_INCREMENT PRIMARY KEY,b CHAR(1))ENGINE=InnoDB;
+INSERT INTO bug59733 VALUES(0,'x');
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+CREATE INDEX b ON bug59733 (b);
+DELETE FROM bug59733 WHERE (a%100)=0;
+DROP INDEX b ON bug59733;
+CREATE INDEX b ON bug59733 (b);
+DROP TABLE bug59733;

=== added file 'mysql-test/suite/innodb/r/innodb_corrupt_bit.result'
--- a/mysql-test/suite/innodb/r/innodb_corrupt_bit.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/r/innodb_corrupt_bit.result	2011-08-17 09:39:55 +0000
@@ -0,0 +1,81 @@
+set names utf8;
+CREATE TABLE corrupt_bit_test_ā(
+a INT AUTO_INCREMENT PRIMARY KEY,
+b CHAR(100),
+c INT,
+z INT,
+INDEX(b))
+ENGINE=InnoDB;
+INSERT INTO corrupt_bit_test_ā VALUES(0,'x',1, 1);
+CREATE UNIQUE INDEX idxā ON corrupt_bit_test_ā(c, b);
+CREATE UNIQUE INDEX idxē ON corrupt_bit_test_ā(z, b);
+SELECT * FROM corrupt_bit_test_ā;
+a	b	c	z
+1	x	1	1
+select @@unique_checks;
+@@unique_checks
+0
+select @@innodb_change_buffering_debug;
+@@innodb_change_buffering_debug
+1
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1,z+1 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+10,z+10 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+20,z+20 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+50,z+50 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+100,z+100 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+200,z+200 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+400,z+400 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+800,z+800 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1600,z+1600 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+4000,z+4000 FROM corrupt_bit_test_ā;
+select count(*) from corrupt_bit_test_ā;
+count(*)
+1024
+CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
+INSERT INTO corrupt_bit_test_ā VALUES(13000,'x',1,1);
+CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
+check table corrupt_bit_test_ā;
+Table	Op	Msg_type	Msg_text
+test.corrupt_bit_test_ā	check	Warning	InnoDB: The B-tree of index "idxā" is corrupted.
+test.corrupt_bit_test_ā	check	Warning	InnoDB: The B-tree of index "idxē" is corrupted.
+test.corrupt_bit_test_ā	check	error	Corrupt
+select c from corrupt_bit_test_ā;
+ERROR HY000: Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+select z from corrupt_bit_test_ā;
+ERROR HY000: Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+show warnings;
+Level	Code	Message
+Warning	179	InnoDB: Index "idxē" for table "test"."corrupt_bit_test_ā" is marked as corrupted
+Error	1034	Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
+select * from corrupt_bit_test_ā use index(primary) where a = 10001;
+a	b	c	z
+10001	a	20001	20001
+begin;
+insert into corrupt_bit_test_ā values (10002, "a", 20002, 20002);
+delete from corrupt_bit_test_ā where a = 10001;
+insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
+rollback;
+drop index idxā on corrupt_bit_test_ā;
+check table corrupt_bit_test_ā;
+Table	Op	Msg_type	Msg_text
+test.corrupt_bit_test_ā	check	Warning	InnoDB: Index "idxē" is marked as corrupted
+test.corrupt_bit_test_ā	check	error	Corrupt
+set names utf8;
+select z from corrupt_bit_test_ā;
+ERROR HY000: Incorrect key file for table 'corrupt_bit_test_ā'; try to repair it
+drop index idxē on corrupt_bit_test_ā;
+select z from corrupt_bit_test_ā limit 10;
+z
+20001
+1
+1
+2
+11
+12
+21
+22
+31
+32
+drop table corrupt_bit_test_ā;
+SET GLOBAL innodb_change_buffering_debug = 0;

=== modified file 'mysql-test/suite/innodb/t/innodb-index.test'
--- a/mysql-test/suite/innodb/t/innodb-index.test	2011-07-08 13:16:23 +0000
+++ b/mysql-test/suite/innodb/t/innodb-index.test	2011-09-26 07:08:42 +0000
@@ -9,7 +9,7 @@ let $format=`select @@innodb_file_format
 set global innodb_file_per_table=on;
 set global innodb_file_format='Barracuda';
 
-# Test an assertion failure on purge.
+# Bug #12429576 - Test an assertion failure on purge.
 CREATE TABLE t1_purge (
 A INT,
 B BLOB, C BLOB, D BLOB, E BLOB,
@@ -59,6 +59,68 @@ DELETE FROM t1_purge;
 DELETE FROM t2_purge;
 DELETE FROM t3_purge;
 DELETE FROM t4_purge;
+# Instead of doing a --sleep 10, wait until the rest of the tests in
+# this file complete before dropping the tables.  By then, the purge thread
+# will have delt with the updates above.
+
+# Bug#12637786 - Bad assert by purge thread for records with external data
+# used in secondary indexes.
+SET @r=REPEAT('a',500);
+CREATE TABLE t12637786(a INT,
+ v1 VARCHAR(500), v2 VARCHAR(500), v3 VARCHAR(500),
+ v4 VARCHAR(500), v5 VARCHAR(500), v6 VARCHAR(500),
+ v7 VARCHAR(500), v8 VARCHAR(500), v9 VARCHAR(500),
+ v10 VARCHAR(500), v11 VARCHAR(500), v12 VARCHAR(500),
+ v13 VARCHAR(500), v14 VARCHAR(500), v15 VARCHAR(500),
+ v16 VARCHAR(500), v17 VARCHAR(500), v18 VARCHAR(500)
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+CREATE INDEX idx1 ON t12637786(a,v1);
+INSERT INTO t12637786 VALUES(9,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r);
+UPDATE t12637786 SET a=1000;
+DELETE FROM t12637786;
+# We need to activate the purge thread at this point to make sure it does not
+# assert and is able to clean up the old versions of secondary index entries.
+# But instead of doing a --sleep 10,  wait until the rest of the tests in
+# this file complete before dropping the table.  By then, the purge thread
+# will have delt with the updates above.
+
+# Bug#12963823 - Test that the purge thread does not crash when
+# the number of indexes has changed since the UNDO record was logged.
+create table t12963823(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
+		       i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob)
+	engine=innodb row_format=dynamic;
+SET @r = repeat('a', 767);
+insert into t12963823 values (@r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r, @r,@r,@r,@r);
+create index ndx_a on t12963823 (a(500));
+create index ndx_b on t12963823 (b(500));
+create index ndx_c on t12963823 (c(500));
+create index ndx_d on t12963823 (d(500));
+create index ndx_e on t12963823 (e(500));
+create index ndx_f on t12963823 (f(500));
+create index ndx_k on t12963823 (k(500));
+create index ndx_l on t12963823 (l(500));
+
+SET @r = repeat('b', 500);
+update t12963823 set a=@r,b=@r,c=@r,d=@r;
+update t12963823 set e=@r,f=@r,g=@r,h=@r;
+update t12963823 set i=@r,j=@r,k=@r,l=@r;
+update t12963823 set m=@r,n=@r,o=@r,p=@r;
+alter table t12963823 drop index ndx_a;
+alter table t12963823 drop index ndx_b;
+create index ndx_g on t12963823 (g(500));
+create index ndx_h on t12963823 (h(500));
+create index ndx_i on t12963823 (i(500));
+create index ndx_j on t12963823 (j(500));
+create index ndx_m on t12963823 (m(500));
+create index ndx_n on t12963823 (n(500));
+create index ndx_o on t12963823 (o(500));
+create index ndx_p on t12963823 (p(500));
+show create table t12963823;
+# We need to activate the purge thread at this point to see if it crashes
+# but instead of doing a --sleep 10,  wait until the rest of the tests in
+# this file complete before dropping the table.  By then, the purge thread
+# will have delt with the updates above.
+
 
 eval set global innodb_file_per_table=$per_table;
 eval set global innodb_file_format=$format;
@@ -459,23 +521,18 @@ create index t1u on t1 (u(767));
 
 drop table t1;
 
-# Bug#12637786
-SET @r=REPEAT('a',500);
-CREATE TABLE t1(a INT,
- v1 VARCHAR(500), v2 VARCHAR(500), v3 VARCHAR(500),
- v4 VARCHAR(500), v5 VARCHAR(500), v6 VARCHAR(500),
- v7 VARCHAR(500), v8 VARCHAR(500), v9 VARCHAR(500),
- v10 VARCHAR(500), v11 VARCHAR(500), v12 VARCHAR(500),
- v13 VARCHAR(500), v14 VARCHAR(500), v15 VARCHAR(500),
- v16 VARCHAR(500), v17 VARCHAR(500), v18 VARCHAR(500)
+# Bug#12547647 UPDATE LOGGING COULD EXCEED LOG PAGE SIZE
+CREATE TABLE bug12547647(
+a INT NOT NULL, b BLOB NOT NULL, c TEXT,
+PRIMARY KEY (b(10), a), INDEX (c(767)), INDEX(b(767))
 ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
-CREATE INDEX idx1 ON t1(a,v1);
-INSERT INTO t1 VALUES(9,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r);
-UPDATE t1 SET a=1000;
-DELETE FROM t1;
-# Let the purge thread clean up this file.
--- sleep 10
-DROP TABLE t1;
+
+INSERT INTO bug12547647 VALUES (5,repeat('khdfo5AlOq',1900),repeat('g',7751));
+COMMIT;
+# The following used to cause infinite undo log allocation.
+--error ER_UNDO_RECORD_TOO_BIG
+UPDATE bug12547647 SET c = REPEAT('b',16928);
+DROP TABLE bug12547647;
 
 eval set global innodb_file_per_table=$per_table;
 eval set global innodb_file_format=$format;
@@ -623,6 +680,8 @@ DROP TABLE t1;
 #this delay is needed because 45225_2 is disabled, to allow the purge to run
 SELECT SLEEP(10);
 DROP TABLE t1_purge, t2_purge, t3_purge, t4_purge;
+DROP TABLE t12637786;
+DROP TABLE t12963823;
 
 #
 # restore environment to the state it was before this test execution

=== added file 'mysql-test/suite/innodb/t/innodb_bug59733.test'
--- a/mysql-test/suite/innodb/t/innodb_bug59733.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/t/innodb_bug59733.test	2011-08-15 09:18:34 +0000
@@ -0,0 +1,53 @@
+#
+# Bug #59733 Possible deadlock when buffered changes are to be discarded
+# in buf_page_create
+#
+-- source include/have_innodb.inc
+
+-- disable_query_log
+# The flag innodb_change_buffering_debug is only available in debug builds.
+# It instructs InnoDB to try to evict pages from the buffer pool when
+# change buffering is possible, so that the change buffer will be used
+# whenever possible.
+-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE
+SET @innodb_change_buffering_debug_orig = @@innodb_change_buffering_debug;
+-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE
+SET GLOBAL innodb_change_buffering_debug = 1;
+-- enable_query_log
+
+CREATE TABLE bug59733(a INT AUTO_INCREMENT PRIMARY KEY,b CHAR(1))ENGINE=InnoDB;
+
+# Create enough rows for the table, so that the insert buffer will be
+# used. There must be multiple index pages, because changes to the
+# root page are never buffered.
+
+INSERT INTO bug59733 VALUES(0,'x');
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+INSERT INTO bug59733 SELECT 0,b FROM bug59733;
+
+# Create the secondary index for which changes will be buffered.
+CREATE INDEX b ON bug59733 (b);
+
+# This should be buffered, if innodb_change_buffering_debug = 1 is in effect.
+DELETE FROM bug59733 WHERE (a%100)=0;
+
+# Drop the index in order to get free pages with orphaned buffered changes.
+DROP INDEX b ON bug59733;
+
+# Create the index and attempt to reuse pages for which buffered changes exist.
+CREATE INDEX b ON bug59733 (b);
+
+DROP TABLE bug59733;
+
+-- disable_query_log
+-- error 0, ER_UNKNOWN_SYSTEM_VARIABLE
+SET GLOBAL innodb_change_buffering_debug = @innodb_change_buffering_debug_orig;

=== added file 'mysql-test/suite/innodb/t/innodb_corrupt_bit.test'
--- a/mysql-test/suite/innodb/t/innodb_corrupt_bit.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/t/innodb_corrupt_bit.test	2011-08-17 03:51:40 +0000
@@ -0,0 +1,120 @@
+#
+# Test for persistent corrupt bit for corrupted index and table
+#
+-- source include/have_innodb.inc
+
+# This test needs debug server
+--source include/have_debug.inc
+
+-- disable_query_log
+# This test setup is extracted from bug56680.test:
+# The flag innodb_change_buffering_debug is only available in debug builds.
+# It instructs InnoDB to try to evict pages from the buffer pool when
+# change buffering is possible, so that the change buffer will be used
+# whenever possible.
+-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE
+SET @innodb_change_buffering_debug_orig = @@innodb_change_buffering_debug;
+-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE
+SET GLOBAL innodb_change_buffering_debug = 1;
+
+# Turn off Unique Check to create corrupted index with dup key
+SET UNIQUE_CHECKS=0;
+
+-- enable_query_log
+
+set names utf8;
+
+CREATE TABLE corrupt_bit_test_ā(
+       a INT AUTO_INCREMENT PRIMARY KEY,
+       b CHAR(100),
+       c INT,
+       z INT,
+       INDEX(b))
+ENGINE=InnoDB;
+
+INSERT INTO corrupt_bit_test_ā VALUES(0,'x',1, 1);
+
+# This is the first unique index we intend to corrupt
+CREATE UNIQUE INDEX idxā ON corrupt_bit_test_ā(c, b);
+
+# This is the second unique index we intend to corrupt
+CREATE UNIQUE INDEX idxē ON corrupt_bit_test_ā(z, b);
+
+SELECT * FROM corrupt_bit_test_ā;
+
+select @@unique_checks;
+select @@innodb_change_buffering_debug;
+
+# Create enough rows for the table, so that the insert buffer will be
+# used for modifying the secondary index page. There must be multiple
+# index pages, because changes to the root page are never buffered.
+
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1,z+1 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+10,z+10 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+20,z+20 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+50,z+50 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+100,z+100 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+200,z+200 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+400,z+400 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+800,z+800 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1600,z+1600 FROM corrupt_bit_test_ā;
+INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+4000,z+4000 FROM corrupt_bit_test_ā;
+
+select count(*) from corrupt_bit_test_ā;
+
+CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
+
+# Create a dup key error on index "idxē" and "idxā" by inserting a dup value
+INSERT INTO corrupt_bit_test_ā VALUES(13000,'x',1,1);
+
+# creating an index should succeed even if other secondary indexes are corrupted
+CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
+
+# Check table will find the unique indexes corrupted
+# with dup key
+check table corrupt_bit_test_ā;
+
+# This selection intend to use the corrupted index. Expect to fail
+-- error ER_NOT_KEYFILE
+select c from corrupt_bit_test_ā;
+
+-- error ER_NOT_KEYFILE
+select z from corrupt_bit_test_ā;
+
+show warnings;
+
+# Since corrupted index is a secondary index, we only disable such
+# index and allow other DML to proceed
+insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
+
+# This does not use the corrupted index, expect to succeed
+select * from corrupt_bit_test_ā use index(primary) where a = 10001;
+
+# Some more DMLs
+begin;
+insert into corrupt_bit_test_ā values (10002, "a", 20002, 20002);
+delete from corrupt_bit_test_ā where a = 10001;
+insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
+rollback;
+
+# Drop one corrupted index before reboot
+drop index idxā on corrupt_bit_test_ā;
+
+check table corrupt_bit_test_ā;
+
+set names utf8;
+
+-- error ER_NOT_KEYFILE
+select z from corrupt_bit_test_ā;
+
+# Drop the corrupted index
+drop index idxē on corrupt_bit_test_ā;
+
+# Now select back to normal
+select z from corrupt_bit_test_ā limit 10;
+
+# Drop table
+drop table corrupt_bit_test_ā;
+
+-- error 0, ER_UNKNOWN_SYSTEM_VARIABLE
+SET GLOBAL innodb_change_buffering_debug = 0;

=== added file 'mysql-test/suite/stress/t/wrapper.test'
--- a/mysql-test/suite/stress/t/wrapper.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/stress/t/wrapper.test	2011-09-15 10:34:32 +0000
@@ -0,0 +1,29 @@
+#
+# This is a wrapper "pseudo" test for mtr --stress execution.
+# It should not be run directly (will be skipped)
+# Do not create a result file!
+# 
+
+if (!$MST_OPTIONS) {
+  skip Only to be run with mtr --stress;
+}
+
+# echo Running MST with options $MST_OPTIONS;
+
+perl;
+  my ($mtest)= split " ", $ENV{MYSQL_TEST};
+  open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/mtest.inc") or die;
+  print FILE "let \$MYSQLTEST_BIN= $mtest;\n";
+  close FILE;
+EOF
+
+--source $MYSQL_TMP_DIR/mtest.inc
+--remove_file $MYSQL_TMP_DIR/mtest.inc
+
+exec perl mysql-stress-test.pl --mysqltest=$MYSQLTEST_BIN
+         --server-port=$MASTER_MYPORT --server-socket=$MASTER_MYSOCK
+         --server-user=root --cleanup
+         --server-logs-dir=$MYSQLTEST_VARDIR/log
+         --stress-basedir=$MYSQLTEST_VARDIR
+	 $MST_OPTIONS
+;

=== modified file 'mysql-test/suite/sys_vars/r/all_vars.result'
--- a/mysql-test/suite/sys_vars/r/all_vars.result	2011-08-15 14:29:38 +0000
+++ b/mysql-test/suite/sys_vars/r/all_vars.result	2011-09-26 08:47:08 +0000
@@ -11,7 +11,5 @@ There should be *no* long test name list
 select variable_name as `There should be *no* variables listed below:` from t2
 left join t1 on variable_name=test_name where test_name is null;
 There should be *no* variables listed below:
-INNODB_LARGE_PREFIX
-INNODB_LARGE_PREFIX
 drop table t1;
 drop table t2;

=== modified file 'mysql-test/suite/sys_vars/r/innodb_file_per_table_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_file_per_table_basic.result	2009-08-07 20:04:53 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_file_per_table_basic.result	2011-08-16 10:36:34 +0000
@@ -1,13 +1,29 @@
+SET @start_global_value = @@global.innodb_file_per_table;
+SELECT @start_global_value;
+@start_global_value
+0
 '#---------------------BS_STVARS_028_01----------------------#'
 SELECT COUNT(@@GLOBAL.innodb_file_per_table);
 COUNT(@@GLOBAL.innodb_file_per_table)
 1
 1 Expected
 '#---------------------BS_STVARS_028_02----------------------#'
-SELECT COUNT(@@GLOBAL.innodb_file_per_table);
-COUNT(@@GLOBAL.innodb_file_per_table)
+SET @@global.innodb_file_per_table = 0;
+SELECT @@global.innodb_file_per_table;
+@@global.innodb_file_per_table
+0
+SET @@global.innodb_file_per_table ='On' ;
+SELECT @@global.innodb_file_per_table;
+@@global.innodb_file_per_table
+1
+SET @@global.innodb_file_per_table ='Off' ;
+SELECT @@global.innodb_file_per_table;
+@@global.innodb_file_per_table
+0
+SET @@global.innodb_file_per_table = 1;
+SELECT @@global.innodb_file_per_table;
+@@global.innodb_file_per_table
 1
-1 Expected
 '#---------------------BS_STVARS_028_03----------------------#'
 SELECT IF(@@GLOBAL.innodb_file_per_table,'ON','OFF') = VARIABLE_VALUE
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
@@ -47,4 +63,7 @@ COUNT(@@GLOBAL.innodb_file_per_table)
 1 Expected
 SELECT innodb_file_per_table = @@SESSION.innodb_file_per_table;
 ERROR 42S22: Unknown column 'innodb_file_per_table' in 'field list'
-Expected error 'Readonly variable'
+SET @@global.innodb_file_per_table = @start_global_value;
+SELECT @@global.innodb_file_per_table;
+@@global.innodb_file_per_table
+0

=== added file 'mysql-test/suite/sys_vars/r/innodb_force_load_corrupted_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_force_load_corrupted_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_force_load_corrupted_basic.result	2011-08-17 03:51:40 +0000
@@ -0,0 +1,53 @@
+'#---------------------BS_STVARS_031_01----------------------#'
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+COUNT(@@GLOBAL.innodb_force_load_corrupted)
+1
+1 Expected
+'#---------------------BS_STVARS_031_02----------------------#'
+SET @@GLOBAL.innodb_force_load_corrupted=1;
+ERROR HY000: Variable 'innodb_force_load_corrupted' is a read only variable
+Expected error 'Read only variable'
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+COUNT(@@GLOBAL.innodb_force_load_corrupted)
+1
+1 Expected
+'#---------------------BS_STVARS_031_03----------------------#'
+SELECT IF(@@GLOBAL.innodb_force_load_corrupted, "ON", "OFF") = VARIABLE_VALUE
+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+WHERE VARIABLE_NAME='innodb_force_load_corrupted';
+IF(@@GLOBAL.innodb_force_load_corrupted, "ON", "OFF") = VARIABLE_VALUE
+1
+1 Expected
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+COUNT(@@GLOBAL.innodb_force_load_corrupted)
+1
+1 Expected
+SELECT COUNT(VARIABLE_VALUE)
+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
+WHERE VARIABLE_NAME='innodb_force_load_corrupted';
+COUNT(VARIABLE_VALUE)
+1
+1 Expected
+'#---------------------BS_STVARS_031_04----------------------#'
+SELECT @@innodb_force_load_corrupted = @@GLOBAL.innodb_force_load_corrupted;
+@@innodb_force_load_corrupted = @@GLOBAL.innodb_force_load_corrupted
+1
+1 Expected
+'#---------------------BS_STVARS_031_05----------------------#'
+SELECT COUNT(@@innodb_force_load_corrupted);
+COUNT(@@innodb_force_load_corrupted)
+1
+1 Expected
+SELECT COUNT(@@local.innodb_force_load_corrupted);
+ERROR HY000: Variable 'innodb_force_load_corrupted' is a GLOBAL variable
+Expected error 'Variable is a GLOBAL variable'
+SELECT COUNT(@@SESSION.innodb_force_load_corrupted);
+ERROR HY000: Variable 'innodb_force_load_corrupted' is a GLOBAL variable
+Expected error 'Variable is a GLOBAL variable'
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+COUNT(@@GLOBAL.innodb_force_load_corrupted)
+1
+1 Expected
+SELECT innodb_force_load_corrupted = @@SESSION.innodb_force_load_corrupted;
+ERROR 42S22: Unknown column 'innodb_force_load_corrupted' in 'field list'
+Expected error 'Readonly variable'

=== added file 'mysql-test/suite/sys_vars/r/innodb_large_prefix_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_large_prefix_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_large_prefix_basic.result	2011-08-17 03:51:40 +0000
@@ -0,0 +1,92 @@
+SET @start_global_value = @@global.innodb_large_prefix;
+SELECT @start_global_value;
+@start_global_value
+0
+Valid values are 'ON' and 'OFF' 
+select @@global.innodb_large_prefix in (0, 1);
+@@global.innodb_large_prefix in (0, 1)
+1
+select @@global.innodb_large_prefix;
+@@global.innodb_large_prefix
+0
+select @@session.innodb_large_prefix;
+ERROR HY000: Variable 'innodb_large_prefix' is a GLOBAL variable
+show global variables like 'innodb_large_prefix';
+Variable_name	Value
+innodb_large_prefix	OFF
+show session variables like 'innodb_large_prefix';
+Variable_name	Value
+innodb_large_prefix	OFF
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	OFF
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	OFF
+set global innodb_large_prefix='OFF';
+select @@global.innodb_large_prefix;
+@@global.innodb_large_prefix
+0
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	OFF
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	OFF
+set @@global.innodb_large_prefix=1;
+select @@global.innodb_large_prefix;
+@@global.innodb_large_prefix
+1
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	ON
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	ON
+set global innodb_large_prefix=0;
+select @@global.innodb_large_prefix;
+@@global.innodb_large_prefix
+0
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	OFF
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	OFF
+set @@global.innodb_large_prefix='ON';
+select @@global.innodb_large_prefix;
+@@global.innodb_large_prefix
+1
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	ON
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	ON
+set session innodb_large_prefix='OFF';
+ERROR HY000: Variable 'innodb_large_prefix' is a GLOBAL variable and should be set with SET GLOBAL
+set @@session.innodb_large_prefix='ON';
+ERROR HY000: Variable 'innodb_large_prefix' is a GLOBAL variable and should be set with SET GLOBAL
+set global innodb_large_prefix=1.1;
+ERROR 42000: Incorrect argument type to variable 'innodb_large_prefix'
+set global innodb_large_prefix=1e1;
+ERROR 42000: Incorrect argument type to variable 'innodb_large_prefix'
+set global innodb_large_prefix=2;
+ERROR 42000: Variable 'innodb_large_prefix' can't be set to the value of '2'
+NOTE: The following should fail with ER_WRONG_VALUE_FOR_VAR (BUG#50643)
+set global innodb_large_prefix=-3;
+select @@global.innodb_large_prefix;
+@@global.innodb_large_prefix
+1
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	ON
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+VARIABLE_NAME	VARIABLE_VALUE
+INNODB_LARGE_PREFIX	ON
+set global innodb_large_prefix='AUTO';
+ERROR 42000: Variable 'innodb_large_prefix' can't be set to the value of 'AUTO'
+SET @@global.innodb_large_prefix = @start_global_value;
+SELECT @@global.innodb_large_prefix;
+@@global.innodb_large_prefix
+0

=== modified file 'mysql-test/suite/sys_vars/r/innodb_lock_wait_timeout_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_lock_wait_timeout_basic.result	2009-08-07 20:04:53 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_lock_wait_timeout_basic.result	2011-08-16 10:36:34 +0000
@@ -1,13 +1,21 @@
+SET @start_global_value=@@global.innodb_lock_wait_timeout;
+SELECT @start_global_value;
+@start_global_value
+50
 '#---------------------BS_STVARS_032_01----------------------#'
 SELECT COUNT(@@GLOBAL.innodb_lock_wait_timeout);
 COUNT(@@GLOBAL.innodb_lock_wait_timeout)
 1
 1 Expected
 '#---------------------BS_STVARS_032_02----------------------#'
-SELECT COUNT(@@GLOBAL.innodb_lock_wait_timeout);
-COUNT(@@GLOBAL.innodb_lock_wait_timeout)
-1
-1 Expected
+SET global innodb_lock_wait_timeout=60;
+SELECT @@global.innodb_lock_wait_timeout;
+@@global.innodb_lock_wait_timeout
+60
+SET session innodb_lock_wait_timeout=60;
+SELECT @@session.innodb_lock_wait_timeout;
+@@session.innodb_lock_wait_timeout
+60
 '#---------------------BS_STVARS_032_03----------------------#'
 SELECT @@GLOBAL.innodb_lock_wait_timeout = VARIABLE_VALUE
 FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
@@ -47,4 +55,7 @@ COUNT(@@GLOBAL.innodb_lock_wait_timeout)
 1 Expected
 SELECT innodb_lock_wait_timeout = @@SESSION.innodb_lock_wait_timeout;
 ERROR 42S22: Unknown column 'innodb_lock_wait_timeout' in 'field list'
-Expected error 'Readonly variable'
+SET @@global.innodb_lock_wait_timeout = @start_global_value;
+SELECT @@global.innodb_lock_wait_timeout;
+@@global.innodb_lock_wait_timeout
+50

=== modified file 'mysql-test/suite/sys_vars/r/plugin_dir_basic.result'
--- a/mysql-test/suite/sys_vars/r/plugin_dir_basic.result	2009-12-22 09:35:56 +0000
+++ b/mysql-test/suite/sys_vars/r/plugin_dir_basic.result	2011-08-16 09:08:10 +0000
@@ -1,20 +1,20 @@
 select @@global.plugin_dir;
 @@global.plugin_dir
-MYSQL_LIBDIR/plugin
+MYSQL_TMP_DIR
 select @@session.plugin_dir;
 ERROR HY000: Variable 'plugin_dir' is a GLOBAL variable
 show global variables like 'plugin_dir';
 Variable_name	Value
-plugin_dir	MYSQL_LIBDIR/plugin
+plugin_dir	MYSQL_TMP_DIR
 show session variables like 'plugin_dir';
 Variable_name	Value
-plugin_dir	MYSQL_LIBDIR/plugin
+plugin_dir	MYSQL_TMP_DIR
 select * from information_schema.global_variables where variable_name='plugin_dir';
 VARIABLE_NAME	VARIABLE_VALUE
-PLUGIN_DIR	MYSQL_LIBDIR/plugin
+PLUGIN_DIR	MYSQL_TMP_DIR
 select * from information_schema.session_variables where variable_name='plugin_dir';
 VARIABLE_NAME	VARIABLE_VALUE
-PLUGIN_DIR	MYSQL_LIBDIR/plugin
+PLUGIN_DIR	MYSQL_TMP_DIR
 set global plugin_dir=1;
 ERROR HY000: Variable 'plugin_dir' is a read only variable
 set session plugin_dir=1;

=== modified file 'mysql-test/suite/sys_vars/t/innodb_autoinc_lock_mode_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_autoinc_lock_mode_basic.test	2008-12-19 15:12:15 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_autoinc_lock_mode_basic.test	2011-08-16 10:36:34 +0000
@@ -1,8 +1,7 @@
 ################# mysql-test\t\innodb_autoinc_lock_mode_basic.test ############
 #                                                                             #
 # Variable Name: innodb_autoinc_lock_mode                                     #
-# Scope: GLOBAL                                                               #
-# Access Type: Dynamic                                                        #
+# Access Type: Static                                                         #
 # Data Type: Numeric                                                          #
 # Default Value: 1                                                            #
 # Range: 0,1,2                                                                #

=== modified file 'mysql-test/suite/sys_vars/t/innodb_fast_shutdown_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_fast_shutdown_basic.test	2010-07-15 11:13:30 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_fast_shutdown_basic.test	2011-08-16 10:36:34 +0000
@@ -3,9 +3,9 @@
 # Variable Name: innodb_fast_shutdown                                         #
 # Scope: GLOBAL                                                               #
 # Access Type: Dynamic                                                        #
-# Data Type: boolean                                                          #
+# Data Type: numeric                                                          #
 # Default Value: 1                                                            #
-# Valid Values: 0,1                                                           #
+# Valid Values: 0,1,2                                                           #
 #                                                                             #
 #                                                                             #
 # Creation Date: 2008-02-20                                                   #

=== modified file 'mysql-test/suite/sys_vars/t/innodb_file_per_table_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_file_per_table_basic.test	2009-08-07 20:04:53 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_file_per_table_basic.test	2011-08-16 10:36:34 +0000
@@ -4,7 +4,7 @@
 #                                                                             #
 # Variable Name: innodb_file_per_table                                        #
 # Scope: Global                                                               #
-# Access Type: Static                                                         #
+# Access Type: Dynamic                                                        #
 # Data Type: boolean                                                          #
 #                                                                             #
 #                                                                             #
@@ -24,6 +24,10 @@
 
 --source include/have_innodb.inc
 
+SET @start_global_value = @@global.innodb_file_per_table;
+SELECT @start_global_value;
+
+
 --echo '#---------------------BS_STVARS_028_01----------------------#'
 ####################################################################
 #   Displaying default value                                       #
@@ -37,11 +41,17 @@ SELECT COUNT(@@GLOBAL.innodb_file_per_ta
 #   Check if Value can set                                         #
 ####################################################################
 
-SELECT COUNT(@@GLOBAL.innodb_file_per_table);
---echo 1 Expected
+SET @@global.innodb_file_per_table = 0;
+SELECT @@global.innodb_file_per_table;
 
+SET @@global.innodb_file_per_table ='On' ;
+SELECT @@global.innodb_file_per_table;
 
+SET @@global.innodb_file_per_table ='Off' ;
+SELECT @@global.innodb_file_per_table;
 
+SET @@global.innodb_file_per_table = 1;
+SELECT @@global.innodb_file_per_table;
 
 --echo '#---------------------BS_STVARS_028_03----------------------#'
 #################################################################
@@ -93,6 +103,10 @@ SELECT COUNT(@@GLOBAL.innodb_file_per_ta
 
 --Error ER_BAD_FIELD_ERROR
 SELECT innodb_file_per_table = @@SESSION.innodb_file_per_table;
---echo Expected error 'Readonly variable'
 
+#
+# Cleanup
+#
 
+SET @@global.innodb_file_per_table = @start_global_value;
+SELECT @@global.innodb_file_per_table;

=== added file 'mysql-test/suite/sys_vars/t/innodb_force_load_corrupted_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_force_load_corrupted_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_force_load_corrupted_basic.test	2011-08-17 03:51:40 +0000
@@ -0,0 +1,102 @@
+
+
+################## mysql-test\t\innodb_force_load_corrupted_basic.test #####
+#                                                                             #
+# Variable Name: innodb_force_load_corrupted                               #
+# Scope: Global                                                               #
+# Access Type: Static                                                         #
+# Data Type: boolean                                                          #
+#                                                                             #
+#                                                                             #
+# Creation Date: 2008-02-07                                                   #
+# Author : Sharique Abdullah                                                      #
+#                                                                             #
+#                                                                             #
+# Description:Test Cases of Dynamic System Variable innodb_force_load_corrupted#
+#             that checks the behavior of this variable in the following ways #
+#              * Value Check                                                  #
+#              * Scope Check                                                  #
+#                                                                             #
+# Reference: http://dev.mysql.com/doc/refman/5.1/en/                          #
+#  server-system-variables.html                                               #
+#                                                                             #
+###############################################################################
+
+--source include/have_innodb.inc
+
+--echo '#---------------------BS_STVARS_031_01----------------------#'
+####################################################################
+#   Displaying default value                                       #
+####################################################################
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+--echo 1 Expected
+
+
+--echo '#---------------------BS_STVARS_031_02----------------------#'
+####################################################################
+#   Check if Value can set                                         #
+####################################################################
+
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+SET @@GLOBAL.innodb_force_load_corrupted=1;
+--echo Expected error 'Read only variable'
+
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+--echo 1 Expected
+
+
+
+
+--echo '#---------------------BS_STVARS_031_03----------------------#'
+#################################################################
+# Check if the value in GLOBAL Table matches value in variable  #
+#################################################################
+
+SELECT IF(@@GLOBAL.innodb_force_load_corrupted, "ON", "OFF") = VARIABLE_VALUE
+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+WHERE VARIABLE_NAME='innodb_force_load_corrupted';
+--echo 1 Expected
+
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+--echo 1 Expected
+
+SELECT COUNT(VARIABLE_VALUE)
+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
+WHERE VARIABLE_NAME='innodb_force_load_corrupted';
+--echo 1 Expected
+
+
+
+--echo '#---------------------BS_STVARS_031_04----------------------#'
+################################################################################
+#  Check if accessing variable with and without GLOBAL point to same variable  #
+################################################################################
+SELECT @@innodb_force_load_corrupted = @@GLOBAL.innodb_force_load_corrupted;
+--echo 1 Expected
+
+
+
+--echo '#---------------------BS_STVARS_031_05----------------------#'
+################################################################################
+#   Check if innodb_force_load_corrupted can be accessed with and without @@ sign #
+################################################################################
+
+SELECT COUNT(@@innodb_force_load_corrupted);
+--echo 1 Expected
+
+--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
+SELECT COUNT(@@local.innodb_force_load_corrupted);
+--echo Expected error 'Variable is a GLOBAL variable'
+
+--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
+SELECT COUNT(@@SESSION.innodb_force_load_corrupted);
+--echo Expected error 'Variable is a GLOBAL variable'
+
+SELECT COUNT(@@GLOBAL.innodb_force_load_corrupted);
+--echo 1 Expected
+
+--Error ER_BAD_FIELD_ERROR
+SELECT innodb_force_load_corrupted = @@SESSION.innodb_force_load_corrupted;
+--echo Expected error 'Readonly variable'
+
+

=== modified file 'mysql-test/suite/sys_vars/t/innodb_io_capacity_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_io_capacity_basic.test	2010-01-29 06:33:00 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_io_capacity_basic.test	2011-08-16 10:36:34 +0000
@@ -54,5 +54,9 @@ select * from information_schema.global_
 set global innodb_io_capacity=100;
 select @@global.innodb_io_capacity;
 
+#
+# cleanup
+#
+
 SET @@global.innodb_io_capacity = @start_global_value;
 SELECT @@global.innodb_io_capacity;

=== added file 'mysql-test/suite/sys_vars/t/innodb_large_prefix_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_large_prefix_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_large_prefix_basic.test	2011-08-17 03:51:40 +0000
@@ -0,0 +1,70 @@
+
+
+# 2010-01-25 - Added
+#
+
+--source include/have_innodb.inc
+
+SET @start_global_value = @@global.innodb_large_prefix;
+SELECT @start_global_value;
+
+#
+# exists as global only
+#
+--echo Valid values are 'ON' and 'OFF' 
+select @@global.innodb_large_prefix in (0, 1);
+select @@global.innodb_large_prefix;
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+select @@session.innodb_large_prefix;
+show global variables like 'innodb_large_prefix';
+show session variables like 'innodb_large_prefix';
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+
+#
+# show that it's writable
+#
+set global innodb_large_prefix='OFF';
+select @@global.innodb_large_prefix;
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+set @@global.innodb_large_prefix=1;
+select @@global.innodb_large_prefix;
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+set global innodb_large_prefix=0;
+select @@global.innodb_large_prefix;
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+set @@global.innodb_large_prefix='ON';
+select @@global.innodb_large_prefix;
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+--error ER_GLOBAL_VARIABLE
+set session innodb_large_prefix='OFF';
+--error ER_GLOBAL_VARIABLE
+set @@session.innodb_large_prefix='ON';
+
+#
+# incorrect types
+#
+--error ER_WRONG_TYPE_FOR_VAR
+set global innodb_large_prefix=1.1;
+--error ER_WRONG_TYPE_FOR_VAR
+set global innodb_large_prefix=1e1;
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_large_prefix=2;
+--echo NOTE: The following should fail with ER_WRONG_VALUE_FOR_VAR (BUG#50643)
+set global innodb_large_prefix=-3;
+select @@global.innodb_large_prefix;
+select * from information_schema.global_variables where variable_name='innodb_large_prefix';
+select * from information_schema.session_variables where variable_name='innodb_large_prefix';
+--error ER_WRONG_VALUE_FOR_VAR
+set global innodb_large_prefix='AUTO';
+
+#
+# Cleanup
+#
+
+SET @@global.innodb_large_prefix = @start_global_value;
+SELECT @@global.innodb_large_prefix;

=== modified file 'mysql-test/suite/sys_vars/t/innodb_lock_wait_timeout_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_lock_wait_timeout_basic.test	2009-08-07 20:04:53 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_lock_wait_timeout_basic.test	2011-08-16 10:36:34 +0000
@@ -3,13 +3,13 @@
 ################## mysql-test\t\innodb_lock_wait_timeout_basic.test ###########
 #                                                                             #
 # Variable Name: innodb_lock_wait_timeout                                     #
-# Scope: Global                                                               #
-# Access Type: Static                                                         #
+# Scope: Global , Session                                                     #
+# Access Type: Dynamic                                                        #
 # Data Type: numeric                                                          #
 #                                                                             #
 #                                                                             #
 # Creation Date: 2008-02-07                                                   #
-# Author : Sharique Abdullah                                                      #
+# Author : Sharique Abdullah                                                  #
 #                                                                             #
 #                                                                             #
 # Description:Test Cases of Dynamic System Variable innodb_lock_wait_timeout  #
@@ -24,6 +24,9 @@
 
 --source include/have_innodb.inc
 
+SET @start_global_value=@@global.innodb_lock_wait_timeout;
+SELECT @start_global_value;
+
 --echo '#---------------------BS_STVARS_032_01----------------------#'
 ####################################################################
 #   Displaying default value                                       #
@@ -37,11 +40,10 @@ SELECT COUNT(@@GLOBAL.innodb_lock_wait_t
 #   Check if Value can set                                         #
 ####################################################################
 
-SELECT COUNT(@@GLOBAL.innodb_lock_wait_timeout);
---echo 1 Expected
-
-
-
+SET global innodb_lock_wait_timeout=60;
+SELECT @@global.innodb_lock_wait_timeout;
+SET session innodb_lock_wait_timeout=60;
+SELECT @@session.innodb_lock_wait_timeout;
 
 --echo '#---------------------BS_STVARS_032_03----------------------#'
 #################################################################
@@ -89,6 +91,10 @@ SELECT COUNT(@@GLOBAL.innodb_lock_wait_t
 
 --Error ER_BAD_FIELD_ERROR
 SELECT innodb_lock_wait_timeout = @@SESSION.innodb_lock_wait_timeout;
---echo Expected error 'Readonly variable'
 
+#
+# Cleanup
+#
 
+SET @@global.innodb_lock_wait_timeout = @start_global_value;
+SELECT @@global.innodb_lock_wait_timeout;

=== modified file 'mysql-test/suite/sys_vars/t/innodb_max_dirty_pages_pct_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_max_dirty_pages_pct_basic.test	2009-02-17 12:24:09 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_max_dirty_pages_pct_basic.test	2011-08-16 10:36:34 +0000
@@ -4,8 +4,8 @@
 # Scope: GLOBAL                                                               #
 # Access Type: Dynamic                                                        #
 # Data Type: Numeric                                                          #
-# Default Value: 90                                                           #
-# Range: 0-1000                                                               #
+# Default Value: 75                                                           #
+# Range: 0-99                                                                 #
 #                                                                             #
 #                                                                             #
 # Creation Date: 2008-02-07                                                   #

=== added file 'mysql-test/suite/sys_vars/t/plugin_dir_basic-master.opt'
--- a/mysql-test/suite/sys_vars/t/plugin_dir_basic-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/plugin_dir_basic-master.opt	2011-08-16 09:08:10 +0000
@@ -0,0 +1 @@
+--plugin-dir=$MYSQL_TMP_DIR

=== modified file 'mysql-test/suite/sys_vars/t/plugin_dir_basic.test'
--- a/mysql-test/suite/sys_vars/t/plugin_dir_basic.test	2009-12-22 09:35:56 +0000
+++ b/mysql-test/suite/sys_vars/t/plugin_dir_basic.test	2011-08-16 09:08:10 +0000
@@ -3,20 +3,20 @@
 #
 
 #
-# on windows it's <basedir>/lib/plugin
-# on unix it's <basedir>/lib/mysql/plugin
+# Don't rely on being able to guess the correct default.
+# -master.opt file for this test sets plugin_dir to a known directory
 #
---replace_result $MYSQL_LIBDIR MYSQL_LIBDIR /mysql/ /
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR /mysql/ /
 select @@global.plugin_dir;
 --error ER_INCORRECT_GLOBAL_LOCAL_VAR
 select @@session.plugin_dir;
---replace_result $MYSQL_LIBDIR MYSQL_LIBDIR /mysql/ /
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR /mysql/ /
 show global variables like 'plugin_dir';
---replace_result $MYSQL_LIBDIR MYSQL_LIBDIR /mysql/ /
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR /mysql/ /
 show session variables like 'plugin_dir';
---replace_result $MYSQL_LIBDIR MYSQL_LIBDIR /mysql/ /
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR /mysql/ /
 select * from information_schema.global_variables where variable_name='plugin_dir';
---replace_result $MYSQL_LIBDIR MYSQL_LIBDIR /mysql/ /
+--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR /mysql/ /
 select * from information_schema.session_variables where variable_name='plugin_dir';
 
 #

=== added file 'mysql-test/t/auth_rpl-master.opt'
--- a/mysql-test/t/auth_rpl-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/auth_rpl-master.opt	2011-09-14 14:10:18 +0000
@@ -0,0 +1,2 @@
+$PLUGIN_AUTH_OPT
+$PLUGIN_AUTH_LOAD

=== added file 'mysql-test/t/auth_rpl-slave.opt'
--- a/mysql-test/t/auth_rpl-slave.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/auth_rpl-slave.opt	2011-09-14 14:10:18 +0000
@@ -0,0 +1,4 @@
+--master-retry-count=1
+$PLUGIN_AUTH_OPT
+$PLUGIN_AUTH_LOAD
+

=== added file 'mysql-test/t/auth_rpl.test'
--- a/mysql-test/t/auth_rpl.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/auth_rpl.test	2011-09-16 12:35:25 +0000
@@ -0,0 +1,66 @@
+--source include/have_plugin_auth.inc
+--source include/not_embedded.inc
+--source include/master-slave.inc
+
+#
+# Check that replication slave can connect to master using an account
+# which authenticates with an external authentication plugin (bug#12897501).
+
+#
+# First stop the slave to guarantee that nothing is replicated.
+#
+--connection slave
+--echo [connection slave]
+--source include/stop_slave.inc
+#
+# Create an replication account on the master.
+#
+--connection master
+--echo [connection master]
+CREATE USER 'plug_user' IDENTIFIED WITH 'test_plugin_server' AS 'plug_user';
+GRANT REPLICATION SLAVE ON *.* TO plug_user;
+FLUSH PRIVILEGES;
+
+#
+# Now go to slave and change the replication user.
+#
+--connection slave
+--echo [connection slave]
+--let $master_user= query_get_value(SHOW SLAVE STATUS, Master_User, 1)
+CHANGE MASTER TO 
+  MASTER_USER=     'plug_user',
+  MASTER_PASSWORD= 'plug_user';
+
+#
+# Start slave with new replication account - this should trigger connection
+# to the master server.
+#
+--source include/start_slave.inc
+
+# Replicate all statements executed on master, in this case,
+# (creation of the plug_user account).
+#
+--connection master
+--sync_slave_with_master
+--echo # Slave in-sync with master now.
+
+SELECT user, plugin, authentication_string FROM mysql.user WHERE user LIKE 'plug_user';
+
+#
+# Now we can stop the slave and clean up.
+#
+# Note: it is important that slave is stopped at this
+# moment - otherwise master's cleanup statements
+# would be replicated on slave!
+#
+--echo # Cleanup (on slave).
+--source include/stop_slave.inc
+eval CHANGE MASTER TO MASTER_USER='$master_user';
+DROP USER 'plug_user';
+
+--echo # Cleanup (on master).
+--connection master
+DROP USER 'plug_user';
+
+--let $rpl_only_running_threads= 1
+--source include/rpl_end.inc

=== modified file 'mysql-test/t/execution_constants.test'
--- a/mysql-test/t/execution_constants.test	2010-11-17 10:16:13 +0000
+++ b/mysql-test/t/execution_constants.test	2011-08-22 11:58:49 +0000
@@ -38,7 +38,7 @@ while ($i)
 {
   # If we SEGV because the min stack size is exceeded, this would return error
   # 2013 .
-  error 0,1436 //
+  error 0,ER_STACK_OVERRUN_NEED_MORE //
   eval $query_head 0 $query_tail//
 
   if ($mysql_errno)
@@ -48,10 +48,10 @@ while ($i)
     # limit, we still have enough space reserved to report an error.
     let $i = 1//
 
-    # Check that mysql_errno is 1436
-    if ($mysql_errno != 1436)
+    # Check that mysql_errname is ER_STACK_OVERRUN_NEED_MORE
+    if ($mysql_errname != ER_STACK_OVERRUN_NEED_MORE)
     {
-      die Wrong error triggered, expected 1436 but got $mysql_errno//
+      die Wrong error triggered, expected ER_STACK_OVERRUN_NEED_MORE but got $mysql_errname//
     }
 
   }
@@ -76,7 +76,7 @@ while ($i)
 enable_result_log//
 enable_query_log//
 
-echo Assertion: mysql_errno 1436 == $mysql_errno//
+echo Assertion: mysql_errname ER_STACK_OVERRUN_NEED_MORE == $mysql_errname//
 
 delimiter ;//
 DROP TABLE `t_bug21476`;

=== modified file 'mysql-test/t/func_str.test'
--- a/mysql-test/t/func_str.test	2011-01-13 08:07:21 +0000
+++ b/mysql-test/t/func_str.test	2011-09-26 12:21:28 +0000
@@ -1437,5 +1437,24 @@ SELECT * FROM t1;
 DROP TABLE t1;
 
 --echo #
+--echo # Bug#12985030 SIMPLE QUERY WITH DECIMAL NUMBERS LEAKS MEMORY
+--echo #
+
+SELECT (rpad(1.0,2048,1)) IS NOT FALSE;
+SELECT ((+0) IN
+((0b111111111111111111111111111111111111111111111111111),(rpad(1.0,2048,1)),
+(32767.1)));
+SELECT ((rpad(1.0,2048,1)) = ('4(') ^ (0.1));
+
+--error 1690
+SELECT
+pow((rpad(10.0,2048,1)),(b'1111111111111111111111111111111111111111111'));
+SELECT ((rpad(1.0,2048,1)) + (0) ^ ('../'));
+SELECT stddev_samp(rpad(1.0,2048,1));
+SELECT ((127.1) not in ((rpad(1.0,2048,1)),(''),(-1.1)));
+SELECT ((0xf3) * (rpad(1.0,2048,1)) << (0xcc));
+
+
+--echo #
 --echo # End of 5.5 tests
 --echo #

=== modified file 'mysql-test/t/group_by.test'
--- a/mysql-test/t/group_by.test	2011-02-18 10:55:24 +0000
+++ b/mysql-test/t/group_by.test	2011-08-30 08:16:23 +0000
@@ -1284,6 +1284,20 @@ FROM t1 GROUP BY a;
 
 DROP TABLE t1;
 
+--echo #
+--echo # Bug#11765254 (58200): Assertion failed: param.sort_length when grouping
+--echo # by functions
+--echo #
+
+SET SQL_BIG_TABLES=1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (0),(0);
+SELECT 1 FROM t1 GROUP BY IF(`a`,'','');
+SELECT 1 FROM t1 GROUP BY TRIM(LEADING RAND() FROM '');
+SELECT 1 FROM t1 GROUP BY SUBSTRING('',SLEEP(0),'');
+SELECT 1 FROM t1 GROUP BY SUBSTRING(SYSDATE() FROM 'K' FOR 'jxW<');
+DROP TABLE t1;
+SET SQL_BIG_TABLES=0;
 
 --echo # End of 5.1 tests
 

=== modified file 'mysql-test/t/heap.test'
--- a/mysql-test/t/heap.test	2007-06-06 17:57:07 +0000
+++ b/mysql-test/t/heap.test	2011-09-27 12:08:51 +0000
@@ -454,7 +454,7 @@ drop table t1;
 #
 create table t1 (c char(10)) engine=memory;
 create table t2 (c varchar(10)) engine=memory;
---replace_column 8 #
+--replace_column 8 # 12 #
 show table status like 't_';
 drop table t1, t2;
 

=== modified file 'mysql-test/t/myisampack.test'
--- a/mysql-test/t/myisampack.test	2009-11-26 12:47:55 +0000
+++ b/mysql-test/t/myisampack.test	2011-09-16 12:21:05 +0000
@@ -221,3 +221,47 @@ DROP TABLE t1,t2,t3;
 DROP TABLE mysql_db1.t1;
 DROP DATABASE mysql_db1;
 
+--echo #
+--echo # BUG#11761180 - 53646: MYISAMPACK CORRUPTS TABLES WITH FULLTEXT INDEXES
+--echo #
+CREATE TABLE t1(a CHAR(4), FULLTEXT(a));
+INSERT INTO t1 VALUES('aaaa'),('bbbb'),('cccc');
+FLUSH TABLE t1;
+--exec $MYISAMPACK -sf $MYSQLD_DATADIR/test/t1
+--exec $MYISAMCHK -srq $MYSQLD_DATADIR/test/t1
+CHECK TABLE t1;
+SELECT * FROM t1 WHERE MATCH(a) AGAINST('aaaa' IN BOOLEAN MODE);
+SELECT * FROM t1 WHERE MATCH(a) AGAINST('aaaa');
+DROP TABLE t1;
+
+--echo # Test table with key_reflength > rec_reflength
+CREATE TABLE t1(a CHAR(30), FULLTEXT(a));
+--disable_query_log
+--echo # Populating a table, so it's index file exceeds 65K
+let $1=1700;
+while ($1)
+{
+  eval INSERT INTO t1 VALUES('$1aaaaaaaaaaaaaaaaaaaaaaaaaa');
+  dec $1;
+}
+
+--echo # Populating a table, so index file has second level fulltext tree
+let $1=60;
+while ($1)
+{
+  eval INSERT INTO t1 VALUES('aaaa'),('aaaa'),('aaaa'),('aaaa'),('aaaa');
+  dec $1;
+}
+--enable_query_log
+
+FLUSH TABLE t1;
+--echo # Compressing table
+--exec $MYISAMPACK -sf $MYSQLD_DATADIR/test/t1
+--echo # Fixing index (repair by sort)
+--exec $MYISAMCHK -srnq $MYSQLD_DATADIR/test/t1
+CHECK TABLE t1;
+FLUSH TABLE t1;
+--echo # Fixing index (repair with keycache)
+--exec $MYISAMCHK -soq $MYSQLD_DATADIR/test/t1
+CHECK TABLE t1;
+DROP TABLE t1;

=== modified file 'mysql-test/t/mysql_plugin.test'
--- a/mysql-test/t/mysql_plugin.test	2011-09-09 14:39:44 +0000
+++ b/mysql-test/t/mysql_plugin.test	2011-09-26 08:27:54 +0000
@@ -45,7 +45,6 @@ use File::Basename;
   my $plugindir_ini= "$ENV{PLUGIN_DIR}/daemon_example.ini";
   my $notfound= "";
   open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/mysqld.inc") or die;
-  print FILE "let \$MYSQLD= $mysqld;\n";
   print FILE "let \$MYSQLD_BASEDIR= $mysqld_basedir;\n";
   print FILE "let \$MYSQL_MY_PRINT_DEFAULTS_BASEDIR= $my_print_defaults_basedir;\n";
   if ((!-e $daemonexample_ini) || (!-r $daemonexample_ini))

=== modified file 'mysql-test/t/mysqld--defaults-file.test'
--- a/mysql-test/t/mysqld--defaults-file.test	2011-02-08 10:21:14 +0000
+++ b/mysql-test/t/mysqld--defaults-file.test	2011-09-15 11:18:12 +0000
@@ -5,21 +5,6 @@
 source include/not_embedded.inc;
 source include/not_windows.inc;
 
-# We need to use a plain "mysqld" without any other options to trigger
-# the bug. In particular, it seems that passing --bootstrap does not
-# trigger the bug. To do that, we extract the "command name" from the
-# MYSQLD_BOOTSTRAP_CMD variable and store that in a file, which we
-# then load into the test case.
-
-perl;
-  my ($mysqld)= split " ", $ENV{MYSQLD_BOOTSTRAP_CMD};
-  open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/mysqld.inc") or die;
-  print FILE "let \$MYSQLD= $mysqld;\n";
-  close FILE;
-EOF
-
-source $MYSQL_TMP_DIR/mysqld.inc;
-
 # All these tests refer to configuration files that do not exist
 
 --error 1
@@ -44,4 +29,3 @@ exec $MYSQLD --defaults-file=with.ext --
 --error 1
 exec $MYSQLD --defaults-file=no_extension --print-defaults 2>&1;
 
-remove_file $MYSQL_TMP_DIR/mysqld.inc;

=== modified file 'mysql-test/t/mysqltest.test'
--- a/mysql-test/t/mysqltest.test	2011-01-11 14:15:25 +0000
+++ b/mysql-test/t/mysqltest.test	2011-09-15 11:09:24 +0000
@@ -1,3 +1,14 @@
+# ----------------------------------------------------------------------------
+# $mysql_errno contains the return code of the last command
+# sent to the server.
+# ----------------------------------------------------------------------------
+# get $mysql_errno before the first statement
+#     $mysql_errno should be -1
+# get $mysql_errname as well
+
+echo $mysql_errno before test;
+echo $mysql_errname before test;
+
 -- source include/have_log_bin.inc
 
 # This test should work in embedded server after mysqltest is fixed
@@ -34,15 +45,6 @@
 # ============================================================================
 
 # ----------------------------------------------------------------------------
-# $mysql_errno contains the return code of the last command
-# sent to the server.
-# ----------------------------------------------------------------------------
-# get $mysql_errno before the first statement
-#     $mysql_errno should be -1
-eval select $mysql_errno as "before_use_test" ;
-
-
-# ----------------------------------------------------------------------------
 # Positive case(statement)
 # ----------------------------------------------------------------------------
 
@@ -134,6 +136,7 @@ select friedrich from (select 1 as otto)
 # check mysql_errno = 0 after successful statement
 # ----------------------------------------------------------------------------
 select otto from (select 1 as otto) as t1;
+echo $mysql_errname;
 eval select $mysql_errno as "after_successful_stmt_errno" ;
 
 #----------------------------------------------------------------------------
@@ -142,6 +145,7 @@ eval select $mysql_errno as "after_succe
 --error ER_PARSE_ERROR
 
 garbage ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_wrong_syntax_errno" ;
 
 # ----------------------------------------------------------------------------
@@ -151,6 +155,7 @@ eval select $mysql_errno as "after_wrong
 
 garbage ;
 let $my_var= 'abc' ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_let_var_equal_value" ;
 
 # ----------------------------------------------------------------------------
@@ -160,6 +165,7 @@ eval select $mysql_errno as "after_let_v
 
 garbage ;
 set @my_var= 'abc' ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_set_var_equal_value" ;
 
 # ----------------------------------------------------------------------------
@@ -170,6 +176,7 @@ eval select $mysql_errno as "after_set_v
 
 garbage ;
 --disable_warnings
+echo $mysql_errname;
 eval select $mysql_errno as "after_disable_warnings_command" ;
 
 # ----------------------------------------------------------------------------
@@ -182,6 +189,7 @@ drop table if exists t1 ;
 
 garbage ;
 drop table if exists t1 ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_disable_warnings" ;
 --enable_warnings
 
@@ -194,6 +202,7 @@ garbage ;
 --error ER_NO_SUCH_TABLE
 
 select 3 from t1 ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_minus_masked" ;
 --error ER_PARSE_ERROR
 
@@ -201,6 +210,7 @@ garbage ;
 --error ER_NO_SUCH_TABLE
 
 select 3 from t1 ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_!_masked" ;
 
 # ----------------------------------------------------------------------------
@@ -222,6 +232,7 @@ garbage ;
 --error ER_NO_SUCH_TABLE
 
 prepare stmt from "select 3 from t1" ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_failing_prepare" ;
 create table t1 ( f1 char(10));
 
@@ -230,6 +241,7 @@ create table t1 ( f1 char(10));
 
 garbage ;
 prepare stmt from "select 3 from t1" ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_successful_prepare" ;
 
 # successful execute
@@ -237,6 +249,7 @@ eval select $mysql_errno as "after_succe
 
 garbage ;
 execute stmt;
+echo $mysql_errname;
 eval select $mysql_errno as "after_successful_execute" ;
 
 # failing execute (table has been dropped)
@@ -247,6 +260,7 @@ garbage ;
 --error ER_NO_SUCH_TABLE
 
 execute stmt;
+echo $mysql_errname;
 eval select $mysql_errno as "after_failing_execute" ;
 
 # failing execute (unknown statement)
@@ -256,6 +270,7 @@ garbage ;
 --error ER_UNKNOWN_STMT_HANDLER
 
 execute __stmt_;
+echo $mysql_errname;
 eval select $mysql_errno as "after_failing_execute" ;
 
 # successful deallocate
@@ -263,6 +278,7 @@ eval select $mysql_errno as "after_faili
 
 garbage ;
 deallocate prepare stmt;
+echo $mysql_errname;
 eval select $mysql_errno as "after_successful_deallocate" ;
 
 # failing deallocate ( statement handle does not exist )
@@ -272,6 +288,7 @@ garbage ;
 --error ER_UNKNOWN_STMT_HANDLER
 
 deallocate prepare __stmt_;
+echo $mysql_errname;
 eval select $mysql_errno as "after_failing_deallocate" ;
 
 
@@ -299,6 +316,7 @@ eval select $mysql_errno as "after_faili
 
 garbage ;
 --disable_abort_on_error
+echo $mysql_errname;
 eval select $mysql_errno as "after_--disable_abort_on_error" ;
 
 # ----------------------------------------------------------------------------
@@ -316,6 +334,7 @@ select 3 from t1 ;
 --error ER_NO_SUCH_TABLE
 
 select 3 from t1 ;
+echo $mysql_errname;
 eval select $mysql_errno as "after_!errno_masked_error" ;
 # expected error <> response
 # --error 1000
@@ -335,12 +354,21 @@ eval select $mysql_errno as "after_!errn
 EOF
 
 # ----------------------------------------------------------------------------
+# Check backtick and query_get_value, result should be empty
+# ----------------------------------------------------------------------------
+let $empty= `garbage`;
+echo $empty is empty;
+let $empty= query_get_value(nonsense, blabla, 1);
+echo $empty is empty;
+
+# ----------------------------------------------------------------------------
 # Switch the abort on error on and check the effect on $mysql_errno
 # ----------------------------------------------------------------------------
 --error ER_PARSE_ERROR
 
 garbage ;
 --enable_abort_on_error
+echo $mysql_errname;
 eval select $mysql_errno as "after_--enable_abort_on_error" ;
 
 # ----------------------------------------------------------------------------
@@ -363,6 +391,71 @@ select 3 from t1 ;
 --error 1
 --exec echo "disable_abort_on_error; enable_abort_on_error; error 1064; select 3 from t1; select 3 from t1;" | $MYSQL_TEST  2>&1
 
+# ----------------------------------------------------------------------------
+# Test --enable and --disable with ONCE
+# ----------------------------------------------------------------------------
+
+--disable_abort_on_error ONCE
+garbage;
+--disable_abort_on_error ONCE
+--remove_file DoesNotExist
+
+--disable_result_log
+select 2;
+--enable_result_log ONCE
+select 3;
+select 5;
+--enable_result_log
+
+# ----------------------------------------------------------------------------
+# Test cumulative ONCE
+# ----------------------------------------------------------------------------
+
+--disable_abort_on_error ONCE
+--disable_query_log ONCE
+select 3 from t1;
+select 7;
+
+--error 1
+--exec echo "--disable_info OCNE" | $MYSQL_TEST 2>&1
+
+--enable_connect_log ONCE
+connect (con1,localhost,root,,);
+connection default;
+disconnect con1;
+
+# ----------------------------------------------------------------------------
+# Test ONCE can be combined with --error or modifiers like lowercase
+# ----------------------------------------------------------------------------
+
+--disable_result_log ONCE
+--error ER_NO_SUCH_TABLE
+select 5 from t1;
+
+--disable_query_log ONCE
+--lowercase_result
+select "CASE" as "LOWER";
+
+--sorted_result
+--disable_query_log ONCE
+select "xyz" as name union select "abc" as name order by name desc;
+
+# ----------------------------------------------------------------------------
+# Test --error with backtick operator or query_get_value
+# ----------------------------------------------------------------------------
+
+--error 0,ER_NO_SUCH_TABLE
+let $empty= `SELECT foo from bar`;
+echo $empty is empty;
+
+--error 0,ER_BAD_FIELD_ERROR
+let $empty= query_get_value(SELECT bar as foo, baz, 1);
+echo $empty is empty;
+
+--error 0,ER_NO_SUCH_TABLE
+if (!`SELECT foo from bar`) {
+  echo "Yes it's empty";
+}
 
 # ----------------------------------------------------------------------------
 # Test comments
@@ -932,10 +1025,9 @@ while ($outer)
     --source $MYSQLTEST_VARDIR/tmp/sourced.inc
     --error ER_NO_SUCH_TABLE
     SELECT * from nowhere;
-    --disable_abort_on_error
+    --disable_abort_on_error ONCE
 # Statement giving a different error, to make sure we don't mask it
     SELECT * FROM nowhere else;
-    --enable_abort_on_error
   }
   dec $outer;
   inc $ifval;
@@ -1084,9 +1176,8 @@ system echo "hej" > /dev/null;
 --error 1
 --exec echo "system $NONEXISTSINFVAREABLI;" | $MYSQL_TEST 2>&1
 
---disable_abort_on_error
+--disable_abort_on_error ONCE
 system NonExistsinfComamdn 2> /dev/null;
---enable_abort_on_error
 
 
 # ----------------------------------------------------------------------------
@@ -2497,10 +2588,9 @@ INSERT INTO t1 SELECT f1 - 64 FROM t1;
 INSERT INTO t1 SELECT f1 - 128 FROM t1;
 INSERT INTO t1 SELECT f1 - 256 FROM t1;
 INSERT INTO t1 SELECT f1 - 512 FROM t1;
---disable_result_log
+--disable_result_log ONCE
 --sorted_result
 SELECT * FROM t1;
---enable_result_log
 DROP TABLE t1;
 
 # ----------------------------------------------------------------------------
@@ -2548,11 +2638,9 @@ SELECT 0 as "WILL NOT lower case ��;
 --exec $MYSQL_TEST --help 2>&1 > /dev/null
 --exec $MYSQL_TEST --version 2>&1 > /dev/null
 --enable_query_log
---disable_abort_on_error
+--disable_abort_on_error ONCE
 --error 1
 --exec $MYSQL_TEST a b c 2>&1 > /dev/null
---enable_abort_on_error
---enable_query_log
 
 # ----------------------------------------------------------------------------
 # test for query_get_value

=== modified file 'mysql-test/t/show_check.test'
--- a/mysql-test/t/show_check.test	2011-03-30 12:55:53 +0000
+++ b/mysql-test/t/show_check.test	2011-09-27 12:14:31 +0000
@@ -295,37 +295,37 @@ CREATE TABLE t3 (
 insert into t1 values (1),(2);
 insert into t2 values (1),(2);
 insert into t3 values (1,1),(2,2);
---replace_column 6 # 7 # 8 # 9 #
+--replace_column 6 # 7 # 8 # 9 # 12 #
 show table status;
 insert into t1 values (3),(4);
 insert into t2 values (3),(4);
 insert into t3 values (3,3),(4,4);
---replace_column 6 # 7 # 8 # 9 #
+--replace_column 6 # 7 # 8 # 9 # 12 #
 show table status;
 insert into t1 values (5);
 insert into t2 values (5);
 insert into t3 values (5,5);
---replace_column 6 # 7 # 8 # 9 #
+--replace_column 6 # 7 # 8 # 9 # 12 #
 show table status;
 delete from t1 where a=3;
 delete from t2 where b=3;
 delete from t3 where a=3;
---replace_column 6 # 7 # 8 # 9 # 10 #
+--replace_column 6 # 7 # 8 # 9 # 10 # 12 #
 show table status;
 truncate table t1;
 truncate table t2;
 truncate table t3;
---replace_column 6 # 7 # 8 # 9 #
+--replace_column 6 # 7 # 8 # 9 # 12 #
 show table status;
 insert into t1 values (5);
 insert into t2 values (5);
 insert into t3 values (5,5);
---replace_column 6 # 7 # 8 # 9 #
+--replace_column 6 # 7 # 8 # 9 # 12 #
 show table status;
 delete from t1 where a=5;
 delete from t2 where b=5;
 delete from t3 where a=5;
---replace_column 6 # 7 # 8 # 9 # 10 #
+--replace_column 6 # 7 # 8 # 9 # 10 # 12 #
 show table status;
 
 drop table t1, t2, t3;
@@ -443,7 +443,7 @@ flush tables;
 # Create a junk frm file on disk
 let $MYSQLD_DATADIR= `select @@datadir`;
 system echo "this is a junk file for test" >> $MYSQLD_DATADIR/test/t1.frm ;
---replace_column 6 # 7 # 8 # 9 #
+--replace_column 6 # 7 # 8 # 9 # 12 #
 SHOW TABLE STATUS like 't1';
 --error ER_NOT_FORM_FILE
 show create table t1;
@@ -1073,7 +1073,7 @@ set names latin1;
 SET NAMES latin1;
 CREATE DATABASE `e_column 6 # 7 # 8 # 9 #
+--replace_column 6 # 7 # 8 # 9 # 12 #
 SHOW TABLE STATUS FROM `�LIKE '�
 DROP DATABASE `�
 

=== modified file 'mysql-test/t/sp_trans.test'
--- a/mysql-test/t/sp_trans.test	2010-10-06 14:34:28 +0000
+++ b/mysql-test/t/sp_trans.test	2011-08-08 16:45:43 +0000
@@ -598,6 +598,39 @@ select distinct f1, bug13575(f1) from t3
 drop function bug13575|
 drop table t3|
 
+#
+# BUG#11758414: Default storage_engine not honored when set
+#               from within a stored procedure
+#
+SELECT @@GLOBAL.storage_engine INTO @old_engine|
+SET @@GLOBAL.storage_engine=InnoDB|
+SET @@SESSION.storage_engine=InnoDB|
+# show defaults at define-time
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+CREATE PROCEDURE bug11758414()
+BEGIN
+ SET @@GLOBAL.storage_engine="MyISAM";
+ SET @@SESSION.storage_engine="MyISAM"; 
+ # show defaults at execution time / that setting them worked
+ SHOW GLOBAL VARIABLES LIKE 'storage_engine';
+ SHOW SESSION VARIABLES LIKE 'storage_engine';
+ CREATE TABLE t1 (id int);
+ CREATE TABLE t2 (id int) ENGINE=InnoDB;
+ # show we're heeding the default (at run-time, not parse-time!)
+ SHOW CREATE TABLE t1;
+ # show that we didn't break explicit override with ENGINE=...
+ SHOW CREATE TABLE t2;
+END;
+|
+CALL bug11758414|
+# show that changing defaults within SP stuck
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+DROP PROCEDURE bug11758414|
+DROP TABLE t1, t2|
+SET @@GLOBAL.storage_engine=@old_engine|
+
 --echo #
 --echo # End of 5.1 tests
 --echo #

=== modified file 'mysql-test/t/type_newdecimal.test'
--- a/mysql-test/t/type_newdecimal.test	2011-05-12 03:05:12 +0000
+++ b/mysql-test/t/type_newdecimal.test	2011-08-29 09:34:48 +0000
@@ -1535,3 +1535,17 @@ DROP TABLE IF EXISTS t1;
 
 
 --echo End of 5.1 tests
+
+--echo #
+--echo # BUG#12911710 - VALGRIND FAILURE IN 
+--echo # ROW-DEBUG:PERFSCHEMA.SOCKET_SUMMARY_BY_INSTANCE_FUNC 
+--echo #
+
+CREATE TABLE t1(d1 DECIMAL(60,0) NOT NULL,
+                d2 DECIMAL(60,0) NOT NULL);
+
+INSERT INTO t1 (d1, d2) VALUES(0.0, 0.0);
+SELECT d1 * d2 FROM t1;
+
+DROP TABLE t1;
+

=== modified file 'mysql-test/valgrind.supp'
--- a/mysql-test/valgrind.supp	2011-06-30 15:46:53 +0000
+++ b/mysql-test/valgrind.supp	2011-09-05 14:04:33 +0000
@@ -876,3 +876,46 @@
    fun:buf_buddy_free_low
    fun:buf_buddy_free
 }
+
+# Note the wildcard in the (mangled) function signatures of
+# write_keys() and find_all_keys().
+# They both return ha_rows, which is platform dependent.
+#
+# The '...' wildcards are for 'fun:inline_mysql_file_write' which *may*
+# be inlined.
+{
+   Bug#12856915 VALGRIND FAILURE IN FILESORT/CREATE_SORT_INDEX / one
+   Memcheck:Param
+   write(buf)
+   obj:*/libpthread*.so
+   fun:my_write
+   ...
+   fun:my_b_flush_io_cache
+   fun:_my_b_write
+   fun:_Z*10write_keysP13st_sort_paramPPhjP11st_io_cacheS4_
+   fun:_Z*13find_all_keysP13st_sort_paramP10SQL_SELECTPPhP11st_io_cacheS6_S6_
+   fun:_Z8filesortP3THDP5TABLEP13st_sort_fieldjP10SQL_SELECTybPy
+}
+
+{
+   Bug#12856915 VALGRIND FAILURE IN FILESORT/CREATE_SORT_INDEX / two
+   Memcheck:Param
+   write(buf)
+   obj:*/libpthread*.so
+   fun:my_write
+   ...
+   fun:my_b_flush_io_cache
+   fun:_Z15merge_many_buffP13st_sort_paramPhP10st_buffpekPjP11st_io_cache
+   fun:_Z8filesortP3THDP5TABLEP13st_sort_fieldjP10SQL_SELECTybPy
+}
+
+{
+   Bug#12856915 VALGRIND FAILURE IN FILESORT/CREATE_SORT_INDEX / three
+   Memcheck:Param
+   write(buf)
+   obj:*/libpthread*.so
+   fun:my_write
+   ...
+   fun:my_b_flush_io_cache
+   fun:_Z8filesortP3THDP5TABLEP13st_sort_fieldjP10SQL_SELECTybPy
+}

=== modified file 'mysys/my_handler_errors.h'
--- a/mysys/my_handler_errors.h	2011-06-30 15:46:53 +0000
+++ b/mysys/my_handler_errors.h	2011-09-01 18:48:04 +0000
@@ -81,7 +81,9 @@ static const char *handler_error_message
   "File to short; Expected more data in file",
   "Read page with wrong checksum",
   "Too many active concurrent transactions",
-  "Index column length exceeds limit"
+  "Index column length exceeds limit",
+  "Index corrupted",
+  "Undo record too big"
 };
 
 extern void my_handler_error_register(void);

=== modified file 'plugin/semisync/semisync_master.cc'
--- a/plugin/semisync/semisync_master.cc	2011-06-30 15:46:53 +0000
+++ b/plugin/semisync/semisync_master.cc	2011-09-08 10:10:26 +0000
@@ -312,18 +312,18 @@ int ActiveTranx::clear_active_tranx_node
  * The most important functions during semi-syn replication listed:
  *
  * Master:
- *  . reportReplyBinlog(): called by the binlog dump thread when it receives
- *                         the slave's status information.
- *  . updateSyncHeader():  based on transaction waiting information, decide
- *                         whether to request the slave to reply.
- *  . writeTraxInBinlog(): called by the transaction thread when it finishes
- *                         writing all transaction events in binlog.
- *  . commitTrx():         transaction thread wait for the slave reply.
+ *  . reportReplyBinlog():  called by the binlog dump thread when it receives
+ *                          the slave's status information.
+ *  . updateSyncHeader():   based on transaction waiting information, decide
+ *                          whether to request the slave to reply.
+ *  . writeTranxInBinlog(): called by the transaction thread when it finishes
+ *                          writing all transaction events in binlog.
+ *  . commitTrx():          transaction thread wait for the slave reply.
  *
  * Slave:
  *  . slaveReadSyncHeader(): read the semi-sync header from the master, get the
- *                         sync status and get the payload for events.
- *  . slaveReply():        reply to the master about the replication progress.
+ *                           sync status and get the payload for events.
+ *  . slaveReply():          reply to the master about the replication progress.
  *
  ******************************************************************************/
 

=== modified file 'scripts/CMakeLists.txt'
--- a/scripts/CMakeLists.txt	2010-11-13 22:16:52 +0000
+++ b/scripts/CMakeLists.txt	2011-09-13 10:32:53 +0000
@@ -1,4 +1,4 @@
-# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -65,7 +65,7 @@ ADD_CUSTOM_TARGET(GenFixPrivs
 
 IF(UNIX)
  FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/make_binary_distribution 
-   "cd ${CMAKE_BINARY_DIR} && '${CMAKE_CPACK_COMMAND}' -G TGZ --config CPackConfig.cmake" )
+   "cd ${CMAKE_BINARY_DIR} && '${CMAKE_CPACK_COMMAND}' -G TGZ --config CPackConfig.cmake\n" )
  EXECUTE_PROCESS(
   COMMAND chmod +x ${CMAKE_CURRENT_BINARY_DIR}/make_binary_distribution
 )
@@ -104,11 +104,11 @@ IF(UNIX)
   # FIND_PROC and CHECK_PID are used by mysqld_safe
 IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
   SET (FIND_PROC 
-    "ps wwwp $PID | grep -v \" grep\" | grep -v mysqld_safe | grep -- \"$MYSQLD\" > /dev/null")
+    "ps wwwp $PID | grep -v mysqld_safe | grep -- $MYSQLD > /dev/null")
 ENDIF()
 IF(NOT FIND_PROC AND CMAKE_SYSTEM_NAME MATCHES "SunOS")
   SET (FIND_PROC 
-    "ps -p $PID | grep -v \" grep\" | grep -v mysqld_safe | grep -- \"$MYSQLD\" > /dev/null")
+    "ps -p $PID | grep -v mysqld_safe | grep -- $MYSQLD > /dev/null")
 ENDIF()
 
 IF(NOT FIND_PROC)
@@ -116,7 +116,7 @@ IF(NOT FIND_PROC)
   EXECUTE_PROCESS(COMMAND ps -uaxww OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE result)
   IF(result MATCHES 0) 
      SET( FIND_PROC
-        "ps -uaxww | grep -v \" grep\" | grep -v mysqld_safe | grep -- \"$MYSQLD\" | grep \" $PID \" > /dev/null")
+       "ps -uaxww | grep -v mysqld_safe | grep -- $MYSQLD | grep $PID > /dev/null")
   ENDIF()
 ENDIF()
 
@@ -124,7 +124,7 @@ IF(NOT FIND_PROC)
   # SysV style
   EXECUTE_PROCESS(COMMAND ps -ef OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE result)
   IF(result MATCHES 0)
-    SET( FIND_PROC "ps -ef | grep -v \" grep\" | grep -v mysqld_safe | grep -- \"$MYSQLD\" | grep \" $PID \" > /dev/null")
+    SET( FIND_PROC "ps -ef | grep -v mysqld_safe | grep -- $MYSQLD | grep $PID > /dev/null")
   ENDIF()
 ENDIF()
   

=== removed file 'scripts/make_binary_distribution.sh'
--- a/scripts/make_binary_distribution.sh	2011-06-30 15:46:53 +0000
+++ b/scripts/make_binary_distribution.sh	1970-01-01 00:00:00 +0000
@@ -1,342 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
-# 
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-##############################################################################
-#
-#  This is a script to create a TAR or ZIP binary distribution out of a
-#  built source tree. The output file will be put at the top level of
-#  the source tree, as "mysql-<vsn>....{tar.gz,zip}"
-#
-#  Note that the structure created by this script is slightly different from
-#  what a normal "make install" would produce. No extra "mysql" sub directory
-#  will be created, i.e. no "$prefix/include/mysql", "$prefix/lib/mysql" or
-#  "$prefix/share/mysql".  This is because the build system explicitly calls
-#  make with pkgdatadir=<datadir>, etc.
-#
-#  In GNU make/automake terms
-#
-#    "pkglibdir"     is set to the same as "libdir"
-#    "pkgincludedir" is set to the same as "includedir"
-#    "pkgdatadir"    is set to the same as "datadir"
-#    "pkgplugindir"  is set to "$pkglibdir/plugin"
-#    "pkgsuppdir"    is set to "@prefix@/support-files",
-#                    normally the same as "datadir"
-#
-#  The temporary directory path given to "--tmp=<path>" has to be
-#  absolute and with no spaces.
-#
-#  Note that for best result, the original "make" should be done with
-#  the same arguments as used for "make install" below, especially the
-#  'pkglibdir', as the RPATH should to be set correctly.
-#
-##############################################################################
-
-##############################################################################
-#
-#  Read the command line arguments that control this script
-#
-##############################################################################
-
-machine=@MACHINE_TYPE@
-system=@SYSTEM_TYPE@
-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
-MALLOC_LIB=
-PLATFORM=""
-TMP=/tmp
-NEW_NAME=""			# Final top directory and TAR package name
-SUFFIX=""
-SHORT_PRODUCT_TAG=""		# If don't want server suffix in package name
-NDBCLUSTER=""			# Option ignored
-
-for arg do
-  case "$arg" in
-    --tmp=*)    TMP=`echo "$arg" | sed -e "s;--tmp=;;"` ;;
-    --suffix=*) SUFFIX=`echo "$arg" | sed -e "s;--suffix=;;"` ;;
-    --short-product-tag=*) SHORT_PRODUCT_TAG=`echo "$arg" | sed -e "s;--short-product-tag=;;"` ;;
-    --inject-malloc-lib=*) MALLOC_LIB=`echo "$arg" | sed -e 's;^[^=]*=;;'` ;;
-    --no-strip) STRIP=0 ;;
-    --machine=*) machine=`echo "$arg" | sed -e "s;--machine=;;"` ;;
-    --platform=*) PLATFORM=`echo "$arg" | sed -e "s;--platform=;;"` ;;
-    --silent)   SILENT=1 ;;
-    --with-ndbcluster) NDBCLUSTER=1 ;;
-    *)
-      echo "Unknown argument '$arg'"
-      exit 1
-      ;;
-  esac
-done
-
-# ----------------------------------------------------------------------
-# Adjust "system" output from "uname" to be more human readable
-# ----------------------------------------------------------------------
-
-if [ x"$PLATFORM" = x"" ] ; then
-  # FIXME move this to the build tools
-  # Remove vendor from $system
-  system=`echo $system | sed -e 's/[a-z]*-\(.*\)/\1/g'`
-
-  # Map OS names to "our" OS names (eg. darwin6.8 -> osx10.2)
-  system=`echo $system | sed -e 's/darwin6.*/osx10.2/g'`
-  system=`echo $system | sed -e 's/darwin7.*/osx10.3/g'`
-  system=`echo $system | sed -e 's/darwin8.*/osx10.4/g'`
-  system=`echo $system | sed -e 's/darwin9.*/osx10.5/g'`
-  system=`echo $system | sed -e 's/\(aix4.3\).*/\1/g'`
-  system=`echo $system | sed -e 's/\(aix5.1\).*/\1/g'`
-  system=`echo $system | sed -e 's/\(aix5.2\).*/\1/g'`
-  system=`echo $system | sed -e 's/\(aix5.3\).*/\1/g'`
-  system=`echo $system | sed -e 's/osf5.1b/tru64/g'`
-  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
-
-# Print the platform name for build logs
-echo "PLATFORM NAME: $PLATFORM"
-
-# Change the distribution to a long descriptive name
-# For the cluster product, concentrate on the second part
-VERSION_NAME=@VERSION@
-case $VERSION_NAME in
-  *-ndb-* )  VERSION_NAME=`echo $VERSION_NAME | sed -e 's/[.0-9]*-ndb-//'` ;;
-esac
-if [ x"$SHORT_PRODUCT_TAG" != x"" ] ; then
-  NEW_NAME=mysql-$SHORT_PRODUCT_TAG-$VERSION_NAME-$PLATFORM$SUFFIX
-else
-  NEW_NAME=mysql@MYSQL_SERVER_SUFFIX@-$VERSION_NAME-$PLATFORM$SUFFIX
-fi
-
-# ----------------------------------------------------------------------
-# Define BASE, and remove the old BASE directory if any
-# ----------------------------------------------------------------------
-BASE=$TMP/my_dist$SUFFIX
-if [ -d $BASE ] ; then
- rm -rf $BASE
-fi
-
-# ----------------------------------------------------------------------
-# Find the TAR to use
-# ----------------------------------------------------------------------
-
-# This is needed to prefer GNU tar over platform tar because that can't
-# always handle long filenames
-
-PATH_DIRS=`echo $PATH | \
-    sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' `
-
-which_1 ()
-{
-  for cmd
-  do
-    for d in $PATH_DIRS
-    do
-      for file in $d/$cmd
-      do
-        if [ -x $file -a ! -d $file ] ; then
-          echo $file
-          exit 0
-        fi
-      done
-    done
-  done
-  exit 1
-}
-
-tar=`which_1 gnutar gtar`
-if [ $? -ne 0 -o x"$tar" = x"" ] ; then
-  tar=tar
-fi
-
-
-##############################################################################
-#
-#  Handle the Unix/Linux packaging using "make install"
-#
-##############################################################################
-
-# ----------------------------------------------------------------------
-# Terminate on any base level error
-# ----------------------------------------------------------------------
-set -e
-
-# ----------------------------------------------------------------------
-# Really ugly, one script, "mysql_install_db", needs prefix set to ".",
-# i.e. makes access relative the current directory. This matches
-# the documentation, so better not change this. And for another script,
-# "mysql.server", we make some relative, others not.
-# ----------------------------------------------------------------------
-
-cd scripts
-rm -f mysql_install_db
-@MAKE@ mysql_install_db \
-  prefix=. \
-  bindir=./bin \
-  sbindir=./bin \
-  scriptdir=./bin \
-  libexecdir=./bin \
-  pkgdatadir=./share \
-  localstatedir=./data
-cd ..
-
-cd support-files
-rm -f mysql.server
-@MAKE@ mysql.server \
-  bindir=./bin \
-  sbindir=./bin \
-  scriptdir=./bin \
-  libexecdir=./bin \
-  pkgdatadir=@pkgdatadir@
-cd ..
-
-# ----------------------------------------------------------------------
-# Do a install that we later are to pack. Use the same paths as in
-# the build for the relevant directories.
-# ----------------------------------------------------------------------
-@MAKE@ DESTDIR=$BASE install \
-  pkglibdir=@pkglibdir@ \
-  pkgincludedir=@pkgincludedir@ \
-  pkgdatadir=@pkgdatadir@ \
-  pkgplugindir=@pkgplugindir@ \
-  pkgsuppdir=@pkgsuppdir@ \
-  mandir=@mandir@ \
-  infodir=@infodir@
-
-# ----------------------------------------------------------------------
-# Rename top directory, and set DEST to the new directory
-# ----------------------------------------------------------------------
-mv $BASE@prefix@ $BASE/$NEW_NAME
-DEST=$BASE/$NEW_NAME
-
-# ----------------------------------------------------------------------
-# If we compiled with gcc, copy libgcc.a to the dist as libmygcc.a
-# ----------------------------------------------------------------------
-if [ x"@GXX@" = x"yes" ] ; then
-  gcclib=`@CC@ @CFLAGS@ --print-libgcc-file 2>/dev/null` || true
-  if [ -z "$gcclib" ] ; then
-    echo "Warning: Compiler doesn't tell libgcc.a!"
-  elif [ -f "$gcclib" ] ; then
-    $CP $gcclib $DEST/lib/libmygcc.a
-  else
-    echo "Warning: Compiler result '$gcclib' not found / no file!"
-  fi
-fi
-
-# If requested, add a malloc library .so into pkglibdir for use
-# by mysqld_safe
-if [ -n "$MALLOC_LIB" ]; then
-  cp "$MALLOC_LIB" "$DEST/lib/"
-fi
-
-# FIXME let this script be in "bin/", where it is in the RPMs?
-# http://dev.mysql.com/doc/refman/5.1/en/mysql-install-db-problems.html
-mkdir $DEST/scripts
-mv $DEST/bin/mysql_install_db $DEST/scripts/
-
-# Note, no legacy "safe_mysqld" link to "mysqld_safe" in 5.1
-
-# Copy readme and license files
-cp README Docs/INSTALL-BINARY  $DEST/
-if [ -f COPYING ] ; then
-  cp COPYING $DEST/
-elif [ -f LICENSE.mysql ] ; then
-  cp LICENSE.mysql $DEST/
-else
-  echo "ERROR: no license files found"
-  exit 1
-fi
-
-# FIXME should be handled by make file, and to other dir
-mkdir -p $DEST/bin $DEST/support-files
-cp scripts/mysqlaccess.conf $DEST/bin/
-cp support-files/magic      $DEST/support-files/
-
-# Create empty data directories, set permission (FIXME why?)
-mkdir       $DEST/data $DEST/data/mysql $DEST/data/test
-chmod o-rwx $DEST/data $DEST/data/mysql $DEST/data/test
-
-# ----------------------------------------------------------------------
-# Create the result tar file
-# ----------------------------------------------------------------------
-
-echo "Using $tar to create archive"
-OPT=cvf
-if [ x$SILENT = x1 ] ; then
-  OPT=cf
-fi
-
-echo "Creating and compressing archive"
-rm -f $NEW_NAME.tar.gz
-(cd $BASE ; $tar $OPT -  $NEW_NAME) | gzip -9 > $NEW_NAME.tar.gz
-echo "$NEW_NAME.tar.gz created"
-
-echo "Removing temporary directory"
-rm -rf $BASE
-exit 0

=== removed file 'scripts/make_win_bin_dist'
--- a/scripts/make_win_bin_dist	2011-07-03 23:48:19 +0000
+++ b/scripts/make_win_bin_dist	1970-01-01 00:00:00 +0000
@@ -1,425 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
-# 
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-# 
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-# Exit if failing to copy, we want exact specifications, not
-# just "what happen to be built".
-set -e
-
-# ----------------------------------------------------------------------
-# Read first argument that is the base name of the resulting TAR file.
-# See usage() function below for a description on the arguments.
-#
-# NOTE: We will read the rest of the command line later on.
-# NOTE: Pattern matching with "{..,..}" can't be used, not portable.
-# ----------------------------------------------------------------------
-
-# FIXME why "libmysql.dll" installed both in "bin" and "lib/opt"?
-
-usage()
-{
-  echo <<EOF
-Usage: make_win_bin_dist [ options ] package-base-name [ copy-defs... ]
-
-This is a script to run from the top of a source tree built on Windows.
-The "package-base-name" argument should be something like
-
-  mysql-noinstall-5.0.25-win32  (or winx64)
-
-and will become the name of the directory of the unpacked ZIP (stripping
-away the "noinstall" part of the ZIP file name if any) and the base
-for the resulting package name.
-
-Options are
-
-  --embedded       Pack the embedded server and give error if not built.
-                   The default is to pack it if it is built.
-
-  --no-embedded    Don't pack the embedded server even if built
-
-  --debug          Pack the debug binaries and give error if not built.
-                   The default is to pack them if they are built.
-
-  --no-debug       Don't pack the debug binaries even if built
-
-  --only-debug     The target for this build was "Debug", and we just
-                   want to replace the normal binaries with debug
-                   versions, i.e. no separate "debug" directories.
-
-  --exe-suffix=SUF Add a suffix to the filename part of the "mysqld" binary.
-
-As you might want to include files of directories from other builds
-(like a "mysqld-max.exe" server), you can instruct this script to copy
-them in for you. This is the "copy-def" arguments, and they are of the
-form
-
-  relative-dest-name=source-name .....
-
-i.e. can be something like
-
-  bin/mysqld-max.exe=../my-max-build/sql/release/mysqld.exe
-
-If you specify a directory the whole directory will be copied.
-
-EOF
-  exit 1
-}
-
-# ----------------------------------------------------------------------
-# We need to be at the top of a source tree, check that we are
-# ----------------------------------------------------------------------
-
-if [ ! -d "sql" ] ; then
-  echo "You need to run this script from inside the source tree"
-  usage
-fi
-
-# ----------------------------------------------------------------------
-# Actual argument processing, first part
-# ----------------------------------------------------------------------
-
-NOINST_NAME=""
-TARGET="release"
-PACK_EMBEDDED=""		# Could be "no", "yes" or empty
-PACK_DEBUG=""			# Could be "no", "yes" or empty
-EXE_SUFFIX=""
-
-for arg do
-  shift
-  case "$arg" in
-    --embedded)       PACK_EMBEDDED="yes" ;;
-    --no-embedded)    PACK_EMBEDDED="no" ;;
-    --debug)          PACK_DEBUG="yes" ;;
-    --no-debug)       PACK_DEBUG="no" ;;
-    --only-debug)     TARGET="debug" ; PACK_DEBUG="no" ;;
-    --exe-suffix=*)   EXE_SUFFIX=`echo "$arg" | sed -e "s,--exe-suffix=,,"` ;;
-    -*)
-      echo "Unknown argument '$arg'"
-      usage
-      ;;
-    *)
-      NOINST_NAME="$arg"
-      break
-  esac
-done
-
-if [ x"$NOINST_NAME" = x"" ] ; then
-  echo "No base package name given"
-  usage
-fi
-DESTDIR=`echo $NOINST_NAME | sed 's/-noinstall-/-/'`
-
-if [ -e $DESTDIR ] ; then
-  echo "Please remove the old $DESTDIR before running this script"
-  usage
-fi
-
-trap 'echo "Cleaning up and exiting..." ; rm -fr $DESTDIR; exit 1' ERR
-
-# ----------------------------------------------------------------------
-# Adjust target name if needed, release with debug info has another name
-# ----------------------------------------------------------------------
-
-if [ x"$TARGET" = x"release" -a -f "client/relwithdebinfo/mysql.exe" ]
-then
-  TARGET="relwithdebinfo"
-fi
-
-# ----------------------------------------------------------------------
-# Copy executables, and client DLL
-# ----------------------------------------------------------------------
-
-mkdir $DESTDIR
-mkdir $DESTDIR/bin
-cp client/$TARGET/*.exe                                  $DESTDIR/bin/
-cp extra/$TARGET/*.exe                                   $DESTDIR/bin/
-cp storage/myisam/$TARGET/*.exe                          $DESTDIR/bin/
-if [ x"$TARGET" != x"release" ] ; then
-  cp client/$TARGET/mysql.pdb                            $DESTDIR/bin/
-  cp client/$TARGET/mysqladmin.pdb                       $DESTDIR/bin/
-  cp client/$TARGET/mysqlbinlog.pdb                      $DESTDIR/bin/
-  cp client/$TARGET/mysqldump.pdb                        $DESTDIR/bin/
-  cp client/$TARGET/mysqlimport.pdb                      $DESTDIR/bin/
-  cp client/$TARGET/mysqlshow.pdb                        $DESTDIR/bin/
-fi
-cp tests/$TARGET/*.exe                                   $DESTDIR/bin/
-cp libmysql/$TARGET/libmysql.dll                         $DESTDIR/bin/
-
-cp sql/$TARGET/mysqld.exe                $DESTDIR/bin/mysqld$EXE_SUFFIX.exe
-if [ x"$TARGET" != x"release" ] ; then
-  cp sql/$TARGET/mysqld.pdb              $DESTDIR/bin/mysqld$EXE_SUFFIX.pdb
-fi
-
-if [ x"$PACK_DEBUG" = x"" -a -f "sql/debug/mysqld.exe" -o \
-     x"$PACK_DEBUG" = x"yes" ] ; then
-  cp sql/debug/mysqld.exe                $DESTDIR/bin/mysqld-debug.exe
-  cp sql/debug/mysqld.pdb                $DESTDIR/bin/mysqld-debug.pdb
-fi
-
-# ----------------------------------------------------------------------
-# Copy data directory, readme files etc
-# ----------------------------------------------------------------------
-
-if [ -d win/data ] ; then
-  cp -pR win/data $DESTDIR/
-fi
-
-mkdir $DESTDIR/Docs
-cp Docs/INSTALL-BINARY    $DESTDIR/Docs/
-cp Docs/manual.chm        $DESTDIR/Docs/ || /bin/true
-cp ChangeLog              $DESTDIR/Docs/ || /bin/true
-cp support-files/my-*.ini $DESTDIR/
-cp README                 $DESTDIR/
-
-if [ -f COPYING ] ; then
-  cp COPYING $DESTDIR/
-  cp COPYING $DESTDIR/Docs/
-fi
-
-# ----------------------------------------------------------------------
-# These will be filled in when we enable embedded. Note that if no
-# argument is given, it is copied if exists, else a check is done.
-# ----------------------------------------------------------------------
-
-copy_embedded()
-{
-  mkdir -p $DESTDIR/Embedded/DLL/release \
-           $DESTDIR/Embedded/static/release \
-           $DESTDIR/include
-  cp libmysqld/libmysqld.def           $DESTDIR/include/
-  cp libmysqld/$TARGET/mysqlserver.lib $DESTDIR/Embedded/static/release/
-  cp libmysqld/$TARGET/libmysqld.dll   $DESTDIR/Embedded/DLL/release/
-  cp libmysqld/$TARGET/libmysqld.exp   $DESTDIR/Embedded/DLL/release/
-  cp libmysqld/$TARGET/libmysqld.lib   $DESTDIR/Embedded/DLL/release/
-  if [ x"$TARGET" != x"release" ] ; then
-    cp libmysqld/$TARGET/mysqlserver.pdb $DESTDIR/Embedded/static/release/
-    cp libmysqld/$TARGET/libmysqld.pdb   $DESTDIR/Embedded/DLL/release/
-  fi
-
-  if [ x"$PACK_DEBUG" = x"" -a -f "libmysqld/debug/libmysqld.lib" -o \
-       x"$PACK_DEBUG" = x"yes" ] ; then
-    mkdir -p $DESTDIR/Embedded/DLL/debug \
-             $DESTDIR/Embedded/static/debug
-    cp libmysqld/debug/mysqlserver.lib   $DESTDIR/Embedded/static/debug/
-    cp libmysqld/debug/mysqlserver.pdb   $DESTDIR/Embedded/static/debug/
-    cp libmysqld/debug/libmysqld.dll     $DESTDIR/Embedded/DLL/debug/
-    cp libmysqld/debug/libmysqld.exp     $DESTDIR/Embedded/DLL/debug/
-    cp libmysqld/debug/libmysqld.lib     $DESTDIR/Embedded/DLL/debug/
-    cp libmysqld/debug/libmysqld.pdb     $DESTDIR/Embedded/DLL/debug/
-  fi
-}
-
-if [ x"$PACK_EMBEDDED" = x"" -a \
-     -f "libmysqld/$TARGET/mysqlserver.lib" -a \
-     -f "libmysqld/$TARGET/libmysqld.lib" -o \
-     x"$PACK_EMBEDDED" = x"yes" ] ; then
-  copy_embedded
-fi
-
-# ----------------------------------------------------------------------
-# Note: Make sure to sync with include/Makefile.am and WiX installer
-# XML specifications
-# ----------------------------------------------------------------------
-
-mkdir -p $DESTDIR/include
-cp include/mysql.h \
-   include/mysql_com.h \
-   include/mysql_time.h \
-   include/my_list.h \
-   include/my_alloc.h \
-   include/typelib.h \
-   include/my_dbug.h \
-   include/m_string.h \
-   include/my_sys.h \
-   include/my_xml.h \
-   include/mysql_embed.h \
-   include/my_pthread.h \
-   include/my_no_pthread.h \
-   include/decimal.h \
-   include/errmsg.h \
-   include/my_global.h \
-   include/my_config.h \
-   include/my_net.h \
-   include/my_getopt.h \
-   include/sslopt-longopts.h \
-   include/my_dir.h \
-   include/sslopt-vars.h \
-   include/sslopt-case.h \
-   include/sql_common.h \
-   include/keycache.h \
-   include/m_ctype.h \
-   include/my_attribute.h \
-   include/my_compiler.h \
-   include/mysqld_error.h \
-   include/sql_state.h \
-   include/mysqld_ername.h \
-   include/mysql_version.h \
-   libmysql/libmysql.def \
-   $DESTDIR/include/
-
-mkdir -p $DESTDIR/include/mysql
-cp include/mysql/plugin.h $DESTDIR/include/mysql/
-
-# ----------------------------------------------------------------------
-# Client libraries, and other libraries
-# ----------------------------------------------------------------------
-
-mkdir -p $DESTDIR/lib/opt
-mkdir -p $DESTDIR/lib/plugin
-cp sql/$TARGET/mysqld.lib $DESTDIR/lib/
-cp libmysql/$TARGET/libmysql.dll \
-   libmysql/$TARGET/libmysql.lib \
-   libmysql/$TARGET/mysqlclient.lib \
-   mysys/$TARGET/mysys.lib \
-   regex/$TARGET/regex.lib \
-   strings/$TARGET/strings.lib \
-   zlib/$TARGET/zlib.lib $DESTDIR/lib/opt/
-if [ -d storage/innodb_plugin ]; then
-  cp storage/innodb_plugin/$TARGET/ha_innodb_plugin.dll \
-     $DESTDIR/lib/plugin/
-fi
-if [ -d plugin/semisync ]; then
-  cp plugin/semisync/$TARGET/semisync_master.dll \
-     plugin/semisync/$TARGET/semisync_slave.dll \
-     $DESTDIR/lib/plugin/
-fi
-
-if [ x"$TARGET" != x"release" ] ; then
-  cp libmysql/$TARGET/libmysql.pdb \
-     libmysql/$TARGET/mysqlclient.pdb \
-     mysys/$TARGET/mysys.pdb \
-     regex/$TARGET/regex.pdb \
-     strings/$TARGET/strings.pdb \
-     zlib/$TARGET/zlib.pdb $DESTDIR/lib/opt/
-  if [ -d storage/innodb_plugin ]; then
-    cp storage/innodb_plugin/$TARGET/ha_innodb_plugin.pdb \
-       $DESTDIR/lib/plugin/
-  fi
-  if [ -d plugin/semisync ]; then
-    cp plugin/semisync/$TARGET/semisync_master.pdb \
-       plugin/semisync/$TARGET/semisync_slave.pdb \
-       $DESTDIR/lib/plugin/
-  fi
-fi
-
-
-if [ x"$PACK_DEBUG" = x"" -a -f "libmysql/debug/libmysql.lib" -o \
-     x"$PACK_DEBUG" = x"yes" ] ; then
-  mkdir -p $DESTDIR/lib/debug
-  mkdir -p $DESTDIR/lib/plugin/debug
-  cp libmysql/debug/libmysql.dll \
-     libmysql/debug/libmysql.lib \
-     libmysql/debug/libmysql.pdb \
-     libmysql/debug/mysqlclient.lib \
-     libmysql/debug/mysqlclient.pdb \
-     mysys/debug/mysys.lib \
-     mysys/debug/mysys.pdb \
-     regex/debug/regex.lib \
-     regex/debug/regex.pdb \
-     strings/debug/strings.lib \
-     strings/debug/strings.pdb \
-     zlib/debug/zlib.lib \
-     zlib/debug/zlib.pdb $DESTDIR/lib/debug/
-  if [ -d storage/innodb_plugin ]; then
-    cp storage/innodb_plugin/debug/ha_innodb_plugin.dll \
-       storage/innodb_plugin/debug/ha_innodb_plugin.lib \
-       storage/innodb_plugin/debug/ha_innodb_plugin.pdb \
-       $DESTDIR/lib/plugin/debug/
-  fi
-  if [ -d plugin/semisync ]; then
-    cp plugin/semisync/debug/semisync_master.dll \
-       plugin/semisync/debug/semisync_master.lib \
-       plugin/semisync/debug/semisync_master.pdb \
-       plugin/semisync/debug/semisync_slave.dll \
-       plugin/semisync/debug/semisync_slave.lib \
-       plugin/semisync/debug/semisync_slave.pdb \
-       $DESTDIR/lib/plugin/debug/
-  fi
-fi
-
-# ----------------------------------------------------------------------
-# Copy the test directory
-# ----------------------------------------------------------------------
-
-mkdir $DESTDIR/mysql-test
-cp mysql-test/mysql-test-run.pl $DESTDIR/mysql-test/
-cp mysql-test/mysql-stress-test.pl $DESTDIR/mysql-test/
-cp mysql-test/README $DESTDIR/mysql-test/
-cp -R mysql-test/{t,r,include,suite,std_data,lib,collections} $DESTDIR/mysql-test/
-
-# Note that this will not copy "extra" if a soft link
-if [ -d mysql-test/extra ] ; then
-  mkdir $DESTDIR/mysql-test/extra
-  cp -pR mysql-test/extra/* $DESTDIR/mysql-test/extra/
-fi
-
-# ----------------------------------------------------------------------
-# Copy what could be usable in the "scripts" directory
-# ----------------------------------------------------------------------
-
-mysql_scripts="\
-mysql_config.pl \
-mysql_convert_table_format.pl \
-mysql_install_db.pl \
-mysql_secure_installation.pl \
-mysqld_multi.pl \
-mysqldumpslow.pl \
-mysqlhotcopy.pl \
-"
-
-mkdir -p $DESTDIR/scripts
-
-for i in $mysql_scripts
-do
-  cp scripts/$i $DESTDIR/scripts/$i
-done
-
-cp -pR sql/share $DESTDIR/
-cp -pR sql-bench $DESTDIR/
-rm -f $DESTDIR/sql-bench/*.sh $DESTDIR/sql-bench/Makefile*
-
-# The SQL initialisation code is to be in "share"
-cp scripts/*.sql $DESTDIR/share/
-
-# ----------------------------------------------------------------------
-# Clean up from possibly copied SCCS directories
-# ----------------------------------------------------------------------
-
-rm -rf `find $DESTDIR -type d -name SCCS -print`
-
-# ----------------------------------------------------------------------
-# Copy other files specified on command line DEST=SOURCE
-# ----------------------------------------------------------------------
-
-for arg do
-  dst=`echo $arg | sed -n 's/=.*$//p'`
-  src=`echo $arg | sed -n 's/^.*=//p'`
-
-  if [ x"$dst" = x"" -o x"$src" = x"" ] ; then
-    echo "Invalid specification of what to copy"
-    usage
-  fi
-
-  mkdir -p `dirname $DESTDIR/$dst`
-  cp -pR "$src" $DESTDIR/$dst
-done
-
-# ----------------------------------------------------------------------
-# Finally create the ZIP archive
-# ----------------------------------------------------------------------
-
-rm -f $NOINST_NAME.zip
-zip -r $NOINST_NAME.zip $DESTDIR
-rm -Rf $DESTDIR

=== modified file 'scripts/mysql_install_db.pl.in'
--- a/scripts/mysql_install_db.pl.in	2007-12-28 00:02:28 +0000
+++ b/scripts/mysql_install_db.pl.in	2011-09-06 16:20:04 +0000
@@ -61,10 +61,15 @@ Usage: $0 [OPTIONS]
   --cross-bootstrap    For internal use.  Used when building the MySQL system
                        tables on a different host than the target.
   --datadir=path       The path to the MySQL data directory.
+  --defaults-extra-file=name
+                       Read this file after the global files are read.
+  --defaults-file=name Only read default options from the given file name.
   --force              Causes mysql_install_db to run even if DNS does not
                        work.  In that case, grant table entries that normally
                        use hostnames will use IP addresses.
+  --help               Display this help and exit.                     
   --ldata=path         The path to the MySQL data directory. Same as --datadir.
+  --no-defaults        Don't read default options from any option file.
   --rpm                For internal use.  This option is used by RPM files
                        during the MySQL installation process.
   --skip-name-resolve  Use IP addresses rather than hostnames when creating

=== modified file 'scripts/mysql_install_db.sh'
--- a/scripts/mysql_install_db.sh	2011-06-30 15:46:53 +0000
+++ b/scripts/mysql_install_db.sh	2011-09-06 15:57:32 +0000
@@ -46,10 +46,15 @@ Usage: $0 [OPTIONS]
   --cross-bootstrap    For internal use.  Used when building the MySQL system
                        tables on a different host than the target.
   --datadir=path       The path to the MySQL data directory.
+  --defaults-extra-file=name
+                       Read this file after the global files are read.
+  --defaults-file=name Only read default options from the given file name.
   --force              Causes mysql_install_db to run even if DNS does not
                        work.  In that case, grant table entries that normally
                        use hostnames will use IP addresses.
+  --help               Display this help and exit.                     
   --ldata=path         The path to the MySQL data directory. Same as --datadir.
+  --no-defaults        Don't read default options from any option file.
   --rpm                For internal use.  This option is used by RPM files
                        during the MySQL installation process.
   --skip-name-resolve  Use IP addresses rather than hostnames when creating

=== modified file 'sql/client_settings.h'
--- a/sql/client_settings.h	2011-06-30 15:46:53 +0000
+++ b/sql/client_settings.h	2011-09-14 14:10:18 +0000
@@ -23,9 +23,18 @@
 #include <thr_alarm.h>
 #include <sql_common.h>
 
-#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG |	  \
-                             CLIENT_SECURE_CONNECTION | CLIENT_TRANSACTIONS | \
-			     CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION)
+/*
+ Note: CLIENT_CAPABILITIES is also defined in libmysql/client_settings.h.
+ When adding capabilities here, consider if they should be also added to
+ the libmysql version.
+*/
+#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | \
+                             CLIENT_LONG_FLAG |     \
+                             CLIENT_SECURE_CONNECTION | \
+                             CLIENT_TRANSACTIONS |  \
+                             CLIENT_PROTOCOL_41 |   \
+                             CLIENT_SECURE_CONNECTION | \
+                             CLIENT_PLUGIN_AUTH)
 
 #define read_user_name(A) {}
 #undef HAVE_SMEM

=== modified file 'sql/filesort.cc'
--- a/sql/filesort.cc	2011-06-30 15:46:53 +0000
+++ b/sql/filesort.cc	2011-08-30 08:16:23 +0000
@@ -147,8 +147,6 @@ ha_rows filesort(THD *thd, TABLE *table,
   error= 1;
   bzero((char*) &param,sizeof(param));
   param.sort_length= sortlength(thd, sortorder, s_length, &multi_byte_charset);
-  /* filesort cannot handle zero-length records. */
-  DBUG_ASSERT(param.sort_length);
   param.ref_length= table->file->ref_length;
   param.addon_field= 0;
   param.addon_length= 0;
@@ -260,6 +258,9 @@ ha_rows filesort(THD *thd, TABLE *table,
   }
   else
   {
+    /* filesort cannot handle zero-length records during merge. */
+    DBUG_ASSERT(param.sort_length != 0);
+
     if (table_sort.buffpek && table_sort.buffpek_len < maxbuffer)
     {
       my_free(table_sort.buffpek);
@@ -972,21 +973,10 @@ static void make_sortkey(register SORTPA
       if (addonf->null_bit && field->is_null())
       {
         nulls[addonf->null_offset]|= addonf->null_bit;
-#ifdef HAVE_purify
-	bzero(to, addonf->length);
-#endif
       }
       else
       {
-#ifdef HAVE_purify
-        uchar *end= field->pack(to, field->ptr);
-	uint length= (uint) ((to + addonf->length) - end);
-	DBUG_ASSERT((int) length >= 0);
-	if (length)
-	  bzero(end, length);
-#else
         (void) field->pack(to, field->ptr);
-#endif
       }
       to+= addonf->length;
     }

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2011-07-03 23:48:19 +0000
+++ b/sql/handler.cc	2011-09-01 18:48:04 +0000
@@ -358,6 +358,7 @@ int ha_init_errors(void)
   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));
   SETMSG(HA_ERR_INDEX_COL_TOO_LONG,	ER_DEFAULT(ER_INDEX_COLUMN_TOO_LONG));
+  SETMSG(HA_ERR_INDEX_CORRUPT,		ER_DEFAULT(ER_INDEX_CORRUPT));
 
   /* Register the error messages for use with my_error(). */
   return my_error_register(get_handler_errmsgs, HA_ERR_FIRST, HA_ERR_LAST);
@@ -2865,6 +2866,12 @@ void handler::print_error(int error, myf
   case HA_ERR_INDEX_COL_TOO_LONG:
     textno= ER_INDEX_COLUMN_TOO_LONG;
     break;
+  case HA_ERR_INDEX_CORRUPT:
+    textno= ER_INDEX_CORRUPT;
+    break;
+  case HA_ERR_UNDO_REC_TOO_BIG:
+    textno= ER_UNDO_RECORD_TOO_BIG;
+    break;
   default:
     {
       /* The error was "unknown" to this function.

=== modified file 'sql/my_decimal.h'
--- a/sql/my_decimal.h	2011-07-05 23:13:50 +0000
+++ b/sql/my_decimal.h	2011-08-29 09:34:48 +0000
@@ -124,12 +124,8 @@ public:
   {
     len= DECIMAL_BUFF_LENGTH;
     buf= buffer;
-#if !defined (HAVE_purify) && !defined(DBUG_OFF)
-    /* Set buffer to 'random' value to find wrong buffer usage */
-    for (uint i= 0; i < DECIMAL_BUFF_LENGTH; i++)
-      buffer[i]= i;
-#endif
   }
+
   my_decimal()
   {
     init();

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2011-08-15 18:12:11 +0000
+++ b/sql/share/errmsg-utf8.txt	2011-09-21 10:40:41 +0000
@@ -6415,6 +6415,12 @@ ER_ERROR_IN_TRIGGER_BODY
 ER_ERROR_IN_UNKNOWN_TRIGGER_BODY
   eng "Unknown trigger has an error in its body: '%-.256s'"
 
+ER_INDEX_CORRUPT
+  eng "Index %s is corrupted"
+
+ER_UNDO_RECORD_TOO_BIG
+  eng "Undo log record is too big."
+
 ER_PLUGIN_NO_UNINSTALL
   eng "Plugin '%s' is marked as not dynamically uninstallable. You have to stop the server to uninstall it."
 

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2011-07-03 23:48:19 +0000
+++ b/sql/slave.cc	2011-09-14 14:10:18 +0000
@@ -4204,6 +4204,10 @@ static int connect_to_master(THD* thd, M
   /* This one is not strictly needed but we have it here for completeness */
   mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
 
+  /* Set MYSQL_PLUGIN_DIR in case master asks for an external authentication plugin */
+  if (opt_plugin_dir_ptr && *opt_plugin_dir_ptr)
+    mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir_ptr);
+
   while (!(slave_was_killed = io_slave_killed(thd,mi)) &&
          (reconnect ? mysql_reconnect(mysql) != 0 :
           mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2011-08-09 08:50:55 +0000
+++ b/sql/sql_lex.cc	2011-09-23 11:39:08 +0000
@@ -435,6 +435,7 @@ void lex_start(THD *thd)
 
   lex->is_lex_started= TRUE;
   lex->used_tables= 0;
+  lex->reset_slave_info.all= false;
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2011-07-03 23:48:19 +0000
+++ b/sql/sql_parse.cc	2011-08-08 16:45:43 +0000
@@ -2348,6 +2348,12 @@ case SQLCOM_PREPARE:
       goto end_with_restore_list;
 #endif
     /*
+      If no engine type was given, work out the default now
+      rather than at parse-time.
+    */
+    if (!(create_info.used_fields & HA_CREATE_USED_ENGINE))
+      create_info.db_type= ha_default_handlerton(thd);
+    /*
       If we are using SET CHARSET without DEFAULT, add an implicit
       DEFAULT to not confuse old users. (This may change).
     */

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2011-08-09 08:03:29 +0000
+++ b/sql/sql_yacc.yy	2011-09-26 07:08:42 +0000
@@ -2038,7 +2038,6 @@ create:
             lex->change=NullS;
             bzero((char*) &lex->create_info,sizeof(lex->create_info));
             lex->create_info.options=$2 | $4;
-            lex->create_info.db_type= ha_default_handlerton(thd);
             lex->create_info.default_table_charset= NULL;
             lex->name.str= 0;
             lex->name.length= 0;
@@ -2048,7 +2047,8 @@ create:
           {
             LEX *lex= YYTHD->lex;
             lex->current_select= &lex->select_lex; 
-            if (!lex->create_info.db_type)
+            if ((lex->create_info.used_fields & HA_CREATE_USED_ENGINE) &&
+                !lex->create_info.db_type)
             {
               lex->create_info.db_type= ha_default_handlerton(YYTHD);
               push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
@@ -5036,8 +5036,7 @@ create_table_option:
           ENGINE_SYM opt_equal storage_engines
           {
             Lex->create_info.db_type= $3;
-            if ($3)
-              Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
+            Lex->create_info.used_fields|= HA_CREATE_USED_ENGINE;
           }
         | MAX_ROWS opt_equal ulonglong_num
           {
@@ -6748,6 +6747,11 @@ alter_list_item:
           {
             LEX *lex=Lex;
             lex->alter_info.flags|= ALTER_OPTIONS;
+            if ((lex->create_info.used_fields & HA_CREATE_USED_ENGINE) &&
+                !lex->create_info.db_type)
+            {
+              lex->create_info.used_fields&= ~HA_CREATE_USED_ENGINE;
+            }
           }
         | FORCE_SYM
           {

=== modified file 'storage/heap/ha_heap.cc'
--- a/storage/heap/ha_heap.cc	2011-08-15 18:12:11 +0000
+++ b/storage/heap/ha_heap.cc	2011-09-27 12:14:31 +0000
@@ -416,6 +416,7 @@ int ha_heap::info(uint flag)
   stats.index_file_length=    hp_info.index_length;
   stats.max_data_file_length= hp_info.max_records * hp_info.reclength;
   stats.delete_length=        hp_info.deleted * hp_info.reclength;
+  stats.create_time=          (ulong) hp_info.create_time;
   if (flag & HA_STATUS_AUTO)
     stats.auto_increment_value= hp_info.auto_increment;
   /*

=== modified file 'storage/heap/hp_create.c'
--- a/storage/heap/hp_create.c	2011-06-30 15:46:53 +0000
+++ b/storage/heap/hp_create.c	2011-09-27 12:14:31 +0000
@@ -186,6 +186,7 @@ int heap_create(const char *name, HP_CRE
     share->auto_key= create_info->auto_key;
     share->auto_key_type= create_info->auto_key_type;
     share->auto_increment= create_info->auto_increment;
+    share->create_time= (long) time((time_t*) 0);
     /* Must be allocated separately for rename to work */
     if (!(share->name= my_strdup(name,MYF(0))))
     {

=== modified file 'storage/heap/hp_info.c'
--- a/storage/heap/hp_info.c	2007-05-10 09:59:39 +0000
+++ b/storage/heap/hp_info.c	2011-09-27 12:08:51 +0000
@@ -53,6 +53,7 @@ int heap_info(reg1 HP_INFO *info,reg2 HE
   x->index_length    = info->s->index_length;
   x->max_records     = info->s->max_records;
   x->errkey          = info->errkey;
+  x->create_time     = info->s->create_time;
   if (flag & HA_STATUS_AUTO)
     x->auto_increment= info->s->auto_increment + 1;
   DBUG_RETURN(0);

=== modified file 'storage/innobase/btr/btr0btr.c'
--- a/storage/innobase/btr/btr0btr.c	2011-06-16 13:14:16 +0000
+++ b/storage/innobase/btr/btr0btr.c	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -690,7 +690,8 @@ btr_root_block_get(
 	zip_size = dict_table_zip_size(index->table);
 	root_page_no = dict_index_get_page(index);
 
-	block = btr_block_get(space, zip_size, root_page_no, RW_X_LATCH, mtr);
+	block = btr_block_get(space, zip_size, root_page_no, RW_X_LATCH,
+			      index, mtr);
 	ut_a((ibool)!!page_is_comp(buf_block_get_frame(block))
 	     == dict_table_is_comp(index->table));
 #ifdef UNIV_BTR_DEBUG
@@ -891,7 +892,7 @@ btr_page_alloc_for_ibuf(
 				 dict_table_zip_size(index->table),
 				 node_addr.page, RW_X_LATCH, mtr);
 	new_page = buf_block_get_frame(new_block);
-	buf_block_dbg_add_level(new_block, SYNC_TREE_NODE_NEW);
+	buf_block_dbg_add_level(new_block, SYNC_IBUF_TREE_NODE_NEW);
 
 	flst_remove(root + PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST,
 		    new_page + PAGE_HEADER + PAGE_BTR_IBUF_FREE_LIST_NODE,
@@ -1139,7 +1140,7 @@ btr_node_ptr_get_child(
 	page_no = btr_node_ptr_get_child_page_no(node_ptr, offsets);
 
 	return(btr_block_get(space, dict_table_zip_size(index->table),
-			     page_no, RW_X_LATCH, mtr));
+			     page_no, RW_X_LATCH, index, mtr));
 }
 
 /************************************************************//**
@@ -1312,7 +1313,8 @@ btr_create(
 			space, 0,
 			IBUF_HEADER + IBUF_TREE_SEG_HEADER, mtr);
 
-		buf_block_dbg_add_level(ibuf_hdr_block, SYNC_TREE_NODE_NEW);
+		buf_block_dbg_add_level(
+			ibuf_hdr_block, SYNC_IBUF_TREE_NODE_NEW);
 
 		ut_ad(buf_block_get_page_no(ibuf_hdr_block)
 		      == IBUF_HEADER_PAGE_NO);
@@ -1350,10 +1352,9 @@ btr_create(
 	page_no = buf_block_get_page_no(block);
 	frame = buf_block_get_frame(block);
 
-	buf_block_dbg_add_level(block, SYNC_TREE_NODE_NEW);
-
 	if (type & DICT_IBUF) {
 		/* It is an insert buffer tree: initialize the free list */
+		buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE_NEW);
 
 		ut_ad(page_no == IBUF_TREE_ROOT_PAGE_NO);
 
@@ -1361,6 +1362,8 @@ btr_create(
 	} else {
 		/* It is a non-ibuf tree: create a file segment for leaf
 		pages */
+		buf_block_dbg_add_level(block, SYNC_TREE_NODE_NEW);
+
 		if (!fseg_create(space, page_no,
 				 PAGE_HEADER + PAGE_BTR_SEG_LEAF, mtr)) {
 			/* Not enough space for new segment, free root
@@ -1432,7 +1435,8 @@ btr_free_but_not_root(
 leaf_loop:
 	mtr_start(&mtr);
 
-	root = btr_page_get(space, zip_size, root_page_no, RW_X_LATCH, &mtr);
+	root = btr_page_get(space, zip_size, root_page_no, RW_X_LATCH,
+			    NULL, &mtr);
 #ifdef UNIV_BTR_DEBUG
 	ut_a(btr_root_fseg_validate(FIL_PAGE_DATA + PAGE_BTR_SEG_LEAF
 				    + root, space));
@@ -1454,7 +1458,8 @@ leaf_loop:
 top_loop:
 	mtr_start(&mtr);
 
-	root = btr_page_get(space, zip_size, root_page_no, RW_X_LATCH, &mtr);
+	root = btr_page_get(space, zip_size, root_page_no, RW_X_LATCH,
+			    NULL, &mtr);
 #ifdef UNIV_BTR_DEBUG
 	ut_a(btr_root_fseg_validate(FIL_PAGE_DATA + PAGE_BTR_SEG_TOP
 				    + root, space));
@@ -1480,13 +1485,13 @@ btr_free_root(
 	ulint	zip_size,	/*!< in: compressed page size in bytes
 				or 0 for uncompressed pages */
 	ulint	root_page_no,	/*!< in: root page number */
-	mtr_t*	mtr)		/*!< in: a mini-transaction which has already
-				been started */
+	mtr_t*	mtr)		/*!< in/out: mini-transaction */
 {
 	buf_block_t*	block;
 	fseg_header_t*	header;
 
-	block = btr_block_get(space, zip_size, root_page_no, RW_X_LATCH, mtr);
+	block = btr_block_get(space, zip_size, root_page_no, RW_X_LATCH,
+			      NULL, mtr);
 
 	btr_search_drop_page_hash_index(block);
 
@@ -2275,7 +2280,7 @@ btr_attach_half_pages(
 /*==================*/
 	dict_index_t*	index,		/*!< in: the index tree */
 	buf_block_t*	block,		/*!< in/out: page to be split */
-	const rec_t*	split_rec,	/*!< in: first record on upper
+	rec_t*		split_rec,	/*!< in: first record on upper
 					half page */
 	buf_block_t*	new_block,	/*!< in/out: the new half page */
 	ulint		direction,	/*!< in: FSP_UP or FSP_DOWN */
@@ -2365,9 +2370,8 @@ btr_attach_half_pages(
 	/* Update page links of the level */
 
 	if (prev_page_no != FIL_NULL) {
-		buf_block_t*	prev_block = btr_block_get(space, zip_size,
-							   prev_page_no,
-							   RW_X_LATCH, mtr);
+		buf_block_t*	prev_block = btr_block_get(
+			space, zip_size, prev_page_no, RW_X_LATCH, index, mtr);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(page_is_comp(prev_block->frame) == page_is_comp(page));
 		ut_a(btr_page_get_next(prev_block->frame, mtr)
@@ -2380,9 +2384,8 @@ btr_attach_half_pages(
 	}
 
 	if (next_page_no != FIL_NULL) {
-		buf_block_t*	next_block = btr_block_get(space, zip_size,
-							   next_page_no,
-							   RW_X_LATCH, mtr);
+		buf_block_t*	next_block = btr_block_get(
+			space, zip_size, next_page_no, RW_X_LATCH, index, mtr);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(page_is_comp(next_block->frame) == page_is_comp(page));
 		ut_a(btr_page_get_prev(next_block->frame, mtr)
@@ -2804,17 +2807,42 @@ func_exit:
 	return(rec);
 }
 
+#ifdef UNIV_SYNC_DEBUG
+/*************************************************************//**
+Removes a page from the level list of pages.
+@param space	in: space where removed
+@param zip_size	in: compressed page size in bytes, or 0 for uncompressed
+@param page	in/out: page to remove
+@param index	in: index tree
+@param mtr	in/out: mini-transaction */
+# define btr_level_list_remove(space,zip_size,page,index,mtr)		\
+	btr_level_list_remove_func(space,zip_size,page,index,mtr)
+#else /* UNIV_SYNC_DEBUG */
+/*************************************************************//**
+Removes a page from the level list of pages.
+@param space	in: space where removed
+@param zip_size	in: compressed page size in bytes, or 0 for uncompressed
+@param page	in/out: page to remove
+@param index	in: index tree
+@param mtr	in/out: mini-transaction */
+# define btr_level_list_remove(space,zip_size,page,index,mtr)		\
+	btr_level_list_remove_func(space,zip_size,page,mtr)
+#endif /* UNIV_SYNC_DEBUG */
+
 /*************************************************************//**
 Removes a page from the level list of pages. */
-static
+static __attribute__((nonnull))
 void
-btr_level_list_remove(
-/*==================*/
-	ulint		space,	/*!< in: space where removed */
-	ulint		zip_size,/*!< in: compressed page size in bytes
-				or 0 for uncompressed pages */
-	page_t*		page,	/*!< in: page to remove */
-	mtr_t*		mtr)	/*!< in: mtr */
+btr_level_list_remove_func(
+/*=======================*/
+	ulint			space,	/*!< in: space where removed */
+	ulint			zip_size,/*!< in: compressed page size in bytes
+					or 0 for uncompressed pages */
+	page_t*			page,	/*!< in/out: page to remove */
+#ifdef UNIV_SYNC_DEBUG
+	const dict_index_t*	index,	/*!< in: index tree */
+#endif /* UNIV_SYNC_DEBUG */
+	mtr_t*			mtr)	/*!< in/out: mini-transaction */
 {
 	ulint	prev_page_no;
 	ulint	next_page_no;
@@ -2832,7 +2860,7 @@ btr_level_list_remove(
 	if (prev_page_no != FIL_NULL) {
 		buf_block_t*	prev_block
 			= btr_block_get(space, zip_size, prev_page_no,
-					RW_X_LATCH, mtr);
+					RW_X_LATCH, index, mtr);
 		page_t*		prev_page
 			= buf_block_get_frame(prev_block);
 #ifdef UNIV_BTR_DEBUG
@@ -2849,7 +2877,7 @@ btr_level_list_remove(
 	if (next_page_no != FIL_NULL) {
 		buf_block_t*	next_block
 			= btr_block_get(space, zip_size, next_page_no,
-					RW_X_LATCH, mtr);
+					RW_X_LATCH, index, mtr);
 		page_t*		next_page
 			= buf_block_get_frame(next_block);
 #ifdef UNIV_BTR_DEBUG
@@ -2967,16 +2995,15 @@ btr_node_ptr_delete(
 	ut_a(err == DB_SUCCESS);
 
 	if (!compressed) {
-		btr_cur_compress_if_useful(&cursor, FALSE, mtr);
+		btr_cur_compress_if_useful(&cursor, mtr);
 	}
 }
 
 /*************************************************************//**
 If page is the only on its level, this function moves its records to the
-father page, thus reducing the tree height.
-@return father block */
+father page, thus reducing the tree height. */
 static
-buf_block_t*
+void
 btr_lift_page_up(
 /*=============*/
 	dict_index_t*	index,	/*!< in: index tree */
@@ -3093,8 +3120,6 @@ btr_lift_page_up(
 	}
 	ut_ad(page_validate(father_page, index));
 	ut_ad(btr_check_node_ptr(index, father_block, mtr));
-
-	return(father_block);
 }
 
 /*************************************************************//**
@@ -3111,13 +3136,11 @@ UNIV_INTERN
 ibool
 btr_compress(
 /*=========*/
-	btr_cur_t*	cursor,	/*!< in/out: cursor on the page to merge
-				or lift; the page must not be empty:
-				when deleting records, use btr_discard_page()
-				if the page would become empty */
-	ibool		adjust,	/*!< in: TRUE if should adjust the
-				cursor position even if compression occurs */
-	mtr_t*		mtr)	/*!< in/out: mini-transaction */
+	btr_cur_t*	cursor,	/*!< in: cursor on the page to merge or lift;
+				the page must not be empty: in record delete
+				use btr_discard_page if the page would become
+				empty */
+	mtr_t*		mtr)	/*!< in: mtr */
 {
 	dict_index_t*	index;
 	ulint		space;
@@ -3135,14 +3158,12 @@ btr_compress(
 	ulint*		offsets;
 	ulint		data_size;
 	ulint		n_recs;
-	ulint		nth_rec = 0; /* remove bogus warning */
 	ulint		max_ins_size;
 	ulint		max_ins_size_reorg;
 
 	block = btr_cur_get_block(cursor);
 	page = btr_cur_get_page(cursor);
 	index = btr_cur_get_index(cursor);
-
 	ut_a((ibool) !!page_is_comp(page) == dict_table_is_comp(index->table));
 
 	ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(index),
@@ -3163,10 +3184,6 @@ btr_compress(
 	offsets = btr_page_get_father_block(NULL, heap, index, block, mtr,
 					    &father_cursor);
 
-	if (adjust) {
-		nth_rec = page_rec_get_n_recs_before(btr_cur_get_rec(cursor));
-	}
-
 	/* Decide the page to which we try to merge and which will inherit
 	the locks */
 
@@ -3175,7 +3192,7 @@ btr_compress(
 	if (is_left) {
 
 		merge_block = btr_block_get(space, zip_size, left_page_no,
-					    RW_X_LATCH, mtr);
+					    RW_X_LATCH, index, mtr);
 		merge_page = buf_block_get_frame(merge_block);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(btr_page_get_next(merge_page, mtr)
@@ -3184,7 +3201,7 @@ btr_compress(
 	} else if (right_page_no != FIL_NULL) {
 
 		merge_block = btr_block_get(space, zip_size, right_page_no,
-					    RW_X_LATCH, mtr);
+					    RW_X_LATCH, index, mtr);
 		merge_page = buf_block_get_frame(merge_block);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(btr_page_get_prev(merge_page, mtr)
@@ -3193,9 +3210,9 @@ btr_compress(
 	} else {
 		/* The page is the only one on the level, lift the records
 		to the father */
-
-		merge_block = btr_lift_page_up(index, block, mtr);
-		goto func_exit;
+		btr_lift_page_up(index, block, mtr);
+		mem_heap_free(heap);
+		return(TRUE);
 	}
 
 	n_recs = page_get_n_recs(page);
@@ -3273,14 +3290,10 @@ err_exit:
 		btr_search_drop_page_hash_index(block);
 
 		/* Remove the page from the level list */
-		btr_level_list_remove(space, zip_size, page, mtr);
+		btr_level_list_remove(space, zip_size, page, index, mtr);
 
 		btr_node_ptr_delete(index, block, mtr);
 		lock_update_merge_left(merge_block, orig_pred, block);
-
-		if (adjust) {
-			nth_rec += page_rec_get_n_recs_before(orig_pred);
-		}
 	} else {
 		rec_t*		orig_succ;
 #ifdef UNIV_BTR_DEBUG
@@ -3330,7 +3343,7 @@ err_exit:
 #endif /* UNIV_BTR_DEBUG */
 
 		/* Remove the page from the level list */
-		btr_level_list_remove(space, zip_size, page, mtr);
+		btr_level_list_remove(space, zip_size, page, index, mtr);
 
 		/* Replace the address of the old child node (= page) with the
 		address of the merge page to the right */
@@ -3345,6 +3358,7 @@ err_exit:
 	}
 
 	btr_blob_dbg_remove(page, index, "btr_compress");
+	mem_heap_free(heap);
 
 	if (!dict_index_is_clust(index) && page_is_leaf(merge_page)) {
 		/* Update the free bits of the B-tree page in the
@@ -3396,16 +3410,6 @@ err_exit:
 	btr_page_free(index, block, mtr);
 
 	ut_ad(btr_check_node_ptr(index, merge_block, mtr));
-func_exit:
-	mem_heap_free(heap);
-
-	if (adjust) {
-		btr_cur_position(
-			index,
-			page_rec_get_nth(merge_block->frame, nth_rec),
-			merge_block, cursor);
-	}
-
 	return(TRUE);
 }
 
@@ -3522,7 +3526,7 @@ btr_discard_page(
 
 	if (left_page_no != FIL_NULL) {
 		merge_block = btr_block_get(space, zip_size, left_page_no,
-					    RW_X_LATCH, mtr);
+					    RW_X_LATCH, index, mtr);
 		merge_page = buf_block_get_frame(merge_block);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(btr_page_get_next(merge_page, mtr)
@@ -3530,7 +3534,7 @@ btr_discard_page(
 #endif /* UNIV_BTR_DEBUG */
 	} else if (right_page_no != FIL_NULL) {
 		merge_block = btr_block_get(space, zip_size, right_page_no,
-					    RW_X_LATCH, mtr);
+					    RW_X_LATCH, index, mtr);
 		merge_page = buf_block_get_frame(merge_block);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(btr_page_get_prev(merge_page, mtr)
@@ -3565,7 +3569,7 @@ btr_discard_page(
 	btr_node_ptr_delete(index, block, mtr);
 
 	/* Remove the page from the level list */
-	btr_level_list_remove(space, zip_size, page, mtr);
+	btr_level_list_remove(space, zip_size, page, index, mtr);
 #ifdef UNIV_ZIP_DEBUG
 	{
 		page_zip_des_t*	merge_page_zip
@@ -4083,7 +4087,7 @@ loop:
 	if (right_page_no != FIL_NULL) {
 		const rec_t*	right_rec;
 		right_block = btr_block_get(space, zip_size, right_page_no,
-					    RW_X_LATCH, &mtr);
+					    RW_X_LATCH, index, &mtr);
 		right_page = buf_block_get_frame(right_block);
 		if (UNIV_UNLIKELY(btr_page_get_prev(right_page, &mtr)
 				  != page_get_page_no(page))) {
@@ -4309,7 +4313,7 @@ node_ptr_fails:
 		mtr_start(&mtr);
 
 		block = btr_block_get(space, zip_size, right_page_no,
-				      RW_X_LATCH, &mtr);
+				      RW_X_LATCH, index, &mtr);
 		page = buf_block_get_frame(block);
 
 		goto loop;

=== modified file 'storage/innobase/btr/btr0cur.c'
--- a/storage/innobase/btr/btr0cur.c	2011-07-07 11:22:43 +0000
+++ b/storage/innobase/btr/btr0cur.c	2011-09-30 11:37:22 +0000
@@ -249,7 +249,8 @@ btr_cur_latch_leaves(
 	case BTR_SEARCH_LEAF:
 	case BTR_MODIFY_LEAF:
 		mode = latch_mode == BTR_SEARCH_LEAF ? RW_S_LATCH : RW_X_LATCH;
-		get_block = btr_block_get(space, zip_size, page_no, mode, mtr);
+		get_block = btr_block_get(
+			space, zip_size, page_no, mode, cursor->index, mtr);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(page_is_comp(get_block->frame) == page_is_comp(page));
 #endif /* UNIV_BTR_DEBUG */
@@ -260,9 +261,9 @@ btr_cur_latch_leaves(
 		left_page_no = btr_page_get_prev(page, mtr);
 
 		if (left_page_no != FIL_NULL) {
-			get_block = btr_block_get(space, zip_size,
-						  left_page_no,
-						  RW_X_LATCH, mtr);
+			get_block = btr_block_get(
+				space, zip_size, left_page_no,
+				RW_X_LATCH, cursor->index, mtr);
 #ifdef UNIV_BTR_DEBUG
 			ut_a(page_is_comp(get_block->frame)
 			     == page_is_comp(page));
@@ -272,8 +273,9 @@ btr_cur_latch_leaves(
 			get_block->check_index_page_at_flush = TRUE;
 		}
 
-		get_block = btr_block_get(space, zip_size, page_no,
-					  RW_X_LATCH, mtr);
+		get_block = btr_block_get(
+			space, zip_size, page_no,
+			RW_X_LATCH, cursor->index, mtr);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(page_is_comp(get_block->frame) == page_is_comp(page));
 #endif /* UNIV_BTR_DEBUG */
@@ -282,9 +284,9 @@ btr_cur_latch_leaves(
 		right_page_no = btr_page_get_next(page, mtr);
 
 		if (right_page_no != FIL_NULL) {
-			get_block = btr_block_get(space, zip_size,
-						  right_page_no,
-						  RW_X_LATCH, mtr);
+			get_block = btr_block_get(
+				space, zip_size, right_page_no,
+				RW_X_LATCH, cursor->index, mtr);
 #ifdef UNIV_BTR_DEBUG
 			ut_a(page_is_comp(get_block->frame)
 			     == page_is_comp(page));
@@ -303,8 +305,9 @@ btr_cur_latch_leaves(
 		left_page_no = btr_page_get_prev(page, mtr);
 
 		if (left_page_no != FIL_NULL) {
-			get_block = btr_block_get(space, zip_size,
-						  left_page_no, mode, mtr);
+			get_block = btr_block_get(
+				space, zip_size,
+				left_page_no, mode, cursor->index, mtr);
 			cursor->left_block = get_block;
 #ifdef UNIV_BTR_DEBUG
 			ut_a(page_is_comp(get_block->frame)
@@ -315,7 +318,8 @@ btr_cur_latch_leaves(
 			get_block->check_index_page_at_flush = TRUE;
 		}
 
-		get_block = btr_block_get(space, zip_size, page_no, mode, mtr);
+		get_block = btr_block_get(
+			space, zip_size, page_no, mode, cursor->index, mtr);
 #ifdef UNIV_BTR_DEBUG
 		ut_a(page_is_comp(get_block->frame) == page_is_comp(page));
 #endif /* UNIV_BTR_DEBUG */
@@ -669,7 +673,9 @@ retry_page_get:
 		ut_a(!page_zip || page_zip_validate(page_zip, page));
 #endif /* UNIV_ZIP_DEBUG */
 
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+		buf_block_dbg_add_level(
+			block, dict_index_is_ibuf(index)
+			? SYNC_IBUF_TREE_NODE : SYNC_TREE_NODE);
 	}
 
 	ut_ad(index->id == btr_page_get_index_id(page));
@@ -767,7 +773,7 @@ retry_page_get:
 	if (level != 0) {
 		/* x-latch the page */
 		page = btr_page_get(
-			space, zip_size, page_no, RW_X_LATCH, mtr);
+			space, zip_size, page_no, RW_X_LATCH, index, mtr);
 
 		ut_a((ibool)!!page_is_comp(page)
 		     == dict_table_is_comp(index->table));
@@ -1839,6 +1845,7 @@ btr_cur_update_in_place(
 	roll_ptr_t	roll_ptr	= 0;
 	trx_t*		trx;
 	ulint		was_delete_marked;
+	ibool		is_hashed;
 	mem_heap_t*	heap		= NULL;
 	ulint		offsets_[REC_OFFS_NORMAL_SIZE];
 	ulint*		offsets		= offsets_;
@@ -1880,7 +1887,21 @@ btr_cur_update_in_place(
 		return(err);
 	}
 
-	if (block->is_hashed) {
+	if (!(flags & BTR_KEEP_SYS_FLAG)) {
+		row_upd_rec_sys_fields(rec, NULL,
+				       index, offsets, trx, roll_ptr);
+	}
+
+	was_delete_marked = rec_get_deleted_flag(
+		rec, page_is_comp(buf_block_get_frame(block)));
+
+	is_hashed = block->is_hashed;
+
+	if (is_hashed) {
+		/* TO DO: Can we skip this if none of the fields
+		index->search_info->curr_n_fields
+		are being updated? */
+
 		/* The function row_upd_changes_ord_field_binary works only
 		if the update vector was built for a clustered index, we must
 		NOT call it if index is secondary */
@@ -1896,17 +1917,9 @@ btr_cur_update_in_place(
 		rw_lock_x_lock(&btr_search_latch);
 	}
 
-	if (!(flags & BTR_KEEP_SYS_FLAG)) {
-		row_upd_rec_sys_fields(rec, NULL,
-				       index, offsets, trx, roll_ptr);
-	}
-
-	was_delete_marked = rec_get_deleted_flag(
-		rec, page_is_comp(buf_block_get_frame(block)));
-
 	row_upd_rec_in_place(rec, index, offsets, update, page_zip);
 
-	if (block->is_hashed) {
+	if (is_hashed) {
 		rw_lock_x_unlock(&btr_search_latch);
 	}
 
@@ -1972,6 +1985,7 @@ btr_cur_optimistic_update(
 	ulint		old_rec_size;
 	dtuple_t*	new_entry;
 	roll_ptr_t	roll_ptr;
+	trx_t*		trx;
 	mem_heap_t*	heap;
 	ulint		i;
 	ulint		n_ext;
@@ -1988,10 +2002,9 @@ btr_cur_optimistic_update(
 
 	heap = mem_heap_create(1024);
 	offsets = rec_get_offsets(rec, index, NULL, ULINT_UNDEFINED, &heap);
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
-	ut_a(!rec_offs_any_null_extern(rec, offsets)
-	     || trx_is_recv(thr_get_trx(thr)));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#ifdef UNIV_BLOB_NULL_DEBUG
+	ut_a(!rec_offs_any_null_extern(rec, offsets));
+#endif /* UNIV_BLOB_NULL_DEBUG */
 
 #ifdef UNIV_DEBUG
 	if (btr_cur_print_record_ops && thr) {
@@ -2114,11 +2127,13 @@ any_extern:
 
 	page_cur_move_to_prev(page_cursor);
 
+	trx = thr_get_trx(thr);
+
 	if (!(flags & BTR_KEEP_SYS_FLAG)) {
 		row_upd_index_entry_sys_field(new_entry, index, DATA_ROLL_PTR,
 					      roll_ptr);
 		row_upd_index_entry_sys_field(new_entry, index, DATA_TRX_ID,
-					      thr_get_trx(thr)->id);
+					      trx->id);
 	}
 
 	/* There are no externally stored columns in new_entry */
@@ -2204,9 +2219,7 @@ btr_cur_pessimistic_update(
 /*=======================*/
 	ulint		flags,	/*!< in: undo logging, locking, and rollback
 				flags */
-	btr_cur_t*	cursor,	/*!< in/out: cursor on the record to update;
-				cursor may become invalid if *big_rec == NULL
-				|| !(flags & BTR_KEEP_POS_FLAG) */
+	btr_cur_t*	cursor,	/*!< in: cursor on the record to update */
 	mem_heap_t**	heap,	/*!< in/out: pointer to memory heap, or NULL */
 	big_rec_t**	big_rec,/*!< out: big rec vector whose fields have to
 				be stored externally by the caller, or NULL */
@@ -2345,7 +2358,7 @@ btr_cur_pessimistic_update(
 	record to be inserted: we have to remember which fields were such */
 
 	ut_ad(!page_is_comp(page) || !rec_get_node_ptr_flag(rec));
-	ut_ad(rec_offs_validate(rec, index, offsets));
+	offsets = rec_get_offsets(rec, index, offsets, ULINT_UNDEFINED, heap);
 	n_ext += btr_push_update_extern_fields(new_entry, update, *heap);
 
 	if (UNIV_LIKELY_NULL(page_zip)) {
@@ -2368,10 +2381,6 @@ make_external:
 			err = DB_TOO_BIG_RECORD;
 			goto return_after_reservations;
 		}
-
-		ut_ad(page_is_leaf(page));
-		ut_ad(dict_index_is_clust(index));
-		ut_ad(flags & BTR_KEEP_POS_FLAG);
 	}
 
 	/* Store state of explicit locks on rec on the page infimum record,
@@ -2399,8 +2408,6 @@ make_external:
 	rec = btr_cur_insert_if_possible(cursor, new_entry, n_ext, mtr);
 
 	if (rec) {
-		page_cursor->rec = rec;
-
 		lock_rec_restore_from_page_infimum(btr_cur_get_block(cursor),
 						   rec, block);
 
@@ -2414,10 +2421,7 @@ make_external:
 						     rec, index, offsets, mtr);
 		}
 
-		btr_cur_compress_if_useful(
-			cursor,
-			big_rec_vec != NULL && (flags & BTR_KEEP_POS_FLAG),
-			mtr);
+		btr_cur_compress_if_useful(cursor, mtr);
 
 		if (page_zip && !dict_index_is_clust(index)
 		    && page_is_leaf(page)) {
@@ -2437,21 +2441,6 @@ make_external:
 		}
 	}
 
-	if (big_rec_vec) {
-		ut_ad(page_is_leaf(page));
-		ut_ad(dict_index_is_clust(index));
-		ut_ad(flags & BTR_KEEP_POS_FLAG);
-
-		/* btr_page_split_and_insert() in
-		btr_cur_pessimistic_insert() invokes
-		mtr_memo_release(mtr, index->lock, MTR_MEMO_X_LOCK).
-		We must keep the index->lock when we created a
-		big_rec, so that row_upd_clust_rec() can store the
-		big_rec in the same mini-transaction. */
-
-		mtr_x_lock(dict_index_get_lock(index), mtr);
-	}
-
 	/* Was the record to be updated positioned as the first user
 	record on its page? */
 	was_first = page_cur_is_before_first(page_cursor);
@@ -2467,7 +2456,6 @@ make_external:
 	ut_a(rec);
 	ut_a(err == DB_SUCCESS);
 	ut_a(dummy_big_rec == NULL);
-	page_cursor->rec = rec;
 
 	if (dict_index_is_sec_or_ibuf(index)) {
 		/* Update PAGE_MAX_TRX_ID in the index page header.
@@ -2526,39 +2514,6 @@ return_after_reservations:
 	return(err);
 }
 
-/**************************************************************//**
-Commits and restarts a mini-transaction so that it will retain an
-x-lock on index->lock and the cursor page. */
-UNIV_INTERN
-void
-btr_cur_mtr_commit_and_start(
-/*=========================*/
-	btr_cur_t*	cursor,	/*!< in: cursor */
-	mtr_t*		mtr)	/*!< in/out: mini-transaction */
-{
-	buf_block_t*	block;
-
-	block = btr_cur_get_block(cursor);
-
-	ut_ad(mtr_memo_contains(mtr, dict_index_get_lock(cursor->index),
-				MTR_MEMO_X_LOCK));
-	ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
-	/* Keep the locks across the mtr_commit(mtr). */
-	rw_lock_x_lock(dict_index_get_lock(cursor->index));
-	rw_lock_x_lock(&block->lock);
-	mutex_enter(&block->mutex);
-	buf_block_buf_fix_inc(block, __FILE__, __LINE__);
-	mutex_exit(&block->mutex);
-	/* Write out the redo log. */
-	mtr_commit(mtr);
-	mtr_start(mtr);
-	/* Reassociate the locks with the mini-transaction.
-	They will be released on mtr_commit(mtr). */
-	mtr_memo_push(mtr, dict_index_get_lock(cursor->index),
-		      MTR_MEMO_X_LOCK);
-	mtr_memo_push(mtr, block, MTR_MEMO_PAGE_X_FIX);
-}
-
 /*==================== B-TREE DELETE MARK AND UNMARK ===============*/
 
 /****************************************************************//**
@@ -2665,7 +2620,8 @@ btr_cur_parse_del_mark_set_clust_rec(
 
 		/* We do not need to reserve btr_search_latch, as the page
 		is only being recovered, and there cannot be a hash index to
-		it. */
+		it. Besides, these fields are being updated in place
+		and the adaptive hash index does not depend on them. */
 
 		btr_rec_set_deleted_flag(rec, page_zip, val);
 
@@ -2745,9 +2701,9 @@ btr_cur_del_mark_set_clust_rec(
 		return(err);
 	}
 
-	if (block->is_hashed) {
-		rw_lock_x_lock(&btr_search_latch);
-	}
+	/* The btr_search_latch is not needed here, because
+	the adaptive hash index does not depend on the delete-mark
+	and the delete-mark is being updated in place. */
 
 	page_zip = buf_block_get_page_zip(block);
 
@@ -2761,10 +2717,6 @@ btr_cur_del_mark_set_clust_rec(
 				       index, offsets, trx, roll_ptr);
 	}
 
-	if (block->is_hashed) {
-		rw_lock_x_unlock(&btr_search_latch);
-	}
-
 	btr_cur_del_mark_set_clust_rec_log(flags, rec, index, val, trx,
 					   roll_ptr, mtr);
 
@@ -2840,7 +2792,8 @@ btr_cur_parse_del_mark_set_sec_rec(
 
 		/* We do not need to reserve btr_search_latch, as the page
 		is only being recovered, and there cannot be a hash index to
-		it. */
+		it. Besides, the delete-mark flag is being updated in place
+		and the adaptive hash index does not depend on it. */
 
 		btr_rec_set_deleted_flag(rec, page_zip, val);
 	}
@@ -2888,16 +2841,11 @@ btr_cur_del_mark_set_sec_rec(
 	ut_ad(!!page_rec_is_comp(rec)
 	      == dict_table_is_comp(cursor->index->table));
 
-	if (block->is_hashed) {
-		rw_lock_x_lock(&btr_search_latch);
-	}
-
+	/* We do not need to reserve btr_search_latch, as the
+	delete-mark flag is being updated in place and the adaptive
+	hash index does not depend on it. */
 	btr_rec_set_deleted_flag(rec, buf_block_get_page_zip(block), val);
 
-	if (block->is_hashed) {
-		rw_lock_x_unlock(&btr_search_latch);
-	}
-
 	btr_cur_del_mark_set_sec_rec_log(rec, val, mtr);
 
 	return(DB_SUCCESS);
@@ -2918,8 +2866,11 @@ btr_cur_set_deleted_flag_for_ibuf(
 	ibool		val,		/*!< in: value to set */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
-	/* We do not need to reserve btr_search_latch, as the page has just
-	been read to the buffer pool and there cannot be a hash index to it. */
+	/* We do not need to reserve btr_search_latch, as the page
+	has just been read to the buffer pool and there cannot be
+	a hash index to it.  Besides, the delete-mark flag is being
+	updated in place and the adaptive hash index does not depend
+	on it. */
 
 	btr_rec_set_deleted_flag(rec, page_zip, val);
 
@@ -2939,12 +2890,10 @@ UNIV_INTERN
 ibool
 btr_cur_compress_if_useful(
 /*=======================*/
-	btr_cur_t*	cursor,	/*!< in/out: cursor on the page to compress;
-				cursor does not stay valid if !adjust and
-				compression occurs */
-	ibool		adjust,	/*!< in: TRUE if should adjust the
-				cursor position even if compression occurs */
-	mtr_t*		mtr)	/*!< in/out: mini-transaction */
+	btr_cur_t*	cursor,	/*!< in: cursor on the page to compress;
+				cursor does not stay valid if compression
+				occurs */
+	mtr_t*		mtr)	/*!< in: mtr */
 {
 	ut_ad(mtr_memo_contains(mtr,
 				dict_index_get_lock(btr_cur_get_index(cursor)),
@@ -2953,7 +2902,7 @@ btr_cur_compress_if_useful(
 				MTR_MEMO_PAGE_X_FIX));
 
 	return(btr_cur_compress_recommendation(cursor, mtr)
-	       && btr_compress(cursor, adjust, mtr));
+	       && btr_compress(cursor, mtr));
 }
 
 /*******************************************************//**
@@ -3195,7 +3144,7 @@ return_after_reservations:
 	mem_heap_free(heap);
 
 	if (ret == FALSE) {
-		ret = btr_cur_compress_if_useful(cursor, FALSE, mtr);
+		ret = btr_cur_compress_if_useful(cursor, mtr);
 	}
 
 	if (n_extents > 0) {

=== modified file 'storage/innobase/btr/btr0pcur.c'
--- a/storage/innobase/btr/btr0pcur.c	2011-08-10 12:03:33 +0000
+++ b/storage/innobase/btr/btr0pcur.c	2011-09-26 07:08:42 +0000
@@ -266,8 +266,10 @@ btr_pcur_restore_position_func(
 					file, line, mtr))) {
 			cursor->pos_state = BTR_PCUR_IS_POSITIONED;
 
-			buf_block_dbg_add_level(btr_pcur_get_block(cursor),
-						SYNC_TREE_NODE);
+			buf_block_dbg_add_level(
+				btr_pcur_get_block(cursor),
+				dict_index_is_ibuf(index)
+				? SYNC_IBUF_TREE_NODE : SYNC_TREE_NODE);
 
 			if (cursor->rel_pos == BTR_PCUR_ON) {
 #ifdef UNIV_DEBUG
@@ -390,7 +392,8 @@ btr_pcur_move_to_next_page(
 	ut_ad(next_page_no != FIL_NULL);
 
 	next_block = btr_block_get(space, zip_size, next_page_no,
-				   cursor->latch_mode, mtr);
+				   cursor->latch_mode,
+				   btr_pcur_get_btr_cur(cursor)->index, mtr);
 	next_page = buf_block_get_frame(next_block);
 #ifdef UNIV_BTR_DEBUG
 	ut_a(page_is_comp(next_page) == page_is_comp(page));

=== modified file 'storage/innobase/btr/btr0sea.c'
--- a/storage/innobase/btr/btr0sea.c	2011-02-28 13:39:07 +0000
+++ b/storage/innobase/btr/btr0sea.c	2011-08-15 09:18:34 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
+Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -845,6 +845,7 @@ btr_search_guess_on_hash(
 	btr_pcur_t	pcur;
 #endif
 	ut_ad(index && info && tuple && cursor && mtr);
+	ut_ad(!dict_index_is_ibuf(index));
 	ut_ad((latch_mode == BTR_SEARCH_LEAF)
 	      || (latch_mode == BTR_MODIFY_LEAF));
 

=== modified file 'storage/innobase/buf/buf0buddy.c'
--- a/storage/innobase/buf/buf0buddy.c	2011-06-23 12:57:25 +0000
+++ b/storage/innobase/buf/buf0buddy.c	2011-09-06 07:14:45 +0000
@@ -330,7 +330,6 @@ buf_buddy_relocate(
 {
 	buf_page_t*	bpage;
 	const ulint	size	= BUF_BUDDY_LOW << i;
-	ullint		usec	= ut_time_us(NULL);
 	mutex_t*	mutex;
 	ulint		space;
 	ulint		page_no;
@@ -397,6 +396,7 @@ buf_buddy_relocate(
 
 	if (buf_page_can_relocate(bpage)) {
 		/* Relocate the compressed page. */
+		ullint	usec	= ut_time_us(NULL);
 		ut_a(bpage->zip.data == src);
 		memcpy(dst, src, size);
 		bpage->zip.data = dst;

=== modified file 'storage/innobase/buf/buf0buf.c'
--- a/storage/innobase/buf/buf0buf.c	2011-07-19 14:54:59 +0000
+++ b/storage/innobase/buf/buf0buf.c	2011-09-30 11:37:22 +0000
@@ -3015,19 +3015,20 @@ buf_page_init_low(
 
 /********************************************************************//**
 Inits a page to the buffer buf_pool. */
-static
+static __attribute__((nonnull))
 void
 buf_page_init(
 /*==========*/
+	buf_pool_t*	buf_pool,/*!< in/out: buffer pool */
 	ulint		space,	/*!< in: space id */
 	ulint		offset,	/*!< in: offset of the page within space
 				in units of a page */
 	ulint		fold,	/*!< in: buf_page_address_fold(space,offset) */
-	buf_block_t*	block)	/*!< in: block to init */
+	buf_block_t*	block)	/*!< in/out: block to init */
 {
 	buf_page_t*	hash_page;
-	buf_pool_t*	buf_pool = buf_pool_get(space, offset);
 
+	ut_ad(buf_pool == buf_pool_get(space, offset));
 	ut_ad(buf_pool_mutex_own(buf_pool));
 	ut_ad(mutex_own(&(block->mutex)));
 	ut_a(buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE);
@@ -3186,7 +3187,7 @@ err_exit:
 
 		ut_ad(buf_pool_from_bpage(bpage) == buf_pool);
 
-		buf_page_init(space, offset, fold, block);
+		buf_page_init(buf_pool, space, offset, fold, block);
 
 		/* The block must be put to the LRU list, to the old blocks */
 		buf_LRU_add_block(bpage, TRUE/* to old blocks */);
@@ -3390,7 +3391,7 @@ buf_page_create(
 
 	mutex_enter(&block->mutex);
 
-	buf_page_init(space, offset, fold, block);
+	buf_page_init(buf_pool, space, offset, fold, block);
 
 	/* The block must be put to the LRU list */
 	buf_LRU_add_block(&block->page, FALSE);
@@ -3474,6 +3475,53 @@ buf_page_create(
 }
 
 /********************************************************************//**
+Mark a table with the specified space pointed by bpage->space corrupted.
+Also remove the bpage from LRU list.
+@return TRUE if successful */
+static
+ibool
+buf_mark_space_corrupt(
+/*===================*/
+	buf_page_t*	bpage)	/*!< in: pointer to the block in question */
+{
+	buf_pool_t*	buf_pool = buf_pool_from_bpage(bpage);
+	const ibool	uncompressed = (buf_page_get_state(bpage)
+					== BUF_BLOCK_FILE_PAGE);
+	ulint		space = bpage->space;
+	ibool		ret = TRUE;
+
+	/* First unfix and release lock on the bpage */
+	buf_pool_mutex_enter(buf_pool);
+	mutex_enter(buf_page_get_mutex(bpage));
+	ut_ad(buf_page_get_io_fix(bpage) == BUF_IO_READ);
+	ut_ad(bpage->buf_fix_count == 0);
+
+	/* Set BUF_IO_NONE before we remove the block from LRU list */
+	buf_page_set_io_fix(bpage, BUF_IO_NONE);
+
+	if (uncompressed) {
+		rw_lock_x_unlock_gen(
+			&((buf_block_t*) bpage)->lock,
+			BUF_IO_READ);
+	}
+
+	/* Find the table with specified space id, and mark it corrupted */
+	if (dict_set_corrupted_by_space(space)) {
+		buf_LRU_free_one_page(bpage);
+	} else {
+		ret = FALSE;
+	}
+
+	ut_ad(buf_pool->n_pend_reads > 0);
+	buf_pool->n_pend_reads--;
+
+	mutex_exit(buf_page_get_mutex(bpage));
+	buf_pool_mutex_exit(buf_pool);
+
+	return(ret);
+}
+
+/********************************************************************//**
 Completes an asynchronous read or write request of a file page to or from
 the buffer pool. */
 UNIV_INTERN
@@ -3598,10 +3646,19 @@ corrupt:
 			      "InnoDB: about forcing recovery.\n", stderr);
 
 			if (srv_force_recovery < SRV_FORCE_IGNORE_CORRUPT) {
-				fputs("InnoDB: Ending processing because of"
-				      " a corrupt database page.\n",
-				      stderr);
-				exit(1);
+				/* If page space id is larger than TRX_SYS_SPACE
+				(0), we will attempt to mark the corresponding
+				table as corrupted instead of crashing server */
+				if (bpage->space > TRX_SYS_SPACE
+				    && buf_mark_space_corrupt(bpage)) {
+					return;
+				} else {
+					fputs("InnoDB: Ending processing"
+					      " because of"
+					      " a corrupt database page.\n",
+					      stderr);
+					ut_error;
+				}
 			}
 		}
 

=== modified file 'storage/innobase/buf/buf0lru.c'
--- a/storage/innobase/buf/buf0lru.c	2011-06-23 12:57:25 +0000
+++ b/storage/innobase/buf/buf0lru.c	2011-08-17 01:07:59 +0000
@@ -1885,6 +1885,22 @@ buf_LRU_block_free_hashed_page(
 	buf_LRU_block_free_non_file_page(block);
 }
 
+/******************************************************************//**
+Remove one page from LRU list and put it to free list */
+UNIV_INTERN
+void
+buf_LRU_free_one_page(
+/*==================*/
+	buf_page_t*	bpage)	/*!< in/out: block, must contain a file page and
+				be in a state where it can be freed; there
+				may or may not be a hash index to the page */
+{
+	if (buf_LRU_block_remove_hashed_page(bpage, TRUE)
+	    != BUF_BLOCK_ZIP_FREE) {
+		buf_LRU_block_free_hashed_page((buf_block_t*) bpage);
+	}
+}
+
 /**********************************************************************//**
 Updates buf_pool->LRU_old_ratio for one buffer pool instance.
 @return	updated old_pct */

=== modified file 'storage/innobase/dict/dict0crea.c'
--- a/storage/innobase/dict/dict0crea.c	2011-05-09 08:12:26 +0000
+++ b/storage/innobase/dict/dict0crea.c	2011-08-15 09:18:34 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
+Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -827,7 +827,7 @@ dict_truncate_index_tree(
 	appropriate field in the SYS_INDEXES record: this mini-transaction
 	marks the B-tree totally truncated */
 
-	btr_block_get(space, zip_size, root_page_no, RW_X_LATCH, mtr);
+	btr_block_get(space, zip_size, root_page_no, RW_X_LATCH, NULL, mtr);
 
 	btr_free_root(space, zip_size, root_page_no, mtr);
 create:

=== modified file 'storage/innobase/dict/dict0dict.c'
--- a/storage/innobase/dict/dict0dict.c	2011-05-31 09:12:32 +0000
+++ b/storage/innobase/dict/dict0dict.c	2011-08-29 09:44:28 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
+Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -54,6 +54,7 @@ UNIV_INTERN dict_index_t*	dict_ind_compa
 #include "row0merge.h"
 #include "m_ctype.h" /* my_isspace() */
 #include "ha_prototypes.h" /* innobase_strcasecmp(), innobase_casedn_str()*/
+#include "row0upd.h"
 
 #include <ctype.h>
 
@@ -611,8 +612,7 @@ dict_table_get_on_id(
 {
 	dict_table_t*	table;
 
-	if (table_id <= DICT_FIELDS_ID
-	    || trx->dict_operation_lock_mode == RW_X_LATCH) {
+	if (trx->dict_operation_lock_mode == RW_X_LATCH) {
 
 		/* Note: An X latch implies that the transaction
 		already owns the dictionary mutex. */
@@ -1714,7 +1714,8 @@ undo_size_ok:
 
 	new_index->page = page_no;
 	rw_lock_create(index_tree_rw_lock_key, &new_index->lock,
-		       SYNC_INDEX_TREE);
+		       dict_index_is_ibuf(index)
+		       ? SYNC_IBUF_INDEX_TREE : SYNC_INDEX_TREE);
 
 	if (!UNIV_UNLIKELY(new_index->type & DICT_UNIVERSAL)) {
 
@@ -5045,4 +5046,187 @@ dict_close(void)
 		rw_lock_free(&dict_table_stats_latches[i]);
 	}
 }
+
+/**********************************************************************//**
+Find a table in dict_sys->table_LRU list with specified space id
+@return table if found, NULL if not */
+static
+dict_table_t*
+dict_find_table_by_space(
+/*=====================*/
+	ulint	space_id)		/*!< in: space ID */
+{
+	dict_table_t*   table;
+	ulint		num_item;
+	ulint		count = 0;
+
+	ut_ad(space_id > 0);
+
+	table = UT_LIST_GET_FIRST(dict_sys->table_LRU);
+	num_item =  UT_LIST_GET_LEN(dict_sys->table_LRU);
+
+	/* This function intentionally does not acquire mutex as it is used
+	by error handling code in deep call stack as last means to avoid
+	killing the server, so it worth to risk some consequencies for
+	the action. */
+	while (table && count < num_item) {
+		if (table->space == space_id) {
+			return(table);
+		}
+
+		table = UT_LIST_GET_NEXT(table_LRU, table);
+		count++;
+	}
+
+	return(NULL);
+}
+
+/**********************************************************************//**
+Flags a table with specified space_id corrupted in the data dictionary
+cache
+@return TRUE if successful */
+UNIV_INTERN
+ibool
+dict_set_corrupted_by_space(
+/*========================*/
+	ulint	space_id)		/*!< in: space ID */
+{
+	dict_table_t*   table;
+
+	table = dict_find_table_by_space(space_id);
+
+	if (!table) {
+		return(FALSE);
+	}
+
+	/* mark the table->corrupted bit only, since the caller
+	could be too deep in the stack for SYS_INDEXES update */
+	table->corrupted = TRUE;
+
+	return(TRUE);
+}
+
+/**********************************************************************//**
+Flags an index corrupted both in the data dictionary cache
+and in the SYS_INDEXES */
+UNIV_INTERN
+void
+dict_set_corrupted(
+/*===============*/
+	dict_index_t*	index)		/*!< in/out: index */
+{
+	mem_heap_t*	heap;
+	mtr_t		mtr;
+	dict_index_t*	sys_index;
+	dtuple_t*	tuple;
+	dfield_t*	dfield;
+	byte*		buf;
+	const char*	status;
+	btr_cur_t	cursor;
+
+	ut_ad(index);
+	ut_ad(mutex_own(&dict_sys->mutex));
+	ut_ad(!dict_table_is_comp(dict_sys->sys_tables));
+	ut_ad(!dict_table_is_comp(dict_sys->sys_indexes));
+
+#ifdef UNIV_SYNC_DEBUG
+        ut_ad(sync_thread_levels_empty_except_dict());
+#endif
+
+	/* Mark the table as corrupted only if the clustered index
+	is corrupted */
+	if (dict_index_is_clust(index)) {
+		index->table->corrupted = TRUE;
+	}
+
+	if (UNIV_UNLIKELY(dict_index_is_corrupted(index))) {
+		/* The index was already flagged corrupted. */
+		ut_ad(index->table->corrupted);
+		return;
+	}
+
+	heap = mem_heap_create(sizeof(dtuple_t) + 2 * (sizeof(dfield_t)
+			       + sizeof(que_fork_t) + sizeof(upd_node_t)
+			       + sizeof(upd_t) + 12));
+	mtr_start(&mtr);
+	index->type |= DICT_CORRUPT;
+
+	sys_index = UT_LIST_GET_FIRST(dict_sys->sys_indexes->indexes);
+
+	/* Find the index row in SYS_INDEXES */
+	tuple = dtuple_create(heap, 2);
+
+	dfield = dtuple_get_nth_field(tuple, 0);
+	buf = mem_heap_alloc(heap, 8);
+	mach_write_to_8(buf, index->table->id);
+	dfield_set_data(dfield, buf, 8);
+
+	dfield = dtuple_get_nth_field(tuple, 1);
+	buf = mem_heap_alloc(heap, 8);
+	mach_write_to_8(buf, index->id);
+	dfield_set_data(dfield, buf, 8);
+
+	dict_index_copy_types(tuple, sys_index, 2);
+
+	btr_cur_search_to_nth_level(sys_index, 0, tuple, PAGE_CUR_GE,
+				    BTR_MODIFY_LEAF,
+				    &cursor, 0, __FILE__, __LINE__, &mtr);
+
+	if (cursor.up_match == dtuple_get_n_fields(tuple)) {
+		/* UPDATE SYS_INDEXES SET TYPE=index->type
+		WHERE TABLE_ID=index->table->id AND INDEX_ID=index->id */
+		ulint	len;
+		byte*	field	= rec_get_nth_field_old(
+			btr_cur_get_rec(&cursor),
+			DICT_SYS_INDEXES_TYPE_FIELD, &len);
+		if (len != 4) {
+			goto fail;
+		}
+		mlog_write_ulint(field, index->type, MLOG_4BYTES, &mtr);
+		status = "  InnoDB: Flagged corruption of ";
+	} else {
+fail:
+		status = "  InnoDB: Unable to flag corruption of ";
+	}
+
+	mtr_commit(&mtr);
+	mem_heap_free(heap);
+
+	ut_print_timestamp(stderr);
+	fputs(status, stderr);
+	dict_index_name_print(stderr, NULL, index);
+	putc('\n', stderr);
+}
+
+/**********************************************************************//**
+Flags an index corrupted in the data dictionary cache only. This
+is used mostly to mark a corrupted index when index's own dictionary
+is corrupted, and we force to load such index for repair purpose */
+UNIV_INTERN
+void
+dict_set_corrupted_index_cache_only(
+/*================================*/
+	dict_index_t*	index,		/*!< in/out: index */
+	dict_table_t*	table)		/*!< in/out: table */
+{
+	ut_ad(index);
+	ut_ad(mutex_own(&dict_sys->mutex));
+	ut_ad(!dict_table_is_comp(dict_sys->sys_tables));
+	ut_ad(!dict_table_is_comp(dict_sys->sys_indexes));
+
+	/* Mark the table as corrupted only if the clustered index
+	is corrupted */
+	if (dict_index_is_clust(index)) {
+		dict_table_t*	corrupt_table;
+
+		corrupt_table = table ? table : index->table;
+		ut_ad(!index->table || !table || index->table  == table);
+
+		if (corrupt_table) {
+			corrupt_table->corrupted = TRUE;
+		}
+	}
+
+	index->type |= DICT_CORRUPT;
+}
 #endif /* !UNIV_HOTBACKUP */

=== modified file 'storage/innobase/dict/dict0load.c'
--- a/storage/innobase/dict/dict0load.c	2011-05-31 09:12:32 +0000
+++ b/storage/innobase/dict/dict0load.c	2011-08-29 09:44:28 +0000
@@ -52,6 +52,11 @@ static const char* SYSTEM_TABLE_NAME[] =
 	"SYS_FOREIGN",
 	"SYS_FOREIGN_COLS"
 };
+
+/* If this flag is TRUE, then we will load the cluster index's (and tables')
+metadata even if it is marked as "corrupted". */
+UNIV_INTERN my_bool     srv_load_corrupted = FALSE;
+
 /****************************************************************//**
 Compare the name of an index column.
 @return	TRUE if the i'th column of index is 'name'. */
@@ -1324,6 +1329,9 @@ err_len:
 		goto err_len;
 	}
 	type = mach_read_from_4(field);
+	if (UNIV_UNLIKELY(type & (~0 << DICT_IT_BITS))) {
+		return("unknown SYS_INDEXES.TYPE bits");
+	}
 
 	field = rec_get_nth_field_old(rec, 7/*SPACE*/, &len);
 	if (UNIV_UNLIKELY(len != 4)) {
@@ -1423,16 +1431,47 @@ dict_load_indexes(
 			goto next_rec;
 		} else if (err_msg) {
 			fprintf(stderr, "InnoDB: %s\n", err_msg);
+			if (ignore_err & DICT_ERR_IGNORE_CORRUPT) {
+				goto next_rec;
+			}
 			error = DB_CORRUPTION;
 			goto func_exit;
 		}
 
 		ut_ad(index);
 
+		/* Check whether the index is corrupted */
+		if (dict_index_is_corrupted(index)) {
+			ut_print_timestamp(stderr);
+			fputs("  InnoDB: ", stderr);
+			dict_index_name_print(stderr, NULL, index);
+			fputs(" is corrupted\n", stderr);
+
+			if (!srv_load_corrupted
+			    && !(ignore_err & DICT_ERR_IGNORE_CORRUPT)
+			    && dict_index_is_clust(index)) {
+				dict_mem_index_free(index);
+
+				error = DB_INDEX_CORRUPT;
+				goto func_exit;
+			} else {
+				/* We will load the index if
+				1) srv_load_corrupted is TRUE
+				2) ignore_err is set with
+				DICT_ERR_IGNORE_CORRUPT
+				3) if the index corrupted is a secondary
+				index */
+				ut_print_timestamp(stderr);
+				fputs("  InnoDB: load corrupted index ", stderr);
+				dict_index_name_print(stderr, NULL, index);
+				putc('\n', stderr);
+			}
+		}
+
 		/* We check for unsupported types first, so that the
 		subsequent checks are relevant for the supported types. */
-		if (index->type & ~(DICT_CLUSTERED | DICT_UNIQUE)) {
-
+		if (index->type & ~(DICT_CLUSTERED | DICT_UNIQUE
+				    | DICT_CORRUPT)) {
 			fprintf(stderr,
 				"InnoDB: Error: unknown type %lu"
 				" of index %s of table %s\n",
@@ -1453,9 +1492,14 @@ dict_load_indexes(
 				/* If caller can tolerate this error,
 				we will continue to load the index and
 				let caller deal with this error. However
-				mark the index and table corrupted */
-				index->corrupted = TRUE;
-				table->corrupted = TRUE;
+				mark the index and table corrupted. We
+				only need to mark such in the index
+				dictionary cache for such metadata corruption,
+				since we would always be able to set it
+				when loading the dictionary cache */
+				dict_set_corrupted_index_cache_only(
+					index, table);
+
 				fprintf(stderr,
 					"InnoDB: Index is corrupt but forcing"
 					" load into data dictionary\n");
@@ -1495,9 +1539,10 @@ corrupted:
 					index->name, table->name);
 
 				/* If the force recovery flag is set, and
-				if the failed index is not the primary index, we
-				will continue and open other indexes */
-				if (srv_force_recovery
+				if the failed index is not the clustered index,
+				we will continue and open other indexes */
+				if ((srv_force_recovery
+				     || srv_load_corrupted)
 				    && !dict_index_is_clust(index)) {
 					error = DB_SUCCESS;
 					goto next_rec;
@@ -1812,6 +1857,30 @@ err_exit:
 
 	err = dict_load_indexes(table, heap, ignore_err);
 
+	if (err == DB_INDEX_CORRUPT) {
+		/* Refuse to load the table if the table has a corrupted
+		cluster index */
+		if (!srv_load_corrupted) {
+			fprintf(stderr, "InnoDB: Error: Load table ");
+			ut_print_name(stderr, NULL, TRUE, table->name);
+			fprintf(stderr, " failed, the table has corrupted"
+					" clustered indexes. Turn on"
+					" 'innodb_force_load_corrupted'"
+					" to drop it\n");
+
+			dict_table_remove_from_cache(table);
+			table = NULL;
+			goto func_exit;
+		} else {
+			dict_index_t*	clust_index;
+			clust_index = dict_table_get_first_index(table);
+
+			if (dict_index_is_corrupted(clust_index)) {
+				table->corrupted = TRUE;
+			}
+		}
+	}
+
 	/* Initialize table foreign_child value. Its value could be
 	changed when dict_load_foreigns() is called below */
 	table->fk_max_recusive_level = 0;
@@ -1838,9 +1907,15 @@ err_exit:
 		index = dict_table_get_first_index(table);
 
 		if (!srv_force_recovery || !index
-		     || !dict_index_is_clust(index)) {
+		    || !dict_index_is_clust(index)) {
 			dict_table_remove_from_cache(table);
 			table = NULL;
+		} else if (dict_index_is_corrupted(index)) {
+
+			/* It is possible we force to load a corrupted
+			clustered index if srv_load_corrupted is set.
+			Mark the table as corrupted in this case */
+			table->corrupted = TRUE;
 		}
 	}
 #if 0
@@ -1867,6 +1942,7 @@ err_exit:
 		mutex_exit(&dict_foreign_err_mutex);
 	}
 #endif /* 0 */
+func_exit:
 	mem_heap_free(heap);
 
 	return(table);

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2011-08-15 18:12:11 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2011-09-21 10:40:41 +0000
@@ -1043,6 +1043,10 @@ convert_error_code_to_mysql(
 #endif /* HA_ERR_TOO_MANY_CONCURRENT_TRXS */
 	case DB_UNSUPPORTED:
 		return(HA_ERR_UNSUPPORTED);
+	case DB_INDEX_CORRUPT:
+		return(HA_ERR_INDEX_CORRUPT);
+	case DB_UNDO_RECORD_TOO_BIG:
+		return(HA_ERR_UNDO_REC_TOO_BIG);
 	}
 }
 
@@ -2078,6 +2082,29 @@ no_db_name:
 
 }
 
+/*****************************************************************//**
+A wrapper function of innobase_convert_name(), convert a table or
+index name to the MySQL system_charset_info (UTF-8) and quote it if needed.
+@return	pointer to the end of buf */
+static inline
+void
+innobase_format_name(
+/*==================*/
+	char*		buf,	/*!< out: buffer for converted identifier */
+	ulint		buflen,	/*!< in: length of buf, in bytes */
+	const char*	name,	/*!< in: index or table name to format */
+	ibool		is_index_name) /*!< in: index name */
+{
+	const char*     bufend;
+
+	bufend = innobase_convert_name(buf, buflen, name, strlen(name),
+				       NULL, !is_index_name);
+
+	ut_ad((ulint) (bufend - buf) < buflen);
+
+	buf[bufend - buf] = '\0';
+}
+
 /**********************************************************************//**
 Determines if the currently running transaction has been interrupted.
 @return	TRUE if interrupted */
@@ -5645,12 +5672,14 @@ ha_innobase::index_read(
 
 	index = prebuilt->index;
 
-	if (UNIV_UNLIKELY(index == NULL)) {
+	if (UNIV_UNLIKELY(index == NULL) || dict_index_is_corrupted(index)) {
 		prebuilt->index_usable = FALSE;
 		DBUG_RETURN(HA_ERR_CRASHED);
 	}
 	if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
-		DBUG_RETURN(HA_ERR_TABLE_DEF_CHANGED);
+		DBUG_RETURN(dict_index_is_corrupted(index)
+			    ? HA_ERR_INDEX_CORRUPT
+			    : HA_ERR_TABLE_DEF_CHANGED);
 	}
 
 	/* Note that if the index for which the search template is built is not
@@ -5836,10 +5865,33 @@ ha_innobase::change_active_index(
 							   prebuilt->index);
 
 	if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
-		push_warning_printf(user_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-				    HA_ERR_TABLE_DEF_CHANGED,
-				    "InnoDB: insufficient history for index %u",
-				    keynr);
+		if (dict_index_is_corrupted(prebuilt->index)) {
+			char	index_name[MAX_FULL_NAME_LEN + 1];
+			char	table_name[MAX_FULL_NAME_LEN + 1];
+
+			innobase_format_name(
+				index_name, sizeof index_name,
+				prebuilt->index->name, TRUE);
+
+			innobase_format_name(
+				table_name, sizeof table_name,
+				prebuilt->index->table->name, FALSE);
+
+			push_warning_printf(
+				user_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+				HA_ERR_INDEX_CORRUPT,
+				"InnoDB: Index %s for table %s is"
+				" marked as corrupted",
+				index_name, table_name);
+			DBUG_RETURN(1);
+		} else {
+			push_warning_printf(
+				user_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+				HA_ERR_TABLE_DEF_CHANGED,
+				"InnoDB: insufficient history for index %u",
+				keynr);
+		}
+
 		/* The caller seems to ignore this.  Thus, we must check
 		this again in row_search_for_mysql(). */
 		DBUG_RETURN(2);
@@ -7499,6 +7551,10 @@ ha_innobase::records_in_range(
 		n_rows = HA_POS_ERROR;
 		goto func_exit;
 	}
+	if (dict_index_is_corrupted(index)) {
+		n_rows = HA_ERR_INDEX_CORRUPT;
+		goto func_exit;
+	}
 	if (UNIV_UNLIKELY(!row_merge_is_index_usable(prebuilt->trx, index))) {
 		n_rows = HA_ERR_TABLE_DEF_CHANGED;
 		goto func_exit;
@@ -8165,6 +8221,7 @@ ha_innobase::check(
 	ulint		n_rows_in_table	= ULINT_UNDEFINED;
 	ibool		is_ok		= TRUE;
 	ulint		old_isolation_level;
+	ibool		table_corrupted;
 
 	DBUG_ENTER("ha_innobase::check");
 	DBUG_ASSERT(thd == ha_thd());
@@ -8206,6 +8263,14 @@ ha_innobase::check(
 
 	prebuilt->trx->isolation_level = TRX_ISO_REPEATABLE_READ;
 
+	/* Check whether the table is already marked as corrupted
+	before running the check table */
+	table_corrupted = prebuilt->table->corrupted;
+
+	/* Reset table->corrupted bit so that check table can proceed to
+	do additional check */
+	prebuilt->table->corrupted = FALSE;
+
 	/* Enlarge the fatal lock wait timeout during CHECK TABLE. */
 	mutex_enter(&kernel_mutex);
 	srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */
@@ -8214,6 +8279,7 @@ ha_innobase::check(
 	for (index = dict_table_get_first_index(prebuilt->table);
 	     index != NULL;
 	     index = dict_table_get_next_index(index)) {
+		char	index_name[MAX_FULL_NAME_LEN + 1];
 #if 0
 		fputs("Validating index ", stderr);
 		ut_print_name(stderr, trx, FALSE, index->name);
@@ -8222,11 +8288,16 @@ ha_innobase::check(
 
 		if (!btr_validate_index(index, prebuilt->trx)) {
 			is_ok = FALSE;
+
+			innobase_format_name(
+				index_name, sizeof index_name,
+				prebuilt->index->name, TRUE);
+
 			push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 					    ER_NOT_KEYFILE,
 					    "InnoDB: The B-tree of"
-					    " index '%-.200s' is corrupted.",
-					    index->name);
+					    " index %s is corrupted.",
+					    index_name);
 			continue;
 		}
 
@@ -8239,11 +8310,26 @@ ha_innobase::check(
 			prebuilt->trx, prebuilt->index);
 
 		if (UNIV_UNLIKELY(!prebuilt->index_usable)) {
-			push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-					    HA_ERR_TABLE_DEF_CHANGED,
-					    "InnoDB: Insufficient history for"
-					    " index '%-.200s'",
-					    index->name);
+			innobase_format_name(
+				index_name, sizeof index_name,
+				prebuilt->index->name, TRUE);
+
+			if (dict_index_is_corrupted(prebuilt->index)) {
+				push_warning_printf(
+					user_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+					HA_ERR_INDEX_CORRUPT,
+					"InnoDB: Index %s is marked as"
+					" corrupted",
+					index_name);
+				is_ok = FALSE;
+			} else {
+				push_warning_printf(
+					thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+					HA_ERR_TABLE_DEF_CHANGED,
+					"InnoDB: Insufficient history for"
+					" index %s",
+					index_name);
+			}
 			continue;
 		}
 
@@ -8257,12 +8343,19 @@ ha_innobase::check(
 		prebuilt->select_lock_type = LOCK_NONE;
 
 		if (!row_check_index_for_mysql(prebuilt, index, &n_rows)) {
+			innobase_format_name(
+				index_name, sizeof index_name,
+				index->name, TRUE);
+
 			push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 					    ER_NOT_KEYFILE,
 					    "InnoDB: The B-tree of"
-					    " index '%-.200s' is corrupted.",
-					    index->name);
+					    " index %s is corrupted.",
+					    index_name);
 			is_ok = FALSE;
+			row_mysql_lock_data_dictionary(prebuilt->trx);
+			dict_set_corrupted(index);
+			row_mysql_unlock_data_dictionary(prebuilt->trx);
 		}
 
 		if (thd_killed(user_thd)) {
@@ -8289,6 +8382,20 @@ ha_innobase::check(
 		}
 	}
 
+	if (table_corrupted) {
+		/* If some previous operation has marked the table as
+		corrupted in memory, and has not propagated such to
+		clustered index, we will do so here */
+		index = dict_table_get_first_index(prebuilt->table);
+
+		if (!dict_index_is_corrupted(index)) {
+			mutex_enter(&dict_sys->mutex);
+			dict_set_corrupted(index);
+			mutex_exit(&dict_sys->mutex);
+		}
+		prebuilt->table->corrupted = TRUE;
+	}
+
 	/* Restore the original isolation level */
 	prebuilt->trx->isolation_level = old_isolation_level;
 
@@ -11082,6 +11189,11 @@ static MYSQL_SYSVAR_BOOL(large_prefix, i
   "Support large index prefix length of REC_VERSION_56_MAX_INDEX_COL_LEN (3072) bytes.",
   NULL, NULL, FALSE);
 
+static MYSQL_SYSVAR_BOOL(force_load_corrupted, srv_load_corrupted,
+  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
+  "Force InnoDB to load metadata of corrupted table.",
+  NULL, NULL, FALSE);
+
 static MYSQL_SYSVAR_BOOL(locks_unsafe_for_binlog, innobase_locks_unsafe_for_binlog,
   PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
   "Force InnoDB to not use next-key locking, to use only row-level locking.",
@@ -11341,6 +11453,7 @@ static struct st_mysql_sys_var* innobase
   MYSQL_SYSVAR(flush_method),
   MYSQL_SYSVAR(force_recovery),
   MYSQL_SYSVAR(large_prefix),
+  MYSQL_SYSVAR(force_load_corrupted),
   MYSQL_SYSVAR(locks_unsafe_for_binlog),
   MYSQL_SYSVAR(lock_wait_timeout),
 #ifdef UNIV_LOG_ARCHIVE

=== modified file 'storage/innobase/ibuf/ibuf0ibuf.c'
--- a/storage/innobase/ibuf/ibuf0ibuf.c	2011-05-04 09:08:07 +0000
+++ b/storage/innobase/ibuf/ibuf0ibuf.c	2011-09-13 06:21:39 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1997, 2010, Innobase Oy. All Rights Reserved.
+Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -402,7 +402,7 @@ ibuf_tree_root_get(
 	block = buf_page_get(
 		IBUF_SPACE_ID, 0, FSP_IBUF_TREE_ROOT_PAGE_NO, RW_X_LATCH, mtr);
 
-	buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+	buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE_NEW);
 
 	root = buf_block_get_frame(block);
 
@@ -549,7 +549,7 @@ ibuf_init_at_db_start(void)
 		block = buf_page_get(
 			IBUF_SPACE_ID, 0, FSP_IBUF_TREE_ROOT_PAGE_NO,
 			RW_X_LATCH, &mtr);
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+		buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE);
 
 		root = buf_block_get_frame(block);
 	}
@@ -2209,16 +2209,17 @@ ibuf_add_free_page(void)
 	} else {
 		buf_block_t*	block = buf_page_get(
 			IBUF_SPACE_ID, 0, page_no, RW_X_LATCH, &mtr);
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE_NEW);
 
-		page = buf_block_get_frame(block);
-	}
+		ibuf_enter(&mtr);
 
-	ibuf_enter(&mtr);
+		mutex_enter(&ibuf_mutex);
 
-	mutex_enter(&ibuf_mutex);
+		root = ibuf_tree_root_get(&mtr);
 
-	root = ibuf_tree_root_get(&mtr);
+		buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE_NEW);
+
+		page = buf_block_get_frame(block);
+	}
 
 	/* Add the page to the free list and update the ibuf size data */
 
@@ -2332,8 +2333,7 @@ ibuf_remove_free_page(void)
 		block = buf_page_get(
 			IBUF_SPACE_ID, 0, page_no, RW_X_LATCH, &mtr);
 
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE);
-
+		buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE);
 
 		page = buf_block_get_frame(block);
 	}
@@ -3022,7 +3022,7 @@ ibuf_get_volume_buffered(
 			IBUF_SPACE_ID, 0, prev_page_no, RW_X_LATCH,
 			mtr);
 
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+		buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE);
 
 
 		prev_page = buf_block_get_frame(block);
@@ -3095,7 +3095,7 @@ count_later:
 			IBUF_SPACE_ID, 0, next_page_no, RW_X_LATCH,
 			mtr);
 
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+		buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE);
 
 
 		next_page = buf_block_get_frame(block);
@@ -3333,7 +3333,7 @@ ibuf_set_entry_counter(
 				IBUF_SPACE_ID, 0, prev_page_no,
 				RW_X_LATCH, mtr);
 
-			buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+			buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE);
 
 			prev_page = buf_block_get_frame(block);
 
@@ -4419,6 +4419,7 @@ ibuf_merge_or_delete_for_page(
 	ut_ad(!block || buf_block_get_space(block) == space);
 	ut_ad(!block || buf_block_get_page_no(block) == page_no);
 	ut_ad(!block || buf_block_get_zip_size(block) == zip_size);
+	ut_ad(!block || buf_block_get_io_fix(block) == BUF_IO_READ);
 
 	if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE
 	    || trx_sys_hdr_page(space, page_no)) {
@@ -4571,7 +4572,13 @@ loop:
 
 		ut_a(success);
 
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+		/* This is a user page (secondary index leaf page),
+		but we pretend that it is a change buffer page in
+		order to obey the latching order. This should be OK,
+		because buffered changes are applied immediately while
+		the block is io-fixed. Other threads must not try to
+		latch an io-fixed block. */
+		buf_block_dbg_add_level(block, SYNC_IBUF_TREE_NODE);
 	}
 
 	/* Position pcur in the insert buffer at the first entry for this
@@ -4675,7 +4682,12 @@ loop:
 					__FILE__, __LINE__, &mtr);
 				ut_a(success);
 
-				buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+				/* This is a user page (secondary
+				index leaf page), but it should be OK
+				to use too low latching order for it,
+				as the block is io-fixed. */
+				buf_block_dbg_add_level(
+					block, SYNC_IBUF_TREE_NODE);
 
 				if (!ibuf_restore_pos(space, page_no,
 						      search_tuple,

=== modified file 'storage/innobase/include/btr0btr.h'
--- a/storage/innobase/include/btr0btr.h	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/btr0btr.h	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -199,26 +199,45 @@ btr_block_get_func(
 	ulint		mode,		/*!< in: latch mode */
 	const char*	file,		/*!< in: file name */
 	ulint		line,		/*!< in: line where called */
-	mtr_t*		mtr)		/*!< in/out: mtr */
-	__attribute__((nonnull));
+# ifdef UNIV_SYNC_DEBUG
+	const dict_index_t*	index,	/*!< in: index tree, may be NULL
+					if it is not an insert buffer tree */
+# endif /* UNIV_SYNC_DEBUG */
+	mtr_t*		mtr);		/*!< in/out: mini-transaction */
+# ifdef UNIV_SYNC_DEBUG
+/** Gets a buffer page and declares its latching order level.
+@param space	tablespace identifier
+@param zip_size	compressed page size in bytes or 0 for uncompressed pages
+@param page_no	page number
+@param mode	latch mode
+@param index	index tree, may be NULL if not the insert buffer tree
+@param mtr	mini-transaction handle
+@return the block descriptor */
+#  define btr_block_get(space,zip_size,page_no,mode,index,mtr)	\
+	btr_block_get_func(space,zip_size,page_no,mode,		\
+			   __FILE__,__LINE__,index,mtr)
+# else /* UNIV_SYNC_DEBUG */
 /** Gets a buffer page and declares its latching order level.
 @param space	tablespace identifier
 @param zip_size	compressed page size in bytes or 0 for uncompressed pages
 @param page_no	page number
 @param mode	latch mode
+@param idx	index tree, may be NULL if not the insert buffer tree
 @param mtr	mini-transaction handle
 @return the block descriptor */
-# define btr_block_get(space,zip_size,page_no,mode,mtr) \
+#  define btr_block_get(space,zip_size,page_no,mode,idx,mtr)		\
 	btr_block_get_func(space,zip_size,page_no,mode,__FILE__,__LINE__,mtr)
+# endif /* UNIV_SYNC_DEBUG */
 /** Gets a buffer page and declares its latching order level.
 @param space	tablespace identifier
 @param zip_size	compressed page size in bytes or 0 for uncompressed pages
 @param page_no	page number
 @param mode	latch mode
+@param idx	index tree, may be NULL if not the insert buffer tree
 @param mtr	mini-transaction handle
 @return the uncompressed page frame */
-# define btr_page_get(space,zip_size,page_no,mode,mtr) \
-	buf_block_get_frame(btr_block_get(space,zip_size,page_no,mode,mtr))
+# define btr_page_get(space,zip_size,page_no,mode,idx,mtr)		\
+	buf_block_get_frame(btr_block_get(space,zip_size,page_no,mode,idx,mtr))
 #endif /* !UNIV_HOTBACKUP */
 /**************************************************************//**
 Gets the index id field of a page.
@@ -344,8 +363,7 @@ btr_free_root(
 	ulint	zip_size,	/*!< in: compressed page size in bytes
 				or 0 for uncompressed pages */
 	ulint	root_page_no,	/*!< in: root page number */
-	mtr_t*	mtr);		/*!< in: a mini-transaction which has already
-				been started */
+	mtr_t*	mtr);		/*!< in/out: mini-transaction */
 /*************************************************************//**
 Makes tree one level higher by splitting the root, and inserts
 the tuple. It is assumed that mtr contains an x-latch on the tree.
@@ -481,14 +499,11 @@ UNIV_INTERN
 ibool
 btr_compress(
 /*=========*/
-	btr_cur_t*	cursor,	/*!< in/out: cursor on the page to merge
-				or lift; the page must not be empty:
-				when deleting records, use btr_discard_page()
-				if the page would become empty */
-	ibool		adjust,	/*!< in: TRUE if should adjust the
-				cursor position even if compression occurs */
-	mtr_t*		mtr)	/*!< in/out: mini-transaction */
-	__attribute__((nonnull));
+	btr_cur_t*	cursor,	/*!< in: cursor on the page to merge or lift;
+				the page must not be empty: in record delete
+				use btr_discard_page if the page would become
+				empty */
+	mtr_t*		mtr);	/*!< in: mtr */
 /*************************************************************//**
 Discards a page from a B-tree. This is used to remove the last record from
 a B-tree page: the whole page must be removed at the same time. This cannot

=== modified file 'storage/innobase/include/btr0btr.ic'
--- a/storage/innobase/include/btr0btr.ic	2010-11-03 09:25:14 +0000
+++ b/storage/innobase/include/btr0btr.ic	2011-08-15 09:18:34 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved.
+Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -48,6 +48,10 @@ btr_block_get_func(
 	ulint		mode,		/*!< in: latch mode */
 	const char*	file,		/*!< in: file name */
 	ulint		line,		/*!< in: line where called */
+#ifdef UNIV_SYNC_DEBUG
+	const dict_index_t*	index,	/*!< in: index tree, may be NULL
+					if it is not an insert buffer tree */
+#endif /* UNIV_SYNC_DEBUG */
 	mtr_t*		mtr)		/*!< in/out: mtr */
 {
 	buf_block_t*	block;
@@ -57,7 +61,9 @@ btr_block_get_func(
 
 	if (mode != RW_NO_LATCH) {
 
-		buf_block_dbg_add_level(block, SYNC_TREE_NODE);
+		buf_block_dbg_add_level(
+			block, index != NULL && dict_index_is_ibuf(index)
+			? SYNC_IBUF_TREE_NODE : SYNC_TREE_NODE);
 	}
 
 	return(block);

=== modified file 'storage/innobase/include/btr0cur.h'
--- a/storage/innobase/include/btr0cur.h	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/btr0cur.h	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -36,9 +36,6 @@ Created 10/16/1994 Heikki Tuuri
 #define BTR_NO_LOCKING_FLAG	2	/* do no record lock checking */
 #define BTR_KEEP_SYS_FLAG	4	/* sys fields will be found from the
 					update vector or inserted entry */
-#define BTR_KEEP_POS_FLAG	8	/* btr_cur_pessimistic_update()
-					must keep cursor position when
-					moving columns to big_rec */
 
 #ifndef UNIV_HOTBACKUP
 #include "que0types.h"
@@ -313,9 +310,7 @@ btr_cur_pessimistic_update(
 /*=======================*/
 	ulint		flags,	/*!< in: undo logging, locking, and rollback
 				flags */
-	btr_cur_t*	cursor,	/*!< in/out: cursor on the record to update;
-				cursor may become invalid if *big_rec == NULL
-				|| !(flags & BTR_KEEP_POS_FLAG) */
+	btr_cur_t*	cursor,	/*!< in: cursor on the record to update */
 	mem_heap_t**	heap,	/*!< in/out: pointer to memory heap, or NULL */
 	big_rec_t**	big_rec,/*!< out: big rec vector whose fields have to
 				be stored externally by the caller, or NULL */
@@ -327,16 +322,6 @@ btr_cur_pessimistic_update(
 	que_thr_t*	thr,	/*!< in: query thread */
 	mtr_t*		mtr);	/*!< in: mtr; must be committed before
 				latching any further pages */
-/*****************************************************************
-Commits and restarts a mini-transaction so that it will retain an
-x-lock on index->lock and the cursor page. */
-UNIV_INTERN
-void
-btr_cur_mtr_commit_and_start(
-/*=========================*/
-	btr_cur_t*	cursor,	/*!< in: cursor */
-	mtr_t*		mtr)	/*!< in/out: mini-transaction */
-	UNIV_COLD __attribute__((nonnull));
 /***********************************************************//**
 Marks a clustered index record deleted. Writes an undo log record to
 undo log on this delete marking. Writes in the trx id field the id
@@ -379,13 +364,10 @@ UNIV_INTERN
 ibool
 btr_cur_compress_if_useful(
 /*=======================*/
-	btr_cur_t*	cursor,	/*!< in/out: cursor on the page to compress;
+	btr_cur_t*	cursor,	/*!< in: cursor on the page to compress;
 				cursor does not stay valid if compression
 				occurs */
-	ibool		adjust,	/*!< in: TRUE if should adjust the
-				cursor position even if compression occurs */
-	mtr_t*		mtr)	/*!< in/out: mini-transaction */
-	__attribute__((nonnull));
+	mtr_t*		mtr);	/*!< in: mtr */
 /*******************************************************//**
 Removes the record on which the tree cursor is positioned. It is assumed
 that the mtr has an x-latch on the page where the cursor is positioned,

=== modified file 'storage/innobase/include/btr0cur.ic'
--- a/storage/innobase/include/btr0cur.ic	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/btr0cur.ic	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -139,7 +139,7 @@ btr_cur_compress_recommendation(
 	btr_cur_t*	cursor,	/*!< in: btr cursor */
 	mtr_t*		mtr)	/*!< in: mtr */
 {
-	const page_t*		page;
+	page_t*		page;
 
 	ut_ad(mtr_memo_contains(mtr, btr_cur_get_block(cursor),
 				MTR_MEMO_PAGE_X_FIX));

=== modified file 'storage/innobase/include/buf0buf.h'
--- a/storage/innobase/include/buf0buf.h	2011-07-19 14:54:59 +0000
+++ b/storage/innobase/include/buf0buf.h	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -609,31 +609,6 @@ buf_block_get_modify_clock(
 #else /* !UNIV_HOTBACKUP */
 # define buf_block_modify_clock_inc(block) ((void) 0)
 #endif /* !UNIV_HOTBACKUP */
-/*******************************************************************//**
-Increments the bufferfix count. */
-UNIV_INLINE
-void
-buf_block_buf_fix_inc_func(
-/*=======================*/
-#ifdef UNIV_SYNC_DEBUG
-	const char*	file,	/*!< in: file name */
-	ulint		line,	/*!< in: line */
-#endif /* UNIV_SYNC_DEBUG */
-	buf_block_t*	block)	/*!< in/out: block to bufferfix */
-	__attribute__((nonnull));
-#ifdef UNIV_SYNC_DEBUG
-/** Increments the bufferfix count.
-@param b	in/out: block to bufferfix
-@param f	in: file name where requested
-@param l	in: line number where requested */
-# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b)
-#else /* UNIV_SYNC_DEBUG */
-/** Increments the bufferfix count.
-@param b	in/out: block to bufferfix
-@param f	in: file name where requested
-@param l	in: line number where requested */
-# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b)
-#endif /* UNIV_SYNC_DEBUG */
 /********************************************************************//**
 Calculates a page checksum which is stored to the page when it is written
 to a file. Note that we must be careful to calculate the same value

=== modified file 'storage/innobase/include/buf0buf.ic'
--- a/storage/innobase/include/buf0buf.ic	2011-07-19 14:54:59 +0000
+++ b/storage/innobase/include/buf0buf.ic	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -944,6 +944,19 @@ buf_block_buf_fix_inc_func(
 
 	block->page.buf_fix_count++;
 }
+#ifdef UNIV_SYNC_DEBUG
+/** Increments the bufferfix count.
+@param b	in/out: block to bufferfix
+@param f	in: file name where requested
+@param l	in: line number where requested */
+# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b)
+#else /* UNIV_SYNC_DEBUG */
+/** Increments the bufferfix count.
+@param b	in/out: block to bufferfix
+@param f	in: file name where requested
+@param l	in: line number where requested */
+# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b)
+#endif /* UNIV_SYNC_DEBUG */
 
 /*******************************************************************//**
 Decrements the bufferfix count. */
@@ -1194,7 +1207,7 @@ buf_block_dbg_add_level(
 				where we have acquired latch */
 	ulint		level)	/*!< in: latching order level */
 {
-	sync_thread_add_level(&block->lock, level, FALSE);
+	sync_thread_add_level(&block->lock, level);
 }
 #endif /* UNIV_SYNC_DEBUG */
 /********************************************************************//**

=== modified file 'storage/innobase/include/buf0lru.h'
--- a/storage/innobase/include/buf0lru.h	2011-07-19 14:54:59 +0000
+++ b/storage/innobase/include/buf0lru.h	2011-08-17 01:07:59 +0000
@@ -203,6 +203,17 @@ void
 buf_LRU_stat_update(void);
 /*=====================*/
 
+/******************************************************************//**
+Remove one page from LRU list and put it to free list */
+UNIV_INTERN
+void
+buf_LRU_free_one_page(
+/*==================*/
+	buf_page_t*	bpage)	/*!< in/out: block, must contain a file page and
+				be in a state where it can be freed; there
+				may or may not be a hash index to the page */
+	__attribute__((nonnull));
+
 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
 /**********************************************************************//**
 Validates the LRU list.

=== modified file 'storage/innobase/include/db0err.h'
--- a/storage/innobase/include/db0err.h	2011-06-28 12:28:21 +0000
+++ b/storage/innobase/include/db0err.h	2011-09-01 18:48:04 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
+Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -110,6 +110,8 @@ enum db_err {
 					foreign keys as its prefix columns */
 	DB_TOO_BIG_INDEX_COL,		/* index column size exceeds maximum
 					limit */
+	DB_INDEX_CORRUPT,		/* we have corrupted index */
+	DB_UNDO_RECORD_TOO_BIG,		/* the undo log record is too big */
 
 	/* The following are partial failure codes */
 	DB_FAIL = 1000,

=== modified file 'storage/innobase/include/dict0boot.h'
--- a/storage/innobase/include/dict0boot.h	2010-07-21 14:22:29 +0000
+++ b/storage/innobase/include/dict0boot.h	2011-08-17 01:07:59 +0000
@@ -137,8 +137,10 @@ dict_create(void);
 					header is created */
 /*-------------------------------------------------------------*/
 
-/* The field number of the page number field in the sys_indexes table
-clustered index */
+/* The field numbers in the SYS_TABLES clustered index */
+#define DICT_SYS_TABLES_TYPE_FIELD		5
+
+/* The field numbers in the SYS_INDEXES clustered index */
 #define DICT_SYS_INDEXES_PAGE_NO_FIELD	 8
 #define DICT_SYS_INDEXES_SPACE_NO_FIELD	 7
 #define DICT_SYS_INDEXES_TYPE_FIELD	 6

=== modified file 'storage/innobase/include/dict0dict.h'
--- a/storage/innobase/include/dict0dict.h	2011-05-31 09:12:32 +0000
+++ b/storage/innobase/include/dict0dict.h	2011-08-29 09:44:28 +0000
@@ -585,6 +585,20 @@ dict_table_get_next_index(
 # define dict_table_get_next_index(index) UT_LIST_GET_NEXT(indexes, index)
 #endif /* UNIV_DEBUG */
 #endif /* !UNIV_HOTBACKUP */
+
+/* Skip corrupted index */
+#define dict_table_skip_corrupt_index(index)			\
+	while (index && dict_index_is_corrupted(index)) {	\
+		index = dict_table_get_next_index(index);	\
+	}
+
+/* Get the next non-corrupt index */
+#define dict_table_next_uncorrupted_index(index)		\
+do {								\
+	index = dict_table_get_next_index(index);		\
+	dict_table_skip_corrupt_index(index);			\
+} while (0)
+
 /********************************************************************//**
 Check whether the index is the clustered index.
 @return	nonzero for clustered index, zero for other indexes */
@@ -593,7 +607,7 @@ ulint
 dict_index_is_clust(
 /*================*/
 	const dict_index_t*	index)	/*!< in: index */
-	__attribute__((pure));
+	__attribute__((nonnull, pure, warn_unused_result));
 /********************************************************************//**
 Check whether the index is unique.
 @return	nonzero for unique index, zero for other indexes */
@@ -602,7 +616,7 @@ ulint
 dict_index_is_unique(
 /*=================*/
 	const dict_index_t*	index)	/*!< in: index */
-	__attribute__((pure));
+	__attribute__((nonnull, pure, warn_unused_result));
 /********************************************************************//**
 Check whether the index is the insert buffer tree.
 @return	nonzero for insert buffer, zero for other indexes */
@@ -611,7 +625,7 @@ ulint
 dict_index_is_ibuf(
 /*===============*/
 	const dict_index_t*	index)	/*!< in: index */
-	__attribute__((pure));
+	__attribute__((nonnull, pure, warn_unused_result));
 /********************************************************************//**
 Check whether the index is a secondary index or the insert buffer tree.
 @return	nonzero for insert buffer, zero for other indexes */
@@ -620,7 +634,7 @@ ulint
 dict_index_is_sec_or_ibuf(
 /*======================*/
 	const dict_index_t*	index)	/*!< in: index */
-	__attribute__((pure));
+	__attribute__((nonnull, pure, warn_unused_result));
 
 /********************************************************************//**
 Gets the number of user-defined columns in a table in the dictionary
@@ -630,7 +644,8 @@ UNIV_INLINE
 ulint
 dict_table_get_n_user_cols(
 /*=======================*/
-	const dict_table_t*	table);	/*!< in: table */
+	const dict_table_t*	table)	/*!< in: table */
+	__attribute__((nonnull, pure, warn_unused_result));
 /********************************************************************//**
 Gets the number of system columns in a table in the dictionary cache.
 @return	number of system (e.g., ROW_ID) columns of a table */
@@ -638,7 +653,8 @@ UNIV_INLINE
 ulint
 dict_table_get_n_sys_cols(
 /*======================*/
-	const dict_table_t*	table);	/*!< in: table */
+	const dict_table_t*	table)	/*!< in: table */
+	__attribute__((nonnull, pure, warn_unused_result));
 /********************************************************************//**
 Gets the number of all columns (also system) in a table in the dictionary
 cache.
@@ -647,7 +663,8 @@ UNIV_INLINE
 ulint
 dict_table_get_n_cols(
 /*==================*/
-	const dict_table_t*	table);	/*!< in: table */
+	const dict_table_t*	table)	/*!< in: table */
+	__attribute__((nonnull, pure, warn_unused_result));
 #ifdef UNIV_DEBUG
 /********************************************************************//**
 Gets the nth column of a table.
@@ -1243,6 +1260,57 @@ void
 dict_close(void);
 /*============*/
 
+/**********************************************************************//**
+Check whether the table is corrupted.
+@return	nonzero for corrupted table, zero for valid tables */
+UNIV_INLINE
+ulint
+dict_table_is_corrupted(
+/*====================*/
+	const dict_table_t*	table)	/*!< in: table */
+	__attribute__((nonnull, pure, warn_unused_result));
+
+/**********************************************************************//**
+Check whether the index is corrupted.
+@return	nonzero for corrupted index, zero for valid indexes */
+UNIV_INLINE
+ulint
+dict_index_is_corrupted(
+/*====================*/
+	const dict_index_t*	index)	/*!< in: index */
+	__attribute__((nonnull, pure, warn_unused_result));
+
+/**********************************************************************//**
+Flags an index and table corrupted both in the data dictionary cache
+and in the system table SYS_INDEXES. */
+UNIV_INTERN
+void
+dict_set_corrupted(
+/*===============*/
+	dict_index_t*	index)		/*!< in/out: index */
+	UNIV_COLD __attribute__((nonnull));
+
+/**********************************************************************//**
+Flags an index corrupted in the data dictionary cache only. This
+is used mostly to mark a corrupted index when index's own dictionary
+is corrupted, and we force to load such index for repair purpose */
+UNIV_INTERN
+void
+dict_set_corrupted_index_cache_only(
+/*================================*/
+	dict_index_t*	index,		/*!< in/out: index */
+	dict_table_t*	table);		/*!< in/out: table */
+
+/**********************************************************************//**
+Flags a table with specified space_id corrupted in the table dictionary
+cache.
+@return TRUE if successful */
+UNIV_INTERN
+ibool
+dict_set_corrupted_by_space(
+/*========================*/
+	ulint		space_id);	/*!< in: space ID */
+
 #ifndef UNIV_NONINL
 #include "dict0dict.ic"
 #endif

=== modified file 'storage/innobase/include/dict0dict.ic'
--- a/storage/innobase/include/dict0dict.ic	2011-05-31 09:12:32 +0000
+++ b/storage/innobase/include/dict0dict.ic	2011-08-17 01:07:59 +0000
@@ -27,6 +27,7 @@ Created 1/8/1996 Heikki Tuuri
 #ifndef UNIV_HOTBACKUP
 #include "dict0load.h"
 #include "rem0types.h"
+#include "srv0srv.h"
 
 /*********************************************************************//**
 Gets the minimum number of bytes per character.
@@ -828,7 +829,7 @@ dict_table_check_if_in_cache_low(
 }
 
 /**********************************************************************//**
-load a table into dictionary cache, ignore any error specified during load; 
+load a table into dictionary cache, ignore any error specified during load;
 @return	table, NULL if not found */
 UNIV_INLINE
 dict_table_t*
@@ -872,6 +873,18 @@ dict_table_get_low(
 
 	table = dict_table_check_if_in_cache_low(table_name);
 
+	if (table && table->corrupted) {
+		fprintf(stderr, "InnoDB: table");
+		ut_print_name(stderr, NULL, TRUE, table->name);
+		if (srv_load_corrupted) {
+			fputs(" is corrupted, but"
+			      " innodb_force_load_corrupted is set\n", stderr);
+		} else {
+			fputs(" is corrupted\n", stderr);
+			return(NULL);
+		}
+	}
+
 	if (table == NULL) {
 		table = dict_load_table(table_name, TRUE, DICT_ERR_IGNORE_NONE);
 	}
@@ -937,4 +950,35 @@ dict_max_field_len_store_undo(
 	return(prefix_len);
 }
 
+/********************************************************************//**
+Check whether the table is corrupted.
+@return	nonzero for corrupted table, zero for valid tables */
+UNIV_INLINE
+ulint
+dict_table_is_corrupted(
+/*====================*/
+	const dict_table_t*	table)	/*!< in: table */
+{
+	ut_ad(table);
+	ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
+
+	return(UNIV_UNLIKELY(table->corrupted));
+}
+
+/********************************************************************//**
+Check whether the index is corrupted.
+@return	nonzero for corrupted index, zero for valid indexes */
+UNIV_INLINE
+ulint
+dict_index_is_corrupted(
+/*====================*/
+	const dict_index_t*	index)	/*!< in: index */
+{
+	ut_ad(index);
+	ut_ad(index->magic_n == DICT_INDEX_MAGIC_N);
+
+	return(UNIV_UNLIKELY((index->type & DICT_CORRUPT)
+	       || (index->table && index->table->corrupted)));
+}
+
 #endif /* !UNIV_HOTBACKUP */

=== modified file 'storage/innobase/include/dict0mem.h'
--- a/storage/innobase/include/dict0mem.h	2011-05-31 09:12:32 +0000
+++ b/storage/innobase/include/dict0mem.h	2011-08-17 01:07:59 +0000
@@ -51,7 +51,12 @@ combination of types */
 #define DICT_UNIQUE	2	/*!< unique index */
 #define	DICT_UNIVERSAL	4	/*!< index which can contain records from any
 				other index */
-#define	DICT_IBUF 	8	/*!< insert buffer tree */
+#define	DICT_IBUF	8	/*!< insert buffer tree */
+#define	DICT_CORRUPT	16	/*!< bit to store the corrupted flag
+				in SYS_INDEXES.TYPE */
+
+#define	DICT_IT_BITS	5	/*!< number of bits used for
+				SYS_INDEXES.TYPE */
 /* @} */
 
 /** Types for a table object */
@@ -369,8 +374,9 @@ struct dict_index_struct{
 				/*!< space where the index tree is placed */
 	unsigned	page:32;/*!< index tree root page number */
 #endif /* !UNIV_HOTBACKUP */
-	unsigned	type:4;	/*!< index type (DICT_CLUSTERED, DICT_UNIQUE,
-				DICT_UNIVERSAL, DICT_IBUF) */
+	unsigned	type:DICT_IT_BITS;
+				/*!< index type (DICT_CLUSTERED, DICT_UNIQUE,
+				DICT_UNIVERSAL, DICT_IBUF, DICT_CORRUPT) */
 	unsigned	trx_id_offset:10;/*!< position of the trx id column
 				in a clustered index record, if the fields
 				before it are known to be of a fixed size,
@@ -391,8 +397,6 @@ struct dict_index_struct{
 				/*!< TRUE if this index is marked to be
 				dropped in ha_innobase::prepare_drop_index(),
 				otherwise FALSE */
-	unsigned	corrupted:1;
-				/*!< TRUE if the index object is corrupted */
 	dict_field_t*	fields;	/*!< array of field descriptions */
 #ifndef UNIV_HOTBACKUP
 	UT_LIST_NODE_T(dict_index_t)

=== modified file 'storage/innobase/include/dict0types.h'
--- a/storage/innobase/include/dict0types.h	2011-02-09 09:15:06 +0000
+++ b/storage/innobase/include/dict0types.h	2011-08-17 01:07:59 +0000
@@ -51,7 +51,8 @@ be or-ed together */
 enum dict_err_ignore {
         DICT_ERR_IGNORE_NONE = 0,        /*!< no error to ignore */
         DICT_ERR_IGNORE_INDEX_ROOT = 1, /*!< ignore error if index root
-					page is FIL_NUL or incorrect value */
+					page is FIL_NULL or incorrect value */
+	DICT_ERR_IGNORE_CORRUPT = 2,	/*!< skip corrupted indexes */
         DICT_ERR_IGNORE_ALL = 0xFFFF	/*!< ignore all errors */
 };
 

=== modified file 'storage/innobase/include/mtr0mtr.h'
--- a/storage/innobase/include/mtr0mtr.h	2011-08-10 12:03:33 +0000
+++ b/storage/innobase/include/mtr0mtr.h	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software

=== modified file 'storage/innobase/include/page0cur.ic'
--- a/storage/innobase/include/page0cur.ic	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/page0cur.ic	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -27,8 +27,6 @@ Created 10/4/1994 Heikki Tuuri
 #include "buf0types.h"
 
 #ifdef UNIV_DEBUG
-# include "rem0cmp.h"
-
 /*********************************************************//**
 Gets pointer to the page frame where the cursor is positioned.
 @return	page */
@@ -270,7 +268,6 @@ page_cur_tuple_insert(
 					      index, rec, offsets, mtr);
 	}
 
-	ut_ad(!rec || !cmp_dtuple_rec(tuple, rec, offsets));
 	mem_heap_free(heap);
 	return(rec);
 }

=== modified file 'storage/innobase/include/page0page.h'
--- a/storage/innobase/include/page0page.h	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/page0page.h	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -68,10 +68,7 @@ typedef	byte		page_header_t;
 #define PAGE_MAX_TRX_ID	 18	/* highest id of a trx which may have modified
 				a record on the page; trx_id_t; defined only
 				in secondary indexes and in the insert buffer
-				tree; NOTE: this may be modified only
-				when the thread has an x-latch to the page,
-				and ALSO an x-latch to btr_search_latch
-				if there is a hash index to the page! */
+				tree */
 #define PAGE_HEADER_PRIV_END 26	/* end of private data structure of the page
 				header which are set in a page create */
 /*----*/
@@ -284,42 +281,16 @@ page_get_supremum_offset(
 	const page_t*	page);	/*!< in: page which must have record(s) */
 #define page_get_infimum_rec(page) ((page) + page_get_infimum_offset(page))
 #define page_get_supremum_rec(page) ((page) + page_get_supremum_offset(page))
-
-/************************************************************//**
-Returns the nth record of the record list.
-This is the inverse function of page_rec_get_n_recs_before().
-@return	nth record */
-UNIV_INTERN
-const rec_t*
-page_rec_get_nth_const(
-/*===================*/
-	const page_t*	page,	/*!< in: page */
-	ulint		nth)	/*!< in: nth record */
-	__attribute__((nonnull, warn_unused_result));
-/************************************************************//**
-Returns the nth record of the record list.
-This is the inverse function of page_rec_get_n_recs_before().
-@return	nth record */
-UNIV_INLINE
-rec_t*
-page_rec_get_nth(
-/*=============*/
-	page_t*	page,	/*< in: page */
-	ulint	nth)	/*!< in: nth record */
-	__attribute__((nonnull, warn_unused_result));
-
-#ifndef UNIV_HOTBACKUP
 /************************************************************//**
-Returns the middle record of the records on the page. If there is an
-even number of records in the list, returns the first record of the
-upper half-list.
+Returns the middle record of record list. If there are an even number
+of records in the list, returns the first record of upper half-list.
 @return	middle record */
-UNIV_INLINE
+UNIV_INTERN
 rec_t*
 page_get_middle_rec(
 /*================*/
-	page_t*	page)	/*!< in: page */
-	__attribute__((nonnull, warn_unused_result));
+	page_t*	page);	/*!< in: page */
+#ifndef UNIV_HOTBACKUP
 /*************************************************************//**
 Compares a data tuple to a physical record. Differs from the function
 cmp_dtuple_rec_with_match in the way that the record must reside on an
@@ -374,7 +345,6 @@ page_get_n_recs(
 /***************************************************************//**
 Returns the number of records before the given record in chain.
 The number includes infimum and supremum records.
-This is the inverse function of page_rec_get_nth().
 @return	number of records */
 UNIV_INTERN
 ulint

=== modified file 'storage/innobase/include/page0page.ic'
--- a/storage/innobase/include/page0page.ic	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/page0page.ic	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -419,37 +419,7 @@ page_rec_is_infimum(
 	return(page_rec_is_infimum_low(page_offset(rec)));
 }
 
-/************************************************************//**
-Returns the nth record of the record list.
-This is the inverse function of page_rec_get_n_recs_before().
-@return	nth record */
-UNIV_INLINE
-rec_t*
-page_rec_get_nth(
-/*=============*/
-	page_t*	page,	/*!< in: page */
-	ulint	nth)	/*!< in: nth record */
-{
-	return((rec_t*) page_rec_get_nth_const(page, nth));
-}
-
 #ifndef UNIV_HOTBACKUP
-/************************************************************//**
-Returns the middle record of the records on the page. If there is an
-even number of records in the list, returns the first record of the
-upper half-list.
-@return	middle record */
-UNIV_INLINE
-rec_t*
-page_get_middle_rec(
-/*================*/
-	page_t*	page)	/*!< in: page */
-{
-	ulint	middle = (page_get_n_recs(page) + PAGE_HEAP_NO_USER_LOW) / 2;
-
-	return(page_rec_get_nth(page, middle));
-}
-
 /*************************************************************//**
 Compares a data tuple to a physical record. Differs from the function
 cmp_dtuple_rec_with_match in the way that the record must reside on an

=== modified file 'storage/innobase/include/rem0rec.h'
--- a/storage/innobase/include/rem0rec.h	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/rem0rec.h	2011-09-30 11:37:22 +0000
@@ -480,7 +480,7 @@ ulint
 rec_offs_any_extern(
 /*================*/
 	const ulint*	offsets);/*!< in: array returned by rec_get_offsets() */
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+#ifdef UNIV_BLOB_NULL_DEBUG
 /******************************************************//**
 Determine if the offsets are for a record containing null BLOB pointers.
 @return	first field containing a null BLOB pointer, or NULL if none found */
@@ -491,7 +491,7 @@ rec_offs_any_null_extern(
 	const rec_t*	rec,		/*!< in: record */
 	const ulint*	offsets)	/*!< in: rec_get_offsets(rec) */
 	__attribute__((nonnull, warn_unused_result));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#endif /* UNIV_BLOB_NULL_DEBUG */
 /******************************************************//**
 Returns nonzero if the extern bit is set in nth field of rec.
 @return	nonzero if externally stored */

=== modified file 'storage/innobase/include/rem0rec.ic'
--- a/storage/innobase/include/rem0rec.ic	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/rem0rec.ic	2011-09-30 11:37:22 +0000
@@ -1088,7 +1088,7 @@ rec_offs_any_extern(
 	return(UNIV_UNLIKELY(*rec_offs_base(offsets) & REC_OFFS_EXTERNAL));
 }
 
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+#ifdef UNIV_BLOB_NULL_DEBUG
 /******************************************************//**
 Determine if the offsets are for a record containing null BLOB pointers.
 @return	first field containing a null BLOB pointer, or NULL if none found */
@@ -1124,7 +1124,7 @@ rec_offs_any_null_extern(
 
 	return(NULL);
 }
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#endif /* UNIV_BLOB_NULL_DEBUG */
 
 /******************************************************//**
 Returns nonzero if the extern bit is set in nth field of rec.

=== modified file 'storage/innobase/include/row0upd.ic'
--- a/storage/innobase/include/row0upd.ic	2011-06-29 07:04:00 +0000
+++ b/storage/innobase/include/row0upd.ic	2011-09-08 13:25:45 +0000
@@ -157,11 +157,6 @@ row_upd_rec_sys_fields(
 {
 	ut_ad(dict_index_is_clust(index));
 	ut_ad(rec_offs_validate(rec, index, offsets));
-#ifdef UNIV_SYNC_DEBUG
-	if (!rw_lock_own(&btr_search_latch, RW_LOCK_EX)) {
-		ut_ad(!buf_block_align(rec)->is_hashed);
-	}
-#endif /* UNIV_SYNC_DEBUG */
 
 	if (UNIV_LIKELY_NULL(page_zip)) {
 		ulint	pos = dict_index_get_sys_col_pos(index, DATA_TRX_ID);

=== modified file 'storage/innobase/include/srv0srv.h'
--- a/storage/innobase/include/srv0srv.h	2011-07-19 14:54:59 +0000
+++ b/storage/innobase/include/srv0srv.h	2011-08-17 01:07:59 +0000
@@ -141,6 +141,10 @@ extern ulint	srv_log_buffer_size;
 extern ulong	srv_flush_log_at_trx_commit;
 extern char	srv_adaptive_flushing;
 
+/* If this flag is TRUE, then we will load the indexes' (and tables') metadata
+even if they are marked as "corrupted". Mostly it is for DBA to process
+corrupted index and table */
+extern my_bool	srv_load_corrupted;
 
 /* The sort order table of the MySQL latin1_swedish_ci character set
 collation */

=== modified file 'storage/innobase/include/sync0rw.ic'
--- a/storage/innobase/include/sync0rw.ic	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/sync0rw.ic	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -603,16 +603,16 @@ rw_lock_x_unlock_direct(
 
 	ut_ad((lock->lock_word % X_LOCK_DECR) == 0);
 
+#ifdef UNIV_SYNC_DEBUG
+	rw_lock_remove_debug_info(lock, 0, RW_LOCK_EX);
+#endif
+
 	if (lock->lock_word == 0) {
 		lock->recursive = FALSE;
 		UNIV_MEM_INVALID(&lock->writer_thread,
 				 sizeof lock->writer_thread);
 	}
 
-#ifdef UNIV_SYNC_DEBUG
-	rw_lock_remove_debug_info(lock, 0, RW_LOCK_EX);
-#endif
-
 	lock->lock_word += X_LOCK_DECR;
 
 	ut_ad(!lock->waiters);

=== modified file 'storage/innobase/include/sync0sync.h'
--- a/storage/innobase/include/sync0sync.h	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/sync0sync.h	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2011, Innobase Oy. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -400,10 +400,8 @@ void
 sync_thread_add_level(
 /*==================*/
 	void*	latch,	/*!< in: pointer to a mutex or an rw-lock */
-	ulint	level,	/*!< in: level in the latching order; if
+	ulint	level);	/*!< in: level in the latching order; if
 			SYNC_LEVEL_VARYING, nothing is done */
-	ibool	relock)	/*!< in: TRUE if re-entering an x-lock */
-	__attribute__((nonnull));
 /******************************************************************//**
 Removes a latch from the thread level array if it is found there.
 @return TRUE if found in the array; it is no error if the latch is
@@ -638,10 +636,6 @@ or row lock! */
 #define SYNC_DICT_HEADER	995
 #define SYNC_IBUF_HEADER	914
 #define SYNC_IBUF_PESS_INSERT_MUTEX 912
-#define SYNC_IBUF_MUTEX		910	/* ibuf mutex is really below
-					SYNC_FSP_PAGE: we assign a value this
-					high only to make the program to pass
-					the debug checks */
 /*-------------------------------*/
 #define	SYNC_INDEX_TREE		900
 #define SYNC_TREE_NODE_NEW	892
@@ -657,8 +651,11 @@ or row lock! */
 #define	SYNC_FSP		400
 #define	SYNC_FSP_PAGE		395
 /*------------------------------------- Insert buffer headers */
-/*------------------------------------- ibuf_mutex */
+#define SYNC_IBUF_MUTEX		370	/* ibuf_mutex */
 /*------------------------------------- Insert buffer tree */
+#define SYNC_IBUF_INDEX_TREE	360
+#define SYNC_IBUF_TREE_NODE_NEW	359
+#define SYNC_IBUF_TREE_NODE	358
 #define	SYNC_IBUF_BITMAP_MUTEX	351
 #define	SYNC_IBUF_BITMAP	350
 /*------------------------------------- MySQL query cache mutex */
@@ -685,7 +682,6 @@ or row lock! */
 #define	SYNC_BUF_FLUSH_LIST	145	/* Buffer flush list mutex */
 #define SYNC_DOUBLEWRITE	140
 #define	SYNC_ANY_LATCH		135
-#define SYNC_THR_LOCAL		133
 #define	SYNC_MEM_HASH		131
 #define	SYNC_MEM_POOL		130
 

=== modified file 'storage/innobase/include/sync0sync.ic'
--- a/storage/innobase/include/sync0sync.ic	2010-07-15 13:47:50 +0000
+++ b/storage/innobase/include/sync0sync.ic	2011-08-29 08:29:57 +0000
@@ -272,11 +272,10 @@ pfs_mutex_enter_nowait_func(
 	ulint	ret;
 	struct PSI_mutex_locker*	locker = NULL;
 	PSI_mutex_locker_state		state;
-	int	result = 0;
 
 	if (UNIV_LIKELY(PSI_server && mutex->pfs_psi)) {
 		locker = PSI_server->get_thread_mutex_locker(
-				&state, mutex->pfs_psi, PSI_MUTEX_LOCK);
+				&state, mutex->pfs_psi, PSI_MUTEX_TRYLOCK);
 		if (locker) {
 			PSI_server->start_mutex_wait(locker, file_name, line);
 		}
@@ -285,7 +284,7 @@ pfs_mutex_enter_nowait_func(
 	ret = mutex_enter_nowait_func(mutex, file_name, line);
 
 	if (locker) {
-		PSI_server->end_mutex_wait(locker, result);
+		PSI_server->end_mutex_wait(locker, ret);
 	}
 
 	return(ret);

=== modified file 'storage/innobase/include/trx0undo.h'
--- a/storage/innobase/include/trx0undo.h	2011-04-11 14:03:32 +0000
+++ b/storage/innobase/include/trx0undo.h	2011-09-01 18:48:04 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
+Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -204,17 +204,51 @@ trx_undo_add_page(
 	mtr_t*		mtr);	/*!< in: mtr which does not have a latch to any
 				undo log page; the caller must have reserved
 				the rollback segment mutex */
+/********************************************************************//**
+Frees the last undo log page.
+The caller must hold the rollback segment mutex. */
+UNIV_INTERN
+void
+trx_undo_free_last_page_func(
+/*==========================*/
+#ifdef UNIV_DEBUG
+	const trx_t*	trx,	/*!< in: transaction */
+#endif /* UNIV_DEBUG */
+	trx_undo_t*	undo,	/*!< in/out: undo log memory copy */
+	mtr_t*		mtr)	/*!< in/out: mini-transaction which does not
+				have a latch to any undo log page or which
+				has allocated the undo log page */
+	__attribute__((nonnull));
+#ifdef UNIV_DEBUG
+# define trx_undo_free_last_page(trx,undo,mtr)	\
+	trx_undo_free_last_page_func(trx,undo,mtr)
+#else /* UNIV_DEBUG */
+# define trx_undo_free_last_page(trx,undo,mtr)	\
+	trx_undo_free_last_page_func(undo,mtr)
+#endif /* UNIV_DEBUG */
+
 /***********************************************************************//**
 Truncates an undo log from the end. This function is used during a rollback
 to free space from an undo log. */
 UNIV_INTERN
 void
-trx_undo_truncate_end(
-/*==================*/
-	trx_t*		trx,	/*!< in: transaction whose undo log it is */
-	trx_undo_t*	undo,	/*!< in: undo log */
-	undo_no_t	limit);	/*!< in: all undo records with undo number
+trx_undo_truncate_end_func(
+/*=======================*/
+#ifdef UNIV_DEBUG
+	const trx_t*	trx,	/*!< in: transaction whose undo log it is */
+#endif /* UNIV_DEBUG */
+	trx_undo_t*	undo,	/*!< in/out: undo log */
+	undo_no_t	limit)	/*!< in: all undo records with undo number
 				>= this value should be truncated */
+	__attribute__((nonnull));
+#ifdef UNIV_DEBUG
+# define trx_undo_truncate_end(trx,undo,limit)		\
+	trx_undo_truncate_end_func(trx,undo,limit)
+#else /* UNIV_DEBUG */
+# define trx_undo_truncate_end(trx,undo,limit)		\
+	trx_undo_truncate_end_func(undo,limit)
+#endif /* UNIV_DEBUG */
+
 /***********************************************************************//**
 Truncates an undo log from the start. This function is used during a purge
 operation. */

=== modified file 'storage/innobase/include/univ.i'
--- a/storage/innobase/include/univ.i	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/include/univ.i	2011-09-30 11:37:22 +0000
@@ -1,7 +1,8 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
+Copyright (c) 2009, Sun Microsystems, Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
 Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -185,6 +186,8 @@ command. Not tested on Windows. */
 						debugging without UNIV_DEBUG */
 #define UNIV_BLOB_LIGHT_DEBUG			/* Enable off-page column
 						debugging without UNIV_DEBUG */
+#define UNIV_BLOB_NULL_DEBUG			/* Enable deep off-page
+						column debugging */
 #define UNIV_DEBUG				/* Enable ut_ad() assertions
 						and disable UNIV_INLINE */
 #define UNIV_DEBUG_LOCK_VALIDATE		/* Enable

=== modified file 'storage/innobase/mtr/mtr0mtr.c'
--- a/storage/innobase/mtr/mtr0mtr.c	2011-08-10 12:03:33 +0000
+++ b/storage/innobase/mtr/mtr0mtr.c	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software

=== modified file 'storage/innobase/page/page0cur.c'
--- a/storage/innobase/page/page0cur.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/page/page0cur.c	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -1180,15 +1180,14 @@ page_cur_insert_rec_zip_reorg(
 	/* Before trying to reorganize the page,
 	store the number of preceding records on the page. */
 	pos = page_rec_get_n_recs_before(rec);
-	ut_ad(pos > 0);
 
 	if (page_zip_reorganize(block, index, mtr)) {
 		/* The page was reorganized: Find rec by seeking to pos,
 		and update *current_rec. */
-		if (pos > 1) {
-			rec = page_rec_get_nth(page, pos - 1);
-		} else {
-			rec = page + PAGE_NEW_INFIMUM;
+		rec = page + PAGE_NEW_INFIMUM;
+
+		while (--pos) {
+			rec = page + rec_get_next_offs(rec, TRUE);
 		}
 
 		*current_rec = rec;
@@ -1284,12 +1283,6 @@ page_cur_insert_rec_zip(
 			insert_rec = page_cur_insert_rec_zip_reorg(
 				current_rec, block, index, insert_rec,
 				page, page_zip, mtr);
-#ifdef UNIV_DEBUG
-			if (insert_rec) {
-				rec_offs_make_valid(
-					insert_rec, index, offsets);
-			}
-#endif /* UNIV_DEBUG */
 		}
 
 		return(insert_rec);

=== modified file 'storage/innobase/page/page0page.c'
--- a/storage/innobase/page/page0page.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/page/page0page.c	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1994, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1994, 2010, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -1465,54 +1465,55 @@ page_dir_balance_slot(
 	}
 }
 
+#ifndef UNIV_HOTBACKUP
 /************************************************************//**
-Returns the nth record of the record list.
-This is the inverse function of page_rec_get_n_recs_before().
-@return	nth record */
+Returns the middle record of the record list. If there are an even number
+of records in the list, returns the first record of the upper half-list.
+@return	middle record */
 UNIV_INTERN
-const rec_t*
-page_rec_get_nth_const(
-/*===================*/
-	const page_t*	page,	/*!< in: page */
-	ulint		nth)	/*!< in: nth record */
+rec_t*
+page_get_middle_rec(
+/*================*/
+	page_t*	page)	/*!< in: page */
 {
-	const page_dir_slot_t*	slot;
+	page_dir_slot_t*	slot;
+	ulint			middle;
 	ulint			i;
 	ulint			n_owned;
-	const rec_t*		rec;
+	ulint			count;
+	rec_t*			rec;
 
-	ut_ad(nth < UNIV_PAGE_SIZE / (REC_N_NEW_EXTRA_BYTES + 1));
+	/* This many records we must leave behind */
+	middle = (page_get_n_recs(page) + PAGE_HEAP_NO_USER_LOW) / 2;
+
+	count = 0;
 
 	for (i = 0;; i++) {
 
 		slot = page_dir_get_nth_slot(page, i);
 		n_owned = page_dir_slot_get_n_owned(slot);
 
-		if (n_owned > nth) {
+		if (count + n_owned > middle) {
 			break;
 		} else {
-			nth -= n_owned;
+			count += n_owned;
 		}
 	}
 
 	ut_ad(i > 0);
 	slot = page_dir_get_nth_slot(page, i - 1);
-	rec = page_dir_slot_get_rec(slot);
+	rec = (rec_t*) page_dir_slot_get_rec(slot);
+	rec = page_rec_get_next(rec);
 
-	if (page_is_comp(page)) {
-		do {
-			rec = page_rec_get_next_low(rec, TRUE);
-			ut_ad(rec);
-		} while (nth--);
-	} else {
-		do {
-			rec = page_rec_get_next_low(rec, FALSE);
-			ut_ad(rec);
-		} while (nth--);
+	/* There are now count records behind rec */
+
+	for (i = 0; i < middle - count; i++) {
+		rec = page_rec_get_next(rec);
 	}
 
 	return(rec);
 }
+#endif /* !UNIV_HOTBACKUP */
 
 /***************************************************************//**
 Returns the number of records before the given record in chain.
@@ -1574,7 +1575,6 @@ page_rec_get_n_recs_before(
 	n--;
 
 	ut_ad(n >= 0);
-	ut_ad(n < UNIV_PAGE_SIZE / (REC_N_NEW_EXTRA_BYTES + 1));
 
 	return((ulint) n);
 }

=== modified file 'storage/innobase/pars/pars0opt.c'
--- a/storage/innobase/pars/pars0opt.c	2010-06-22 15:58:28 +0000
+++ b/storage/innobase/pars/pars0opt.c	2011-08-17 01:07:59 +0000
@@ -568,7 +568,7 @@ opt_search_plan_for_table(
 			best_last_op = last_op;
 		}
 
-		index = dict_table_get_next_index(index);
+		dict_table_next_uncorrupted_index(index);
 	}
 
 	plan->index = best_index;

=== modified file 'storage/innobase/row/row0ins.c'
--- a/storage/innobase/row/row0ins.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/row/row0ins.c	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -118,6 +118,9 @@ ins_node_create_entry_list(
 					      node->entry_sys_heap);
 		UT_LIST_ADD_LAST(tuple_list, node->entry_list, entry);
 
+		/* We will include all indexes (include those corrupted
+		secondary indexes) in the entry list. Filteration of
+		these corrupted index will be done in row_ins() */
 		index = dict_table_get_next_index(index);
 	}
 }
@@ -345,9 +348,9 @@ row_ins_clust_index_entry_by_modify(
 			return(DB_LOCK_TABLE_FULL);
 
 		}
-		err = btr_cur_pessimistic_update(
-			BTR_KEEP_POS_FLAG, cursor, heap, big_rec, update,
-			0, thr, mtr);
+		err = btr_cur_pessimistic_update(0, cursor,
+						 heap, big_rec, update,
+						 0, thr, mtr);
 	}
 
 	return(err);
@@ -1973,7 +1976,6 @@ row_ins_index_entry_low(
 	ulint		modify = 0; /* remove warning */
 	rec_t*		insert_rec;
 	rec_t*		rec;
-	ulint*		offsets;
 	ulint		err;
 	ulint		n_unique;
 	big_rec_t*	big_rec			= NULL;
@@ -2046,7 +2048,6 @@ row_ins_index_entry_low(
 			mtr_start(&mtr);
 
 			if (err != DB_SUCCESS) {
-
 				goto function_exit;
 			}
 
@@ -2082,42 +2083,6 @@ row_ins_index_entry_low(
 			err = row_ins_clust_index_entry_by_modify(
 				mode, &cursor, &heap, &big_rec, entry,
 				thr, &mtr);
-
-			if (big_rec) {
-				ut_a(err == DB_SUCCESS);
-				/* Write out the externally stored
-				columns while still x-latching
-				index->lock and block->lock. We have
-				to mtr_commit(mtr) first, so that the
-				redo log will be written in the
-				correct order. Otherwise, we would run
-				into trouble on crash recovery if mtr
-				freed B-tree pages on which some of
-				the big_rec fields will be written. */
-				btr_cur_mtr_commit_and_start(&cursor, &mtr);
-
-				rec = btr_cur_get_rec(&cursor);
-				offsets = rec_get_offsets(
-					rec, index, NULL,
-					ULINT_UNDEFINED, &heap);
-
-				err = btr_store_big_rec_extern_fields(
-					index, btr_cur_get_block(&cursor),
-					rec, offsets, &mtr, FALSE, big_rec);
-				/* If writing big_rec fails (for
-				example, because of DB_OUT_OF_FILE_SPACE),
-				the record will be corrupted. Even if
-				we did not update any externally
-				stored columns, our update could cause
-				the record to grow so that a
-				non-updated column was selected for
-				external storage. This non-update
-				would not have been written to the
-				undo log, and thus the record cannot
-				be rolled back. */
-				ut_a(err == DB_SUCCESS);
-				goto stored_big_rec;
-			}
 		} else {
 			ut_ad(!n_ext);
 			err = row_ins_sec_index_entry_by_modify(
@@ -2146,6 +2111,8 @@ function_exit:
 	mtr_commit(&mtr);
 
 	if (UNIV_LIKELY_NULL(big_rec)) {
+		rec_t*	rec;
+		ulint*	offsets;
 		mtr_start(&mtr);
 
 		btr_cur_search_to_nth_level(index, 0, entry, PAGE_CUR_LE,
@@ -2159,7 +2126,6 @@ function_exit:
 			index, btr_cur_get_block(&cursor),
 			rec, offsets, &mtr, FALSE, big_rec);
 
-stored_big_rec:
 		if (modify) {
 			dtuple_big_rec_free(big_rec);
 		} else {
@@ -2431,6 +2397,13 @@ row_ins(
 
 		node->index = dict_table_get_next_index(node->index);
 		node->entry = UT_LIST_GET_NEXT(tuple_list, node->entry);
+
+		/* Skip corrupted secondar index and its entry */
+		while (node->index && dict_index_is_corrupted(node->index)) {
+
+			node->index = dict_table_get_next_index(node->index);
+			node->entry = UT_LIST_GET_NEXT(tuple_list, node->entry);
+		}
 	}
 
 	ut_ad(node->entry == NULL);

=== modified file 'storage/innobase/row/row0merge.c'
--- a/storage/innobase/row/row0merge.c	2011-05-04 09:08:07 +0000
+++ b/storage/innobase/row/row0merge.c	2011-08-17 01:07:59 +0000
@@ -2554,8 +2554,9 @@ row_merge_is_index_usable(
 	const trx_t*		trx,	/*!< in: transaction */
 	const dict_index_t*	index)	/*!< in: index to check */
 {
-	return(!trx->read_view
-	       || read_view_sees_trx_id(trx->read_view, index->trx_id));
+	return(!dict_index_is_corrupted(index)
+	       && (!trx->read_view
+	           || read_view_sees_trx_id(trx->read_view, index->trx_id)));
 }
 
 /*********************************************************************//**

=== modified file 'storage/innobase/row/row0mysql.c'
--- a/storage/innobase/row/row0mysql.c	2011-06-28 12:28:21 +0000
+++ b/storage/innobase/row/row0mysql.c	2011-09-07 15:24:18 +0000
@@ -576,6 +576,7 @@ handle_new_error:
 	case DB_DUPLICATE_KEY:
 	case DB_FOREIGN_DUPLICATE_KEY:
 	case DB_TOO_BIG_RECORD:
+	case DB_UNDO_RECORD_TOO_BIG:
 	case DB_ROW_IS_REFERENCED:
 	case DB_NO_REFERENCED_ROW:
 	case DB_CANNOT_ADD_CONSTRAINT:
@@ -3098,7 +3099,8 @@ row_drop_table_for_mysql(
 	ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
 #endif /* UNIV_SYNC_DEBUG */
 
-	table = dict_table_get_low_ignore_err(name, DICT_ERR_IGNORE_INDEX_ROOT);
+	table = dict_table_get_low_ignore_err(
+		name, DICT_ERR_IGNORE_INDEX_ROOT | DICT_ERR_IGNORE_CORRUPT);
 
 	if (!table) {
 		err = DB_TABLE_NOT_FOUND;
@@ -3245,6 +3247,19 @@ check_next_foreign:
 			   "index_id CHAR;\n"
 			   "foreign_id CHAR;\n"
 			   "found INT;\n"
+
+			   "DECLARE CURSOR cur_fk IS\n"
+			   "SELECT ID FROM SYS_FOREIGN\n"
+			   "WHERE FOR_NAME = :table_name\n"
+			   "AND TO_BINARY(FOR_NAME)\n"
+			   "  = TO_BINARY(:table_name)\n"
+			   "LOCK IN SHARE MODE;\n"
+
+			   "DECLARE CURSOR cur_idx IS\n"
+			   "SELECT ID FROM SYS_INDEXES\n"
+			   "WHERE TABLE_ID = table_id\n"
+			   "LOCK IN SHARE MODE;\n"
+
 			   "BEGIN\n"
 			   "SELECT ID INTO table_id\n"
 			   "FROM SYS_TABLES\n"
@@ -3267,13 +3282,9 @@ check_next_foreign:
 			   "IF (:table_name = 'SYS_FOREIGN_COLS') THEN\n"
 			   "       found := 0;\n"
 			   "END IF;\n"
+			   "OPEN cur_fk;\n"
 			   "WHILE found = 1 LOOP\n"
-			   "       SELECT ID INTO foreign_id\n"
-			   "       FROM SYS_FOREIGN\n"
-			   "       WHERE FOR_NAME = :table_name\n"
-			   "               AND TO_BINARY(FOR_NAME)\n"
-			   "                 = TO_BINARY(:table_name)\n"
-			   "               LOCK IN SHARE MODE;\n"
+			   "       FETCH cur_fk INTO foreign_id;\n"
 			   "       IF (SQL % NOTFOUND) THEN\n"
 			   "               found := 0;\n"
 			   "       ELSE\n"
@@ -3283,12 +3294,11 @@ check_next_foreign:
 			   "               WHERE ID = foreign_id;\n"
 			   "       END IF;\n"
 			   "END LOOP;\n"
+			   "CLOSE cur_fk;\n"
 			   "found := 1;\n"
+			   "OPEN cur_idx;\n"
 			   "WHILE found = 1 LOOP\n"
-			   "       SELECT ID INTO index_id\n"
-			   "       FROM SYS_INDEXES\n"
-			   "       WHERE TABLE_ID = table_id\n"
-			   "       LOCK IN SHARE MODE;\n"
+			   "       FETCH cur_idx INTO index_id;\n"
 			   "       IF (SQL % NOTFOUND) THEN\n"
 			   "               found := 0;\n"
 			   "       ELSE\n"
@@ -3299,6 +3309,7 @@ check_next_foreign:
 			   "               AND TABLE_ID = table_id;\n"
 			   "       END IF;\n"
 			   "END LOOP;\n"
+			   "CLOSE cur_idx;\n"
 			   "DELETE FROM SYS_COLUMNS\n"
 			   "WHERE TABLE_ID = table_id;\n"
 			   "DELETE FROM SYS_TABLES\n"

=== modified file 'storage/innobase/row/row0purge.c'
--- a/storage/innobase/row/row0purge.c	2011-02-02 13:58:01 +0000
+++ b/storage/innobase/row/row0purge.c	2011-09-26 07:08:42 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1997, 2010, Innobase Oy. All Rights Reserved.
+Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -11,8 +11,8 @@ ANY WARRANTY; without even the implied w
 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
+this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
 
 *****************************************************************************/
 
@@ -469,6 +469,13 @@ row_purge_del_mark(
 	heap = mem_heap_create(1024);
 
 	while (node->index != NULL) {
+		/* skip corrupted secondary index */
+		dict_table_skip_corrupt_index(node->index);
+
+		if (!node->index) {
+			break;
+		}
+
 		index = node->index;
 
 		/* Build the index entry */
@@ -508,7 +515,8 @@ row_purge_upd_exist_or_extern_func(
 
 	ut_ad(node);
 
-	if (node->rec_type == TRX_UNDO_UPD_DEL_REC) {
+	if (node->rec_type == TRX_UNDO_UPD_DEL_REC
+	    || (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
 
 		goto skip_secondaries;
 	}
@@ -516,6 +524,12 @@ row_purge_upd_exist_or_extern_func(
 	heap = mem_heap_create(1024);
 
 	while (node->index != NULL) {
+		dict_table_skip_corrupt_index(node->index);
+
+		if (!node->index) {
+			break;
+		}
+
 		index = node->index;
 
 		if (row_upd_changes_ord_field_binary(node->index, node->update,
@@ -632,14 +646,14 @@ row_purge_parse_undo_rec(
 	roll_ptr_t	roll_ptr;
 	ulint		info_bits;
 	ulint		type;
-	ulint		cmpl_info;
 
 	ut_ad(node && thr);
 
 	trx = thr_get_trx(thr);
 
-	ptr = trx_undo_rec_get_pars(node->undo_rec, &type, &cmpl_info,
-				    updated_extern, &undo_no, &table_id);
+	ptr = trx_undo_rec_get_pars(
+		node->undo_rec, &type, &node->cmpl_info,
+		updated_extern, &undo_no, &table_id);
 	node->rec_type = type;
 
 	if (type == TRX_UNDO_UPD_DEL_REC && !(*updated_extern)) {
@@ -652,7 +666,8 @@ row_purge_parse_undo_rec(
 	node->table = NULL;
 
 	if (type == TRX_UNDO_UPD_EXIST_REC
-	    && cmpl_info & UPD_NODE_NO_ORD_CHANGE && !(*updated_extern)) {
+	    && node->cmpl_info & UPD_NODE_NO_ORD_CHANGE
+	    && !(*updated_extern)) {
 
 		/* Purge requires no changes to indexes: we may return */
 
@@ -702,7 +717,7 @@ err_exit:
 
 	/* Read to the partial row the fields that occur in indexes */
 
-	if (!(cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
+	if (!(node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
 		ptr = trx_undo_rec_get_partial_row(
 			ptr, clust_index, &node->row,
 			type == TRX_UNDO_UPD_DEL_REC,

=== modified file 'storage/innobase/row/row0row.c'
--- a/storage/innobase/row/row0row.c	2011-08-09 08:50:55 +0000
+++ b/storage/innobase/row/row0row.c	2011-09-30 11:37:22 +0000
@@ -233,7 +233,6 @@ row_build(
 
 	ut_ad(index && rec && heap);
 	ut_ad(dict_index_is_clust(index));
-	ut_ad(!mutex_own(&kernel_mutex));
 
 	if (!offsets) {
 		offsets = rec_get_offsets(rec, index, offsets_,
@@ -242,21 +241,13 @@ row_build(
 		ut_ad(rec_offs_validate(rec, index, offsets));
 	}
 
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
-	/* This condition can occur during crash recovery before
-	trx_rollback_active() has completed execution.
-
-	This condition is possible if the server crashed
-	during an insert or update before
-	btr_store_big_rec_extern_fields() did mtr_commit() all
-	BLOB pointers to the clustered index record.
-
-	If the record contains a null BLOB pointer, look up the
-	transaction that holds the implicit lock on this record, and
-	assert that it was recovered (and will soon be rolled back). */
-	ut_a(!rec_offs_any_null_extern(rec, offsets)
-	     || trx_assert_recovered(row_get_rec_trx_id(rec, index, offsets)));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#if 0 && defined UNIV_BLOB_NULL_DEBUG
+	/* This one can fail in trx_rollback_active() if
+	the server crashed during an insert before the
+	btr_store_big_rec_extern_fields() did mtr_commit()
+	all BLOB pointers to the clustered index record. */
+	ut_a(!rec_offs_any_null_extern(rec, offsets));
+#endif /* 0 && UNIV_BLOB_NULL_DEBUG */
 
 	if (type != ROW_COPY_POINTERS) {
 		/* Take a copy of rec to heap */
@@ -441,10 +432,10 @@ row_rec_to_index_entry(
 		rec = rec_copy(buf, rec, offsets);
 		/* Avoid a debug assertion in rec_offs_validate(). */
 		rec_offs_make_valid(rec, index, offsets);
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+#ifdef UNIV_BLOB_NULL_DEBUG
 	} else {
 		ut_a(!rec_offs_any_null_extern(rec, offsets));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#endif /* UNIV_BLOB_NULL_DEBUG */
 	}
 
 	entry = row_rec_to_index_entry_low(rec, index, offsets, n_ext, heap);

=== modified file 'storage/innobase/row/row0sel.c'
--- a/storage/innobase/row/row0sel.c	2011-08-10 12:03:33 +0000
+++ b/storage/innobase/row/row0sel.c	2011-09-21 10:40:41 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1997, 2010, Innobase Oy. All Rights Reserved.
+Copyright (c) 1997, 2011, Oracle and/or its affiliates. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -99,14 +99,22 @@ row_sel_sec_rec_is_for_blob(
 	ulint		clust_len,	/*!< in: length of clust_field */
 	const byte*	sec_field,	/*!< in: column in secondary index */
 	ulint		sec_len,	/*!< in: length of sec_field */
+	ulint		prefix_len,	/*!< in: index column prefix length
+					in bytes */
 	dict_table_t*	table)		/*!< in: table */
 {
 	ulint	len;
 	byte	buf[REC_VERSION_56_MAX_INDEX_COL_LEN];
 	ulint	zip_size = dict_table_flags_to_zip_size(table->flags);
-	ulint	max_prefix_len = DICT_MAX_FIELD_LEN_BY_FORMAT(table);
 
+	/* This function should never be invoked on an Antelope format
+	table, because they should always contain enough prefix in the
+	clustered index record. */
+	ut_ad(dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP);
 	ut_a(clust_len >= BTR_EXTERN_FIELD_REF_SIZE);
+	ut_ad(prefix_len >= sec_len);
+	ut_ad(prefix_len > 0);
+	ut_a(prefix_len <= sizeof buf);
 
 	if (UNIV_UNLIKELY
 	    (!memcmp(clust_field + clust_len - BTR_EXTERN_FIELD_REF_SIZE,
@@ -118,7 +126,7 @@ row_sel_sec_rec_is_for_blob(
 		return(FALSE);
 	}
 
-	len = btr_copy_externally_stored_field_prefix(buf, max_prefix_len,
+	len = btr_copy_externally_stored_field_prefix(buf, prefix_len,
 						      zip_size,
 						      clust_field, clust_len);
 
@@ -132,7 +140,7 @@ row_sel_sec_rec_is_for_blob(
 	}
 
 	len = dtype_get_at_most_n_mbchars(prtype, mbminmaxlen,
-					  sec_len, len, (const char*) buf);
+					  prefix_len, len, (const char*) buf);
 
 	return(!cmp_data_data(mtype, prtype, buf, len, sec_field, sec_len));
 }
@@ -224,6 +232,7 @@ row_sel_sec_rec_is_for_clust_rec(
 					    col->mbminmaxlen,
 					    clust_field, clust_len,
 					    sec_field, sec_len,
+					    ifield->prefix_len,
 					    clust_index->table)) {
 					goto inequal;
 				}
@@ -493,7 +502,7 @@ sel_col_prefetch_buf_alloc(
 		sel_buf = column->prefetch_buf + i;
 
 		sel_buf->data = NULL;
-
+		sel_buf->len = 0;
 		sel_buf->val_buf_size = 0;
 	}
 }
@@ -518,6 +527,8 @@ sel_col_prefetch_buf_free(
 			mem_free(sel_buf->data);
 		}
 	}
+
+	mem_free(prefetch_buf);
 }
 
 /*********************************************************************//**
@@ -3441,6 +3452,13 @@ row_search_for_mysql(
 		return(DB_MISSING_HISTORY);
 	}
 
+	if (dict_index_is_corrupted(index)) {
+#ifdef UNIV_SYNC_DEBUG
+		ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
+#endif /* UNIV_SYNC_DEBUG */
+		return(DB_CORRUPTION);
+	}
+
 	if (UNIV_UNLIKELY(prebuilt->magic_n != ROW_PREBUILT_ALLOCATED)) {
 		fprintf(stderr,
 			"InnoDB: Error: trying to free a corrupt\n"

=== modified file 'storage/innobase/row/row0uins.c'
--- a/storage/innobase/row/row0uins.c	2010-07-21 14:22:29 +0000
+++ b/storage/innobase/row/row0uins.c	2011-08-17 01:07:59 +0000
@@ -328,6 +328,8 @@ row_undo_ins(
 	node->index = dict_table_get_next_index(
 		dict_table_get_first_index(node->table));
 
+	dict_table_skip_corrupt_index(node->index);
+
 	while (node->index != NULL) {
 		dtuple_t*	entry;
 		ulint		err;
@@ -355,7 +357,7 @@ row_undo_ins(
 			}
 		}
 
-		node->index = dict_table_get_next_index(node->index);
+		dict_table_next_uncorrupted_index(node->index);
 	}
 
 	log_free_check();

=== modified file 'storage/innobase/row/row0umod.c'
--- a/storage/innobase/row/row0umod.c	2011-02-02 13:58:01 +0000
+++ b/storage/innobase/row/row0umod.c	2011-08-17 01:07:59 +0000
@@ -573,6 +573,14 @@ row_undo_mod_upd_del_sec(
 	heap = mem_heap_create(1024);
 
 	while (node->index != NULL) {
+
+		/* Skip all corrupted secondary index */
+		dict_table_skip_corrupt_index(node->index);
+
+		if (!node->index) {
+			break;
+		}
+
 		index = node->index;
 
 		entry = row_build_index_entry(node->row, node->ext,
@@ -626,6 +634,13 @@ row_undo_mod_del_mark_sec(
 	heap = mem_heap_create(1024);
 
 	while (node->index != NULL) {
+		/* Skip all corrupted secondary index */
+		dict_table_skip_corrupt_index(node->index);
+
+		if (!node->index) {
+			break;
+		}
+
 		index = node->index;
 
 		entry = row_build_index_entry(node->row, node->ext,
@@ -677,6 +692,13 @@ row_undo_mod_upd_exist_sec(
 	heap = mem_heap_create(1024);
 
 	while (node->index != NULL) {
+		/* Skip all corrupted secondary index */
+		dict_table_skip_corrupt_index(node->index);
+
+		if (!node->index) {
+			break;
+		}
+
 		index = node->index;
 
 		if (row_upd_changes_ord_field_binary(node->index, node->update,
@@ -859,6 +881,9 @@ row_undo_mod(
 	node->index = dict_table_get_next_index(
 		dict_table_get_first_index(node->table));
 
+	/* Skip all corrupted secondary index */
+	dict_table_skip_corrupt_index(node->index);
+
 	if (node->rec_type == TRX_UNDO_UPD_EXIST_REC) {
 
 		err = row_undo_mod_upd_exist_sec(node, thr);

=== modified file 'storage/innobase/row/row0upd.c'
--- a/storage/innobase/row/row0upd.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/row/row0upd.c	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -1999,43 +1999,28 @@ row_upd_clust_rec(
 	ut_ad(!rec_get_deleted_flag(btr_pcur_get_rec(pcur),
 				    dict_table_is_comp(index->table)));
 
-	err = btr_cur_pessimistic_update(
-		BTR_NO_LOCKING_FLAG | BTR_KEEP_POS_FLAG, btr_cur,
-		&heap, &big_rec, node->update, node->cmpl_info, thr, mtr);
-	if (big_rec) {
+	err = btr_cur_pessimistic_update(BTR_NO_LOCKING_FLAG, btr_cur,
+					 &heap, &big_rec, node->update,
+					 node->cmpl_info, thr, mtr);
+	mtr_commit(mtr);
+
+	if (err == DB_SUCCESS && big_rec) {
 		ulint		offsets_[REC_OFFS_NORMAL_SIZE];
 		rec_t*		rec;
 		rec_offs_init(offsets_);
 
-		ut_a(err == DB_SUCCESS);
-		/* Write out the externally stored columns while still
-		x-latching index->lock and block->lock. We have to
-		mtr_commit(mtr) first, so that the redo log will be
-		written in the correct order. Otherwise, we would run
-		into trouble on crash recovery if mtr freed B-tree
-		pages on which some of the big_rec fields will be
-		written. */
-		btr_cur_mtr_commit_and_start(btr_cur, mtr);
+		mtr_start(mtr);
 
+		ut_a(btr_pcur_restore_position(BTR_MODIFY_TREE, pcur, mtr));
 		rec = btr_cur_get_rec(btr_cur);
 		err = btr_store_big_rec_extern_fields(
 			index, btr_cur_get_block(btr_cur), rec,
 			rec_get_offsets(rec, index, offsets_,
 					ULINT_UNDEFINED, &heap),
 			mtr, TRUE, big_rec);
-		/* If writing big_rec fails (for example, because of
-		DB_OUT_OF_FILE_SPACE), the record will be corrupted.
-		Even if we did not update any externally stored
-		columns, our update could cause the record to grow so
-		that a non-updated column was selected for external
-		storage. This non-update would not have been written
-		to the undo log, and thus the record cannot be rolled
-		back. */
-		ut_a(err == DB_SUCCESS);
+		mtr_commit(mtr);
 	}
 
-	mtr_commit(mtr);
-
 	if (UNIV_LIKELY_NULL(heap)) {
 		mem_heap_free(heap);
 	}
@@ -2320,6 +2305,13 @@ row_upd(
 
 	while (node->index != NULL) {
 
+		/* Skip corrupted index */
+		dict_table_skip_corrupt_index(node->index);
+
+		if (!node->index) {
+			break;
+		}
+
 		log_free_check();
 		err = row_upd_sec_step(node, thr);
 

=== modified file 'storage/innobase/row/row0vers.c'
--- a/storage/innobase/row/row0vers.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/row/row0vers.c	2011-09-30 11:37:22 +0000
@@ -550,10 +550,10 @@ row_vers_build_for_consistent_read(
 				/* The view already sees this version: we can
 				copy it to in_heap and return */
 
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+#ifdef UNIV_BLOB_NULL_DEBUG
 				ut_a(!rec_offs_any_null_extern(
 					     version, *offsets));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#endif /* UNIV_BLOB_NULL_DEBUG */
 
 				buf = mem_heap_alloc(in_heap,
 						     rec_offs_size(*offsets));
@@ -588,9 +588,9 @@ row_vers_build_for_consistent_read(
 		*offsets = rec_get_offsets(prev_version, index, *offsets,
 					   ULINT_UNDEFINED, offset_heap);
 
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+#ifdef UNIV_BLOB_NULL_DEBUG
 		ut_a(!rec_offs_any_null_extern(prev_version, *offsets));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#endif /* UNIV_BLOB_NULL_DEBUG */
 
 		trx_id = row_get_rec_trx_id(prev_version, index, *offsets);
 
@@ -691,9 +691,9 @@ row_vers_build_for_semi_consistent_read(
 			/* We found a version that belongs to a
 			committed transaction: return it. */
 
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+#ifdef UNIV_BLOB_NULL_DEBUG
 			ut_a(!rec_offs_any_null_extern(version, *offsets));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#endif /* UNIV_BLOB_NULL_DEBUG */
 
 			if (rec == version) {
 				*old_vers = rec;
@@ -752,9 +752,9 @@ row_vers_build_for_semi_consistent_read(
 		version = prev_version;
 		*offsets = rec_get_offsets(version, index, *offsets,
 					   ULINT_UNDEFINED, offset_heap);
-#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+#ifdef UNIV_BLOB_NULL_DEBUG
 		ut_a(!rec_offs_any_null_extern(version, *offsets));
-#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+#endif /* UNIV_BLOB_NULL_DEBUG */
 	}/* for (;;) */
 
 	if (heap) {

=== modified file 'storage/innobase/sync/sync0rw.c'
--- a/storage/innobase/sync/sync0rw.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/sync/sync0rw.c	2011-09-30 11:37:22 +0000
@@ -782,9 +782,7 @@ rw_lock_add_debug_info(
 	rw_lock_debug_mutex_exit();
 
 	if ((pass == 0) && (lock_type != RW_LOCK_WAIT_EX)) {
-		sync_thread_add_level(lock, lock->level,
-				      lock_type == RW_LOCK_EX
-				      && lock->lock_word < 0);
+		sync_thread_add_level(lock, lock->level);
 	}
 }
 

=== modified file 'storage/innobase/sync/sync0sync.c'
--- a/storage/innobase/sync/sync0sync.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/sync/sync0sync.c	2011-09-30 11:37:22 +0000
@@ -1,6 +1,6 @@
 /*****************************************************************************
 
-Copyright (c) 1995, 2011, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 1995, 2011, Innobase Oy. All Rights Reserved.
 Copyright (c) 2008, Google Inc.
 
 Portions of this file contain modifications contributed and copyrighted by
@@ -690,7 +690,7 @@ mutex_set_debug_info(
 	ut_ad(mutex);
 	ut_ad(file_name);
 
-	sync_thread_add_level(mutex, mutex->level, FALSE);
+	sync_thread_add_level(mutex, mutex->level);
 
 	mutex->file_name = file_name;
 	mutex->line	 = line;
@@ -1133,9 +1133,8 @@ void
 sync_thread_add_level(
 /*==================*/
 	void*	latch,	/*!< in: pointer to a mutex or an rw-lock */
-	ulint	level,	/*!< in: level in the latching order; if
+	ulint	level)	/*!< in: level in the latching order; if
 			SYNC_LEVEL_VARYING, nothing is done */
-	ibool	relock)	/*!< in: TRUE if re-entering an x-lock */
 {
 	ulint		i;
 	sync_level_t*	slot;
@@ -1186,10 +1185,6 @@ sync_thread_add_level(
 
 	array = thread_slot->levels;
 
-	if (relock) {
-		goto levels_ok;
-	}
-
 	/* NOTE that there is a problem with _NODE and _LEAF levels: if the
 	B-tree height changes, then a leaf can change to an internal node
 	or the other way around. We do not know at present if this can cause
@@ -1214,7 +1209,6 @@ sync_thread_add_level(
 	case SYNC_WORK_QUEUE:
 	case SYNC_LOG:
 	case SYNC_LOG_FLUSH_ORDER:
-	case SYNC_THR_LOCAL:
 	case SYNC_ANY_LATCH:
 	case SYNC_FILE_FORMAT_TAG:
 	case SYNC_DOUBLEWRITE:
@@ -1232,6 +1226,7 @@ sync_thread_add_level(
 	case SYNC_DICT_HEADER:
 	case SYNC_TRX_I_S_RWLOCK:
 	case SYNC_TRX_I_S_LAST_READ:
+	case SYNC_IBUF_MUTEX:
 		if (!sync_thread_levels_g(array, level, TRUE)) {
 			fprintf(stderr,
 				"InnoDB: sync_thread_levels_g(array, %lu)"
@@ -1317,22 +1312,33 @@ sync_thread_add_level(
 		     || sync_thread_levels_g(array, SYNC_TREE_NODE - 1, TRUE));
 		break;
 	case SYNC_TREE_NODE_NEW:
-		ut_a(sync_thread_levels_contain(array, SYNC_FSP_PAGE)
-		     || sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
+		ut_a(sync_thread_levels_contain(array, SYNC_FSP_PAGE));
 		break;
 	case SYNC_INDEX_TREE:
-		if (sync_thread_levels_contain(array, SYNC_IBUF_MUTEX)
-		    && sync_thread_levels_contain(array, SYNC_FSP)) {
-			ut_a(sync_thread_levels_g(array, SYNC_FSP_PAGE - 1,
-						  TRUE));
+		ut_a(sync_thread_levels_g(array, SYNC_TREE_NODE - 1, TRUE));
+		break;
+	case SYNC_IBUF_TREE_NODE:
+		ut_a(sync_thread_levels_contain(array, SYNC_IBUF_INDEX_TREE)
+		     || sync_thread_levels_g(array, SYNC_IBUF_TREE_NODE - 1,
+					     TRUE));
+		break;
+	case SYNC_IBUF_TREE_NODE_NEW:
+		/* ibuf_add_free_page() allocates new pages for the
+		change buffer while only holding the tablespace
+		x-latch. These pre-allocated new pages may only be
+		taken in use while holding ibuf_mutex, in
+		btr_page_alloc_for_ibuf(). */
+		ut_a(sync_thread_levels_contain(array, SYNC_IBUF_MUTEX)
+		     || sync_thread_levels_contain(array, SYNC_FSP));
+		break;
+	case SYNC_IBUF_INDEX_TREE:
+		if (sync_thread_levels_contain(array, SYNC_FSP)) {
+			ut_a(sync_thread_levels_g(array, level - 1, TRUE));
 		} else {
-			ut_a(sync_thread_levels_g(array, SYNC_TREE_NODE - 1,
-						  TRUE));
+			ut_a(sync_thread_levels_g(
+				     array, SYNC_IBUF_TREE_NODE - 1, TRUE));
 		}
 		break;
-	case SYNC_IBUF_MUTEX:
-		ut_a(sync_thread_levels_g(array, SYNC_FSP_PAGE - 1, TRUE));
-		break;
 	case SYNC_IBUF_PESS_INSERT_MUTEX:
 		ut_a(sync_thread_levels_g(array, SYNC_FSP - 1, TRUE));
 		ut_a(!sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
@@ -1355,7 +1361,6 @@ sync_thread_add_level(
 		ut_error;
 	}
 
-levels_ok:
 	if (array->next_free == ULINT_UNDEFINED) {
 		ut_a(array->n_elems < array->max_elems);
 

=== modified file 'storage/innobase/trx/trx0rec.c'
--- a/storage/innobase/trx/trx0rec.c	2011-06-16 09:07:49 +0000
+++ b/storage/innobase/trx/trx0rec.c	2011-09-30 11:37:22 +0000
@@ -669,7 +669,6 @@ trx_undo_page_report_modify(
 	/* Save to the undo log the old values of the columns to be updated. */
 
 	if (update) {
-
 		if (trx_undo_left(undo_page, ptr) < 5) {
 
 			return(0);
@@ -1119,13 +1118,14 @@ trx_undo_rec_get_partial_row(
 #endif /* !UNIV_HOTBACKUP */
 
 /***********************************************************************//**
-Erases the unused undo log page end. */
-static
-void
+Erases the unused undo log page end.
+@return TRUE if the page contained something, FALSE if it was empty */
+static __attribute__((nonnull))
+ibool
 trx_undo_erase_page_end(
 /*====================*/
-	page_t*	undo_page,	/*!< in: undo page whose end to erase */
-	mtr_t*	mtr)		/*!< in: mtr */
+	page_t*	undo_page,	/*!< in/out: undo page whose end to erase */
+	mtr_t*	mtr)		/*!< in/out: mini-transaction */
 {
 	ulint	first_free;
 
@@ -1135,6 +1135,7 @@ trx_undo_erase_page_end(
 	       (UNIV_PAGE_SIZE - FIL_PAGE_DATA_END) - first_free);
 
 	mlog_write_initial_log_record(undo_page, MLOG_UNDO_ERASE_END, mtr);
+	return(first_free != TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE);
 }
 
 /***********************************************************//**
@@ -1202,6 +1203,9 @@ trx_undo_report_row_operation(
 	mem_heap_t*	heap		= NULL;
 	ulint		offsets_[REC_OFFS_NORMAL_SIZE];
 	ulint*		offsets		= offsets_;
+#ifdef UNIV_DEBUG
+	int		loop_count	= 0;
+#endif /* UNIV_DEBUG */
 	rec_offs_init(offsets_);
 
 	ut_a(dict_index_is_clust(index));
@@ -1264,7 +1268,7 @@ trx_undo_report_row_operation(
 
 	mtr_start(&mtr);
 
-	for (;;) {
+	do {
 		buf_block_t*	undo_block;
 		page_t*		undo_page;
 		ulint		offset;
@@ -1293,7 +1297,31 @@ trx_undo_report_row_operation(
 			version the replicate page constructed using the log
 			records stays identical to the original page */
 
-			trx_undo_erase_page_end(undo_page, &mtr);
+			if (!trx_undo_erase_page_end(undo_page, &mtr)) {
+				/* The record did not fit on an empty
+				undo page. Discard the freshly allocated
+				page and return an error. */
+
+				/* When we remove a page from an undo
+				log, this is analogous to a
+				pessimistic insert in a B-tree, and we
+				must reserve the counterpart of the
+				tree latch, which is the rseg
+				mutex. We must commit the mini-transaction
+				first, because it may be holding lower-level
+				latches, such as SYNC_FSP and SYNC_FSP_PAGE. */
+
+				mtr_commit(&mtr);
+				mtr_start(&mtr);
+
+				mutex_enter(&rseg->mutex);
+				trx_undo_free_last_page(trx, undo, &mtr);
+				mutex_exit(&rseg->mutex);
+
+				err = DB_UNDO_RECORD_TOO_BIG;
+				goto err_exit;
+			}
+
 			mtr_commit(&mtr);
 		} else {
 			/* Success */
@@ -1313,16 +1341,15 @@ trx_undo_report_row_operation(
 			*roll_ptr = trx_undo_build_roll_ptr(
 				op_type == TRX_UNDO_INSERT_OP,
 				rseg->id, page_no, offset);
-			if (UNIV_LIKELY_NULL(heap)) {
-				mem_heap_free(heap);
-			}
-			return(DB_SUCCESS);
+			err = DB_SUCCESS;
+			goto func_exit;
 		}
 
 		ut_ad(page_no == undo->last_page_no);
 
 		/* We have to extend the undo log by one page */
 
+		ut_ad(++loop_count < 2);
 		mtr_start(&mtr);
 
 		/* When we add a page to an undo log, this is analogous to
@@ -1334,18 +1361,19 @@ trx_undo_report_row_operation(
 		page_no = trx_undo_add_page(trx, undo, &mtr);
 
 		mutex_exit(&(rseg->mutex));
+	} while (UNIV_LIKELY(page_no != FIL_NULL));
 
-		if (UNIV_UNLIKELY(page_no == FIL_NULL)) {
-			/* Did not succeed: out of space */
+	/* Did not succeed: out of space */
+	err = DB_OUT_OF_FILE_SPACE;
 
-			mutex_exit(&(trx->undo_mutex));
-			mtr_commit(&mtr);
-			if (UNIV_LIKELY_NULL(heap)) {
-				mem_heap_free(heap);
-			}
-			return(DB_OUT_OF_FILE_SPACE);
-		}
+err_exit:
+	mutex_exit(&trx->undo_mutex);
+	mtr_commit(&mtr);
+func_exit:
+	if (UNIV_LIKELY_NULL(heap)) {
+		mem_heap_free(heap);
 	}
+	return(err);
 }
 
 /*============== BUILDING PREVIOUS VERSION OF A RECORD ===============*/
@@ -1593,9 +1621,9 @@ trx_undo_prev_version_build(
 		return(DB_ERROR);
 	}
 
-# if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
+# ifdef UNIV_BLOB_NULL_DEBUG
 	ut_a(!rec_offs_any_null_extern(rec, offsets));
-# endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
+# endif /* UNIV_BLOB_NULL_DEBUG */
 
 	if (row_upd_changes_field_size_or_external(index, offsets, update)) {
 		ulint	n_ext;

=== modified file 'storage/innobase/trx/trx0undo.c'
--- a/storage/innobase/trx/trx0undo.c	2011-06-14 05:47:33 +0000
+++ b/storage/innobase/trx/trx0undo.c	2011-09-30 11:37:22 +0000
@@ -1004,29 +1004,28 @@ trx_undo_free_page(
 }
 
 /********************************************************************//**
-Frees an undo log page when there is also the memory object for the undo
-log. */
-static
+Frees the last undo log page.
+The caller must hold the rollback segment mutex. */
+UNIV_INTERN
 void
-trx_undo_free_page_in_rollback(
-/*===========================*/
-	trx_t*		trx __attribute__((unused)), /*!< in: transaction */
-	trx_undo_t*	undo,	/*!< in: undo log memory copy */
-	ulint		page_no,/*!< in: page number to free: must not be the
-				header page */
-	mtr_t*		mtr)	/*!< in: mtr which does not have a latch to any
-				undo log page; the caller must have reserved
-				the rollback segment mutex */
-{
-	ulint	last_page_no;
-
-	ut_ad(undo->hdr_page_no != page_no);
-	ut_ad(mutex_own(&(trx->undo_mutex)));
-
-	last_page_no = trx_undo_free_page(undo->rseg, FALSE, undo->space,
-					  undo->hdr_page_no, page_no, mtr);
+trx_undo_free_last_page_func(
+/*==========================*/
+#ifdef UNIV_DEBUG
+	const trx_t*	trx,	/*!< in: transaction */
+#endif /* UNIV_DEBUG */
+	trx_undo_t*	undo,	/*!< in/out: undo log memory copy */
+	mtr_t*		mtr)	/*!< in/out: mini-transaction which does not
+				have a latch to any undo log page or which
+				has allocated the undo log page */
+{
+	ut_ad(mutex_own(&trx->undo_mutex));
+	ut_ad(undo->hdr_page_no != undo->last_page_no);
+	ut_ad(undo->size > 0);
+
+	undo->last_page_no = trx_undo_free_page(
+		undo->rseg, FALSE, undo->space,
+		undo->hdr_page_no, undo->last_page_no, mtr);
 
-	undo->last_page_no = last_page_no;
 	undo->size--;
 }
 
@@ -1062,9 +1061,11 @@ Truncates an undo log from the end. This
 to free space from an undo log. */
 UNIV_INTERN
 void
-trx_undo_truncate_end(
-/*==================*/
-	trx_t*		trx,	/*!< in: transaction whose undo log it is */
+trx_undo_truncate_end_func(
+/*=======================*/
+#ifdef UNIV_DEBUG
+	const trx_t*	trx,	/*!< in: transaction whose undo log it is */
+#endif /* UNIV_DEBUG */
 	trx_undo_t*	undo,	/*!< in: undo log */
 	undo_no_t	limit)	/*!< in: all undo records with undo number
 				>= this value should be truncated */
@@ -1090,18 +1091,7 @@ trx_undo_truncate_end(
 
 		rec = trx_undo_page_get_last_rec(undo_page, undo->hdr_page_no,
 						 undo->hdr_offset);
-		for (;;) {
-			if (rec == NULL) {
-				if (last_page_no == undo->hdr_page_no) {
-
-					goto function_exit;
-				}
-
-				trx_undo_free_page_in_rollback(
-					trx, undo, last_page_no, &mtr);
-				break;
-			}
-
+		while (rec) {
 			if (trx_undo_rec_get_undo_no(rec) >= limit) {
 				/* Truncate at least this record off, maybe
 				more */
@@ -1115,6 +1105,14 @@ trx_undo_truncate_end(
 							 undo->hdr_offset);
 		}
 
+		if (last_page_no == undo->hdr_page_no) {
+
+			goto function_exit;
+		}
+
+		ut_ad(last_page_no == undo->last_page_no);
+		trx_undo_free_last_page(trx, undo, &mtr);
+
 		mtr_commit(&mtr);
 	}
 

=== modified file 'storage/innobase/ut/ut0ut.c'
--- a/storage/innobase/ut/ut0ut.c	2011-06-28 12:28:21 +0000
+++ b/storage/innobase/ut/ut0ut.c	2011-09-01 18:48:04 +0000
@@ -712,6 +712,10 @@ ut_strerr(
 		return("No index on referencing keys in referencing table");
 	case DB_PARENT_NO_INDEX:
 		return("No index on referenced keys in referenced table");
+	case DB_INDEX_CORRUPT:
+		return("Index corrupted");
+	case DB_UNDO_RECORD_TOO_BIG:
+		return("Undo record too big");
 	case DB_END_OF_INDEX:
 		return("End of index");
 	/* do not add default: in order to produce a warning if new code

=== modified file 'storage/myisam/ft_boolean_search.c'
--- a/storage/myisam/ft_boolean_search.c	2011-06-30 15:46:53 +0000
+++ b/storage/myisam/ft_boolean_search.c	2011-09-16 12:21:05 +0000
@@ -360,7 +360,7 @@ static int _ft2_search(FTB *ftb, FTB_WOR
   int subkeys=1;
   my_bool can_go_down;
   MI_INFO *info=ftb->info;
-  uint UNINIT_VAR(off), extra=HA_FT_WLEN+info->s->base.rec_reflength;
+  uint UNINIT_VAR(off), extra= HA_FT_WLEN + info->s->rec_reflength;
   uchar *lastkey_buf=ftbw->word+ftbw->off;
 
   if (ftbw->flags & FTB_FLAG_TRUNC)

=== modified file 'storage/myisam/ft_nlq_search.c'
--- a/storage/myisam/ft_nlq_search.c	2011-06-30 15:46:53 +0000
+++ b/storage/myisam/ft_nlq_search.c	2011-09-16 12:21:05 +0000
@@ -72,7 +72,7 @@ static int walk_and_match(FT_WORD *word,
   uchar        *keybuff=aio->keybuff;
   MI_KEYDEF    *keyinfo=info->s->keyinfo+aio->keynr;
   my_off_t     key_root=info->s->state.key_root[aio->keynr];
-  uint         extra=HA_FT_WLEN+info->s->base.rec_reflength;
+  uint         extra= HA_FT_WLEN + info->s->rec_reflength;
 #if HA_FT_WTYPE == HA_KEYTYPE_FLOAT
   float tmp_weight;
 #else

=== modified file 'storage/myisam/mi_check.c'
--- a/storage/myisam/mi_check.c	2011-07-03 23:48:19 +0000
+++ b/storage/myisam/mi_check.c	2011-09-16 12:21:05 +0000
@@ -3899,7 +3899,7 @@ static int sort_ft_key_write(MI_SORT_PAR
   SORT_FT_BUF *ft_buf=sort_info->ft_buf;
   SORT_KEY_BLOCKS *key_block=sort_info->key_block;
 
-  val_len=HA_FT_WLEN+sort_info->info->s->base.rec_reflength;
+  val_len= HA_FT_WLEN + sort_info->info->s->rec_reflength;
   get_key_full_length_rdonly(a_len, (uchar *)a);
 
   if (!ft_buf)
@@ -3909,7 +3909,7 @@ static int sort_ft_key_write(MI_SORT_PAR
       and row format is NOT static - for _mi_dpointer not to garble offsets
      */
     if ((sort_info->info->s->base.key_reflength <=
-         sort_info->info->s->base.rec_reflength) &&
+         sort_info->info->s->rec_reflength) &&
         (sort_info->info->s->options &
           (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)))
       ft_buf=(SORT_FT_BUF *)my_malloc(sort_param->keyinfo->block_length +

=== modified file 'storage/myisam/mi_write.c'
--- a/storage/myisam/mi_write.c	2011-07-03 23:48:19 +0000
+++ b/storage/myisam/mi_write.c	2011-09-16 12:21:05 +0000
@@ -519,7 +519,7 @@ int _mi_insert(register MI_INFO *info, r
   {
     if (keyinfo->block_length - a_length < 32 &&
         keyinfo->flag & HA_FULLTEXT && key_pos == endpos &&
-        info->s->base.key_reflength <= info->s->base.rec_reflength &&
+        info->s->base.key_reflength <= info->s->rec_reflength &&
         info->s->options & (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD))
     {
       /*

=== modified file 'storage/ndb/compile-cluster'
--- a/storage/ndb/compile-cluster	2011-09-20 11:55:43 +0000
+++ b/storage/ndb/compile-cluster	2011-11-18 11:48:16 +0000
@@ -31,24 +31,31 @@ use Getopt::Long;
 # thus acting like a filter and passing all other arguments
 # straight through
 my $opt_debug;
+my $opt_build_type;
+my $opt_build = 1;
+my $opt_just_print;
+
 Getopt::Long::Configure("pass_through");
 GetOptions(
 
   # Build MySQL Server and NDB with debug
-  'debug' => \$opt_debug,
+  'debug!' => \$opt_debug,
   'with-debug:s' => sub { $opt_debug = 1; },
-
+  'build-type=s' => \$opt_build_type,
+  'build!' => \$opt_build,
+  'c|just-configure' => sub { $opt_build = 0; },
+  'n|just-print' => \$opt_just_print,
 ) or exit(1);
 
 # Find source root directory, assume this script is
 # in <srcroot>/storage/ndb/
-my $srcdir = dirname(dirname(dirname(abs_path($0))));
-die unless -d $srcdir; # Sanity check that the srcdir exist
+my $opt_srcdir = dirname(dirname(dirname(abs_path($0))));
+die unless -d $opt_srcdir; # Sanity check that the srcdir exist
 if ($^O eq "cygwin") {
   # Convert posix path to Windows mixed path since cmake
   # is most likely a windows binary
-  $srcdir= `cygpath -m $srcdir`;
-  chomp $srcdir;
+  $opt_srcdir= `cygpath -m $opt_srcdir`;
+  chomp $opt_srcdir;
 }
 
 # Check that cmake exists and figure out it's version 
@@ -61,7 +68,7 @@ my $cmake_version_id;
   {
     #print "1: $1 2: $2 3: $3\n";
     $cmake_version_id= $1*10000 + $2*100 + $3;
-    print "cmake_version_id: $cmake_version_id\n";
+    #print "cmake_version_id: $cmake_version_id\n";
   }
   die "Could not parse cmake version" unless ($cmake_version_id);
 }
@@ -71,25 +78,221 @@ my $cmake_version_id;
 # Configure
 #
 {
+  # Remove old CMakeCache.txt(ignore if not exists) to
+  # force fresh configure
+  unlink("CMakeCache.txt");
+   
   my @args;
-  push(@args, "$srcdir/cmake/configure.pl");
-
-  # MySQL Server options
-  push(@args, "--with-ssl");
+  
+  # Hardcoded options controlling how to build MySQL Server
+  push(@args, "-DWITH_SSL=bundled");
  
   if ($opt_debug)
   {
-    push(@args, "--with-debug");
-    push(@args, "--disable-mysql-maintainer-mode");
+    push(@args, "-DWITH_DEBUG=1");
+    push(@args, "-DMYSQL_MAINTAINER_MODE=0");
+  }
+
+  # Hardcoded options controlling how to build NDB
+  push(@args, "-DWITH_PLUGIN_NDBCLUSTER=1");
+  push(@args, "-DWITH_NDB_TEST=1");
+
+  # The cmake generator to use
+  if ($opt_build_type)
+  {
+    push(@args, "-G \"$opt_build_type\"");
+  }
+
+  # Sets installation directory,  bindir, libdir, libexecdir etc.
+  # The equivalent CMake variables are given without prefix
+  # e.g if --prefix is /usr and --bindir is /usr/bin
+  # then cmake variable (INSTALL_BINDIR) must be just "bin"
+  my $opt_prefix;
+  sub set_installdir
+  {
+    my($path, $varname) = @_;
+    my $prefix_length = length($opt_prefix);
+    if (($prefix_length > 0) && (index($path,$opt_prefix) == 0))
+    {
+      # path is under the prefix, remove the prefix and
+      # maybe following "/"
+      $path = substr($path, $prefix_length);
+      if(length($path) > 0)
+      {
+        my $char = substr($path, 0, 1);
+        if($char eq "/")
+        {
+          $path= substr($path, 1);
+        }
+      }
+      if(length($path) > 0)
+      {
+        push(@args, "-D$varname=$path");
+      }
+    }
+  }
+
+  # Process --configure style arguments which need special conversion 
+  my $opt_bindir;
+  my $opt_libdir;
+  my $opt_libexecdir;
+  my $opt_includedir;
+  my $opt_with_zlib_dir;
+  my $opt_with_ssl;
+  my $opt_localstatedir;
+  my $opt_mysql_maintainer_mode;
+  my $opt_with_gcov;
+  my $opt_with_comment;
+  my $opt_with_plugins;
+  my $opt_without_plugin;
+  my $opt_extra_charsets;
+  my $opt_with_extra_charsets;  
+  Getopt::Long::Configure("pass_through");
+  GetOptions(
+    'prefix=s' => \$opt_prefix,
+    'srcdir=s' => \$opt_srcdir,
+    'bindir=s' => \$opt_bindir,
+    'libdir=s' => \$opt_libdir,
+    'libexecdir=s' => \$opt_libexecdir,
+    'includedir=s' => \$opt_includedir,
+    'with-zlib-dir=s' => \$opt_with_zlib_dir,
+    'with-ssl:s' => \$opt_with_ssl,
+    'localstatedir=s' => \$opt_localstatedir,
+    'mysql-maintainer-mode=s' => \$opt_mysql_maintainer_mode,
+    'with-gcov' => \$opt_with_gcov,
+    'with-comment=s' => \$opt_with_comment,
+    'with-plugins=s' => \$opt_with_plugins,
+    'without-plugin=s' => \$opt_without_plugin,
+    'with-extra-charsets=s' => \$opt_with_extra_charsets,
+    'extra-charsets=s' => \$opt_extra_charsets,
+  ) or exit(1);
+
+  if($opt_prefix)
+  {
+    push(@args, "-DCMAKE_INSTALL_PREFIX=$opt_prefix");
+  }
+  if($opt_bindir)
+  {
+    set_installdir($opt_bindir, "INSTALL_BINDIR");
+  }
+  if($opt_libdir)
+  {
+    set_installdir($opt_libdir, "INSTALL_LIBDIR");
+  }
+  if($opt_libexecdir)
+  {
+    set_installdir($opt_libexecdir, "INSTALL_SBINDIR");
+  }
+  if($opt_includedir)
+  {
+    set_installdir($opt_includedir, "INSTALL_INCLUDEDIR");
+  }
+  if($opt_with_zlib_dir)
+  {
+    $opt_with_zlib_dir = "system"
+      if ($opt_with_zlib_dir ne "bundled");
+    push(@args, "-DWITH_ZLIB=$opt_with_zlib_dir");
+  }
+  if($opt_with_ssl)
+  {
+    push(@args, "-DWITH_SSL=".($opt_with_ssl ? "yes" : "bundled"));
+  }
+  if ($opt_localstatedir)
+  {
+    push(@args, "-DMYSQL_DATADIR=$opt_localstatedir"); 
   }
+  if ($opt_mysql_maintainer_mode)
+  {
+    push(@args, "-DMYSQL_MAINTAINER_MODE=" .
+                 ($opt_mysql_maintainer_mode =~ /enable/ ? "1" : "0"));
+  }
+  if ($opt_with_gcov)
+  {
+    push(@args, "-DENABLE_GCOV=ON"); 
+  }
+  if ($opt_with_comment)
+  {
+    push(@args, "\"-DWITH_COMMENT=$opt_with_comment\""); 
+  }
+  if($opt_with_plugins)
+  {
+    my @plugins= split(/,/, $opt_with_plugins);
+    foreach my $p (@plugins)
+    {
+      $p =~ s/-/_/g;
+      push(@args, "-DWITH_".uc($p)."=1");
+    }
+  }
+  if($opt_without_plugin)
+  {
+    push(@args, "-DWITHOUT_".uc($opt_without_plugin)."=1");
+  }
+  if ($opt_extra_charsets)
+  {
+    push(@args, "-DWITH_CHARSETS=$opt_extra_charsets"); 
+  }
+  if($opt_with_extra_charsets)
+  {
+    push(@args, "-DWITH_EXTRA_CHARSETS=$opt_with_extra_charsets");
+  }
+  
 
-  # NDB options
-  push(@args, "--with-plugin-ndbcluster");
-  push(@args, "--with-ndb-test");
+  # Default conversion of remaining args in ARGV from
+  # 1) --arg          -> -DARG=1
+  # 2) --arg=value    -> -DARG=value
+  # 3) arg=value      -> environment variable arg=value
+  foreach my $option (@ARGV)
+  {
+    if ($option =~  /^--/)
+    {  
+      # Remove leading --
+      $option = substr($option, 2);
+    
+      my @v  = split('=', $option);
+      my $name = shift(@v);
+      $name = uc($name);
+      $name =~ s/-/_/g;
+      if (@v)
+      {
+        push(@args, "-D$name=".join('=', @v));
+      }
+      else
+      {
+        push(@args, "-D$name=1");
+      }
+    }
+    else
+    {
+ 
+      # This must be environment variable
+      my @v  = split('=', $option);
+      my $name = shift(@v);
+      if(@v)
+      {
+        $ENV{$name} = join('=', @v);  
+      }
+      else
+      {
+        die "unhandled argument '$option' found"; 
+      }
+    }
+  }
+  
+  # The source directory to build from
+  die "srcdir already contains CMakeCache.txt, this will not work!"
+    if (-f "$opt_srcdir/CMakeCache.txt");
+  push(@args, $opt_srcdir);
+  
+  cmd("cmake", @args);
+}
 
-  cmd($^X, @args, @ARGV);
+if (!$opt_build)
+{
+  print "Configuration completed, skipping build(used --no-build)\n";
+  exit(0);
 }
 
+
 #
 # Build
 #
@@ -100,7 +303,7 @@ my $cmake_version_id;
     # which is available from cmake 2.8 and works on all platforms
     my @args;
     push(@args, "--build");
-    push(@args, "$srcdir");
+    push(@args, "$opt_srcdir");
 
     if ($^O eq "cygwin" or $^O eq "MSWin32")
     {
@@ -123,12 +326,18 @@ my $cmake_version_id;
     die "You need to install cmake with version > 2.8"
       if ($^O eq "cygwin" or $^O eq "MSWin32");
 
-    cmd("make -C $srcdir");
+    cmd("make");
   }
 }
 
 sub cmd {
   my ($cmd, @a)= @_;
+  
+  if ($opt_just_print){
+    print "$cmd ", join(' ', @a), "\n";
+    return; 
+  }
+  
   print "compile-cluster: calling '$cmd ", join(' ', @a), "'\n";
   system($cmd, @a)
     and print("command failed: $!\n")

=== modified file 'strings/decimal.c'
--- a/strings/decimal.c	2011-07-18 07:47:39 +0000
+++ b/strings/decimal.c	2011-08-29 09:34:48 +0000
@@ -1403,11 +1403,18 @@ int bin2decimal(const uchar *from, decim
     buf++;
   }
   my_afree(d_copy);
+
+  /*
+    No digits? We have read the number zero, of unspecified precision.
+    Make it a proper zero, with non-zero precision.
+  */
+  if (to->intg == 0 && to->frac == 0)
+    decimal_make_zero(to);
   return error;
 
 err:
   my_afree(d_copy);
-  decimal_make_zero(((decimal_t*) to));
+  decimal_make_zero(to);
   return(E_DEC_BAD_NUM);
 }
 

=== modified file 'strings/dtoa.c'
--- a/strings/dtoa.c	2011-06-30 15:46:53 +0000
+++ b/strings/dtoa.c	2011-09-21 11:46:49 +0000
@@ -46,7 +46,7 @@
      see if it is possible to get rid of malloc().
      this constant is sufficient to avoid malloc() on all inputs I have tried.
 */
-#define DTOA_BUFF_SIZE (420 * sizeof(void *))
+#define DTOA_BUFF_SIZE (460 * sizeof(void *))
 
 /* Magic value returned by dtoa() to indicate overflow */
 #define DTOA_OVERFLOW 9999
@@ -659,6 +659,7 @@ typedef struct Stack_alloc
 static Bigint *Balloc(int k, Stack_alloc *alloc)
 {
   Bigint *rv;
+  DBUG_ASSERT(k <= Kmax);
   if (k <= Kmax &&  alloc->freelist[k])
   {
     rv= alloc->freelist[k];
@@ -1005,9 +1006,10 @@ static Bigint p5_a[]=
 
 static Bigint *pow5mult(Bigint *b, int k, Stack_alloc *alloc)
 {
-  Bigint *b1, *p5, *p51;
+  Bigint *b1, *p5, *p51=NULL;
   int i;
   static int p05[3]= { 5, 25, 125 };
+  my_bool overflow= FALSE;
 
   if ((i= k & 3))
     b= multadd(b, p05[i-1], 0, alloc);
@@ -1026,17 +1028,22 @@ static Bigint *pow5mult(Bigint *b, int k
     if (!(k>>= 1))
       break;
     /* Calculate next power of 5 */
-    if (p5 < p5_a + P5A_MAX)
-      ++p5;
-    else if (p5 == p5_a + P5A_MAX)
-      p5= mult(p5, p5, alloc);
-    else
+    if (overflow)
     {
       p51= mult(p5, p5, alloc);
       Bfree(p5, alloc);
       p5= p51;
     }
+    else if (p5 < p5_a + P5A_MAX)
+      ++p5;
+    else if (p5 == p5_a + P5A_MAX)
+    {
+      p5= mult(p5, p5, alloc);
+      overflow= TRUE;
+    }
   }
+  if (p51)
+    Bfree(p51, alloc);
   return b;
 }
 

=== modified file 'support-files/mysql.spec.sh'
--- a/support-files/mysql.spec.sh	2011-09-08 07:36:06 +0000
+++ b/support-files/mysql.spec.sh	2011-09-28 09:43:16 +0000
@@ -139,43 +139,62 @@
       %endif
     %endif
   %else
-    %if %(test -f /etc/redhat-release && echo 1 || echo 0)
-      %define rhelver %(rpm -qf --qf '%%{version}\\n' /etc/redhat-release | sed -e 's/^\\([0-9]*\\).*/\\1/g')
-      %if "%rhelver" == "4"
-        %define distro_description      Red Hat Enterprise Linux 4
-        %define distro_releasetag       rhel4
-        %define distro_buildreq         gcc-c++ gperf ncurses-devel perl readline-devel time zlib-devel
+    %if %(test -f /etc/oracle-release && echo 1 || echo 0)
+      %define elver %(rpm -qf --qf '%%{version}\\n' /etc/oracle-release | sed -e 's/^\\([0-9]*\\).*/\\1/g')
+      %if "%elver" == "6"
+        %define distro_description      Oracle Linux 6
+        %define distro_releasetag       el6
+        %define distro_buildreq         gcc-c++ ncurses-devel perl readline-devel time zlib-devel
         %define distro_requires         chkconfig coreutils grep procps shadow-utils net-tools
       %else
-        %if "%rhelver" == "5"
-          %define distro_description    Red Hat Enterprise Linux 5
-          %define distro_releasetag     rhel5
-          %define distro_buildreq       gcc-c++ gperf ncurses-devel perl readline-devel time zlib-devel
-          %define distro_requires       chkconfig coreutils grep procps shadow-utils net-tools
-        %else
-          %{error:Red Hat Enterprise Linux %{rhelver} is unsupported}
-        %endif
+        %{error:Oracle Linux %{elver} is unsupported}
       %endif
     %else
-      %if %(test -f /etc/SuSE-release && echo 1 || echo 0)
-        %define susever %(rpm -qf --qf '%%{version}\\n' /etc/SuSE-release)
-        %if "%susever" == "10"
-          %define distro_description    SUSE Linux Enterprise Server 10
-          %define distro_releasetag     sles10
-          %define distro_buildreq       gcc-c++ gdbm-devel gperf ncurses-devel openldap2-client readline-devel zlib-devel
-          %define distro_requires       aaa_base coreutils grep procps pwdutils
+      %if %(test -f /etc/redhat-release && echo 1 || echo 0)
+        %define rhelver %(rpm -qf --qf '%%{version}\\n' /etc/redhat-release | sed -e 's/^\\([0-9]*\\).*/\\1/g')
+        %if "%rhelver" == "4"
+          %define distro_description      Red Hat Enterprise Linux 4
+          %define distro_releasetag       rhel4
+          %define distro_buildreq         gcc-c++ gperf ncurses-devel perl readline-devel time zlib-devel
+          %define distro_requires         chkconfig coreutils grep procps shadow-utils net-tools
         %else
-          %if "%susever" == "11"
-            %define distro_description  SUSE Linux Enterprise Server 11
-            %define distro_releasetag   sles11
-            %define distro_buildreq     gcc-c++ gdbm-devel gperf ncurses-devel openldap2-client procps pwdutils readline-devel zlib-devel
-            %define distro_requires     aaa_base coreutils grep procps pwdutils
+          %if "%rhelver" == "5"
+            %define distro_description    Red Hat Enterprise Linux 5
+            %define distro_releasetag     rhel5
+            %define distro_buildreq       gcc-c++ gperf ncurses-devel perl readline-devel time zlib-devel
+            %define distro_requires       chkconfig coreutils grep procps shadow-utils net-tools
           %else
-            %{error:SuSE %{susever} is unsupported}
+            %if "%rhelver" == "6"
+              %define distro_description    Red Hat Enterprise Linux 6
+              %define distro_releasetag     rhel6
+              %define distro_buildreq       gcc-c++ ncurses-devel perl readline-devel time zlib-devel
+              %define distro_requires       chkconfig coreutils grep procps shadow-utils net-tools
+            %else
+              %{error:Red Hat Enterprise Linux %{rhelver} is unsupported}
+            %endif
           %endif
         %endif
       %else
-        %{error:Unsupported distribution}
+        %if %(test -f /etc/SuSE-release && echo 1 || echo 0)
+          %define susever %(rpm -qf --qf '%%{version}\\n' /etc/SuSE-release)
+          %if "%susever" == "10"
+            %define distro_description    SUSE Linux Enterprise Server 10
+            %define distro_releasetag     sles10
+            %define distro_buildreq       gcc-c++ gdbm-devel gperf ncurses-devel openldap2-client readline-devel zlib-devel
+            %define distro_requires       aaa_base coreutils grep procps pwdutils
+          %else
+            %if "%susever" == "11"
+              %define distro_description  SUSE Linux Enterprise Server 11
+              %define distro_releasetag   sles11
+              %define distro_buildreq     gcc-c++ gdbm-devel gperf ncurses-devel openldap2-client procps pwdutils readline-devel zlib-devel
+              %define distro_requires     aaa_base coreutils grep procps pwdutils
+            %else
+              %{error:SuSE %{susever} is unsupported}
+            %endif
+          %endif
+        %else
+          %{error:Unsupported distribution}
+        %endif
       %endif
     %endif
   %endif
@@ -228,7 +247,7 @@ Distribution:   %{distro_description}
 License:        Copyright (c) 2000, @MYSQL_COPYRIGHT_YEAR@, %{mysql_vendor}. All rights reserved. Under %{license_type} license as shown in the Description field.
 Source:         http://www.mysql.com/Downloads/MySQL-@MYSQL_BASE_VERSION@/%{src_dir}.tar.gz
 URL:            http://www.mysql.com/
-Packager:       MySQL Build Team <build@stripped>
+Packager:       MySQL Release Engineering <mysql-build@stripped>
 Vendor:         %{mysql_vendor}
 Provides:       msqlormysql MySQL-server mysql
 BuildRequires:  %{distro_buildreq}
@@ -421,7 +440,7 @@ mkdir debug
   # XXX: install_layout so we can't just set it based on INSTALL_LAYOUT=RPM
   ${CMAKE} ../%{src_dir} -DBUILD_CONFIG=mysql_release -DINSTALL_LAYOUT=RPM \
            -DCMAKE_BUILD_TYPE=Debug \
-           -DMYSQL_UNIX_ADDR="/var/lib/mysql/mysql.sock" \
+           -DMYSQL_UNIX_ADDR="%{mysqldatadir}/mysql.sock" \
            -DFEATURE_SET="%{feature_set}" \
            -DCOMPILATION_COMMENT="%{compilation_comment_debug}" \
            -DMYSQL_SERVER_SUFFIX="%{server_suffix}"
@@ -436,7 +455,7 @@ mkdir release
   # XXX: install_layout so we can't just set it based on INSTALL_LAYOUT=RPM
   ${CMAKE} ../%{src_dir} -DBUILD_CONFIG=mysql_release -DINSTALL_LAYOUT=RPM \
            -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-           -DMYSQL_UNIX_ADDR="/var/lib/mysql/mysql.sock" \
+           -DMYSQL_UNIX_ADDR="%{mysqldatadir}/mysql.sock" \
            -DFEATURE_SET="%{feature_set}" \
            -DCOMPILATION_COMMENT="%{compilation_comment_release}" \
            -DMYSQL_SERVER_SUFFIX="%{server_suffix}"
@@ -444,25 +463,6 @@ mkdir release
   make ${MAKE_JFLAG} VERBOSE=1
 )
 
-# Use the build root for temporary storage of the shared libraries.
-RBR=$RPM_BUILD_ROOT
-
-# Clean up the BuildRoot first
-[ "$RBR" != "/" ] && [ -d "$RBR" ] && rm -rf "$RBR";
-
-# For gcc builds, include libgcc.a in the devel subpackage (BUG 4921).  This
-# needs to be during build phase as $CC is not set during install.
-if "$CC" -v 2>&1 | grep '^gcc.version' >/dev/null 2>&1
-then
-  libgcc=`$CC $CFLAGS --print-libgcc-file`
-  if [ -f $libgcc ]
-  then
-    mkdir -p $RBR%{_libdir}/mysql
-    install -m 644 $libgcc $RBR%{_libdir}/mysql/libmygcc.a
-    echo "%{_libdir}/mysql/libmygcc.a" >>optional-files-devel
-  fi
-fi
-
 ##############################################################################
 %install
 
@@ -485,6 +485,23 @@ install -d $RBR%{_sbindir}
   make DESTDIR=$RBR install
 )
 
+# For gcc builds, include libgcc.a in the devel subpackage (BUG 4921).  Do
+# this in a sub-shell to ensure we don't pollute the install environment
+# with compiler bits.
+(
+  PATH=${MYSQL_BUILD_PATH:-$PATH}
+  CC=${MYSQL_BUILD_CC:-${CC:-gcc}}
+  CFLAGS=${MYSQL_BUILD_CFLAGS:-${CFLAGS:-$RPM_OPT_FLAGS}}
+  if "${CC}" -v 2>&1 | grep '^gcc.version' >/dev/null 2>&1; then
+    libgcc=`${CC} ${CFLAGS} --print-libgcc-file`
+    if [ -f ${libgcc} ]; then
+      mkdir -p $RBR%{_libdir}/mysql
+      install -m 644 ${libgcc} $RBR%{_libdir}/mysql/libmygcc.a
+      echo "%{_libdir}/mysql/libmygcc.a" >>optional-files-devel
+    fi
+  fi
+)
+
 # FIXME: at some point we should stop doing this and just install everything
 # FIXME: directly into %{_libdir}/mysql - perhaps at the same time as renaming
 # FIXME: the shared libraries to use libmysql*-$major.$minor.so syntax
@@ -516,7 +533,7 @@ install -m 644 "%{malloc_lib_source}" \
 
 # Remove man pages we explicitly do not want to package, avoids 'unpackaged
 # files' warning.
-rm -f $RBR%{_mandir}/man1/make_win_bin_dist.1*
+# This has become obsolete:  rm -f $RBR%{_mandir}/man1/make_win_bin_dist.1*
 
 ##############################################################################
 #  Post processing actions, i.e. when installed
@@ -970,6 +987,7 @@ echo "====="                            
 %doc %attr(644, root, man) %{_mandir}/man1/mysqld_safe.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysqldumpslow.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_install_db.1*
+%doc %attr(644, root, man) %{_mandir}/man1/mysql_plugin.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_secure_installation.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_setpermission.1*
 %doc %attr(644, root, man) %{_mandir}/man1/mysql_upgrade.1*
@@ -984,7 +1002,6 @@ echo "====="                            
 %doc %attr(644, root, man) %{_mandir}/man1/replace.1*
 %doc %attr(644, root, man) %{_mandir}/man1/resolve_stack_dump.1*
 %doc %attr(644, root, man) %{_mandir}/man1/resolveip.1*
-%doc %attr(644, root, man) %{_mandir}/man1/mysql_plugin.1*
 
 %ghost %config(noreplace,missingok) %{_sysconfdir}/my.cnf
 
@@ -997,11 +1014,11 @@ echo "====="                            
 %attr(755, root, root) %{_bindir}/mysql_convert_table_format
 %attr(755, root, root) %{_bindir}/mysql_fix_extensions
 %attr(755, root, root) %{_bindir}/mysql_install_db
+%attr(755, root, root) %{_bindir}/mysql_plugin
 %attr(755, root, root) %{_bindir}/mysql_secure_installation
 %attr(755, root, root) %{_bindir}/mysql_setpermission
 %attr(755, root, root) %{_bindir}/mysql_tzinfo_to_sql
 %attr(755, root, root) %{_bindir}/mysql_upgrade
-%attr(755, root, root) %{_bindir}/mysql_plugin
 %attr(755, root, root) %{_bindir}/mysql_zap
 %attr(755, root, root) %{_bindir}/mysqlbug
 %attr(755, root, root) %{_bindir}/mysqld_multi
@@ -1112,10 +1129,35 @@ echo "====="                            
 # merging BK trees)
 ##############################################################################
 %changelog
+* Wed Sep 28 2011 Joerg Bruehe <joerg.bruehe@stripped>
+
+- Fix duplicate mentioning of "mysql_plugin" and its manual page,
+  it is better to keep alphabetic order in the files list (merging!).
+
+* Tue Sep 13 2011 Jonathan Perkin <jonathan.perkin@stripped>
+
+- Add support for Oracle Linux 6 and Red Hat Enterprise Linux 6.  Due to
+  changes in RPM behaviour ($RPM_BUILD_ROOT is removed prior to install)
+  this necessitated a move of the libmygcc.a installation to the install
+  phase, which is probably where it belonged in the first place.
+
+* Tue Sep 13 2011 Joerg Bruehe <joerg.bruehe@oracle.com>
+
+- "make_win_bin_dist" and its manual are dropped, cmake does it different.
+
 * Thu Sep 08 2011 Daniel Fischer <daniel.fischer@stripped>
 
 - Add mysql_plugin man page.
 
+* Tue Aug 30 2011 Joerg Bruehe <joerg.bruehe@oracle.com>
+
+- Add the manual page for "mysql_plugin" to the server package.
+
+* Fri Aug 19 2011 Joerg Bruehe <joerg.bruehe@stripped>
+
+- Null-upmerge the fix of bug#37165: This spec file is not affected.
+- Replace "/var/lib/mysql" by the spec file variable "%{mysqldatadir}".
+
 * Fri Aug 12 2011 Daniel Fischer <daniel.fischer@oracle.com>
 
 - Source plugin library files list from cmake-generated file.

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5 branch (magnus.blaudd:3242 to 3244) magnus.blaudd21 Nov