List:Commits« Previous MessageNext Message »
From:Mayank Prasad Date:December 26 2011 7:43am
Subject:bzr push into mysql-trunk-wl5767 branch (mayank.prasad:3406 to 3407) WL#5767
View as plain text  
 3407 Mayank Prasad	2011-12-26 [merge]
      WL#5767 : 
      
      Details:
       - Merge from latest mysql-trunk.

    added:
      mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_1.inc
      mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_2.inc
      mysql-test/t/mysql_embedded-master.opt
      storage/innobase/buf/buf0dblwr.cc
      storage/innobase/include/buf0dblwr.h
    renamed:
      mysql-test/r/mysqlbinlog2.result => mysql-test/r/mysqlbinlog_start_stop.result
      mysql-test/suite/rpl/r/rpl_mts_check_concurrency.result => mysql-test/suite/rpl/r/rpl_mts_debug.result
      mysql-test/suite/rpl/t/rpl_mts_check_concurrency-slave.opt => mysql-test/suite/rpl/t/rpl_mts_debug-slave.opt
      mysql-test/suite/rpl/t/rpl_mts_check_concurrency.test => mysql-test/suite/rpl/t/rpl_mts_debug.test
      mysql-test/t/mysqlbinlog2.test => mysql-test/t/mysqlbinlog_start_stop.test
    modified:
      client/mysql_upgrade.c
      client/mysqldump.c
      libmysqld/lib_sql.cc
      mysql-test/include/order_by.inc
      mysql-test/mysql-test-run.pl
      mysql-test/r/func_group.result
      mysql-test/r/mysqldump.result
      mysql-test/r/order_by_all.result
      mysql-test/r/order_by_icp_mrr.result
      mysql-test/r/order_by_none.result
      mysql-test/r/partition_list.result
      mysql-test/r/partition_mgm.result
      mysql-test/r/ps_ddl.result
      mysql-test/r/sp.result
      mysql-test/r/type_temporal_fractional.result
      mysql-test/r/xa.result
      mysql-test/suite/innodb/r/innodb_buffer_pool_load.result
      mysql-test/suite/innodb/t/innodb_buffer_pool_load.test
      mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result
      mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test
      mysql-test/suite/sys_vars/r/innodb_buffer_pool_filename_basic.result
      mysql-test/suite/sys_vars/r/innodb_buffer_pool_load_now_basic.result
      mysql-test/suite/sys_vars/r/slave_checkpoint_group_basic.result
      mysql-test/suite/sys_vars/r/slave_checkpoint_period_basic.result
      mysql-test/suite/sys_vars/r/slave_parallel_workers_basic.result
      mysql-test/suite/sys_vars/r/slave_pending_jobs_size_max_basic.result
      mysql-test/suite/sys_vars/t/innodb_adaptive_max_sleep_delay_basic.test
      mysql-test/suite/sys_vars/t/innodb_buffer_pool_dump_now_basic.test
      mysql-test/suite/sys_vars/t/innodb_buffer_pool_filename_basic.test
      mysql-test/suite/sys_vars/t/innodb_buffer_pool_load_now_basic.test
      mysql-test/suite/sys_vars/t/slave_checkpoint_group_basic.test
      mysql-test/suite/sys_vars/t/slave_checkpoint_period_basic.test
      mysql-test/suite/sys_vars/t/slave_parallel_workers_basic.test
      mysql-test/suite/sys_vars/t/slave_pending_jobs_size_max_basic.test
      mysql-test/t/func_group.test
      mysql-test/t/mysqldump.test
      mysql-test/t/partition_list.test
      mysql-test/t/partition_mgm.test
      mysql-test/t/ps_ddl.test
      mysql-test/t/sp.test
      mysql-test/t/type_temporal_fractional.test
      mysql-test/t/xa.test
      sql/field.h
      sql/ha_partition.cc
      sql/item.h
      sql/item_func.cc
      sql/item_sum.cc
      sql/item_sum.h
      sql/item_timefunc.h
      sql/mysqld.cc
      sql/mysqld.h
      sql/opt_sum.cc
      sql/partition_element.h
      sql/partition_info.cc
      sql/partition_info.h
      sql/rpl_info_factory.cc
      sql/rpl_rli.cc
      sql/rpl_rli.h
      sql/rpl_rli_pdb.cc
      sql/rpl_slave.cc
      sql/rpl_slave.h
      sql/sql_admin.cc
      sql/sql_base.cc
      sql/sql_executor.cc
      sql/sql_partition.cc
      sql/sql_partition.h
      sql/sql_select.cc
      sql/sql_view.cc
      sql/sql_yacc.yy
      sql/sys_vars.cc
      sql/table.h
      sql/unireg.h
      storage/federated/ha_federated.cc
      storage/innobase/CMakeLists.txt
      storage/innobase/buf/buf0buf.cc
      storage/innobase/buf/buf0flu.cc
      storage/innobase/buf/buf0lru.cc
      storage/innobase/buf/buf0rea.cc
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/ibuf/ibuf0ibuf.cc
      storage/innobase/include/buf0types.h
      storage/innobase/include/mtr0log.ic
      storage/innobase/include/os0file.h
      storage/innobase/include/sync0sync.h
      storage/innobase/include/trx0sys.h
      storage/innobase/include/trx0types.h
      storage/innobase/include/ut0rnd.ic
      storage/innobase/log/log0recv.cc
      storage/innobase/os/os0file.cc
      storage/innobase/row/row0sel.cc
      storage/innobase/srv/srv0start.cc
      storage/innobase/trx/trx0sys.cc
      mysql-test/r/mysqlbinlog_start_stop.result
      mysql-test/suite/rpl/r/rpl_mts_debug.result
      mysql-test/suite/rpl/t/rpl_mts_debug.test
      mysql-test/t/mysqlbinlog_start_stop.test
 3406 Mayank Prasad	2011-12-21
      WL#5767 : Performance Schema, Statement Digest
      
      Details:
       - Fixed failing test cases on pb2

    modified:
      mysql-test/r/mysqld--help-notwin.result
      mysql-test/r/mysqld--help-win.result
=== modified file 'client/mysql_upgrade.c'
--- a/client/mysql_upgrade.c	2011-11-15 12:34:23 +0000
+++ b/client/mysql_upgrade.c	2011-12-21 19:46:44 +0000
@@ -243,7 +243,6 @@ get_one_option(int optid, const struct m
   switch (optid) {
 
   case '?':
-    puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2011"));
     printf("%s  Ver %s Distrib %s, for %s (%s)\n",
            my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
     puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010"));

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2011-10-28 12:45:35 +0000
+++ b/client/mysqldump.c	2011-12-24 09:43:56 +0000
@@ -569,6 +569,8 @@ static void verbose_msg(const char *fmt,
   vfprintf(stderr, fmt, args);
   va_end(args);
 
+  fflush(stderr);
+
   DBUG_VOID_RETURN;
 }
 
@@ -4098,6 +4100,8 @@ static int dump_all_tables_in_db(char *d
     if (mysql_refresh(mysql, REFRESH_LOG))
       DB_error(mysql, "when doing refresh");
            /* We shall continue here, if --force was given */
+    else
+      verbose_msg("-- dump_all_tables_in_db : logs flushed successfully!\n");
   }
   while ((table= getTableName(0)))
   {
@@ -4198,6 +4202,8 @@ static my_bool dump_all_views_in_db(char
     if (mysql_refresh(mysql, REFRESH_LOG))
       DB_error(mysql, "when doing refresh");
            /* We shall continue here, if --force was given */
+    else
+      verbose_msg("-- dump_all_views_in_db : logs flushed successfully!\n");
   }
   while ((table= getTableName(0)))
   {
@@ -4336,6 +4342,8 @@ static int dump_selected_tables(char *db
       DB_error(mysql, "when doing refresh");
     }
      /* We shall countinue here, if --force was given */
+    else
+      verbose_msg("-- dump_selected_tables : logs flushed successfully!\n");
   }
   if (opt_xml)
     print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
@@ -4619,6 +4627,7 @@ static int purge_bin_logs_to(MYSQL *mysq
 
 static int start_transaction(MYSQL *mysql_con)
 {
+  verbose_msg("-- Starting transaction...\n");
   /*
     We use BEGIN for old servers. --single-transaction --master-data will fail
     on old servers, but that's ok as it was already silently broken (it didn't
@@ -5218,24 +5227,39 @@ int main(int argc, char **argv)
   if (opt_slave_data && do_stop_slave_sql(mysql))
     goto err;
 
-  if ((opt_lock_all_tables || opt_master_data) &&
+  if ((opt_lock_all_tables || opt_master_data ||
+       (opt_single_transaction && flush_logs)) &&
       do_flush_tables_read_lock(mysql))
     goto err;
-  if (opt_single_transaction && start_transaction(mysql))
-      goto err;
-  if (opt_delete_master_logs)
+
+  /*
+    Flush logs before starting transaction since
+    this causes implicit commit starting mysql-5.5.
+  */
+  if (opt_lock_all_tables || opt_master_data ||
+      (opt_single_transaction && flush_logs) ||
+      opt_delete_master_logs)
   {
-    if (mysql_refresh(mysql, REFRESH_LOG) ||
-        get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name)))
-      goto err;
+    if (flush_logs || opt_delete_master_logs)
+    {
+      if (mysql_refresh(mysql, REFRESH_LOG))
+        goto err;
+      verbose_msg("-- main : logs flushed successfully!\n");
+    }
+
+    /* Not anymore! That would not be sensible. */
     flush_logs= 0;
   }
-  if (opt_lock_all_tables || opt_master_data)
+
+  if (opt_delete_master_logs)
   {
-    if (flush_logs && mysql_refresh(mysql, REFRESH_LOG))
+    if (get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name)))
       goto err;
-    flush_logs= 0; /* not anymore; that would not be sensible */
   }
+
+  if (opt_single_transaction && start_transaction(mysql))
+    goto err;
+
   /* Add 'STOP SLAVE to beginning of dump */
   if (opt_slave_apply && add_stop_slave())
     goto err;

=== modified file 'libmysqld/lib_sql.cc'
--- a/libmysqld/lib_sql.cc	2011-10-13 07:26:28 +0000
+++ b/libmysqld/lib_sql.cc	2011-12-23 08:55:18 +0000
@@ -500,11 +500,14 @@ int init_embedded_server(int argc, char
     This mess is to allow people to call the init function without
     having to mess with a fake argv
    */
-  int *argcp;
-  char ***argvp;
-  int fake_argc = 1;
-  char *fake_argv[] = { (char *)"", 0 };
-  const char *fake_groups[] = { "server", "embedded", 0 };
+  int *argcp= NULL;
+  char ***argvp= NULL;
+  int fake_argc= 1;
+  char *fake_argv[2];
+  char fake_server[]= "server";
+  char fake_embedded[]= "embedded";
+  char *fake_groups[]= { fake_server, fake_embedded, NULL };
+  char fake_name[]= "fake_name";
   my_bool acl_error;
 
   if (my_thread_init())
@@ -513,17 +516,21 @@ int init_embedded_server(int argc, char
   if (argc)
   {
     argcp= &argc;
-    argvp= (char***) &argv;
+    argvp= &argv;
   }
   else
   {
+    fake_argv[0]= fake_name;
+    fake_argv[1]= NULL;
+
+    char **foo= &fake_argv[0];
     argcp= &fake_argc;
-    argvp= (char ***) &fake_argv;
+    argvp= &foo;
   }
   if (!groups)
-    groups= (char**) fake_groups;
+    groups= fake_groups;
 
-  my_progname= (char *)"mysql_embedded";
+  my_progname= "mysql_embedded";
 
   /*
     Perform basic logger initialization logger. Should be called after

=== added file 'mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_1.inc'
--- a/mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_1.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_1.inc	2011-12-20 16:06:32 +0000
@@ -0,0 +1,52 @@
+# ==== Purpose ====
+#
+# Auxiliary file used by main.mysqlbinlog-start-stop.
+#
+# This file runs mysqlbinlog with a fixed set of parameters specifying
+# the source binlog, but varying how the start and stop positions are
+# specified.
+#
+# ==== Usage ====
+#
+# --let $start_position= <binlog offset>
+# --let $stop_position= <binlog offset>
+# --let $start_datetime= <timestamp>
+# --let $stop_datetime= <timestamp>
+# --let $extra_options= <options to mysqlbinlog>
+# --source extra/binlog_tests/mysqlbinlog_start_stop_1.inc
+#
+# Parameters:
+#   $start_position
+#     Offset to pass to --start-position
+#   $stop_position
+#     Offset to pass to --stop-position
+#   $start_datetime
+#     Offset to pass to --start-datetime
+#   $stop_datetime
+#     Offset to pass to --stop-datetime
+#   $extra_options
+#     Options for mysqlbinlog, specifying which input file to read.
+
+--let $option= --base64-output=never
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--let $option= --offset=2
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--let $option= --start-position=$start_position
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--let $option= --stop-position=$stop_position
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--let $option= --start-position=$start_position --stop-position=$stop_position
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--let $option= "--start-datetime=$start_datetime"
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--let $option= "--stop-datetime=$stop_datetime"
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--let $option= "--start-datetime=$start_datetime" "--stop-datetime=$stop_datetime"
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc

=== added file 'mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_2.inc'
--- a/mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_2.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/extra/binlog_tests/mysqlbinlog_start_stop_2.inc	2011-12-20 16:06:32 +0000
@@ -0,0 +1,33 @@
+# ==== Purpose ====
+#
+# Auxiliary file used by include/mysqlbinlog_start_stop_1.inc
+#
+# This prints a header, then runs mysqlbinlog once with given parameters.
+#
+# ==== Usage ====
+#
+# --let $extra_options= X
+# --let $options= Y
+# --source include/mysqlbinlog-start-stop-2.inc
+#
+# Parameters:
+#
+#   $extra_options
+#     Options that will be passed to mysqlbinlog but not printed to the test log
+#
+#   $options
+#     Options that will be printed as a header in the test log.
+
+
+# Pretty-print $option_text
+--let $option_text= `SELECT SUBSTR(REPLACE('$option', '"', ''), 3)`
+while (`SELECT LOCATE('=', '$option_text')`)
+{
+  --let $dash_pos= `SELECT LOCATE('--', '$option_text')`
+  --let $option_text= `SELECT CONCAT(SUBSTR('$option_text', 1, LOCATE('=', '$option_text') - 1), IF($dash_pos, CONCAT(' ', SUBSTR('$option_text', $dash_pos + 2)), ''))`
+}
+--echo
+--echo ---- $option_text ----
+
+# Print output
+--exec $MYSQL_BINLOG --short-form $option $extra_options

=== modified file 'mysql-test/include/order_by.inc'
--- a/mysql-test/include/order_by.inc	2011-10-12 13:30:13 +0000
+++ b/mysql-test/include/order_by.inc	2011-12-19 09:22:28 +0000
@@ -1738,3 +1738,15 @@ SELECT t1.*, t2.* FROM t1 JOIN t2 ON t1.
   ORDER BY t1.i1 LIMIT 5;
 
 DROP TABLE t1, t2, t3;
+
+--echo #
+--echo # Bug #11885377 VOID JOIN_READ_KEY_UNLOCK_ROW(ST_JOIN_TABLE*): ASSERTION
+--echo # `TAB->REF.USE_COUNT'
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY);
+CREATE TABLE t2(b INT,c INT);
+INSERT INTO t1 VALUES (1), (2);
+INSERT INTO t2 VALUES (1,2), (2,3);
+SELECT (SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC) FROM t2;
+DROP TABLE t1, t2;

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2011-12-05 12:01:10 +0000
+++ b/mysql-test/mysql-test-run.pl	2011-12-23 08:55:18 +0000
@@ -2013,8 +2013,9 @@ sub executable_setup () {
   $exe_mysql=          mtr_exe_exists("$path_client_bindir/mysql");
   $exe_mysql_plugin=   mtr_exe_exists("$path_client_bindir/mysql_plugin");
 
-  $exe_mysql_embedded= mtr_exe_maybe_exists("$basedir/libmysqld/examples/mysql_embedded",
-                                            "$bindir/bin/mysql_embedded");
+  $exe_mysql_embedded=
+    mtr_exe_maybe_exists("$bindir/libmysqld/examples/mysql_embedded",
+                         "$bindir/bin/mysql_embedded");
 
   if ( ! $opt_skip_ndbcluster )
   {

=== modified file 'mysql-test/r/func_group.result'
--- a/mysql-test/r/func_group.result	2011-08-03 11:29:20 +0000
+++ b/mysql-test/r/func_group.result	2011-12-22 13:36:08 +0000
@@ -1804,3 +1804,12 @@ AVG(DISTINCT outr.col_int_nokey)
 7.5000
 DROP TABLE t1;
 # End of the bug#57932
+#
+# BUG#12773464 - 61925: WRONG RESULT WITH AGGREGATE + NOT BETWEEN + KEY
+#
+CREATE TABLE t1 (a int, KEY (a));
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
+SELECT MAX(a) FROM t1 WHERE a NOT BETWEEN 3 AND 9;
+MAX(a)
+10
+DROP TABLE t1;

=== renamed file 'mysql-test/r/mysqlbinlog2.result' => 'mysql-test/r/mysqlbinlog_start_stop.result'
--- a/mysql-test/r/mysqlbinlog2.result	2011-12-14 05:03:54 +0000
+++ b/mysql-test/r/mysqlbinlog_start_stop.result	2011-12-20 16:06:32 +0000
@@ -1,26 +1,26 @@
-drop table if exists t1;
-reset master;
-set @a=UNIX_TIMESTAMP("2020-01-21 15:32:22");
-set timestamp=@a;
-create table t1 (a int auto_increment not null primary key, b char(3));
-insert into t1 values(null, "a");
-insert into t1 values(null, "b");
-set timestamp=@a+2;
-insert into t1 values(null, "c");
-set timestamp=@a+4;
-insert into t1 values(null, "d");
-insert into t1 values(null, "e");
-flush logs;
-set timestamp=@a+1;
-insert into t1 values(null, "f");
+CREATE TABLE t1 (a INT);
+RESET MASTER;
+SET TIMESTAMP= UNIX_TIMESTAMP("2031-01-01 12:00:00");
+INSERT INTO t1 VALUES(1);
+SET TIMESTAMP= UNIX_TIMESTAMP("2032-01-01 12:00:00");
+INSERT INTO t1 VALUES(2);
+SET TIMESTAMP= UNIX_TIMESTAMP("2033-01-01 12:00:00");
+INSERT INTO t1 VALUES(3);
+FLUSH LOGS;
+SET TIMESTAMP= UNIX_TIMESTAMP("2034-01-01 12:00:00");
+INSERT INTO t1 VALUES(4);
+SET TIMESTAMP= UNIX_TIMESTAMP("2035-01-01 12:00:00");
+INSERT INTO t1 VALUES(5);
+FLUSH LOGS;
 
---- Local --
+==== Local ====
+
+---- base64-output ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -29,56 +29,74 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+COMMIT
+/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- offset ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+ROLLBACK/*!*/;
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -86,12 +104,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- offset --
+---- start-position ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -102,52 +120,85 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- stop-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- start-position stop-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+use test/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -155,12 +206,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-position --
+---- start-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -171,32 +222,29 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -204,13 +252,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- stop-position --
+---- stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -219,26 +266,13 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -246,12 +280,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start and stop positions ---
+---- start-datetime stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -262,22 +296,26 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
+/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+COMMIT
 /*!*/;
 DELIMITER ;
 # End of log file
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-datetime --
+==== Local with 2 binlogs on command line ====
+
+---- base64-output ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -288,46 +326,34 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
-# End of log file
-ROLLBACK /* added by mysqlbinlog */;
-/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
-
---- stop-datetime --
-/*!40019 SET @@session.max_insert_delayed_threads=0*/;
-/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -336,26 +362,22 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -363,14 +385,13 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- Local with 2 binlogs on command line --
-flush logs;
+---- offset ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -379,61 +400,98 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
+INSERT INTO t1 VALUES(1)
+/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+COMMIT
+/*!*/;
+DELIMITER ;
+DELIMITER /*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- start-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+use test/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -444,12 +502,20 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
+/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+COMMIT
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -457,12 +523,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- offset --
+---- stop-position ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -473,57 +539,91 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+DELIMITER ;
+DELIMITER /*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- start-position stop-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+use test/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -534,12 +634,11 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -547,12 +646,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-position --
+---- start-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -563,37 +662,34 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -604,12 +700,20 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -617,13 +721,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- stop-position --
+---- stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -632,61 +735,36 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -697,17 +775,24 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
+/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+COMMIT
+/*!*/;
 DELIMITER ;
 # End of log file
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-datetime --
+---- start-datetime stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -718,37 +803,34 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -759,12 +841,11 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -772,13 +853,14 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- stop-datetime --
+==== Remote ====
+
+---- base64-output ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -787,26 +869,31 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
+BEGIN
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
+/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -814,13 +901,13 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- Remote --
+---- offset ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -829,56 +916,63 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- start-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+use test/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -886,12 +980,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- offset --
+---- stop-position ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -902,52 +996,47 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
-/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- start-position stop-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+use test/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -955,11 +1044,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-position --
+---- start-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -970,32 +1060,29 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1003,13 +1090,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- stop-position --
+---- stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1018,26 +1104,13 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1045,11 +1118,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start and stop positions ---
+---- start-datetime stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1060,22 +1134,26 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
+/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+COMMIT
 /*!*/;
 DELIMITER ;
 # End of log file
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-datetime --
+==== Remote with 2 binlogs on command line ====
+
+---- base64-output ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1086,46 +1164,34 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
-# End of log file
-ROLLBACK /* added by mysqlbinlog */;
-/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
-
---- stop-datetime --
-/*!40019 SET @@session.max_insert_delayed_threads=0*/;
-/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1134,26 +1200,22 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1161,13 +1223,13 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- Remote with 2 binlogs on command line --
+---- offset ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1176,61 +1238,68 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+DELIMITER ;
+DELIMITER /*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- start-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1241,25 +1310,25 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
+/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
-# End of log file
-ROLLBACK /* added by mysqlbinlog */;
-/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
-
---- offset --
-/*!40019 SET @@session.max_insert_delayed_threads=0*/;
-/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-ROLLBACK/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1270,57 +1339,71 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+DELIMITER ;
+# End of log file
+ROLLBACK /* added by mysqlbinlog */;
+/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
+
+---- stop-position ----
+/*!40019 SET @@session.max_insert_delayed_threads=0*/;
+/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
+DELIMITER /*!*/;
+ROLLBACK/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1331,12 +1414,11 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1344,11 +1426,11 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-position --
+---- start-position stop-position ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1359,37 +1441,25 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
-/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-BEGIN
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
-/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1400,12 +1470,11 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1413,13 +1482,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- stop-position --
+---- start-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1428,61 +1496,36 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1493,17 +1536,33 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
+/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
+BEGIN
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
+/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
+COMMIT
+/*!*/;
 DELIMITER ;
 # End of log file
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- start-datetime --
+---- stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1514,37 +1573,34 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
 DELIMITER /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1555,12 +1611,11 @@ SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
 use test/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1568,13 +1623,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- stop-datetime --
+---- start-datetime stop-datetime ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1583,26 +1637,51 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
+BEGIN
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
+/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+COMMIT
+/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
+COMMIT
+/*!*/;
+DELIMITER ;
+DELIMITER /*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+SET @@session.pseudo_thread_id=999999999/*!*/;
+SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
+SET @@session.sql_mode=0/*!*/;
+SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
+/*!\C latin1 *//*!*/;
+SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
+SET @@session.lc_time_names=0/*!*/;
+SET @@session.collation_database=DEFAULT/*!*/;
+BEGIN
+/*!*/;
+use test/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
+/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1610,13 +1689,12 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- to-last-log --
+---- to-last-log ----
 /*!40019 SET @@session.max_insert_delayed_threads=0*/;
 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
 DELIMITER /*!*/;
 ROLLBACK/*!*/;
-use test/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 SET @@session.pseudo_thread_id=999999999/*!*/;
 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
 SET @@session.sql_mode=0/*!*/;
@@ -1625,66 +1703,49 @@ SET @@session.auto_increment_increment=1
 SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
 SET @@session.lc_time_names=0/*!*/;
 SET @@session.collation_database=DEFAULT/*!*/;
-create table t1 (a int auto_increment not null primary key, b char(3))
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=1/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "a")
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-COMMIT
-/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-BEGIN
-/*!*/;
-SET INSERT_ID=2/*!*/;
-SET TIMESTAMP=1579609942/*!*/;
-insert into t1 values(null, "b")
+use test/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
+INSERT INTO t1 VALUES(1)
 /*!*/;
-SET TIMESTAMP=1579609942/*!*/;
+SET TIMESTAMP=1925024400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=3/*!*/;
-SET TIMESTAMP=1579609944/*!*/;
-insert into t1 values(null, "c")
+SET TIMESTAMP=1956560400/*!*/;
+INSERT INTO t1 VALUES(2)
 /*!*/;
-SET TIMESTAMP=1579609944/*!*/;
+SET TIMESTAMP=1956560400/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=4/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "d")
+SET TIMESTAMP=1988182800/*!*/;
+INSERT INTO t1 VALUES(3)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=1988182800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=5/*!*/;
-SET TIMESTAMP=1579609946/*!*/;
-insert into t1 values(null, "e")
+SET TIMESTAMP=2019718800/*!*/;
+INSERT INTO t1 VALUES(4)
 /*!*/;
-SET TIMESTAMP=1579609946/*!*/;
+SET TIMESTAMP=2019718800/*!*/;
 COMMIT
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 BEGIN
 /*!*/;
-SET INSERT_ID=6/*!*/;
-SET TIMESTAMP=1579609943/*!*/;
-insert into t1 values(null, "f")
+SET TIMESTAMP=2051254800/*!*/;
+INSERT INTO t1 VALUES(5)
 /*!*/;
-SET TIMESTAMP=1579609943/*!*/;
+SET TIMESTAMP=2051254800/*!*/;
 COMMIT
 /*!*/;
 DELIMITER ;
@@ -1692,5 +1753,5 @@ DELIMITER ;
 ROLLBACK /* added by mysqlbinlog */;
 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
 
---- end of test --
-drop table t1;
+==== clean up ====
+DROP TABLE t1;

=== modified file 'mysql-test/r/mysqldump.result'
--- a/mysql-test/r/mysqldump.result	2011-05-10 13:37:37 +0000
+++ b/mysql-test/r/mysqldump.result	2011-12-24 09:43:56 +0000
@@ -4718,3 +4718,107 @@ UNLOCK TABLES;
 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 
 DROP TABLE t1;
+#
+# Bug#12809202 61854: MYSQLDUMP --SINGLE-TRANSACTION --FLUSH-LOG BREAKS
+#                     CONSISTENCY
+#
+DROP DATABASE IF EXISTS b12809202_db;
+CREATE DATABASE b12809202_db;
+CREATE TABLE b12809202_db.t1 (c1 INT);
+CREATE TABLE b12809202_db.t2 (c1 INT);
+INSERT INTO b12809202_db.t1 VALUES (1), (2), (3);
+INSERT INTO b12809202_db.t2 VALUES (1), (2), (3);
+# Starting mysqldump with --single-transaction & --flush-log options..
+# Note : In the following dump the transaction
+#        should start only after the logs are
+#        flushed, as 'flush logs' causes implicit
+#        commit starting 5.5.
+
+#### Dump starts here ####
+-- Connecting to localhost...
+-- main : logs flushed successfully!
+-- Starting transaction...
+-- Retrieving table structure for table t1...
+-- Sending SELECT query...
+-- Retrieving rows...
+--
+-- Host: localhost    Database: b12809202_db
+-- ------------------------------------------------------
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `t1`
+--
+
+DROP TABLE IF EXISTS `t1`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `t1` (
+  `c1` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `t1`
+--
+
+LOCK TABLES `t1` WRITE;
+/*!40000 ALTER TABLE `t1` DISABLE KEYS */;
+INSERT INTO `t1` VALUES (1),(2),(3);
+-- Retrieving table structure for table t2...
+-- Sending SELECT query...
+-- Retrieving rows...
+/*!40000 ALTER TABLE `t1` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `t2`
+--
+
+DROP TABLE IF EXISTS `t2`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `t2` (
+  `c1` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `t2`
+--
+
+LOCK TABLES `t2` WRITE;
+/*!40000 ALTER TABLE `t2` DISABLE KEYS */;
+INSERT INTO `t2` VALUES (1),(2),(3);
+/*!40000 ALTER TABLE `t2` ENABLE KEYS */;
+UNLOCK TABLES;
+-- Disconnecting from localhost...
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed
+#### Dump ends here ####
+DROP TABLE b12809202_db.t1;
+DROP TABLE b12809202_db.t2;
+DROP DATABASE b12809202_db;
+#
+# Delete all existing binary logs.
+#
+RESET MASTER;

=== modified file 'mysql-test/r/order_by_all.result'
--- a/mysql-test/r/order_by_all.result	2011-10-12 13:30:13 +0000
+++ b/mysql-test/r/order_by_all.result	2011-12-19 09:22:28 +0000
@@ -2587,4 +2587,17 @@ i1	i2
 4	4
 5	5
 DROP TABLE t1, t2, t3;
+#
+# Bug #11885377 VOID JOIN_READ_KEY_UNLOCK_ROW(ST_JOIN_TABLE*): ASSERTION
+# `TAB->REF.USE_COUNT'
+#
+CREATE TABLE t1(a INT PRIMARY KEY);
+CREATE TABLE t2(b INT,c INT);
+INSERT INTO t1 VALUES (1), (2);
+INSERT INTO t2 VALUES (1,2), (2,3);
+SELECT (SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC) FROM t2;
+(SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC)
+NULL
+NULL
+DROP TABLE t1, t2;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/order_by_icp_mrr.result'
--- a/mysql-test/r/order_by_icp_mrr.result	2011-10-12 13:30:13 +0000
+++ b/mysql-test/r/order_by_icp_mrr.result	2011-12-19 09:22:28 +0000
@@ -2587,4 +2587,17 @@ i1	i2
 4	4
 5	5
 DROP TABLE t1, t2, t3;
+#
+# Bug #11885377 VOID JOIN_READ_KEY_UNLOCK_ROW(ST_JOIN_TABLE*): ASSERTION
+# `TAB->REF.USE_COUNT'
+#
+CREATE TABLE t1(a INT PRIMARY KEY);
+CREATE TABLE t2(b INT,c INT);
+INSERT INTO t1 VALUES (1), (2);
+INSERT INTO t2 VALUES (1,2), (2,3);
+SELECT (SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC) FROM t2;
+(SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC)
+NULL
+NULL
+DROP TABLE t1, t2;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/order_by_none.result'
--- a/mysql-test/r/order_by_none.result	2011-10-12 13:30:13 +0000
+++ b/mysql-test/r/order_by_none.result	2011-12-19 09:22:28 +0000
@@ -2586,4 +2586,17 @@ i1	i2
 4	4
 5	5
 DROP TABLE t1, t2, t3;
+#
+# Bug #11885377 VOID JOIN_READ_KEY_UNLOCK_ROW(ST_JOIN_TABLE*): ASSERTION
+# `TAB->REF.USE_COUNT'
+#
+CREATE TABLE t1(a INT PRIMARY KEY);
+CREATE TABLE t2(b INT,c INT);
+INSERT INTO t1 VALUES (1), (2);
+INSERT INTO t2 VALUES (1,2), (2,3);
+SELECT (SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC) FROM t2;
+(SELECT 1 FROM t1 WHERE a=b AND c=1 ORDER BY a DESC)
+NULL
+NULL
+DROP TABLE t1, t2;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/partition_list.result'
--- a/mysql-test/r/partition_list.result	2009-10-21 18:04:34 +0000
+++ b/mysql-test/r/partition_list.result	2011-10-12 11:33:18 +0000
@@ -1,4 +1,136 @@
 drop table if exists t1;
+#
+# Bug#62505: ALTER TABLE ADD PARTITION fails for LIST partitions with
+#            more than 16 items
+#
+CREATE TABLE t1 (a INT);
+# SUCCESS with 20 items because this is initial partitioning action
+# (The parser already knows that it is only on column)
+ALTER TABLE t1
+PARTITION BY LIST(a)
+(PARTITION p1 VALUES IN (1,2,3,4,5,6,7,8,9,10,
+11,12,13,14,15,16,17,18,19,20));
+# BUG: FAILED, because number of items > 16 during partition add
+# (The parser do not know how many columns the table is partitioned on)
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2 VALUES IN (21,22,23,24,25,26,27,28,29,30,
+31,32,33,34,35,36,37,38,39,40));
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p1 VALUES IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) ENGINE = MyISAM,
+ PARTITION p2 VALUES IN (21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40) ENGINE = MyISAM) */
+# Test with single column LIST COLUMNS too
+ALTER TABLE t1
+PARTITION BY LIST COLUMNS (a)
+(PARTITION p1 VALUES IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20));
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2 VALUES IN ((71),(72),(73),(74),(75),(76),(77),(78),(79),(80),
+(81),(82),(83),(84),(85),(86),(87),(88),(89),(90)));
+ERROR 42000: Row expressions in VALUES IN only allowed for multi-field column partitioning near '))' at line 3
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2 VALUES IN (21,22,23,24,25,26,27,28,29,30,
+31,32,33,34,35,36,37,38,39,40));
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50500 PARTITION BY LIST  COLUMNS(a)
+(PARTITION p1 VALUES IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) ENGINE = MyISAM,
+ PARTITION p2 VALUES IN (21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40) ENGINE = MyISAM) */
+DROP TABLE t1;
+# Test with two columns in LIST COLUMNS partitioning
+CREATE TABLE t1
+(a INT,
+b CHAR(2))
+PARTITION BY LIST COLUMNS (a, b)
+(PARTITION p0_a VALUES IN
+((0, "a0"), (0, "a1"), (0, "a2"), (0, "a3"), (0, "a4"), (0, "a5"), (0, "a6"),
+(0, "a7"), (0, "a8"), (0, "a9"), (0, "aa"), (0, "ab"), (0, "ac"), (0, "ad"),
+(0, "ae"), (0, "af"), (0, "ag"), (0, "ah"), (0, "ai"), (0, "aj"), (0, "ak"),
+(0, "al")));
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p1_a VALUES IN
+((1, "a0"), (1, "a1"), (1, "a2"), (1, "a3"), (1, "a4"), (1, "a5"), (1, "a6"),
+(1, "a7"), (1, "a8"), (1, "a9"), (1, "aa"), (1, "ab"), (1, "ac"), (1, "ad"),
+(1, "ae"), (1, "af"), (1, "ag"), (1, "ah"), (1, "ai"), (1, "aj"), (1, "ak"),
+(1, "al")));
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` char(2) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50500 PARTITION BY LIST  COLUMNS(a,b)
+(PARTITION p0_a VALUES IN ((0,'a0'),(0,'a1'),(0,'a2'),(0,'a3'),(0,'a4'),(0,'a5'),(0,'a6'),(0,'a7'),(0,'a8'),(0,'a9'),(0,'aa'),(0,'ab'),(0,'ac'),(0,'ad'),(0,'ae'),(0,'af'),(0,'ag'),(0,'ah'),(0,'ai'),(0,'aj'),(0,'ak'),(0,'al')) ENGINE = MyISAM,
+ PARTITION p1_a VALUES IN ((1,'a0'),(1,'a1'),(1,'a2'),(1,'a3'),(1,'a4'),(1,'a5'),(1,'a6'),(1,'a7'),(1,'a8'),(1,'a9'),(1,'aa'),(1,'ab'),(1,'ac'),(1,'ad'),(1,'ae'),(1,'af'),(1,'ag'),(1,'ah'),(1,'ai'),(1,'aj'),(1,'ak'),(1,'al')) ENGINE = MyISAM) */
+# Test of the parser for '('
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2_a VALUES IN
+(((1 + 1), "a0"), (2, "a1"), (2, "a2"), (2, "a3"), (2, "a4"), (2, "a5"),
+(2, "a6"), (2, "a7"), (2, "a8"), (2, "a9"), (2, "aa"), (2, "ab"), (2, "ac"),
+(2, "ad"), (2, "ae"), (2, "af"), (2, "ag"), (2, "ah"), (2, "ai"), (2, "aj"),
+(2, "ak"), (2, "al")));
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` char(2) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50500 PARTITION BY LIST  COLUMNS(a,b)
+(PARTITION p0_a VALUES IN ((0,'a0'),(0,'a1'),(0,'a2'),(0,'a3'),(0,'a4'),(0,'a5'),(0,'a6'),(0,'a7'),(0,'a8'),(0,'a9'),(0,'aa'),(0,'ab'),(0,'ac'),(0,'ad'),(0,'ae'),(0,'af'),(0,'ag'),(0,'ah'),(0,'ai'),(0,'aj'),(0,'ak'),(0,'al')) ENGINE = MyISAM,
+ PARTITION p1_a VALUES IN ((1,'a0'),(1,'a1'),(1,'a2'),(1,'a3'),(1,'a4'),(1,'a5'),(1,'a6'),(1,'a7'),(1,'a8'),(1,'a9'),(1,'aa'),(1,'ab'),(1,'ac'),(1,'ad'),(1,'ae'),(1,'af'),(1,'ag'),(1,'ah'),(1,'ai'),(1,'aj'),(1,'ak'),(1,'al')) ENGINE = MyISAM,
+ PARTITION p2_a VALUES IN ((2,'a0'),(2,'a1'),(2,'a2'),(2,'a3'),(2,'a4'),(2,'a5'),(2,'a6'),(2,'a7'),(2,'a8'),(2,'a9'),(2,'aa'),(2,'ab'),(2,'ac'),(2,'ad'),(2,'ae'),(2,'af'),(2,'ag'),(2,'ah'),(2,'ai'),(2,'aj'),(2,'ak'),(2,'al')) ENGINE = MyISAM) */
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN ((1 + 1 + 1), "a0"));
+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 '"a0"))' at line 2
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN (1 + 1 + 1, "a0"));
+ERROR HY000: Inconsistency in usage of column lists for partitioning
+# Test with 3 columns when it only has 2.
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN ((3, "a1", 0), (3, "a2", 0)));
+ERROR HY000: Inconsistency in usage of column lists for partitioning
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN ((1 + 1 + 1, "a0")));
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` char(2) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50500 PARTITION BY LIST  COLUMNS(a,b)
+(PARTITION p0_a VALUES IN ((0,'a0'),(0,'a1'),(0,'a2'),(0,'a3'),(0,'a4'),(0,'a5'),(0,'a6'),(0,'a7'),(0,'a8'),(0,'a9'),(0,'aa'),(0,'ab'),(0,'ac'),(0,'ad'),(0,'ae'),(0,'af'),(0,'ag'),(0,'ah'),(0,'ai'),(0,'aj'),(0,'ak'),(0,'al')) ENGINE = MyISAM,
+ PARTITION p1_a VALUES IN ((1,'a0'),(1,'a1'),(1,'a2'),(1,'a3'),(1,'a4'),(1,'a5'),(1,'a6'),(1,'a7'),(1,'a8'),(1,'a9'),(1,'aa'),(1,'ab'),(1,'ac'),(1,'ad'),(1,'ae'),(1,'af'),(1,'ag'),(1,'ah'),(1,'ai'),(1,'aj'),(1,'ak'),(1,'al')) ENGINE = MyISAM,
+ PARTITION p2_a VALUES IN ((2,'a0'),(2,'a1'),(2,'a2'),(2,'a3'),(2,'a4'),(2,'a5'),(2,'a6'),(2,'a7'),(2,'a8'),(2,'a9'),(2,'aa'),(2,'ab'),(2,'ac'),(2,'ad'),(2,'ae'),(2,'af'),(2,'ag'),(2,'ah'),(2,'ai'),(2,'aj'),(2,'ak'),(2,'al')) ENGINE = MyISAM,
+ PARTITION p3_a VALUES IN ((3,'a0')) ENGINE = MyISAM) */
+# Test with more than 16 columns (cause of regression)
+ALTER TABLE t1 ADD PARTITION
+(PARTITION part_2 VALUES IN ((21 ,22, 23, 24, 25, 26, 27, 28, 29, 30,
+31 ,32, 33, 34, 35, 36, 37, 38, 39, 40),
+(41 ,42, 43, 44, 45, 46, 47, 48, 49, 50,
+51 ,52, 53, 54, 55, 56, 57, 58, 59, 60)));
+ERROR 42000: Row expressions in VALUES IN only allowed for multi-field column partitioning near '))' at line 5
+ALTER TABLE t1 ADD PARTITION
+(PARTITION part_2 VALUES IN (21 ,22, 23, 24, 25, 26, 27, 28, 29, 30,
+31 ,32, 33, 34, 35, 36, 37, 38, 39, 40));
+ERROR HY000: Inconsistency in usage of column lists for partitioning
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` char(2) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50500 PARTITION BY LIST  COLUMNS(a,b)
+(PARTITION p0_a VALUES IN ((0,'a0'),(0,'a1'),(0,'a2'),(0,'a3'),(0,'a4'),(0,'a5'),(0,'a6'),(0,'a7'),(0,'a8'),(0,'a9'),(0,'aa'),(0,'ab'),(0,'ac'),(0,'ad'),(0,'ae'),(0,'af'),(0,'ag'),(0,'ah'),(0,'ai'),(0,'aj'),(0,'ak'),(0,'al')) ENGINE = MyISAM,
+ PARTITION p1_a VALUES IN ((1,'a0'),(1,'a1'),(1,'a2'),(1,'a3'),(1,'a4'),(1,'a5'),(1,'a6'),(1,'a7'),(1,'a8'),(1,'a9'),(1,'aa'),(1,'ab'),(1,'ac'),(1,'ad'),(1,'ae'),(1,'af'),(1,'ag'),(1,'ah'),(1,'ai'),(1,'aj'),(1,'ak'),(1,'al')) ENGINE = MyISAM,
+ PARTITION p2_a VALUES IN ((2,'a0'),(2,'a1'),(2,'a2'),(2,'a3'),(2,'a4'),(2,'a5'),(2,'a6'),(2,'a7'),(2,'a8'),(2,'a9'),(2,'aa'),(2,'ab'),(2,'ac'),(2,'ad'),(2,'ae'),(2,'af'),(2,'ag'),(2,'ah'),(2,'ai'),(2,'aj'),(2,'ak'),(2,'al')) ENGINE = MyISAM,
+ PARTITION p3_a VALUES IN ((3,'a0')) ENGINE = MyISAM) */
+DROP TABLE t1;
 create table t1 (a int unsigned)
 partition by list (a)
 (partition p0 values in (0),

=== modified file 'mysql-test/r/partition_mgm.result'
--- a/mysql-test/r/partition_mgm.result	2011-10-14 12:28:58 +0000
+++ b/mysql-test/r/partition_mgm.result	2011-12-19 13:21:37 +0000
@@ -1,5 +1,16 @@
 DROP TABLE IF EXISTS t1;
 #
+# Bug#13357766: ASSERT IN HANDLER::HA_CREATE
+#
+CREATE TABLE t1
+(a INT)
+PARTITION BY KEY(a) PARTITIONS 3;
+ALTER TABLE t1 REPAIR PARTITION p2,p3,p1;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	error	Error in list of partitions to test.t1
+ALTER TABLE t1 ORDER BY a;
+DROP TABLE t1;
+#
 # Bug#11764110/bug#56909: REORGANIZE PARTITION is allowed on
 #                         HASH/KEY partitioned tables
 #

=== modified file 'mysql-test/r/ps_ddl.result'
--- a/mysql-test/r/ps_ddl.result	2011-04-01 18:08:48 +0000
+++ b/mysql-test/r/ps_ddl.result	2011-12-19 11:42:11 +0000
@@ -355,25 +355,24 @@ a
 drop view v1;
 create view v1 as select a from t2;
 set @var=8;
-# XXX: bug, the SQL statement in the trigger is still
-# pointing at table 't3', since the view was expanded
-# at first statement execution.
-# Since the view definition is inlined in the statement
-# at prepare, changing the view definition does not cause 
-# repreparation.
-# Repreparation of the main statement doesn't cause repreparation
+# View in the INSERT-statement in the trigger is still pointing to
+# table 't3', because the trigger hasn't noticed the change
+# in view definition. This will be fixed by WL#4179.
+#
+# The prepared INSERT-statement however does notice the change,
+# but repreparation of the main statement doesn't cause repreparation
 # of trigger statements.
+#
+# The following EXECUTE results in ER_NO_SUCH_TABLE (t3) error, because
+# pre-locking list of the prepared statement has been changed
+# (the prepared statement has noticed the meta-data change),
+# but the trigger still tries to deal with 't3', which is not opened.
+# That's why '8' is not inserted neither into 't2', nor into 't3'.
 execute stmt using @var;
-call p_verify_reprepare_count(0);
+ERROR 42S02: Table 'test.t3' doesn't exist
+call p_verify_reprepare_count(1);
 SUCCESS
 
-#
-# Sic: the insert went into t3, even though the view now
-# points at t2. This is because neither the merged view
-#  nor its prelocking list are affected by view DDL
-# The binary log is of course wrong, since it is not
-# using prepared statements
-#
 select * from t2;
 a
 5
@@ -381,7 +380,6 @@ select * from t3;
 a
 6
 7
-8
 flush table t1;
 set @var=9;
 execute stmt using @var;
@@ -396,7 +394,6 @@ select * from t3;
 a
 6
 7
-8
 drop view v1;
 drop table t1,t2,t3;
 # Test 7-d: dependent TABLE has changed
@@ -816,17 +813,14 @@ a	b	c
 10	20	50
 20	40	100
 30	60	150
-# Currently a different result from conventional statements.
-# A view is inlined once at prepare, later on view DDL
-# does not affect prepared statement and it is not re-prepared.
-# This is reported in Bug#36002 Prepared statements: if a view
-# used in a statement is replaced, bad data
+# This is actually a test case for Bug#11748352 (36002 Prepared
+# statements: if a view used in a statement is replaced, bad data).
 execute stmt;
 a	b	c
-10	20	30
-20	40	60
-30	60	90
-call p_verify_reprepare_count(0);
+10	20	50
+20	40	100
+30	60	150
+call p_verify_reprepare_count(1);
 SUCCESS
 
 flush table t2;
@@ -838,9 +832,200 @@ a	b	c
 call p_verify_reprepare_count(1);
 SUCCESS
 
+# Check that we properly handle ALTER VIEW statements.
+execute stmt;
+a	b	c
+10	20	50
+20	40	100
+30	60	150
+call p_verify_reprepare_count(0);
+SUCCESS
+
+alter view t1 as select a, 3*a as b, 4*a as c from t2;
+execute stmt;
+a	b	c
+10	30	40
+20	60	80
+30	90	120
+call p_verify_reprepare_count(1);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	30	40
+20	60	80
+30	90	120
+call p_verify_reprepare_count(0);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	30	40
+20	60	80
+30	90	120
+call p_verify_reprepare_count(0);
+SUCCESS
+
+select * from t1;
+a	b	c
+10	30	40
+20	60	80
+30	90	120
+# Check that DROP & CREATE is properly handled under LOCK TABLES.
+drop view t1;
+flush tables;
+create view t1 as select a, 5*a as b, 6*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+a	b	c
+10	50	60
+20	100	120
+30	150	180
+call p_verify_reprepare_count(1);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	50	60
+20	100	120
+30	150	180
+call p_verify_reprepare_count(0);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	50	60
+20	100	120
+30	150	180
+call p_verify_reprepare_count(0);
+SUCCESS
+
+unlock tables;
+#   ... and once again...
+drop view t1;
+create view t1 as select a, 6*a as b, 7*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+a	b	c
+10	60	70
+20	120	140
+30	180	210
+call p_verify_reprepare_count(1);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	60	70
+20	120	140
+30	180	210
+call p_verify_reprepare_count(0);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	60	70
+20	120	140
+30	180	210
+call p_verify_reprepare_count(0);
+SUCCESS
+
+unlock tables;
+# Check that ALTER VIEW is properly handled under LOCK TABLES.
+alter view t1 as select a, 7*a as b, 8*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+a	b	c
+10	70	80
+20	140	160
+30	210	240
+call p_verify_reprepare_count(1);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	70	80
+20	140	160
+30	210	240
+call p_verify_reprepare_count(0);
+SUCCESS
+
+execute stmt;
+a	b	c
+10	70	80
+20	140	160
+30	210	240
+call p_verify_reprepare_count(0);
+SUCCESS
+
+unlock tables;
 drop table t2;
 drop view t1;
 deallocate prepare stmt;
+# Check that DROP & CREATE is properly handled under LOCK TABLES when
+# LOCK TABLES does not contain the complete set of views.
+create table t1(a int);
+insert into t1 values (1), (2), (3);
+create view v1 as select a from t1;
+lock tables t1 read, v1 read;
+prepare stmt from 'select * from v1';
+execute stmt;
+a
+1
+2
+3
+call p_verify_reprepare_count(0);
+SUCCESS
+
+execute stmt;
+a
+1
+2
+3
+call p_verify_reprepare_count(0);
+SUCCESS
+
+unlock tables;
+drop view v1;
+create view v1 as select 2*a from t1;
+lock tables t1 read;
+execute stmt;
+ERROR HY000: Table 'v1' was not locked with LOCK TABLES
+unlock tables;
+drop table t1;
+drop view v1;
+deallocate prepare stmt;
+# Check that ALTER VIEW is properly handled under LOCK TABLES when
+# LOCK TABLES does not contain the complete set of views.
+create table t1(a int);
+insert into t1 values (1), (2), (3);
+create view v1 as select a from t1;
+lock tables t1 read, v1 read;
+prepare stmt from 'select * from v1';
+execute stmt;
+a
+1
+2
+3
+call p_verify_reprepare_count(0);
+SUCCESS
+
+execute stmt;
+a
+1
+2
+3
+call p_verify_reprepare_count(0);
+SUCCESS
+
+unlock tables;
+alter view v1 as select 2*a from t1;
+lock tables t1 read;
+execute stmt;
+ERROR HY000: Table 'v1' was not locked with LOCK TABLES
+unlock tables;
+drop table t1;
+drop view v1;
+deallocate prepare stmt;
 =====================================================================
 Part 18: VIEW -> VIEW (VIEW dependencies) transitions
 =====================================================================
@@ -938,15 +1123,15 @@ drop view v2;
 create view v2 as select a from t2;
 execute stmt;
 a
-1
-2
-3
+4
+5
+6
 execute stmt;
 a
-1
-2
-3
-call p_verify_reprepare_count(0);
+4
+5
+6
+call p_verify_reprepare_count(1);
 SUCCESS
 
 flush table t1;
@@ -955,7 +1140,7 @@ a
 4
 5
 6
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
 SUCCESS
 
 execute stmt;

=== modified file 'mysql-test/r/sp.result'
--- a/mysql-test/r/sp.result	2011-12-14 17:08:53 +0000
+++ b/mysql-test/r/sp.result	2011-12-22 11:12:32 +0000
@@ -2724,20 +2724,23 @@ userid
 drop procedure bug8116|
 drop table t3|
 drop procedure if exists bug6857|
-create procedure bug6857(counter int)
+create procedure bug6857()
 begin
 declare t0, t1 int;
 declare plus bool default 0;
-set t0 = current_time();
-while counter > 0 do
-set counter = counter - 1;
-end while;
-set t1 = current_time();
+set t0 = unix_timestamp();
+select sleep(1.1);
+set t1 = unix_timestamp();
 if t1 > t0 then
 set plus = 1;
 end if;
 select plus;
 end|
+call bug6857()|
+sleep(1.1)
+0
+plus
+1
 drop procedure bug6857|
 drop procedure if exists bug8757|
 create procedure bug8757()

=== modified file 'mysql-test/r/type_temporal_fractional.result'
--- a/mysql-test/r/type_temporal_fractional.result	2011-12-16 16:57:46 +0000
+++ b/mysql-test/r/type_temporal_fractional.result	2011-12-20 09:45:15 +0000
@@ -16984,3 +16984,40 @@ SEC_TO_TIME(-3200399.000001)
 -838:59:59.000000
 Warnings:
 Warning	1292	Truncated incorrect time value: '-3200399.000001'
+#
+# BUG#13451866 - DIFFERENCE IN RESULTS WHEN USING
+# EXTRACT( MINUTE_MICROSECOND )
+#
+CREATE TABLE t1 (a DATETIME(6) DEFAULT NULL);
+INSERT INTO t1 VALUES ('0000-00-00 00:00:00.000000');
+SELECT * FROM t1;
+a
+0000-00-00 00:00:00.000000
+SELECT EXTRACT(MINUTE_MICROSECOND FROM a) FROM t1;
+EXTRACT(MINUTE_MICROSECOND FROM a)
+0
+SELECT EXTRACT(MINUTE_MICROSECOND FROM '0000-00-00 00:00:00.000000');
+EXTRACT(MINUTE_MICROSECOND FROM '0000-00-00 00:00:00.000000')
+0
+DROP TABLE t1;
+#
+# BUG#13436875 - ASSERTION '!ARGS[0]->IS_TEMPORAL() ||
+# !ARGS[1]->IS_TEMPORAL()'
+#
+CREATE TABLE t1 (a DATETIME NOT NULL);
+SELECT 1 FROM t1 WHERE GREATEST(a, a) / a;
+1
+SELECT 1 FROM t1 WHERE LEAST(a, a) / a;
+1
+SELECT 1 FROM t1 WHERE COALESCE(a, a) / a;
+1
+SELECT 1 FROM t1 WHERE IF(0, a, a) / a;
+1
+SELECT 1 FROM t1 WHERE IFNULL(a, a) / a;
+1
+SELECT 1 FROM t1 WHERE CASE WHEN 0 then a ELSE a END / a;
+1
+SELECT 1 FROM t1 WHERE (SELECT a FROM t1) / a;
+1
+DROP TABLE t1;
+# End of 5.6 tests

=== modified file 'mysql-test/r/xa.result'
--- a/mysql-test/r/xa.result	2011-04-14 08:47:14 +0000
+++ b/mysql-test/r/xa.result	2011-12-22 10:38:23 +0000
@@ -206,8 +206,8 @@ DROP TABLE t1;
 #                FAILED 
 #
 DROP TABLE IF EXISTS t1, t2;
-CREATE TABLE t1 (a INT);
-CREATE TABLE t2 (a INT);
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
 START TRANSACTION;
 INSERT INTO t1 VALUES (1);
 # Connection con2

=== modified file 'mysql-test/suite/innodb/r/innodb_buffer_pool_load.result'
--- a/mysql-test/suite/innodb/r/innodb_buffer_pool_load.result	2011-11-20 21:00:25 +0000
+++ b/mysql-test/suite/innodb/r/innodb_buffer_pool_load.result	2011-12-08 09:14:27 +0000
@@ -16,7 +16,7 @@ count(*)
 SET GLOBAL innodb_buffer_pool_load_now = ON;
 SELECT variable_value
 FROM information_schema.global_status
-WHERE variable_name = 'INNODB_BUFFER_POOL_LOAD_STATUS';
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
 variable_value
 Buffer pool(s) load completed at TIMESTAMP_NOW
 SELECT COUNT(*) FROM information_schema.innodb_buffer_page_lru

=== modified file 'mysql-test/suite/innodb/t/innodb_buffer_pool_load.test'
--- a/mysql-test/suite/innodb/t/innodb_buffer_pool_load.test	2011-11-20 21:00:25 +0000
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_load.test	2011-12-08 09:14:27 +0000
@@ -47,7 +47,7 @@ SET GLOBAL innodb_buffer_pool_dump_now =
 let $wait_condition =
   SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) dump completed at '
   FROM information_schema.global_status
-  WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+  WHERE LOWER(variable_name) = 'innodb_buffer_pool_dump_status';
 -- source include/wait_condition.inc
 
 # Confirm the file has been created
@@ -76,14 +76,14 @@ SET GLOBAL innodb_buffer_pool_load_now =
 let $wait_condition =
   SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) load completed at '
   FROM information_schema.global_status
-  WHERE variable_name = 'INNODB_BUFFER_POOL_LOAD_STATUS';
+  WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
 -- source include/wait_condition.inc
 
 # Show the status, interesting if the above timed out
 -- replace_regex /[0-9]{6}[[:space:]]+[0-9]{1,2}:[0-9]{2}:[0-9]{2}/TIMESTAMP_NOW/
 SELECT variable_value
 FROM information_schema.global_status
-WHERE variable_name = 'INNODB_BUFFER_POOL_LOAD_STATUS';
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
 
 # Accept 329 for 16k page size, 662 for 8k page size & 1392 for 4k page size
 -- replace_result 329 {checked_valid} 662 {checked_valid} 1392 {checked_valid}
@@ -107,7 +107,7 @@ SET GLOBAL innodb_buffer_pool_load_now =
 let $wait_condition =
   SELECT SUBSTR(variable_value, 1, 13) = 'Error parsing'
   FROM information_schema.global_status
-  WHERE variable_name = 'INNODB_BUFFER_POOL_LOAD_STATUS';
+  WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
 -- source include/wait_condition.inc
 
 DROP TABLE ib_bp_test;

=== modified file 'mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result'
--- a/mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result	2011-11-19 08:08:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_circular_for_4_hosts.result	2011-12-19 14:26:51 +0000
@@ -20,6 +20,7 @@ include/rpl_sync.inc
 call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group");
 call mtr.add_suppression("The slave coordinator and worker threads are stopped, possibly leaving data in inconsistent state");
 call mtr.add_suppression("Slave SQL: Coordinator thread of multi-threaded slave is exiting seeing a failed Worker to apply an event");
+call mtr.add_suppression("Slave worker thread has failed to apply an event");
 
 *** Testing schema A->B->C->D->A ***
 

=== renamed file 'mysql-test/suite/rpl/r/rpl_mts_check_concurrency.result' => 'mysql-test/suite/rpl/r/rpl_mts_debug.result'
--- a/mysql-test/suite/rpl/r/rpl_mts_check_concurrency.result	2011-11-19 08:08:03 +0000
+++ b/mysql-test/suite/rpl/r/rpl_mts_debug.result	2011-12-16 15:53:16 +0000
@@ -21,4 +21,19 @@ include/stop_slave.inc
 SET @@global.slave_parallel_workers= save_slave_parallel_workers;
 SET @@global.debug= "";
 include/start_slave.inc
+call mtr.add_suppression('Error reading slave worker configuration');
+call mtr.add_suppression('Failed during slave workers initialization');
+call mtr.add_suppression('Failed during slave worker thread create');
+include/stop_slave.inc
+set @save.slave_checkpoint_group= @@global.slave_checkpoint_group;
+set @save.slave_parallel_workers= @@global.slave_parallel_workers;
+set @save.debug= @@global.debug;
+SET @@global.debug= "d,mts_worker_thread_fails";
+set @@global.slave_parallel_workers= 2;
+start slave sql_thread;
+include/wait_for_slave_sql_error.inc [errno=1593]
+set @@global.slave_checkpoint_group= @save.slave_checkpoint_group;
+set @@global.slave_parallel_workers= @save.slave_parallel_workers;
+set @@global.debug= @save.debug;
+include/start_slave.inc
 include/rpl_end.inc

=== modified file 'mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test'
--- a/mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/rpl/t/rpl_circular_for_4_hosts.test	2011-11-24 18:26:55 +0000
@@ -33,6 +33,7 @@ CREATE TABLE t2 (a INT NOT NULL AUTO_INC
 call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group");
 call mtr.add_suppression("The slave coordinator and worker threads are stopped, possibly leaving data in inconsistent state");
 call mtr.add_suppression("Slave SQL: Coordinator thread of multi-threaded slave is exiting seeing a failed Worker to apply an event");
+call mtr.add_suppression("Slave worker thread has failed to apply an event");
 --echo
 
 #

=== renamed file 'mysql-test/suite/rpl/t/rpl_mts_check_concurrency-slave.opt' => 'mysql-test/suite/rpl/t/rpl_mts_debug-slave.opt'
=== renamed file 'mysql-test/suite/rpl/t/rpl_mts_check_concurrency.test' => 'mysql-test/suite/rpl/t/rpl_mts_debug.test'
--- a/mysql-test/suite/rpl/t/rpl_mts_check_concurrency.test	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/rpl/t/rpl_mts_debug.test	2011-12-16 15:53:16 +0000
@@ -10,6 +10,8 @@
 --source include/master-slave.inc
 --source include/have_debug.inc
 --source include/have_innodb.inc
+# no format specific tests so we run it only in MIXED mode
+--source include/have_binlog_format_mixed.inc
 
 --connection master
 CREATE DATABASE db_1;
@@ -46,4 +48,46 @@ DROP DATABASE db_2;
 --eval SET @@global.slave_parallel_workers= $save_slave_parallel_workers
 --eval SET @@global.debug= "$save_debug"
 --source include/start_slave.inc
+
+#
+# Bug#12964649 MTS memory not released
+#
+# Originally reported when opt_slave_checkpoint_group is set to be greater
+# than sizeof(BLOB) * 8 - 1 Workers initialization code fails.
+# VALID_RANGE() for opt_slave_checkpoint_group is fixed in bug12979420.
+# 
+# The current bug test simulates a failure to start by a Worker
+# thread, checks the error, and verifies that all memory is released
+# (valgrind proves, the user can watch top report).
+#
+
+connection slave;
+
+call mtr.add_suppression('Error reading slave worker configuration');
+call mtr.add_suppression('Failed during slave workers initialization');
+call mtr.add_suppression('Failed during slave worker thread create');
+
+source include/stop_slave.inc;
+set @save.slave_checkpoint_group= @@global.slave_checkpoint_group;
+set @save.slave_parallel_workers= @@global.slave_parallel_workers;
+
+# The following assignment can work only with debug builds.
+# It sets opt_slave_checkpoint_group to one more to its VALID_RANGE() maximum.
+# set @@global.slave_checkpoint_group= 524287 + 1;
+
+set @save.debug= @@global.debug;
+SET @@global.debug= "d,mts_worker_thread_fails";
+set @@global.slave_parallel_workers= 2;
+
+start slave sql_thread;
+--let $slave_sql_errno= 1593
+source include/wait_for_slave_sql_error.inc;
+
+set @@global.slave_checkpoint_group= @save.slave_checkpoint_group;
+set @@global.slave_parallel_workers= @save.slave_parallel_workers;
+set @@global.debug= @save.debug;
+
+source include/start_slave.inc;
+
+
 --source include/rpl_end.inc

=== modified file 'mysql-test/suite/sys_vars/r/innodb_buffer_pool_filename_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_buffer_pool_filename_basic.result	2011-11-17 00:20:31 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_buffer_pool_filename_basic.result	2011-12-08 09:14:27 +0000
@@ -4,7 +4,7 @@ SELECT @orig;
 ib_buffer_pool
 SELECT variable_value
 FROM information_schema.global_status
-WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_dump_status';
 variable_value
 not started
 SET GLOBAL innodb_buffer_pool_filename = 'innodb_foobar_dump';

=== modified file 'mysql-test/suite/sys_vars/r/innodb_buffer_pool_load_now_basic.result'
--- a/mysql-test/suite/sys_vars/r/innodb_buffer_pool_load_now_basic.result	2011-11-17 00:20:31 +0000
+++ b/mysql-test/suite/sys_vars/r/innodb_buffer_pool_load_now_basic.result	2011-12-08 09:14:27 +0000
@@ -6,6 +6,6 @@ SET GLOBAL innodb_buffer_pool_dump_now =
 SET GLOBAL innodb_buffer_pool_load_now = ON;
 SELECT variable_value
 FROM information_schema.global_status
-WHERE variable_name = 'INNODB_BUFFER_POOL_LOAD_STATUS';
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
 variable_value
 Buffer pool(s) load completed at TIMESTAMP_NOW

=== modified file 'mysql-test/suite/sys_vars/r/slave_checkpoint_group_basic.result'
--- a/mysql-test/suite/sys_vars/r/slave_checkpoint_group_basic.result	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/r/slave_checkpoint_group_basic.result	2011-11-24 18:26:55 +0000
@@ -37,6 +37,9 @@ Warning	1292	Truncated incorrect slave_c
 set global slave_checkpoint_group=cast(-1 as unsigned int);
 Warnings:
 Warning	1292	Truncated incorrect slave_checkpoint_group value: '18446744073709551615'
+select @@global.slave_checkpoint_group as "truncated to the maximum" ;
+truncated to the maximum
+524287
 SET @@global.slave_checkpoint_group = @start_global_value;
 SELECT @@global.slave_checkpoint_group;
 @@global.slave_checkpoint_group

=== modified file 'mysql-test/suite/sys_vars/r/slave_checkpoint_period_basic.result'
--- a/mysql-test/suite/sys_vars/r/slave_checkpoint_period_basic.result	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/r/slave_checkpoint_period_basic.result	2011-11-24 18:26:55 +0000
@@ -38,8 +38,8 @@ select @@global.slave_checkpoint_period;
 set global slave_checkpoint_period=cast(-1 as unsigned int);
 Warnings:
 Warning	1292	Truncated incorrect slave_checkpoint_period value: '18446744073709551615'
-select @@global.slave_checkpoint_period;
-@@global.slave_checkpoint_period
+select @@global.slave_checkpoint_period as "truncated to the maximum";
+truncated to the maximum
 4294967295
 SET @@global.slave_checkpoint_period = @start_global_value;
 SELECT @@global.slave_checkpoint_period;

=== modified file 'mysql-test/suite/sys_vars/r/slave_parallel_workers_basic.result'
--- a/mysql-test/suite/sys_vars/r/slave_parallel_workers_basic.result	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/r/slave_parallel_workers_basic.result	2011-11-24 18:26:55 +0000
@@ -17,7 +17,7 @@ set @@global.slave_parallel_workers= 0;
 set @@global.slave_parallel_workers= cast(-1 as unsigned int);
 Warnings:
 Warning	1292	Truncated incorrect slave_parallel_workers value: '18446744073709551615'
-select @@global.slave_parallel_workers;
-@@global.slave_parallel_workers
+select @@global.slave_parallel_workers as "truncated to the maximum";
+truncated to the maximum
 1024
 set @@global.slave_parallel_workers= @save.slave_parallel_workers;

=== modified file 'mysql-test/suite/sys_vars/r/slave_pending_jobs_size_max_basic.result'
--- a/mysql-test/suite/sys_vars/r/slave_pending_jobs_size_max_basic.result	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/r/slave_pending_jobs_size_max_basic.result	2011-11-24 18:26:55 +0000
@@ -27,7 +27,7 @@ Warning	1292	Truncated incorrect slave_p
 set @@global.slave_pending_jobs_size_max= cast(-1 as unsigned int);
 Warnings:
 Warning	1292	Truncated incorrect slave_pending_jobs_size_max value: '18446744073709551615'
-select @@global.slave_pending_jobs_size_max;
-@@global.slave_pending_jobs_size_max
+select @@global.slave_pending_jobs_size_max as "truncated to the maximum";
+truncated to the maximum
 18446744073709550592
 set @@global.slave_pending_jobs_size_max= @save.slave_pending_jobs_size_max;

=== modified file 'mysql-test/suite/sys_vars/t/innodb_adaptive_max_sleep_delay_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_adaptive_max_sleep_delay_basic.test	2011-08-19 06:13:33 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_adaptive_max_sleep_delay_basic.test	2011-12-08 09:14:27 +0000
@@ -20,8 +20,8 @@
 --source include/have_innodb.inc
 
 # Check if builtins are enabled
-if (`SELECT VARIABLE_VALUE='OFF' FROM INFORMATION_SCHEMA.GLOBAL_STATUS
-    WHERE variable_name = 'INNODB_HAVE_ATOMIC_BUILTINS'`) {
+if (`SELECT LOWER(VARIABLE_VALUE)='off' FROM INFORMATION_SCHEMA.GLOBAL_STATUS
+    WHERE LOWER(variable_name) = 'innodb_have_atomic_builtins'`) {
 	--skip Test requires InnoDB atomic builtins
 }
 

=== modified file 'mysql-test/suite/sys_vars/t/innodb_buffer_pool_dump_now_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_buffer_pool_dump_now_basic.test	2011-11-17 00:20:31 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_buffer_pool_dump_now_basic.test	2011-12-08 09:14:27 +0000
@@ -17,7 +17,7 @@ SELECT @@global.innodb_buffer_pool_dump_
 let $wait_condition =
   SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) dump completed at '
   FROM information_schema.global_status
-  WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+  WHERE LOWER(variable_name) = 'innodb_buffer_pool_dump_status';
 -- source include/wait_condition.inc
 
 # Confirm that the dump file has been created

=== modified file 'mysql-test/suite/sys_vars/t/innodb_buffer_pool_filename_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_buffer_pool_filename_basic.test	2011-11-17 00:20:31 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_buffer_pool_filename_basic.test	2011-12-08 09:14:27 +0000
@@ -15,7 +15,7 @@ SELECT @orig;
 # dump actually being complete and file_exists may fail.
 SELECT variable_value
 FROM information_schema.global_status
-WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_dump_status';
 
 # Try with a non-default filename
 
@@ -28,7 +28,7 @@ SET GLOBAL innodb_buffer_pool_dump_now =
 let $wait_condition =
   SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) dump completed at '
   FROM information_schema.global_status
-  WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+  WHERE LOWER(variable_name) = 'innodb_buffer_pool_dump_status';
 -- source include/wait_condition.inc
 
 -- file_exists $file

=== modified file 'mysql-test/suite/sys_vars/t/innodb_buffer_pool_load_now_basic.test'
--- a/mysql-test/suite/sys_vars/t/innodb_buffer_pool_load_now_basic.test	2011-11-17 00:20:31 +0000
+++ b/mysql-test/suite/sys_vars/t/innodb_buffer_pool_load_now_basic.test	2011-12-08 09:14:27 +0000
@@ -15,7 +15,7 @@ SET GLOBAL innodb_buffer_pool_dump_now =
 let $wait_condition =
   SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) dump completed at '
   FROM information_schema.global_status
-  WHERE variable_name = 'INNODB_BUFFER_POOL_DUMP_STATUS';
+  WHERE LOWER(variable_name) = 'innodb_buffer_pool_dump_status';
 -- source include/wait_condition.inc
 
 # Confirm the file is really created
@@ -29,11 +29,11 @@ SET GLOBAL innodb_buffer_pool_load_now =
 let $wait_condition =
   SELECT SUBSTR(variable_value, 1, 33) = 'Buffer pool(s) load completed at '
   FROM information_schema.global_status
-  WHERE variable_name = 'INNODB_BUFFER_POOL_LOAD_STATUS';
+  WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';
 -- source include/wait_condition.inc
 
 # Show the status, interesting if the above timed out
 -- replace_regex /[0-9]{6}[[:space:]]+[0-9]{1,2}:[0-9]{2}:[0-9]{2}/TIMESTAMP_NOW/
 SELECT variable_value
 FROM information_schema.global_status
-WHERE variable_name = 'INNODB_BUFFER_POOL_LOAD_STATUS';
+WHERE LOWER(variable_name) = 'innodb_buffer_pool_load_status';

=== modified file 'mysql-test/suite/sys_vars/t/slave_checkpoint_group_basic.test'
--- a/mysql-test/suite/sys_vars/t/slave_checkpoint_group_basic.test	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/t/slave_checkpoint_group_basic.test	2011-11-24 18:26:55 +0000
@@ -38,5 +38,7 @@ set global slave_checkpoint_group="foo";
 set global slave_checkpoint_group=0;
 set global slave_checkpoint_group=cast(-1 as unsigned int);
 
+select @@global.slave_checkpoint_group as "truncated to the maximum" ;
+
 SET @@global.slave_checkpoint_group = @start_global_value;
 SELECT @@global.slave_checkpoint_group;

=== modified file 'mysql-test/suite/sys_vars/t/slave_checkpoint_period_basic.test'
--- a/mysql-test/suite/sys_vars/t/slave_checkpoint_period_basic.test	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/t/slave_checkpoint_period_basic.test	2011-11-24 18:26:55 +0000
@@ -42,7 +42,7 @@ set global slave_checkpoint_period="foo"
 set global slave_checkpoint_period=1;
 select @@global.slave_checkpoint_period;
 set global slave_checkpoint_period=cast(-1 as unsigned int);
-select @@global.slave_checkpoint_period;
+select @@global.slave_checkpoint_period as "truncated to the maximum";
 
 SET @@global.slave_checkpoint_period = @start_global_value;
 SELECT @@global.slave_checkpoint_period;

=== modified file 'mysql-test/suite/sys_vars/t/slave_parallel_workers_basic.test'
--- a/mysql-test/suite/sys_vars/t/slave_parallel_workers_basic.test	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/t/slave_parallel_workers_basic.test	2011-11-24 18:26:55 +0000
@@ -32,7 +32,7 @@ eval set @@global.$var= "foo";
 #
 eval set @@global.$var= 0;
 eval set @@global.$var= cast(-1 as unsigned int);
-eval select @@global.$var;
+eval select @@global.$var as "truncated to the maximum";
 
 # cleanup
 

=== modified file 'mysql-test/suite/sys_vars/t/slave_pending_jobs_size_max_basic.test'
--- a/mysql-test/suite/sys_vars/t/slave_pending_jobs_size_max_basic.test	2011-08-19 13:04:28 +0000
+++ b/mysql-test/suite/sys_vars/t/slave_pending_jobs_size_max_basic.test	2011-11-24 18:26:55 +0000
@@ -34,7 +34,7 @@ eval set @@global.$var= "foo";
 #
 eval set @@global.$var= 0;
 eval set @@global.$var= cast(-1 as unsigned int);
-eval select @@global.$var;
+eval select @@global.$var as "truncated to the maximum";
 
 # cleanup
 

=== modified file 'mysql-test/t/func_group.test'
--- a/mysql-test/t/func_group.test	2011-04-12 10:31:30 +0000
+++ b/mysql-test/t/func_group.test	2011-12-22 13:36:08 +0000
@@ -1184,3 +1184,12 @@ SELECT AVG(DISTINCT outr.col_int_nokey)
 outr.col_int_nokey = outr2.col_int_nokey;
 DROP TABLE t1;
 --echo # End of the bug#57932
+
+--echo #
+--echo # BUG#12773464 - 61925: WRONG RESULT WITH AGGREGATE + NOT BETWEEN + KEY
+--echo #
+CREATE TABLE t1 (a int, KEY (a));
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
+SELECT MAX(a) FROM t1 WHERE a NOT BETWEEN 3 AND 9;
+
+DROP TABLE t1;

=== added file 'mysql-test/t/mysql_embedded-master.opt'
--- a/mysql-test/t/mysql_embedded-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/mysql_embedded-master.opt	2011-12-23 08:55:18 +0000
@@ -0,0 +1,3 @@
+--default-storage-engine=MyISAM 
+--default-tmp-storage-engine=MyISAM 
+--skip-innodb 

=== renamed file 'mysql-test/t/mysqlbinlog2.test' => 'mysql-test/t/mysqlbinlog_start_stop.test'
--- a/mysql-test/t/mysqlbinlog2.test	2011-10-19 10:15:25 +0000
+++ b/mysql-test/t/mysqlbinlog_start_stop.test	2011-12-20 16:06:32 +0000
@@ -1,146 +1,92 @@
-# Test for the new options --start-datetime, stop-datetime,
-# and a few others.
+# ==== Purpose ====
+#
+# Test the --[start|stop]-[position|datetime] options to mysqlbinlog,
+# with/without --read-from-remote-server, with one or two binary logs
+# as input.
+#
+# ==== Implementation ====
 
 # TODO: Need to look at making row based version once new binlog client is complete.
 -- source include/have_binlog_format_mixed_or_statement.inc
 
+CREATE TABLE t1 (a INT);
+RESET MASTER;
 
---disable_warnings
-drop table if exists t1;
---enable_warnings
-reset master;
-
-# We need this for getting fixed timestamps inside of this test.
-# I use a date in the future to keep a growing timestamp along the
+# We need to set fixed timestamps in this test.
+# Use a date in the future to keep a growing timestamp along the
 # binlog (including the Start_log_event). This test will work 
 # unchanged everywhere, because mysql-test-run has fixed TZ, which it
 # exports (so mysqlbinlog has same fixed TZ).
-set @a=UNIX_TIMESTAMP("2020-01-21 15:32:22");
-set timestamp=@a;
-create table t1 (a int auto_increment not null primary key, b char(3));
-insert into t1 values(null, "a");
-insert into t1 values(null, "b");
-set timestamp=@a+2;
---let $binlog_pos_760=query_get_value(SHOW MASTER STATUS, Position, 1)
-insert into t1 values(null, "c");
---let $binlog_pos_951=query_get_value(SHOW BINLOG EVENTS in 'master-bin.000001' from $binlog_pos_760, Pos, 4)
-set timestamp=@a+4;
-insert into t1 values(null, "d");
-insert into t1 values(null, "e");
-
-flush logs;
-set timestamp=@a+1; # this could happen on a slave
-insert into t1 values(null, "f");
---let $binlog_pos_135=query_get_value(SHOW BINLOG EVENTS in 'master-bin.000002', Pos, 3)
---let $binlog_pos_203=query_get_value(SHOW BINLOG EVENTS in 'master-bin.000002', Pos, 4)
-
-# delimiters are for easier debugging in future
-
---disable_query_log ONCE
-select "--- Local --" as "";
-
-#
-# We should use --short-form everywhere because in other case output will
-# be time dependent (the Start events). Better than nothing.
-#
-let $MYSQLD_DATADIR= `select @@datadir`;
---exec $MYSQL_BINLOG --short-form --base64-output=never $MYSQLD_DATADIR/master-bin.000001 
-
---disable_query_log ONCE
-select "--- offset --" as "";
---exec $MYSQL_BINLOG --short-form --offset=2 $MYSQLD_DATADIR/master-bin.000001 
---disable_query_log ONCE
-select "--- start-position --" as "";
---exec $MYSQL_BINLOG --short-form --start-position=$binlog_pos_760 $MYSQLD_DATADIR/master-bin.000001 
---disable_query_log ONCE
-select "--- stop-position --" as "";
---exec $MYSQL_BINLOG --short-form --stop-position=$binlog_pos_760 $MYSQLD_DATADIR/master-bin.000001 
---disable_query_log ONCE
-select "--- start and stop positions ---" as "";
---exec $MYSQL_BINLOG --short-form --start-position=$binlog_pos_760 --stop-position=$binlog_pos_951  $MYSQLD_DATADIR/master-bin.000001 
---disable_query_log ONCE
-select "--- start-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQLD_DATADIR/master-bin.000001 
---disable_query_log ONCE
-select "--- stop-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQLD_DATADIR/master-bin.000001 
-
---disable_query_log ONCE
-select "--- Local with 2 binlogs on command line --" as "";
+--let $datetime_1= 2031-01-01 12:00:00
+eval SET TIMESTAMP= UNIX_TIMESTAMP("$datetime_1");
+INSERT INTO t1 VALUES(1);
+--let $pos_1= query_get_value(SHOW MASTER STATUS, Position, 1)
+
+--let $datetime_2= 2032-01-01 12:00:00
+eval SET TIMESTAMP= UNIX_TIMESTAMP("$datetime_2");
+INSERT INTO t1 VALUES(2);
+--let $pos_2= query_get_value(SHOW MASTER STATUS, Position, 1)
+
+eval SET TIMESTAMP= UNIX_TIMESTAMP("2033-01-01 12:00:00");
+INSERT INTO t1 VALUES(3);
+
+--let $file_1= query_get_value(SHOW MASTER STATUS, File, 1)
+FLUSH LOGS;
+
+SET TIMESTAMP= UNIX_TIMESTAMP("2034-01-01 12:00:00");
+INSERT INTO t1 VALUES(4);
+--let $pos_3= query_get_value(SHOW MASTER STATUS, Position, 1)
+--let $datetime_3= 2035-01-01 12:00:00
+eval SET TIMESTAMP= UNIX_TIMESTAMP("$datetime_3");
+INSERT INTO t1 VALUES(5);
+
+--let $file_2= query_get_value(SHOW MASTER STATUS, File, 1)
+FLUSH LOGS;
+
+--let $MYSQLD_DATADIR= `select @@datadir`
+
+--echo
+--echo ==== Local ====
+
+--let $start_position= $pos_1
+--let $start_datetime= $datetime_1
+
+--let $stop_position= $pos_2
+--let $stop_datetime= $datetime_2
+--let $extra_options= $MYSQLD_DATADIR/$file_1
+--source extra/binlog_tests/mysqlbinlog_start_stop_1.inc
 
+--echo
+--echo ==== Local with 2 binlogs on command line ====
 # This is to verify that some options apply only to first, or last binlog
 
-flush logs;
---exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
-
---disable_query_log ONCE
-select "--- offset --" as "";
---exec $MYSQL_BINLOG --short-form --offset=2 $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
---disable_query_log ONCE
-select "--- start-position --" as "";
---exec $MYSQL_BINLOG --short-form --start-position=$binlog_pos_760 $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
---disable_query_log ONCE
-select "--- stop-position --" as "";
---exec $MYSQL_BINLOG --short-form --stop-position=$binlog_pos_203 $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
---disable_query_log ONCE
-select "--- start-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
---disable_query_log ONCE
-select "--- stop-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
-
---disable_query_log ONCE
-select "--- Remote --" as "";
---exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
-
---disable_query_log ONCE
-select "--- offset --" as "";
---exec $MYSQL_BINLOG --short-form --offset=2 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
---disable_query_log ONCE
-select "--- start-position --" as "";
---exec $MYSQL_BINLOG --short-form --start-position=$binlog_pos_760 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
---disable_query_log ONCE
-select "--- stop-position --" as "";
---exec $MYSQL_BINLOG --short-form --stop-position=$binlog_pos_760 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
---disable_query_log ONCE
-select "--- start and stop positions ---" as "";
---exec $MYSQL_BINLOG --short-form --start-position=$binlog_pos_760 --stop-position=$binlog_pos_951 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
---disable_query_log ONCE
-select "--- start-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--start-datetime=2020-01-21 15:32:24" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
---disable_query_log ONCE
-select "--- stop-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--stop-datetime=2020-01-21 15:32:24" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
-
---disable_query_log ONCE
-select "--- Remote with 2 binlogs on command line --" as "";
-
---exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
-
---disable_query_log ONCE
-select "--- offset --" as "";
---exec $MYSQL_BINLOG --short-form --offset=2 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001  master-bin.000002
---disable_query_log ONCE
-select "--- start-position --" as "";
---exec $MYSQL_BINLOG --short-form --start-position=$binlog_pos_760 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001  master-bin.000002
---disable_query_log ONCE
-select "--- stop-position --" as "";
---exec $MYSQL_BINLOG --short-form --stop-position=$binlog_pos_135 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001  master-bin.000002
---disable_query_log ONCE
-select "--- start-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--start-datetime=20200121153224" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
---disable_query_log ONCE
-select "--- stop-datetime --" as "";
---exec $MYSQL_BINLOG --short-form "--stop-datetime=2020/01/21 15@32@24" --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 master-bin.000002
-
---disable_query_log ONCE
-select "--- to-last-log --" as "";
-
---exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --to-last-log master-bin.000001
-
-# clean up
---disable_query_log ONCE
-select "--- end of test --" as "";
-drop table t1;
-
-# End of 4.1 tests
+--let $stop_position= $pos_3
+--let $stop_datetime= $datetime_3
+--let $extra_options= $MYSQLD_DATADIR/$file_1 $MYSQLD_DATADIR/$file_2
+--source extra/binlog_tests/mysqlbinlog_start_stop_1.inc
+
+--echo
+--echo ==== Remote ====
+
+--let $stop_position= $pos_2
+--let $stop_datetime= $datetime_2
+--let $extra_options= --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT $file_1
+--source extra/binlog_tests/mysqlbinlog_start_stop_1.inc
+
+--echo
+--echo ==== Remote with 2 binlogs on command line ====
+
+--let $stop_position= $pos_3
+--let $stop_datetime= $datetime_3
+--let $extra_options= --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT $file_1 $file_2
+--source extra/binlog_tests/mysqlbinlog_start_stop_1.inc
+
+# ==== to-last-log ====
+
+--let $extra_options= --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT $file_1
+--let $option= --to-last-log
+--source extra/binlog_tests/mysqlbinlog_start_stop_2.inc
+
+--echo
+--echo ==== clean up ====
+DROP TABLE t1;

=== modified file 'mysql-test/t/mysqldump.test'
--- a/mysql-test/t/mysqldump.test	2011-05-10 13:37:37 +0000
+++ b/mysql-test/t/mysqldump.test	2011-12-24 09:43:56 +0000
@@ -2239,5 +2239,43 @@ CREATE TABLE t1 (a INT);
 --exec $MYSQL_DUMP --compatible=no_t,no_f --skip-comments test
 DROP TABLE t1;
 
+--echo #
+--echo # Bug#12809202 61854: MYSQLDUMP --SINGLE-TRANSACTION --FLUSH-LOG BREAKS
+--echo #                     CONSISTENCY
+--echo #
+
+--disable_warnings
+DROP DATABASE IF EXISTS b12809202_db;
+--enable_warnings
+
+CREATE DATABASE b12809202_db;
+CREATE TABLE b12809202_db.t1 (c1 INT);
+CREATE TABLE b12809202_db.t2 (c1 INT);
+
+INSERT INTO b12809202_db.t1 VALUES (1), (2), (3);
+INSERT INTO b12809202_db.t2 VALUES (1), (2), (3);
+
+--echo # Starting mysqldump with --single-transaction & --flush-log options..
+--echo # Note : In the following dump the transaction
+--echo #        should start only after the logs are
+--echo #        flushed, as 'flush logs' causes implicit
+--echo #        commit starting 5.5.
+--echo
+--echo #### Dump starts here ####
+--replace_regex /-- Server version.*// /-- MySQL dump .*// /-- Dump completed on .*/-- Dump completed/
+--exec $MYSQL_DUMP --verbose --single-transaction --flush-log b12809202_db 2>&1
+--echo
+--echo #### Dump ends here ####
+
+# Cleanup
+DROP TABLE b12809202_db.t1;
+DROP TABLE b12809202_db.t2;
+DROP DATABASE b12809202_db;
+
+--echo #
+--echo # Delete all existing binary logs.
+--echo #
+RESET MASTER;
+
 # Wait till we reached the initial number of concurrent sessions
 --source include/wait_until_count_sessions.inc

=== modified file 'mysql-test/t/partition_list.test'
--- a/mysql-test/t/partition_list.test	2009-10-21 18:04:34 +0000
+++ b/mysql-test/t/partition_list.test	2011-10-12 11:33:18 +0000
@@ -9,6 +9,101 @@
 drop table if exists t1;
 --enable_warnings
 
+--echo #
+--echo # Bug#62505: ALTER TABLE ADD PARTITION fails for LIST partitions with
+--echo #            more than 16 items
+--echo #
+
+CREATE TABLE t1 (a INT);
+
+--echo # SUCCESS with 20 items because this is initial partitioning action
+--echo # (The parser already knows that it is only on column)
+ALTER TABLE t1
+PARTITION BY LIST(a)
+(PARTITION p1 VALUES IN (1,2,3,4,5,6,7,8,9,10,
+                         11,12,13,14,15,16,17,18,19,20));
+
+--echo # BUG: FAILED, because number of items > 16 during partition add
+--echo # (The parser do not know how many columns the table is partitioned on)
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2 VALUES IN (21,22,23,24,25,26,27,28,29,30,
+                         31,32,33,34,35,36,37,38,39,40));
+
+
+SHOW CREATE TABLE t1;
+
+--echo # Test with single column LIST COLUMNS too
+ALTER TABLE t1
+PARTITION BY LIST COLUMNS (a)
+(PARTITION p1 VALUES IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20));
+
+--error ER_PARSE_ERROR
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2 VALUES IN ((71),(72),(73),(74),(75),(76),(77),(78),(79),(80),
+                         (81),(82),(83),(84),(85),(86),(87),(88),(89),(90)));
+
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2 VALUES IN (21,22,23,24,25,26,27,28,29,30,
+                         31,32,33,34,35,36,37,38,39,40));
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo # Test with two columns in LIST COLUMNS partitioning
+CREATE TABLE t1
+(a INT,
+ b CHAR(2))
+PARTITION BY LIST COLUMNS (a, b)
+(PARTITION p0_a VALUES IN
+((0, "a0"), (0, "a1"), (0, "a2"), (0, "a3"), (0, "a4"), (0, "a5"), (0, "a6"),
+ (0, "a7"), (0, "a8"), (0, "a9"), (0, "aa"), (0, "ab"), (0, "ac"), (0, "ad"),
+ (0, "ae"), (0, "af"), (0, "ag"), (0, "ah"), (0, "ai"), (0, "aj"), (0, "ak"),
+ (0, "al")));
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p1_a VALUES IN
+((1, "a0"), (1, "a1"), (1, "a2"), (1, "a3"), (1, "a4"), (1, "a5"), (1, "a6"),
+ (1, "a7"), (1, "a8"), (1, "a9"), (1, "aa"), (1, "ab"), (1, "ac"), (1, "ad"),
+ (1, "ae"), (1, "af"), (1, "ag"), (1, "ah"), (1, "ai"), (1, "aj"), (1, "ak"),
+ (1, "al")));
+SHOW CREATE TABLE t1;
+
+--echo # Test of the parser for '('
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p2_a VALUES IN
+(((1 + 1), "a0"), (2, "a1"), (2, "a2"), (2, "a3"), (2, "a4"), (2, "a5"),
+ (2, "a6"), (2, "a7"), (2, "a8"), (2, "a9"), (2, "aa"), (2, "ab"), (2, "ac"),
+ (2, "ad"), (2, "ae"), (2, "af"), (2, "ag"), (2, "ah"), (2, "ai"), (2, "aj"),
+ (2, "ak"), (2, "al")));
+
+SHOW CREATE TABLE t1;
+
+--error ER_PARSE_ERROR
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN ((1 + 1 + 1), "a0"));
+--error ER_PARTITION_COLUMN_LIST_ERROR
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN (1 + 1 + 1, "a0"));
+
+--echo # Test with 3 columns when it only has 2.
+--error ER_PARTITION_COLUMN_LIST_ERROR
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN ((3, "a1", 0), (3, "a2", 0)));
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p3_a VALUES IN ((1 + 1 + 1, "a0")));
+SHOW CREATE TABLE t1;
+--echo # Test with more than 16 columns (cause of regression)
+--error ER_PARSE_ERROR
+ALTER TABLE t1 ADD PARTITION
+(PARTITION part_2 VALUES IN ((21 ,22, 23, 24, 25, 26, 27, 28, 29, 30,
+                              31 ,32, 33, 34, 35, 36, 37, 38, 39, 40),
+                             (41 ,42, 43, 44, 45, 46, 47, 48, 49, 50,
+                              51 ,52, 53, 54, 55, 56, 57, 58, 59, 60)));
+--error ER_PARTITION_COLUMN_LIST_ERROR
+ALTER TABLE t1 ADD PARTITION
+(PARTITION part_2 VALUES IN (21 ,22, 23, 24, 25, 26, 27, 28, 29, 30,
+                             31 ,32, 33, 34, 35, 36, 37, 38, 39, 40));
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
 #
 # Bug 20733: Zerofill columns gives wrong result with partitioned tables
 #

=== modified file 'mysql-test/t/partition_mgm.test'
--- a/mysql-test/t/partition_mgm.test	2011-10-14 12:28:58 +0000
+++ b/mysql-test/t/partition_mgm.test	2011-12-19 13:21:37 +0000
@@ -4,6 +4,16 @@ DROP TABLE IF EXISTS t1;
 --enable_warnings
 
 --echo #
+--echo # Bug#13357766: ASSERT IN HANDLER::HA_CREATE
+--echo #
+CREATE TABLE t1
+(a INT)
+PARTITION BY KEY(a) PARTITIONS 3;
+ALTER TABLE t1 REPAIR PARTITION p2,p3,p1;
+ALTER TABLE t1 ORDER BY a; 
+DROP TABLE t1;
+
+--echo #
 --echo # Bug#11764110/bug#56909: REORGANIZE PARTITION is allowed on
 --echo #                         HASH/KEY partitioned tables
 --echo #

=== modified file 'mysql-test/t/ps_ddl.test'
--- a/mysql-test/t/ps_ddl.test	2011-10-19 10:15:25 +0000
+++ b/mysql-test/t/ps_ddl.test	2011-12-19 11:42:11 +0000
@@ -349,23 +349,22 @@ select * from t2;
 drop view v1;
 create view v1 as select a from t2;
 set @var=8;
---echo # XXX: bug, the SQL statement in the trigger is still
---echo # pointing at table 't3', since the view was expanded
---echo # at first statement execution.
---echo # Since the view definition is inlined in the statement
---echo # at prepare, changing the view definition does not cause 
---echo # repreparation.
---echo # Repreparation of the main statement doesn't cause repreparation
---echo # of trigger statements.
-execute stmt using @var;
-call p_verify_reprepare_count(0);
+--echo # View in the INSERT-statement in the trigger is still pointing to
+--echo # table 't3', because the trigger hasn't noticed the change
+--echo # in view definition. This will be fixed by WL#4179.
 --echo #
---echo # Sic: the insert went into t3, even though the view now
---echo # points at t2. This is because neither the merged view
---echo #  nor its prelocking list are affected by view DDL
---echo # The binary log is of course wrong, since it is not
---echo # using prepared statements
+--echo # The prepared INSERT-statement however does notice the change,
+--echo # but repreparation of the main statement doesn't cause repreparation
+--echo # of trigger statements.
 --echo #
+--echo # The following EXECUTE results in ER_NO_SUCH_TABLE (t3) error, because
+--echo # pre-locking list of the prepared statement has been changed
+--echo # (the prepared statement has noticed the meta-data change),
+--echo # but the trigger still tries to deal with 't3', which is not opened.
+--echo # That's why '8' is not inserted neither into 't2', nor into 't3'.
+--error ER_NO_SUCH_TABLE
+execute stmt using @var;
+call p_verify_reprepare_count(1);
 select * from t2;
 select * from t3;
 flush table t1;
@@ -732,21 +731,136 @@ drop view t1;
 create view t1 as select a, 2*a as b, 5*a as c from t2;
 select * from t1;
 
---echo # Currently a different result from conventional statements.
---echo # A view is inlined once at prepare, later on view DDL
---echo # does not affect prepared statement and it is not re-prepared.
---echo # This is reported in Bug#36002 Prepared statements: if a view
---echo # used in a statement is replaced, bad data
+--echo # This is actually a test case for Bug#11748352 (36002 Prepared
+--echo # statements: if a view used in a statement is replaced, bad data).
 execute stmt;
-call p_verify_reprepare_count(0);
+call p_verify_reprepare_count(1);
+
 flush table t2;
+
 execute stmt;
 call p_verify_reprepare_count(1);
 
+--echo # Check that we properly handle ALTER VIEW statements.
+execute stmt;
+call p_verify_reprepare_count(0);
+alter view t1 as select a, 3*a as b, 4*a as c from t2;
+execute stmt;
+call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+select * from t1;
+
+--echo # Check that DROP & CREATE is properly handled under LOCK TABLES.
+drop view t1;
+flush tables; # empty TDC
+create view t1 as select a, 5*a as b, 6*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+unlock tables;
+--echo #   ... and once again...
+drop view t1;
+create view t1 as select a, 6*a as b, 7*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+unlock tables;
+
+--echo # Check that ALTER VIEW is properly handled under LOCK TABLES.
+alter view t1 as select a, 7*a as b, 8*a as c from t2;
+lock tables t1 read, t2 read;
+execute stmt;
+call p_verify_reprepare_count(1);
+execute stmt;
+call p_verify_reprepare_count(0);
+execute stmt;
+call p_verify_reprepare_count(0);
+unlock tables;
+
 drop table t2;
 drop view t1;
 deallocate prepare stmt;
 
+--echo # Check that DROP & CREATE is properly handled under LOCK TABLES when
+--echo # LOCK TABLES does not contain the complete set of views.
+
+create table t1(a int);
+insert into t1 values (1), (2), (3);
+
+create view v1 as select a from t1;
+
+lock tables t1 read, v1 read;
+
+prepare stmt from 'select * from v1';
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+unlock tables;
+
+drop view v1;
+create view v1 as select 2*a from t1;
+
+# Miss v1.
+lock tables t1 read;
+
+--error ER_TABLE_NOT_LOCKED
+execute stmt;
+
+unlock tables;
+
+drop table t1;
+drop view v1;
+deallocate prepare stmt;
+
+--echo # Check that ALTER VIEW is properly handled under LOCK TABLES when
+--echo # LOCK TABLES does not contain the complete set of views.
+
+create table t1(a int);
+insert into t1 values (1), (2), (3);
+
+create view v1 as select a from t1;
+
+lock tables t1 read, v1 read;
+
+prepare stmt from 'select * from v1';
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+execute stmt;
+call p_verify_reprepare_count(0);
+
+unlock tables;
+
+alter view v1 as select 2*a from t1;
+
+# Miss v1.
+lock tables t1 read;
+
+--error ER_TABLE_NOT_LOCKED
+execute stmt;
+
+unlock tables;
+
+drop table t1;
+drop view v1;
+deallocate prepare stmt;
+
 --echo =====================================================================
 --echo Part 18: VIEW -> VIEW (VIEW dependencies) transitions
 --echo =====================================================================
@@ -815,10 +929,10 @@ drop view v2;
 create view v2 as select a from t2;
 execute stmt;
 execute stmt;
-call p_verify_reprepare_count(0);
+call p_verify_reprepare_count(1);
 flush table t1;
 execute stmt;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
 execute stmt;
 --echo # Test 18-d: dependent TABLE has changed
 drop view v2;

=== modified file 'mysql-test/t/sp.test'
--- a/mysql-test/t/sp.test	2011-12-14 17:08:53 +0000
+++ b/mysql-test/t/sp.test	2011-12-22 17:43:39 +0000
@@ -3190,30 +3190,23 @@ drop table t3|
 #
 # BUG#6857: current_time() in STORED PROCEDURES
 #
---disable_warnings ONCE
+--disable_warnings 
 drop procedure if exists bug6857|
-create procedure bug6857(counter int)
+--enable_warnings
+create procedure bug6857()
 begin
   declare t0, t1 int;
   declare plus bool default 0;
-
-  set t0 = current_time();
-  while counter > 0 do
-    set counter = counter - 1;
-  end while;
-  set t1 = current_time();
+  set t0 = unix_timestamp();
+  select sleep(1.1);
+  set t1 = unix_timestamp();
   if t1 > t0 then
     set plus = 1;
   end if;
   select plus;
 end|
 
-# QQ: This is currently disabled. Not only does it slow down a normal test
-#     run, it makes running with valgrind (or similar tools) extremely
-#     painful.
-# Make sure this takes at least one second on all machines in all builds.
-# 30000 makes it about 3 seconds on an old 1.1GHz linux.
-#call bug6857(300000)|
+call bug6857()|
 
 drop procedure bug6857|
 

=== modified file 'mysql-test/t/type_temporal_fractional.test'
--- a/mysql-test/t/type_temporal_fractional.test	2011-12-16 16:57:46 +0000
+++ b/mysql-test/t/type_temporal_fractional.test	2011-12-20 09:45:15 +0000
@@ -7488,3 +7488,33 @@ SELECT SEC_TO_TIME(3200399.999999);
 SELECT SEC_TO_TIME(3200399.000001);
 SELECT SEC_TO_TIME(-3200399.999999);
 SELECT SEC_TO_TIME(-3200399.000001);
+
+
+--echo #
+--echo # BUG#13451866 - DIFFERENCE IN RESULTS WHEN USING
+--echo # EXTRACT( MINUTE_MICROSECOND )
+--echo #
+CREATE TABLE t1 (a DATETIME(6) DEFAULT NULL);
+INSERT INTO t1 VALUES ('0000-00-00 00:00:00.000000');
+SELECT * FROM t1;
+SELECT EXTRACT(MINUTE_MICROSECOND FROM a) FROM t1;
+SELECT EXTRACT(MINUTE_MICROSECOND FROM '0000-00-00 00:00:00.000000');
+DROP TABLE t1;
+
+
+--echo #
+--echo # BUG#13436875 - ASSERTION '!ARGS[0]->IS_TEMPORAL() ||
+--echo # !ARGS[1]->IS_TEMPORAL()'
+--echo #
+CREATE TABLE t1 (a DATETIME NOT NULL);
+SELECT 1 FROM t1 WHERE GREATEST(a, a) / a;
+SELECT 1 FROM t1 WHERE LEAST(a, a) / a;
+SELECT 1 FROM t1 WHERE COALESCE(a, a) / a;
+SELECT 1 FROM t1 WHERE IF(0, a, a) / a;
+SELECT 1 FROM t1 WHERE IFNULL(a, a) / a;
+SELECT 1 FROM t1 WHERE CASE WHEN 0 then a ELSE a END / a;    
+SELECT 1 FROM t1 WHERE (SELECT a FROM t1) / a;
+DROP TABLE t1;
+
+
+--echo # End of 5.6 tests

=== modified file 'mysql-test/t/xa.test'
--- a/mysql-test/t/xa.test	2011-05-31 13:52:09 +0000
+++ b/mysql-test/t/xa.test	2011-12-22 09:27:58 +0000
@@ -343,8 +343,8 @@ DROP TABLE t1;
 DROP TABLE IF EXISTS t1, t2;
 --enable_warnings
 
-CREATE TABLE t1 (a INT);
-CREATE TABLE t2 (a INT);
+CREATE TABLE t1 (a INT) ENGINE=InnoDB;
+CREATE TABLE t2 (a INT) ENGINE=InnoDB;
 
 START TRANSACTION;
 INSERT INTO t1 VALUES (1);

=== modified file 'sql/field.h'
--- a/sql/field.h	2011-12-15 12:12:14 +0000
+++ b/sql/field.h	2011-12-20 09:45:15 +0000
@@ -1171,6 +1171,10 @@ public:
 	    uchar null_bit_arg, utype unireg_check_arg,
 	    const char *field_name_arg, const CHARSET_INFO *charset);
   Item_result result_type () const { return STRING_RESULT; }
+  Item_result numeric_context_result_type() const
+  { 
+    return REAL_RESULT; 
+  }
   uint decimals() const { return NOT_FIXED_DEC; }
   void make_field(Send_field *field);
   int  store(double nr);
@@ -1931,7 +1935,7 @@ public:
   virtual uint32 max_display_length() { return field_length; }
   virtual bool str_needs_quotes() { return TRUE; }
   virtual uint is_equal(Create_field *new_field);
-  virtual Item_result numeric_context_result_type() const
+  Item_result numeric_context_result_type() const
   {
     return dec ? DECIMAL_RESULT : INT_RESULT;
   }
@@ -2017,7 +2021,7 @@ public:
   longlong val_date_temporal();
   bool get_time(MYSQL_TIME *ltime)
   {
-    return get_date(ltime, 0);
+    return get_date(ltime, TIME_FUZZY_DATE);
   }
 };
 

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2011-12-14 16:49:31 +0000
+++ b/sql/ha_partition.cc	2011-12-19 22:31:09 +0000
@@ -3801,14 +3801,14 @@ int ha_partition::truncate_partition(Alt
   uint num_parts= m_part_info->num_parts;
   uint num_subparts= m_part_info->num_subparts;
   uint i= 0;
-  uint num_parts_set= alter_info->partition_names.elements;
-  uint num_parts_found= set_part_state(alter_info, m_part_info,
-                                        PART_ADMIN);
   DBUG_ENTER("ha_partition::truncate_partition");
 
   /* Only binlog when it starts any call to the partitions handlers */
   *binlog_stmt= false;
 
+  if (set_part_state(alter_info, m_part_info, PART_ADMIN))
+    DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
+
   /*
     TRUNCATE also means resetting auto_increment. Hence, reset
     it so that it will be initialized again at the next use.
@@ -3818,10 +3818,6 @@ int ha_partition::truncate_partition(Alt
   table_share->ha_part_data->auto_inc_initialized= FALSE;
   unlock_auto_increment();
 
-  if (num_parts_set != num_parts_found &&
-      (!(alter_info->flags & ALTER_ALL_PARTITION)))
-    DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
-
   *binlog_stmt= true;
 
   do

=== modified file 'sql/item.h'
--- a/sql/item.h	2011-11-21 11:58:25 +0000
+++ b/sql/item.h	2011-12-13 18:18:20 +0000
@@ -643,6 +643,10 @@ public:
   */
   virtual enum Item_result numeric_context_result_type() const
   {
+    if (is_temporal())
+      return decimals ? DECIMAL_RESULT : INT_RESULT;
+    if (result_type() == STRING_RESULT)
+      return REAL_RESULT; 
     return result_type();
   }
   virtual Item_result cast_to_int_type() const { return result_type(); }

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2011-11-21 11:58:25 +0000
+++ b/sql/item_func.cc	2011-12-13 18:18:20 +0000
@@ -789,9 +789,10 @@ void Item_num_op::find_num_type(void)
   DBUG_ASSERT(arg_count == 2);
   Item_result r0= args[0]->numeric_context_result_type();
   Item_result r1= args[1]->numeric_context_result_type();
+  
+  DBUG_ASSERT(r0 != STRING_RESULT && r1 != STRING_RESULT);
 
-  if (r0 == REAL_RESULT || r1 == REAL_RESULT ||
-      r0 == STRING_RESULT || r1 ==STRING_RESULT)
+  if (r0 == REAL_RESULT || r1 == REAL_RESULT)
   {
     /*
       Since DATE/TIME/DATETIME data types return INT_RESULT/DECIMAL_RESULT

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2011-12-15 15:15:37 +0000
+++ b/sql/item_sum.cc	2011-12-20 09:45:15 +0000
@@ -1297,7 +1297,6 @@ void Item_sum_sum::fix_length_and_dec()
   decimals= args[0]->decimals;
   switch (args[0]->numeric_context_result_type()) {
   case REAL_RESULT:
-  case STRING_RESULT:
     hybrid_type= REAL_RESULT;
     sum= 0.0;
     break;
@@ -1314,6 +1313,7 @@ void Item_sum_sum::fix_length_and_dec()
     my_decimal_set_zero(dec_buffs);
     break;
   }
+  case STRING_RESULT:
   case ROW_RESULT:
   default:
     DBUG_ASSERT(0);

=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h	2011-11-10 14:58:23 +0000
+++ b/sql/item_sum.h	2011-12-13 18:18:20 +0000
@@ -1051,10 +1051,6 @@ protected:
   bool keep_field_type(void) const { return 1; }
   enum Item_result result_type () const { return hybrid_type; }
   enum enum_field_types field_type() const { return hybrid_field_type; }
-  enum Item_result numeric_context_result_type() const
-  {
-    return args[0]->numeric_context_result_type();
-  }
   void update_field();
   void min_max_update_str_field();
   void min_max_update_temporal_field();

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2011-11-28 10:08:20 +0000
+++ b/sql/item_timefunc.h	2011-12-13 18:18:20 +0000
@@ -513,11 +513,6 @@ public:
     DBUG_ASSERT(fixed);
     return decimals;
   }
-  enum Item_result numeric_context_result_type() const
-  {
-    DBUG_ASSERT(fixed);
-    return decimals ? DECIMAL_RESULT : INT_RESULT;
-  }
 };
 
 
@@ -545,12 +540,6 @@ public:
     sql_mode(0)
   { }
   enum Item_result result_type () const { return STRING_RESULT; }
-  enum Item_result numeric_context_result_type() const
-  {
-    DBUG_ASSERT(fixed);
-    return cached_field_type == MYSQL_TYPE_STRING ? STRING_RESULT :
-           decimals ? DECIMAL_RESULT : INT_RESULT;
-  }
   enum_field_types field_type() const { return cached_field_type; }
   const CHARSET_INFO *charset_for_protocol() const
   {

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-12-13 17:06:27 +0000
+++ b/sql/mysqld.cc	2011-12-16 15:53:16 +0000
@@ -524,7 +524,7 @@ ulong thread_id=1L,current_pid;
 ulong slow_launch_threads = 0;
 uint sync_binlog_period= 0, sync_relaylog_period= 0,
      sync_relayloginfo_period= 0, sync_masterinfo_period= 0,
-     mts_checkpoint_period= 0, mts_checkpoint_group= 0;
+     opt_mts_checkpoint_period, opt_mts_checkpoint_group;
 ulong expire_logs_days = 0;
 
 const double log_10[] = {

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2011-12-06 17:25:19 +0000
+++ b/sql/mysqld.h	2011-12-16 15:53:16 +0000
@@ -140,7 +140,7 @@ extern ulong expire_logs_days;
 extern my_bool relay_log_recovery;
 extern uint sync_binlog_period, sync_relaylog_period, 
             sync_relayloginfo_period, sync_masterinfo_period,
-            mts_checkpoint_period, mts_checkpoint_group;
+            opt_mts_checkpoint_period, opt_mts_checkpoint_group;
 extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
 extern ulong tc_log_page_waits;
 extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;

=== modified file 'sql/opt_sum.cc'
--- a/sql/opt_sum.cc	2011-07-21 17:51:38 +0000
+++ b/sql/opt_sum.cc	2011-12-22 13:36:08 +0000
@@ -674,6 +674,11 @@ static bool matching_cond(bool max_fl, T
     break;
   case Item_func::BETWEEN:
     between= 1;
+
+    // NOT BETWEEN is equivalent to OR and is therefore not a conjunction
+    if (((Item_func_between*)cond)->negated)
+      DBUG_RETURN(false);
+
     break;
   case Item_func::MULT_EQUAL_FUNC:
     eq_type= 1;

=== modified file 'sql/partition_element.h'
--- a/sql/partition_element.h	2011-06-30 15:50:45 +0000
+++ b/sql/partition_element.h	2011-12-19 12:53:11 +0000
@@ -92,7 +92,7 @@ struct st_ddl_log_memory_entry;
 class partition_element :public Sql_alloc {
 public:
   List<partition_element> subpartitions;
-  List<part_elem_value> list_val_list;
+  List<part_elem_value> list_val_list;  // list of LIST values/column arrays
   ha_rows part_max_rows;
   ha_rows part_min_rows;
   longlong range_value;

=== modified file 'sql/partition_info.cc'
--- a/sql/partition_info.cc	2011-07-28 10:54:44 +0000
+++ b/sql/partition_info.cc	2011-12-19 12:53:11 +0000
@@ -900,6 +900,7 @@ bool partition_info::check_range_constan
         List_iterator<part_elem_value> list_val_it(part_def->list_val_list);
         part_elem_value *range_val= list_val_it++;
         part_column_list_val *col_val= range_val->col_val_array;
+        DBUG_ASSERT(part_def->list_val_list.elements == 1);
 
         if (fix_column_value_functions(thd, range_val, i))
           goto end;
@@ -1788,11 +1789,11 @@ id_err:
 
 
 /**
-  Check what kind of error to report
+  Check what kind of error to report.
 
   @param use_subpart_expr Use the subpart_expr instead of part_expr
-  @param part_str         Name of partition to report error (or NULL)
 */
+
 void partition_info::report_part_expr_error(bool use_subpart_expr)
 {
   Item *expr= part_expr;
@@ -1832,18 +1833,17 @@ void partition_info::report_part_expr_er
 }
  
 
-/*
-  Create a new column value in current list with maxvalue
-  Called from parser
+/**
+  Create a new column value in current list with maxvalue.
 
-  SYNOPSIS
-    add_max_value()
-  RETURN
-    TRUE               Error
-    FALSE              Success
+  @return Operation status
+    @retval TRUE   Error
+    @retval FALSE  Success
+
+  @note Called from parser.
 */
 
-int partition_info::add_max_value()
+bool partition_info::add_max_value()
 {
   DBUG_ENTER("partition_info::add_max_value");
 
@@ -1856,16 +1856,16 @@ int partition_info::add_max_value()
   DBUG_RETURN(FALSE);
 }
 
-/*
-  Create a new column value in current list
-  Called from parser
 
-  SYNOPSIS
-    add_column_value()
-  RETURN
-    >0                 A part_column_list_val object which have been
-                       inserted into its list
-    0                  Memory allocation failure
+/**
+  Create a new column value in current list.
+
+  @return Pointer to a new part_column_list_val
+    @retval  != 0  A part_column_list_val object which have been
+                   inserted into its list
+    @retval  NULL  Memory allocation failure
+    
+  @note Called from parser.
 */
 
 part_column_list_val *partition_info::add_column_value()
@@ -1890,7 +1890,7 @@ part_column_list_val *partition_info::ad
       into the structure used for 1 column. After this we call
       ourselves recursively which should always succeed.
     */
-    if (!reorganize_into_single_field_col_val())
+    if (!reorganize_into_single_field_col_val() && !init_column_part())
     {
       DBUG_RETURN(add_column_value());
     }
@@ -1911,19 +1911,19 @@ part_column_list_val *partition_info::ad
 }
 
 
-/*
-  Initialise part_elem_value object at setting of a new object
-  (Helper functions to functions called by parser)
+/**
+  Initialise part_elem_value object at setting of a new object.
 
-  SYNOPSIS
-    init_col_val
-    col_val                  Column value object to be initialised
-    item                     Item object representing column value
+  @param col_val  Column value object to be initialised
+  @param item     Item object representing column value
 
-  RETURN VALUES
-    TRUE                     Failure
-    FALSE                    Success
+  @return Operation status
+    @retval TRUE   Failure
+    @retval FALSE  Success
+
+  @note Helper functions to functions called by parser.
 */
+
 void partition_info::init_col_val(part_column_list_val *col_val, Item *item)
 {
   DBUG_ENTER("partition_info::init_col_val");
@@ -1948,20 +1948,21 @@ void partition_info::init_col_val(part_c
   col_val->part_info= NULL;
   DBUG_VOID_RETURN;
 }
-/*
-  Add a column value in VALUES LESS THAN or VALUES IN
-  (Called from parser)
 
-  SYNOPSIS
-    add_column_list_value()
-    lex                      Parser's lex object
-    thd                      Thread object
-    item                     Item object representing column value
 
-  RETURN VALUES
-    TRUE                     Failure
-    FALSE                    Success
+/**
+  Add a column value in VALUES LESS THAN or VALUES IN.
+
+  @param thd   Thread object
+  @param item  Item object representing column value
+
+  @return Operation status
+    @retval TRUE   Failure
+    @retval FALSE  Success
+
+  @note Called from parser.
 */
+
 bool partition_info::add_column_list_value(THD *thd, Item *item)
 {
   part_column_list_val *col_val;
@@ -2010,19 +2011,19 @@ bool partition_info::add_column_list_val
   DBUG_RETURN(FALSE);
 }
 
-/*
-  Initialise part_info object for receiving a set of column values
+
+/**
+  Initialize a new column for VALUES {LESS THAN|IN}.
+
+  Initialize part_info object for receiving a set of column values
   for a partition, called when parser reaches VALUES LESS THAN or
   VALUES IN.
 
-  SYNOPSIS
-    init_column_part()
-    lex                    Parser's lex object
-
-  RETURN VALUES
-    TRUE                     Failure
-    FALSE                    Success
+  @return Operation status
+    @retval TRUE   Failure
+    @retval FALSE  Success
 */
+
 bool partition_info::init_column_part()
 {
   partition_element *p_elem= curr_part_elem;
@@ -2056,8 +2057,15 @@ bool partition_info::init_column_part()
   DBUG_RETURN(FALSE);
 }
 
-/*
-  In the case of ALTER TABLE ADD/REORGANIZE PARTITION for LIST
+
+/**
+  Reorganize the preallocated buffer into a single field col list.
+
+  @return Operation status
+    @retval  true   Failure
+    @retval  false  Success
+
+  @note In the case of ALTER TABLE ADD/REORGANIZE PARTITION for LIST
   partitions we can specify list values as:
   VALUES IN (v1, v2,,,, v17) if we're using the first partitioning
   variant with a function or a column list partitioned table with
@@ -2069,30 +2077,27 @@ bool partition_info::init_column_part()
   partitioning and we used a VALUES IN like above where number of
   values was smaller than MAX_REF_PARTS or equal, then we will
   reorganize after discovering this in the parser.
-
-  SYNOPSIS
-    reorganize_into_single_field_col_val()
-
-  RETURN VALUES
-    TRUE                     Failure
-    FALSE                    Success
 */
-int partition_info::reorganize_into_single_field_col_val()
+
+bool partition_info::reorganize_into_single_field_col_val()
 {
   part_column_list_val *col_val, *new_col_val;
   part_elem_value *val= curr_list_val;
-  uint loc_num_columns= num_columns;
+  uint num_values= num_columns;
   uint i;
   DBUG_ENTER("partition_info::reorganize_into_single_field_col_val");
+  DBUG_ASSERT(part_type == LIST_PARTITION);
+  DBUG_ASSERT(!num_columns || num_columns == val->added_items);
 
+  if (!num_values)
+    num_values= val->added_items;
   num_columns= 1;
   val->added_items= 1U;
   col_val= &val->col_val_array[0];
   init_col_val(col_val, col_val->item_expression);
-  for (i= 1; i < loc_num_columns; i++)
+  for (i= 1; i < num_values; i++)
   {
     col_val= &val->col_val_array[i];
-    DBUG_ASSERT(part_type == LIST_PARTITION);
     if (init_column_part())
     {
       DBUG_RETURN(TRUE);
@@ -2108,27 +2113,28 @@ int partition_info::reorganize_into_sing
   DBUG_RETURN(FALSE);
 }
 
-/*
+
+/**
   This function handles the case of function-based partitioning.
+  
   It fixes some data structures created in the parser and puts
   them in the format required by the rest of the partitioning
   code.
 
-  SYNOPSIS
-  fix_partition_values()
-  thd                             Thread object
-  col_val                         Array of one value
-  part_elem                       The partition instance
-  part_id                         Id of partition instance
-
-  RETURN VALUES
-    TRUE                     Failure
-    FALSE                    Success
+  @param thd        Thread object
+  @param col_val    Array of one value
+  @param part_elem  The partition instance
+  @param part_id    Id of partition instance
+
+  @return Operation status
+    @retval TRUE   Failure
+    @retval FALSE  Success
 */
-int partition_info::fix_partition_values(THD *thd,
-                                         part_elem_value *val,
-                                         partition_element *part_elem,
-                                         uint part_id)
+
+bool partition_info::fix_partition_values(THD *thd,
+                                          part_elem_value *val,
+                                          partition_element *part_elem,
+                                          uint part_id)
 {
   part_column_list_val *col_val= val->col_val_array;
   DBUG_ENTER("partition_info::fix_partition_values");
@@ -2195,17 +2201,16 @@ int partition_info::fix_partition_values
   DBUG_RETURN(FALSE);
 }
 
-/*
-  Get column item with a proper character set according to the field
 
-  SYNOPSIS
-    get_column_item()
-    item                     Item object to start with
-    field                    Field for which the item will be compared to
+/**
+  Get column item with a proper character set according to the field.
 
-  RETURN VALUES
-    NULL                     Error
-    item                     Returned item
+  @param item   Item object to start with
+  @param field  Field for which the item will be compared to
+
+  @return Column item
+    @retval NULL  Error
+    @retval item  Returned item
 */
 
 Item* partition_info::get_column_item(Item *item, Field *field)
@@ -2224,19 +2229,18 @@ Item* partition_info::get_column_item(It
 }
 
 
-/*
-  Evaluate VALUES functions for column list values
-  SYNOPSIS
-    fix_column_value_functions()
-    thd                              Thread object
-    col_val                          List of column values
-    part_id                          Partition id we are fixing
+/**
+  Evaluate VALUES functions for column list values.
 
-  RETURN VALUES
-    TRUE                             Error
-    FALSE                            Success
-  DESCRIPTION
-    Fix column VALUES and store in memory array adapted to the data type
+  @param thd      Thread object
+  @param col_val  List of column values
+  @param part_id  Partition id we are fixing
+
+  @return Operation status
+    @retval TRUE   Error
+    @retval FALSE  Success
+  
+  @note Fix column VALUES and store in memory array adapted to the data type.
 */
 
 bool partition_info::fix_column_value_functions(THD *thd,
@@ -2306,9 +2310,11 @@ end:
   DBUG_RETURN(result);
 }
 
-/*
-  The parser generates generic data structures, we need to set them up
-  as the rest of the code expects to find them. This is in reality part
+/**
+  Fix partition data from parser.
+
+  @details The parser generates generic data structures, we need to set them
+  up as the rest of the code expects to find them. This is in reality part
   of the syntax check of the parser code.
 
   It is necessary to call this function in the case of a CREATE TABLE
@@ -2340,16 +2346,14 @@ end:
   and number of elements are in synch with each other. So only partitioning
   using functions need to be set-up to their data structures.
 
-  SYNOPSIS
-    fix_parser_data()
-    thd                      Thread object
+  @param thd  Thread object
 
-  RETURN VALUES
-    TRUE                     Failure
-    FALSE                    Success
+  @return Operation status
+    @retval TRUE   Failure
+    @retval FALSE  Success
 */
 
-int partition_info::fix_parser_data(THD *thd)
+bool partition_info::fix_parser_data(THD *thd)
 {
   List_iterator<partition_element> it(partitions);
   partition_element *part_elem;
@@ -2411,6 +2415,7 @@ int partition_info::fix_parser_data(THD
   DBUG_RETURN(FALSE);
 }
 
+
 void partition_info::print_debug(const char *str, uint *value)
 {
   DBUG_ENTER("print_debug");
@@ -2442,7 +2447,7 @@ bool partition_info::set_part_expr(char
   return FALSE;
 }
 
-int partition_info::reorganize_into_single_field_col_val()
+bool partition_info::reorganize_into_single_field_col_val()
 {
   return 0;
 }
@@ -2456,9 +2461,10 @@ bool partition_info::add_column_list_val
 {
   return FALSE;
 }
-int partition_info::add_max_value()
+
+bool partition_info::add_max_value()
 {
-  return 0;
+  return false;
 }
 
 void partition_info::print_debug(const char *str, uint *value)

=== modified file 'sql/partition_info.h'
--- a/sql/partition_info.h	2011-06-30 15:50:45 +0000
+++ b/sql/partition_info.h	2011-12-19 12:53:11 +0000
@@ -164,8 +164,8 @@ public:
   char *part_func_string;
   char *subpart_func_string;
 
-  partition_element *curr_part_elem;
-  partition_element *current_partition;
+  partition_element *curr_part_elem;     // part or sub part
+  partition_element *current_partition;  // partition
   part_elem_value *curr_list_val;
   uint curr_list_object;
   uint num_columns;
@@ -213,14 +213,14 @@ public:
   bool use_default_num_subpartitions;
   bool default_partitions_setup;
   bool defined_max_value;
-  bool list_of_part_fields;
-  bool list_of_subpart_fields;
-  bool linear_hash_ind;
+  bool list_of_part_fields;                  // KEY or COLUMNS PARTITIONING
+  bool list_of_subpart_fields;               // KEY SUBPARTITIONING
+  bool linear_hash_ind;                      // LINEAR HASH/KEY
   bool fixed;
   bool is_auto_partitioned;
   bool from_openfrm;
   bool has_null_value;
-  bool column_list;
+  bool column_list;                          // COLUMNS PARTITIONING, 5.5+
 
   partition_info()
   : get_partition_id(NULL), get_part_partition_id(NULL),
@@ -289,17 +289,17 @@ public:
   void print_no_partition_found(TABLE *table);
   void print_debug(const char *str, uint*);
   Item* get_column_item(Item *item, Field *field);
-  int fix_partition_values(THD *thd,
-                           part_elem_value *val,
-                           partition_element *part_elem,
-                           uint part_id);
+  bool fix_partition_values(THD *thd,
+                            part_elem_value *val,
+                            partition_element *part_elem,
+                            uint part_id);
   bool fix_column_value_functions(THD *thd,
                                   part_elem_value *val,
                                   uint part_id);
-  int fix_parser_data(THD *thd);
-  int add_max_value();
+  bool fix_parser_data(THD *thd);
+  bool add_max_value();
   void init_col_val(part_column_list_val *col_val, Item *item);
-  int reorganize_into_single_field_col_val();
+  bool reorganize_into_single_field_col_val();
   part_column_list_val *add_column_value();
   bool set_part_expr(char *start_token, Item *item_ptr,
                      char *end_token, bool is_subpart);

=== modified file 'sql/rpl_info_factory.cc'
--- a/sql/rpl_info_factory.cc	2011-10-13 14:01:50 +0000
+++ b/sql/rpl_info_factory.cc	2011-12-13 12:13:37 +0000
@@ -401,7 +401,9 @@ bool Rpl_info_factory::decide_repository
       If there is an error, we cannot proceed with the normal operation.
       In this case, we just pick the dest repository if check_info() has
       not failed to execute against it in order to give users the chance
-      to fix the problem and restart the server.
+      to fix the problem and restart the server. One particular case can
+      happen when there is an inplace upgrade: no source table (it did 
+      not exist in 5.5) and the default destination is a file.
 
       Notice that migration will not take place and the destination may
       be empty.
@@ -411,7 +413,9 @@ bool Rpl_info_factory::decide_repository
       sql_print_warning("Error while checking replication metadata. "
                         "Setting the requested repository in order to "
                         "give users the chance to fix the problem and "
-                        "restart the server.");
+                        "restart the server. If this is a live upgrade "
+                        "please consider using mysql_upgrade to fix the "
+                        "problem.");
       delete (*handler_src);
       *handler_src= NULL;
       info->set_rpl_info_handler(*handler_dest);
@@ -421,7 +425,12 @@ bool Rpl_info_factory::decide_repository
     }
     else
     {
-      *msg= "Error while checking replication metadata.";
+      *msg= "Error while checking replication metadata. This might also happen "
+            "when doing a live upgrade from a version that did not make use "
+            "of the replication metadata tables. If that was the case, consider "
+            "starting the server with the option --skip-slave-start which "
+            "causes the server to bypass the replication metadata tables check "
+            "while it is starting up";
       goto err;
     }
   }

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2011-11-16 01:19:40 +0000
+++ b/sql/rpl_rli.cc	2011-12-16 15:53:16 +0000
@@ -82,7 +82,7 @@ Relay_log_info::Relay_log_info(bool is_s
    rows_query_ev(NULL), last_event_start_time(0),
    slave_parallel_workers(0),
    recovery_parallel_workers(0), checkpoint_seqno(0),
-   checkpoint_group(mts_checkpoint_group), mts_recovery_group_cnt(0),
+   checkpoint_group(opt_mts_checkpoint_group), mts_recovery_group_cnt(0),
    mts_recovery_index(0), mts_recovery_group_seen_begin(0),
    mts_group_status(MTS_NOT_IN_GROUP), reported_unsafe_warning(false),
    sql_delay(0), sql_delay_end(0), m_flags(0), row_stmt_start_timestamp(0),

=== modified file 'sql/rpl_rli.h'
--- a/sql/rpl_rli.h	2011-11-21 17:46:02 +0000
+++ b/sql/rpl_rli.h	2011-12-16 15:53:16 +0000
@@ -467,7 +467,7 @@ public:
   ulong slave_parallel_workers; // the one slave session time number of workers
   ulong recovery_parallel_workers; // number of workers while recovering
   uint checkpoint_seqno;  // counter of groups executed after the most recent CP
-  uint checkpoint_group;  // number of groups in one checkpoint interval (period).
+  uint checkpoint_group;  // cache for ::opt_mts_checkpoint_group 
   MY_BITMAP recovery_groups;  // bitmap used during recovery
   ulong mts_recovery_group_cnt; // number of groups to execute at recovery
   ulong mts_recovery_index;     // running index of recoverable groups

=== modified file 'sql/rpl_rli_pdb.cc'
--- a/sql/rpl_rli_pdb.cc	2011-11-22 10:19:19 +0000
+++ b/sql/rpl_rli_pdb.cc	2011-12-16 15:53:16 +0000
@@ -430,20 +430,23 @@ bool init_hash_workers(ulong slave_paral
 {
   DBUG_ENTER("init_hash_workers");
 
-#ifdef HAVE_PSI_INTERFACE
-  mysql_mutex_init(key_mutex_slave_worker_hash, &slave_worker_hash_lock,
-                   MY_MUTEX_INIT_FAST);
-  mysql_cond_init(key_cond_slave_worker_hash, &slave_worker_hash_cond, NULL);
-#else
-  mysql_mutex_init(NULL, &slave_worker_hash_lock,
-                   MY_MUTEX_INIT_FAST);
-  mysql_cond_init(NULL, &slave_worker_hash_cond, NULL);
-#endif
-
   inited_hash_workers=
     (my_hash_init(&mapping_db_to_worker, &my_charset_bin,
                  0, 0, 0, get_key,
                  (my_hash_free_key) free_entry, 0) == 0);
+  if (inited_hash_workers)
+  {
+#ifdef HAVE_PSI_INTERFACE
+    mysql_mutex_init(key_mutex_slave_worker_hash, &slave_worker_hash_lock,
+                     MY_MUTEX_INIT_FAST);
+    mysql_cond_init(key_cond_slave_worker_hash, &slave_worker_hash_cond, NULL);
+#else
+    mysql_mutex_init(NULL, &slave_worker_hash_lock,
+                     MY_MUTEX_INIT_FAST);
+    mysql_cond_init(NULL, &slave_worker_hash_cond, NULL);
+#endif
+  }
+
   DBUG_RETURN (!inited_hash_workers);
 }
 
@@ -453,9 +456,10 @@ void destroy_hash_workers(Relay_log_info
   if (inited_hash_workers)
   {
     my_hash_free(&mapping_db_to_worker);
+    mysql_mutex_destroy(&slave_worker_hash_lock);
+    mysql_cond_destroy(&slave_worker_hash_cond);
+    inited_hash_workers= false;
   }
-  mysql_mutex_destroy(&slave_worker_hash_lock);
-  mysql_cond_destroy(&slave_worker_hash_cond);
 
   DBUG_VOID_RETURN;
 }
@@ -1173,9 +1177,9 @@ bool Slave_committed_queue::count_done(R
 
   DBUG_PRINT("mts", ("Checking if it can simulate a crash:"
              " mts_checkpoint_group %u counter %lu parallel slaves %lu\n",
-             mts_checkpoint_group, cnt, rli->slave_parallel_workers));
+             opt_mts_checkpoint_group, cnt, rli->slave_parallel_workers));
 
-  return (cnt == (rli->slave_parallel_workers * mts_checkpoint_group));
+  return (cnt == (rli->slave_parallel_workers * opt_mts_checkpoint_group));
 }
 #endif
 
@@ -1214,7 +1218,7 @@ ulong Slave_committed_queue::move_queue_
 
 #ifndef DBUG_OFF
     if (DBUG_EVALUATE_IF("check_slave_debug_group", 1, 0) &&
-        cnt == mts_checkpoint_period)
+        cnt == opt_mts_checkpoint_period)
       return cnt;
 #endif
 
@@ -1743,11 +1747,11 @@ int slave_worker_exec_job(Slave_worker *
 
 #ifndef DBUG_OFF
     DBUG_PRINT("mts", ("Check_slave_debug_group worker %lu mts_checkpoint_group"
-               " %u processed %lu debug %d\n", worker->id, mts_checkpoint_group,
+               " %u processed %lu debug %d\n", worker->id, opt_mts_checkpoint_group,
                worker->groups_done,
                DBUG_EVALUATE_IF("check_slave_debug_group", 1, 0)));
     if (DBUG_EVALUATE_IF("check_slave_debug_group", 1, 0) &&
-        mts_checkpoint_group == worker->groups_done)
+        opt_mts_checkpoint_group == worker->groups_done)
     {
       DBUG_PRINT("mts", ("Putting worker %lu in busy wait.", worker->id));
       while (true) my_sleep(6000000);

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	2011-12-02 20:46:47 +0000
+++ b/sql/rpl_slave.cc	2011-12-21 10:29:44 +0000
@@ -87,7 +87,7 @@ const char *relay_log_basename= 0;
   of Relay_log_info::gaq (see @c slave_start_workers()).
   It can be set to any value in [1, ULONG_MAX - 1] range.
 */
-const ulong mts_slave_worker_queue_len_max= 32768;
+const ulong mts_slave_worker_queue_len_max= 16384;
 
 /*
   MTS load-ballancing parameter.
@@ -340,8 +340,9 @@ int init_slave()
   /* If server id is not set, start_slave_thread() will say it */
   if (active_mi->host[0] && !opt_skip_slave_start)
   {
-    /* same as in start_slave() cache the global var value into rli's member */
+    /* same as in start_slave() cache the global var values into rli's members */
     active_mi->rli->opt_slave_parallel_workers= opt_mts_slave_parallel_workers;
+    active_mi->rli->checkpoint_group= opt_mts_checkpoint_group;
     if (start_slave_threads(1 /* need mutex */,
                             0 /* no wait for start*/,
                             active_mi,
@@ -4268,7 +4269,7 @@ bool mts_checkpoint_routine(Relay_log_in
     cnt= rli->gaq->move_queue_head(&rli->workers);
 #ifndef DBUG_OFF
     if (DBUG_EVALUATE_IF("check_slave_debug_group", 1, 0) &&
-        cnt != mts_checkpoint_period)
+        cnt != opt_mts_checkpoint_period)
       sql_print_error("This an error cnt != mts_checkpoint_period");
 #endif
   } while (!sql_slave_killed(rli->info_thd, rli) &&
@@ -4381,7 +4382,8 @@ int slave_start_single_worker(Relay_log_
   }
   set_dynamic(&rli->workers, (uchar*) &w, i);
 
-  if (pthread_create(&th, &connection_attrib, handle_slave_worker,
+  if (DBUG_EVALUATE_IF("mts_worker_thread_fails", i == 1, 0) ||
+      pthread_create(&th, &connection_attrib, handle_slave_worker,
                      (void*) w))
   {
     sql_print_error("Failed during slave worker thread create");
@@ -4397,6 +4399,18 @@ int slave_start_single_worker(Relay_log_
   insert_dynamic(&rli->least_occupied_workers, (uchar*) &w->jobs.len);
 
 err:
+  if (error && w)
+  {
+    w->end_info();
+    delete_dynamic(&w->jobs.Q);
+    delete w;
+    /*
+      Any failure after dynarray inserted must follow with deletion
+      of just created item.
+    */
+    if (rli->workers.elements == i + 1)
+      delete_dynamic_element(&rli->workers, i);
+  }
   return error;
 }
 
@@ -4408,7 +4422,7 @@ err:
    @return 0         success
            non-zero  as failure
 */
-int slave_start_workers(Relay_log_info *rli, ulong n)
+int slave_start_workers(Relay_log_info *rli, ulong n, bool *mts_inited)
 {
   uint i;
   int error= 0;
@@ -4416,6 +4430,8 @@ int slave_start_workers(Relay_log_info *
   if (n == 0) 
     return error;
 
+  *mts_inited= true;
+
   // RLI constructor time alloc/init
 
   rli->init_workers(n);
@@ -4431,7 +4447,7 @@ int slave_start_workers(Relay_log_info *
 
   /* 
      GAQ  queue holds seqno:s of scheduled groups. C polls workers in 
-     @c lwm_checkpoint_period to update GAQ (see @c next_event())
+     @c opt_mts_checkpoint_period to update GAQ (see @c next_event())
      The length of GAQ is set to be equal to checkpoint_group.
      Notice, the size matters for mts_checkpoint_routine's progress loop.
   */
@@ -4462,12 +4478,6 @@ int slave_start_workers(Relay_log_info *
   init_alloc_root(&rli->mts_coor_mem_root, NAME_LEN,
                   (MAX_DBS_IN_EVENT_MTS / 2) * NAME_LEN);
 
-  for (i= 0; i < n; i++)
-  {
-    if ((error= slave_start_single_worker(rli, i)))
-      goto err;
-  }
-
   if (init_hash_workers(n))  // MTS: mapping_db_to_worker
   {
     sql_print_error("Failed to init partitions hash");
@@ -4475,6 +4485,12 @@ int slave_start_workers(Relay_log_info *
     goto err;
   }
 
+  for (i= 0; i < n; i++)
+  {
+    if ((error= slave_start_single_worker(rli, i)))
+      goto err;
+  }
+
 err:
   rli->slave_parallel_workers= rli->workers.elements;
   // end recovery right now if mts_recovery_groups() did not find any gaps
@@ -4494,14 +4510,16 @@ err:
    worker's running_status.
    Coordinator finalizes with its MTS running status to reset few objects.
 */
-void slave_stop_workers(Relay_log_info *rli)
+void slave_stop_workers(Relay_log_info *rli, bool *mts_inited)
 {
   int i;
   THD *thd= rli->info_thd;
 
-  if (rli->slave_parallel_workers == 0) 
+  if (!*mts_inited) 
     return;
-  
+  else if (rli->slave_parallel_workers == 0)
+    goto end;
+
   /*
     In case of the "soft" graceful stop Coordinator
     guaranteed Workers were assigned with full groups so waiting
@@ -4597,6 +4615,7 @@ void slave_stop_workers(Relay_log_info *
   DBUG_ASSERT(rli->pending_jobs == 0);
   DBUG_ASSERT(rli->mts_pending_jobs_size == 0);
 
+end:
   rli->mts_group_status= Relay_log_info::MTS_NOT_IN_GROUP;
   destroy_hash_workers(rli);
   delete rli->gaq;
@@ -4606,6 +4625,7 @@ void slave_stop_workers(Relay_log_info *
   rli->deinit_workers();
   rli->slave_parallel_workers= 0;
   free_root(&rli->mts_coor_mem_root, MYF(0));
+  *mts_inited= false;
 }
 
 /**
@@ -4628,7 +4648,8 @@ pthread_handler_t handle_slave_sql(void
 
   Relay_log_info* rli = ((Master_info*)arg)->rli;
   const char *errmsg;
- 
+  bool mts_inited= false;
+
   // needs to call my_thread_init(), otherwise we get a coredump in DBUG_ stuff
   my_thread_init();
   DBUG_ENTER("handle_slave_sql");
@@ -4671,7 +4692,7 @@ pthread_handler_t handle_slave_sql(void
   mysql_mutex_unlock(&LOCK_thread_count);
 
   /* MTS: starting the worker pool */
-  if (slave_start_workers(rli, rli->opt_slave_parallel_workers) != 0)
+  if (slave_start_workers(rli, rli->opt_slave_parallel_workers, &mts_inited) != 0)
   {
     mysql_cond_broadcast(&rli->start_cond);
     mysql_mutex_unlock(&rli->run_lock);
@@ -4921,7 +4942,7 @@ llstr(rli->get_group_master_log_pos(), l
 
  err:
 
-  slave_stop_workers(rli); // stopping worker pool before clearing own error
+  slave_stop_workers(rli, &mts_inited); // stopping worker pool
 
   /*
     Some events set some playgrounds, which won't be cleared because thread
@@ -6229,9 +6250,9 @@ static Log_event* next_event(Relay_log_i
          MTS checkpoint in the successful read branch 
       */
       bool force= (rli->checkpoint_seqno > (rli->checkpoint_group - 1));
-      if (rli->is_parallel_exec() && (mts_checkpoint_period != 0 || force))
+      if (rli->is_parallel_exec() && (opt_mts_checkpoint_period != 0 || force))
       {
-        ulonglong period= static_cast<ulonglong>(mts_checkpoint_period * 1000000ULL);
+        ulonglong period= static_cast<ulonglong>(opt_mts_checkpoint_period * 1000000ULL);
         mysql_mutex_unlock(&rli->data_lock);
         /*
           At this point the coordinator has is delegating jobs to workers and
@@ -6367,12 +6388,12 @@ static Log_event* next_event(Relay_log_i
         mysql_cond_broadcast(&rli->log_space_cond);
         // Note that wait_for_update_relay_log unlocks lock_log !
 
-        if (rli->is_parallel_exec() && (mts_checkpoint_period != 0 ||
+        if (rli->is_parallel_exec() && (opt_mts_checkpoint_period != 0 ||
             DBUG_EVALUATE_IF("check_slave_debug_group", 1, 0)))
         {
           int ret= 0;
           struct timespec waittime;
-          ulonglong period= static_cast<ulonglong>(mts_checkpoint_period * 1000000ULL);
+          ulonglong period= static_cast<ulonglong>(opt_mts_checkpoint_period * 1000000ULL);
           ulong signal_cnt= rli->relay_log.signal_cnt;
 
           mysql_mutex_unlock(log_lock);
@@ -6863,10 +6884,15 @@ int start_slave(THD* thd , Master_info*
       if (thread_mask & SLAVE_SQL)
       {
         /*
-          To cache the system var value and used it in the following.
-          The system var can change but not the cached.
+          To cache the MTS system var values and used them in the following
+          runtime. The system var:s can change meanwhile but having no other
+          effects.
         */
         mi->rli->opt_slave_parallel_workers= opt_mts_slave_parallel_workers;
+#ifndef DBUG_OFF
+        if (!DBUG_EVALUATE_IF("check_slave_debug_group", 1, 0))
+#endif
+          mi->rli->checkpoint_group= opt_mts_checkpoint_group;
 
         mysql_mutex_lock(&mi->rli->data_lock);
 

=== modified file 'sql/rpl_slave.h'
--- a/sql/rpl_slave.h	2011-08-19 13:04:28 +0000
+++ b/sql/rpl_slave.h	2011-11-24 18:26:55 +0000
@@ -57,6 +57,7 @@ typedef enum { SLAVE_THD_IO, SLAVE_THD_S
 
 #define MTS_WORKER_UNDEF ((ulong) -1)
 #define MTS_MAX_WORKERS  1024
+#define MTS_MAX_BITS_IN_GROUP ((1L << 19) - 1) /* 524287 */
 
 // Forward declarations
 class Relay_log_info;

=== modified file 'sql/sql_admin.cc'
--- a/sql/sql_admin.cc	2011-07-28 10:54:44 +0000
+++ b/sql/sql_admin.cc	2011-12-19 22:31:09 +0000
@@ -417,12 +417,8 @@ static bool mysql_admin_table(THD* thd,
             my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0));
             DBUG_RETURN(TRUE);
           }
-          uint num_parts_found;
-          uint num_parts_opt= alter_info->partition_names.elements;
-          num_parts_found= set_part_state(alter_info, table->table->part_info,
-                                          PART_ADMIN);
-          if (num_parts_found != num_parts_opt &&
-              (!(alter_info->flags & ALTER_ALL_PARTITION)))
+          
+          if (set_part_state(alter_info, table->table->part_info, PART_ADMIN))
           {
             char buff[FN_REFLEN + MYSQL_ERRMSG_SIZE];
             size_t length;
@@ -453,6 +449,9 @@ static bool mysql_admin_table(THD* thd,
       case  1:           // error, message written to net
         trans_rollback_stmt(thd);
         trans_rollback(thd);
+        /* Make sure this table instance is not reused after the operation. */
+        if (table->table)
+          table->table->m_needs_reopen= true;
         close_thread_tables(thd);
         thd->mdl_context.release_transactional_locks();
         DBUG_PRINT("admin", ("simple error, admin next table"));
@@ -525,6 +524,9 @@ static bool mysql_admin_table(THD* thd,
       protocol->store(buff, length, system_charset_info);
       trans_commit_stmt(thd);
       trans_commit(thd);
+      /* Make sure this table instance is not reused after the operation. */
+      if (table->table)
+        table->table->m_needs_reopen= true;
       close_thread_tables(thd);
       thd->mdl_context.release_transactional_locks();
       lex->reset_query_tables_list(FALSE);
@@ -601,6 +603,9 @@ static bool mysql_admin_table(THD* thd,
 
         trans_rollback_stmt(thd);
         trans_rollback(thd);
+        /* Make sure this table instance is not reused after the operation. */
+        if (table->table)
+          table->table->m_needs_reopen= true;
         close_thread_tables(thd);
         thd->mdl_context.release_transactional_locks();
 
@@ -821,6 +826,9 @@ send_result_message:
           }
           thd->clear_error();
         }
+        /* Make sure this table instance is not reused after the operation. */
+        if (table->table)
+          table->table->m_needs_reopen= true;
       }
       result_code= result_code ? HA_ADMIN_FAILED : HA_ADMIN_OK;
       table->next_local= save_next_local;
@@ -920,6 +928,9 @@ send_result_message:
 err:
   trans_rollback_stmt(thd);
   trans_rollback(thd);
+  /* Make sure this table instance is not reused after the operation. */
+  if (table->table)
+    table->table->m_needs_reopen= true;
   close_thread_tables(thd);			// Shouldn't be needed
   thd->mdl_context.release_transactional_locks();
   DBUG_RETURN(TRUE);

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2011-12-14 12:32:55 +0000
+++ b/sql/sql_base.cc	2011-12-19 11:42:11 +0000
@@ -2845,7 +2845,7 @@ bool open_table(THD *thd, TABLE_LIST *ta
       if (dd_frm_type(thd, path, &not_used) == FRMTYPE_VIEW)
       {
         if (!tdc_open_view(thd, table_list, alias, key, key_length,
-                           mem_root, 0))
+                           mem_root, CHECK_METADATA_VERSION))
         {
           DBUG_ASSERT(table_list->view != 0);
           DBUG_RETURN(FALSE); // VIEW
@@ -2983,6 +2983,11 @@ retry_share:
     DBUG_RETURN(TRUE);
   }
 
+  /*
+    Check if this TABLE_SHARE-object corresponds to a view. Note, that there is
+    no need to call TABLE_SHARE::has_old_version() as we do for regular tables,
+    because view shares are always up to date.
+  */
   if (share->is_view)
   {
     /*
@@ -3819,6 +3824,24 @@ bool tdc_open_view(THD *thd, TABLE_LIST
                                hash_value)))
     goto err;
 
+  if ((flags & CHECK_METADATA_VERSION))
+  {
+    /*
+      Check TABLE_SHARE-version of view only if we have been instructed to do
+      so. We do not need to check the version if we're executing CREATE VIEW or
+      ALTER VIEW statements.
+
+      In the future, this functionality should be moved out from
+      tdc_open_view(), and  tdc_open_view() should became a part of a clean
+      table-definition-cache interface.
+    */
+    if (check_and_update_table_version(thd, table_list, share))
+    {
+      release_table_share(share);
+      goto err;
+    }
+  }
+
   if (share->is_view &&
       !open_new_frm(thd, share, alias,
                     (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |

=== modified file 'sql/sql_executor.cc'
--- a/sql/sql_executor.cc	2011-12-15 09:00:42 +0000
+++ b/sql/sql_executor.cc	2011-12-19 09:53:30 +0000
@@ -1738,6 +1738,7 @@ sub_select_sjm(JOIN *join, JOIN_TAB *joi
     last_tab->read_record.copy_field_end= sjm->copy_field +
                                           sjm->table_cols.elements;
     last_tab->read_record.read_record= rr_sequential_and_unpack;
+    DBUG_ASSERT(last_tab->read_record.unlock_row == rr_unlock_row);
 
     // Clear possible outer join information from earlier use of this join tab
     last_tab->last_inner= NULL;
@@ -3188,35 +3189,41 @@ pick_table_access_method(JOIN_TAB *tab)
   case JT_REF:
     tab->read_first_record= join_read_always_key;
     tab->read_record.read_record= join_read_next_same;
+    tab->read_record.unlock_row= rr_unlock_row;
     break;
 
   case JT_REF_OR_NULL:
     tab->read_first_record= join_read_always_key_or_null;
     tab->read_record.read_record= join_read_next_same_or_null;
+    tab->read_record.unlock_row= rr_unlock_row;
     break;
 
   case JT_CONST:
     tab->read_first_record= join_read_const;
     tab->read_record.read_record= join_no_more_records;
+    tab->read_record.unlock_row= rr_unlock_row;
     break;
 
   case JT_EQ_REF:
     tab->read_first_record= join_read_key;
     tab->read_record.read_record= join_no_more_records;
+    tab->read_record.unlock_row= join_read_key_unlock_row;
     break;
 
   case JT_FT:
     tab->read_first_record= join_ft_read_first;
     tab->read_record.read_record= join_ft_read_next;
+    tab->read_record.unlock_row= rr_unlock_row;
     break;
 
   case JT_SYSTEM:
     tab->read_first_record= join_read_system;
     tab->read_record.read_record= join_no_more_records;
+    tab->read_record.unlock_row= rr_unlock_row;
     break;
 
-  /* keep gcc happy */  
   default:
+    tab->read_record.unlock_row= rr_unlock_row;
     break;  
   }
 }

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2011-12-15 12:13:36 +0000
+++ b/sql/sql_partition.cc	2011-12-19 13:21:37 +0000
@@ -4550,11 +4550,20 @@ error:
 }
 
 
-/*
-  Sets which partitions to be used in the command
+/**
+  Sets which partitions to be used in the command.
+
+  @param alter_info     Alter_info pointer holding partition names and flags.
+  @param tab_part_info  partition_info holding all partitions.
+  @param part_state     Which state to set for the named partitions.
+
+  @return Operation status
+    @retval false  Success
+    @retval true   Failure
 */
-uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
-               enum partition_state part_state)
+
+bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
+                    enum partition_state part_state)
 {
   uint part_count= 0;
   uint num_parts_found= 0;
@@ -4580,7 +4589,21 @@ uint set_part_state(Alter_info *alter_in
     else
       part_elem->part_state= PART_NORMAL;
   } while (++part_count < tab_part_info->num_parts);
-  return num_parts_found;
+
+  if (num_parts_found != alter_info->partition_names.elements &&
+      !(alter_info->flags & ALTER_ALL_PARTITION))
+  {
+    /* Not all given partitions found, revert and return failure */
+    part_it.rewind();
+    part_count= 0;
+    do
+    {
+      partition_element *part_elem= part_it++;
+      part_elem->part_state= PART_NORMAL;
+    } while (++part_count < tab_part_info->num_parts);
+    return true;
+  }
+  return false;
 }
 
 
@@ -5149,11 +5172,7 @@ that are reorganised.
     }
     else if (alter_info->flags & ALTER_REBUILD_PARTITION)
     {
-      uint num_parts_found;
-      uint num_parts_opt= alter_info->partition_names.elements;
-      num_parts_found= set_part_state(alter_info, tab_part_info, PART_CHANGED);
-      if (num_parts_found != num_parts_opt &&
-          (!(alter_info->flags & ALTER_ALL_PARTITION)))
+      if (set_part_state(alter_info, tab_part_info, PART_CHANGED))
       {
         my_error(ER_DROP_PARTITION_NON_EXISTENT, MYF(0), "REBUILD");
         goto err;

=== modified file 'sql/sql_partition.h'
--- a/sql/sql_partition.h	2011-06-30 15:50:45 +0000
+++ b/sql/sql_partition.h	2011-11-08 12:55:37 +0000
@@ -250,7 +250,7 @@ uint fast_alter_partition_table(THD *thd
                                 char *db,
                                 const char *table_name,
                                 TABLE  *fast_alter_table);
-uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
+bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
                     enum partition_state part_state);
 uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
                            HA_CREATE_INFO *create_info,

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-12-15 17:14:28 +0000
+++ b/sql/sql_select.cc	2011-12-19 09:53:30 +0000
@@ -2672,7 +2672,6 @@ make_join_readinfo(JOIN *join, ulonglong
     TABLE    *const table= tab->table;
     bool icp_other_tables_ok;
     tab->read_record.table= table;
-    tab->read_record.unlock_row= rr_unlock_row;
     tab->next_select=sub_select;		/* normal select */
     tab->cache_idx_cond= 0;
     /*
@@ -2706,8 +2705,6 @@ make_join_readinfo(JOIN *join, ulonglong
     }
     switch (tab->type) {
     case JT_EQ_REF:
-      tab->read_record.unlock_row= join_read_key_unlock_row;
-      /* fall through */
     case JT_REF_OR_NULL:
     case JT_REF:
       if (tab->select)
@@ -4049,6 +4046,7 @@ check_reverse_order:
         */
         tab->read_first_record= join_read_last_key;
         tab->read_record.read_record= join_read_prev_same;
+        tab->read_record.unlock_row= rr_unlock_row;
       }
     }
     else if (select && select->quick)

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2011-12-09 08:59:22 +0000
+++ b/sql/sql_view.cc	2011-12-19 11:42:11 +0000
@@ -675,6 +675,15 @@ bool mysql_create_view(THD *thd, TABLE_L
 
   res= mysql_register_view(thd, view, mode);
 
+  /*
+    View TABLE_SHARE must be removed from the table definition cache in order to
+    make ALTER VIEW work properly. Otherwise, we would not be able to detect
+    meta-data changes after ALTER VIEW.
+  */
+
+  if (!res)
+    tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db, view->table_name, false);
+
   if (mysql_bin_log.is_open())
   {
     String buff;

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2011-12-14 15:55:30 +0000
+++ b/sql/sql_yacc.yy	2011-12-19 12:53:11 +0000
@@ -5029,7 +5029,7 @@ part_values_in:
                 arrays with one entry in each array. This can happen
                 in the first partition of an ALTER TABLE statement where
                 we ADD or REORGANIZE partitions. Also can only happen
-                for LIST partitions.
+                for LIST [COLUMNS] partitions.
               */
               if (part_info->reorganize_into_single_field_col_val())
               {

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	2011-12-20 12:47:29 +0000
+++ b/sql/sys_vars.cc	2011-12-26 07:06:05 +0000
@@ -3652,7 +3652,7 @@ static Sys_var_uint Sys_checkpoint_mts_p
        "slave_checkpoint_period", "Gather workers' activities to "
        "Update progress status of Multi-threaded slave and flush "
        "the relay log info to disk after every #th milli-seconds.",
-       GLOBAL_VAR(mts_checkpoint_period), CMD_LINE(REQUIRED_ARG),
+       GLOBAL_VAR(opt_mts_checkpoint_period), CMD_LINE(REQUIRED_ARG),
 #ifndef DBUG_OFF
        VALID_RANGE(0, UINT_MAX), DEFAULT(300), BLOCK_SIZE(1));
 #else
@@ -3663,11 +3663,11 @@ static Sys_var_uint Sys_checkpoint_mts_g
        "slave_checkpoint_group",
        "Maximum number of processed transactions by Multi-threaded slave "
        "before a checkpoint operation is called to update progress status.",
-       GLOBAL_VAR(mts_checkpoint_group), CMD_LINE(REQUIRED_ARG),
+       GLOBAL_VAR(opt_mts_checkpoint_group), CMD_LINE(REQUIRED_ARG),
 #ifndef DBUG_OFF
-       VALID_RANGE(1, UINT_MAX), DEFAULT(512), BLOCK_SIZE(1));
+       VALID_RANGE(1, MTS_MAX_BITS_IN_GROUP), DEFAULT(512), BLOCK_SIZE(1));
 #else
-       VALID_RANGE(512, UINT_MAX), DEFAULT(512), BLOCK_SIZE(8));
+       VALID_RANGE(512, MTS_MAX_BITS_IN_GROUP), DEFAULT(512), BLOCK_SIZE(1));
 #endif /* DBUG_OFF */
 #endif /* HAVE_REPLICATION */
 

=== modified file 'sql/table.h'
--- a/sql/table.h	2011-12-15 12:12:14 +0000
+++ b/sql/table.h	2011-12-19 11:42:11 +0000
@@ -867,7 +867,7 @@ struct TABLE_SHARE
   }
   /**
     Return a table metadata version.
-     * for base tables, we return table_map_id.
+     * for base tables and views, we return table_map_id.
        It is assigned from a global counter incremented for each
        new table loaded into the table definition cache (TDC).
      * for temporary tables it's table_map_id again. But for
@@ -876,7 +876,7 @@ struct TABLE_SHARE
        counter incremented for every new SQL statement. Since
        temporary tables are thread-local, each temporary table
        gets a unique id.
-     * for everything else (views, information schema tables),
+     * for everything else (e.g. information schema tables),
        the version id is zero.
 
    This choice of version id is a large compromise
@@ -891,8 +891,8 @@ struct TABLE_SHARE
    version id of a temporary table is never compared with
    a version id of a view, and vice versa.
 
-   Secondly, for base tables, we know that each DDL flushes the
-   respective share from the TDC. This ensures that whenever
+   Secondly, for base tables and views, we know that each DDL flushes
+   the respective share from the TDC. This ensures that whenever
    a table is altered or dropped and recreated, it gets a new
    version id.
    Unfortunately, since elements of the TDC are also flushed on
@@ -913,26 +913,6 @@ struct TABLE_SHARE
    Metadata of information schema tables never changes.
    Thus we can safely assume 0 for a good enough version id.
 
-   Views are a special and tricky case. A view is always inlined
-   into the parse tree of a prepared statement at prepare.
-   Thus, when we execute a prepared statement, the parse tree
-   will not get modified even if the view is replaced with another
-   view.  Therefore, we can safely choose 0 for version id of
-   views and effectively never invalidate a prepared statement
-   when a view definition is altered. Note, that this leads to
-   wrong binary log in statement-based replication, since we log
-   prepared statement execution in form Query_log_events
-   containing conventional statements. But since there is no
-   metadata locking for views, the very same problem exists for
-   conventional statements alone, as reported in Bug#25144. The only
-   difference between prepared and conventional execution is,
-   effectively, that for prepared statements the race condition
-   window is much wider.
-   In 6.0 we plan to support view metadata locking (WL#3726) and
-   extend table definition cache to cache views (WL#4298).
-   When this is done, views will be handled in the same fashion
-   as the base tables.
-
    Finally, by taking into account table type, we always
    track that a change has taken place when a view is replaced
    with a base table, a base table is replaced with a temporary
@@ -942,7 +922,7 @@ struct TABLE_SHARE
   */
   ulong get_table_ref_version() const
   {
-    return (tmp_table == SYSTEM_TMP_TABLE || is_view) ? 0 : table_map_id;
+    return (tmp_table == SYSTEM_TMP_TABLE) ? 0 : table_map_id;
   }
 
   bool visit_subgraph(Wait_for_flush *waiting_ticket,

=== modified file 'sql/unireg.h'
--- a/sql/unireg.h	2011-10-12 13:30:13 +0000
+++ b/sql/unireg.h	2011-12-19 11:42:11 +0000
@@ -134,11 +134,14 @@ typedef struct st_ha_create_information
   The flag means that I_S table uses optimization algorithm.
 */
 #define OPTIMIZE_I_S_TABLE     OPEN_VIEW_FULL*2
-
-/*
+/**
   The flag means that we need to process trigger files only.
 */
 #define OPEN_TRIGGER_ONLY      OPTIMIZE_I_S_TABLE*2
+/**
+  This flag is used to instruct tdc_open_view() to check metadata version.
+*/
+#define CHECK_METADATA_VERSION OPEN_TRIGGER_ONLY*2
 
 #define SC_INFO_LENGTH 4		/* Form format constant */
 #define TE_INFO_LENGTH 3

=== modified file 'storage/federated/ha_federated.cc'
--- a/storage/federated/ha_federated.cc	2011-11-17 13:41:28 +0000
+++ b/storage/federated/ha_federated.cc	2011-12-23 15:00:18 +0000
@@ -1683,6 +1683,16 @@ int ha_federated::close(void)
   mysql_close(mysql);
   mysql= NULL;
 
+  /*
+    mysql_close() might return an error if a remote server's gone
+    for some reason. If that happens while removing a table from
+    the table cache, the error will be propagated to a client even
+    if the original query was not issued against the FEDERATED table.
+    So, don't propagate errors from mysql_close().
+  */
+  if (table->in_use)
+    table->in_use->clear_error();
+
   DBUG_RETURN(free_share(share));
 }
 

=== modified file 'storage/innobase/CMakeLists.txt'
--- a/storage/innobase/CMakeLists.txt	2011-11-30 10:09:12 +0000
+++ b/storage/innobase/CMakeLists.txt	2011-12-23 13:17:36 +0000
@@ -231,6 +231,7 @@ SET(INNOBASE_SOURCES
 	btr/btr0sea.cc
 	buf/buf0buddy.cc
 	buf/buf0buf.cc
+	buf/buf0dblwr.cc
 	buf/buf0checksum.cc
 	buf/buf0dump.cc
 	buf/buf0flu.cc

=== modified file 'storage/innobase/buf/buf0buf.cc'
--- a/storage/innobase/buf/buf0buf.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/buf/buf0buf.cc	2011-12-23 13:17:36 +0000
@@ -3902,7 +3902,7 @@ buf_page_io_complete(
 			frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
 
 		if (bpage->space == TRX_SYS_SPACE
-		    && trx_doublewrite_page_inside(bpage->offset)) {
+		    && buf_dblwr_page_inside(bpage->offset)) {
 
 			ut_print_timestamp(stderr);
 			fprintf(stderr,

=== added file 'storage/innobase/buf/buf0dblwr.cc'
--- a/storage/innobase/buf/buf0dblwr.cc	1970-01-01 00:00:00 +0000
+++ b/storage/innobase/buf/buf0dblwr.cc	2011-12-23 13:17:36 +0000
@@ -0,0 +1,1112 @@
+/*****************************************************************************
+
+Copyright (c) 1995, 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 Street, Suite 500, Boston, MA 02110-1335 USA
+
+*****************************************************************************/
+
+/**************************************************//**
+@file buf/buf0dblwr.cc
+Doublwrite buffer module
+
+Created 2011/12/19
+*******************************************************/
+
+#include "buf0dblwr.h"
+
+#ifdef UNIV_NONINL
+#include "buf0buf.ic"
+#endif
+
+#include "buf0buf.h"
+#include "buf0checksum.h"
+#include "srv0start.h"
+#include "srv0srv.h"
+#include "page0zip.h"
+#include "trx0sys.h"
+
+#ifndef UNIV_HOTBACKUP
+
+/** Time in milliseconds that we sleep when unable to find a slot in
+the doublewrite buffer or when we have to wait for a running batch
+to end. */
+#define TRX_DOUBLEWRITE_BATCH_POLL_DELAY	10000
+
+#ifdef UNIV_PFS_MUTEX
+/* Key to register the mutex with performance schema */
+UNIV_INTERN mysql_pfs_key_t	buf_dblwr_mutex_key;
+#endif /* UNIV_PFS_RWLOCK */
+
+/** The doublewrite buffer */
+UNIV_INTERN buf_dblwr_t*	buf_dblwr = NULL;
+
+/** Set to TRUE when the doublewrite buffer is being created */
+UNIV_INTERN ibool	buf_dblwr_being_created = FALSE;
+
+/****************************************************************//**
+Determines if a page number is located inside the doublewrite buffer.
+@return TRUE if the location is inside the two blocks of the
+doublewrite buffer */
+UNIV_INTERN
+ibool
+buf_dblwr_page_inside(
+/*==================*/
+	ulint	page_no)	/*!< in: page number */
+{
+	if (buf_dblwr == NULL) {
+
+		return(FALSE);
+	}
+
+	if (page_no >= buf_dblwr->block1
+	    && page_no < buf_dblwr->block1
+	    + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
+		return(TRUE);
+	}
+
+	if (page_no >= buf_dblwr->block2
+	    && page_no < buf_dblwr->block2
+	    + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
+		return(TRUE);
+	}
+
+	return(FALSE);
+}
+
+/****************************************************************//**
+Calls buf_page_get() on the TRX_SYS_PAGE and returns a pointer to the
+doublewrite buffer within it.
+@return	pointer to the doublewrite buffer within the filespace header
+page. */
+UNIV_INLINE
+byte*
+buf_dblwr_get(
+/*==========*/
+	mtr_t*	mtr)	/*!< in/out: MTR to hold the page latch */
+{
+	buf_block_t*	block;
+
+	block = buf_page_get(TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO,
+			     RW_X_LATCH, mtr);
+	buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
+
+	return(buf_block_get_frame(block) + TRX_SYS_DOUBLEWRITE);
+}
+
+
+/****************************************************************//**
+Creates or initialializes the doublewrite buffer at a database start. */
+static
+void
+buf_dblwr_init(
+/*===========*/
+	byte*	doublewrite)	/*!< in: pointer to the doublewrite buf
+				header on trx sys page */
+{
+	ulint	buf_size;
+
+	buf_dblwr = static_cast<buf_dblwr_t*>(
+		mem_zalloc(sizeof(buf_dblwr_t)));
+
+	/* There are two blocks of same size in the doublewrite
+	buffer. */
+	buf_size = 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
+
+	/* There must be atleast one buffer for single page writes
+	and one buffer for batch writes. */
+	ut_a(srv_doublewrite_batch_size > 0
+	     && srv_doublewrite_batch_size < buf_size);
+
+	mutex_create(buf_dblwr_mutex_key,
+		     &buf_dblwr->mutex, SYNC_DOUBLEWRITE);
+
+	buf_dblwr->first_free = 0;
+	buf_dblwr->s_reserved = 0;
+	buf_dblwr->b_reserved = 0;
+
+	buf_dblwr->block1 = mach_read_from_4(
+		doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
+	buf_dblwr->block2 = mach_read_from_4(
+		doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK2);
+
+	buf_dblwr->in_use = static_cast<ibool*>(
+		mem_zalloc(buf_size * sizeof(ibool)));
+
+	buf_dblwr->write_buf_unaligned = static_cast<byte*>(
+		ut_malloc((1 + buf_size) * UNIV_PAGE_SIZE));
+
+	buf_dblwr->write_buf = static_cast<byte*>(
+		ut_align(buf_dblwr->write_buf_unaligned,
+			 UNIV_PAGE_SIZE));
+
+	buf_dblwr->buf_block_arr = static_cast<buf_page_t**>(
+		mem_zalloc(buf_size * sizeof(void*)));
+}
+
+/****************************************************************//**
+Creates the doublewrite buffer to a new InnoDB installation. The header of the
+doublewrite buffer is placed on the trx system header page. */
+UNIV_INTERN
+void
+buf_dblwr_create(void)
+/*==================*/
+{
+	buf_block_t*	block2;
+#ifdef UNIV_SYNC_DEBUG
+	buf_block_t*	new_block;
+#endif /* UNIV_SYNC_DEBUG */
+	byte*	doublewrite;
+	byte*	fseg_header;
+	ulint	page_no;
+	ulint	prev_page_no;
+	ulint	i;
+	mtr_t	mtr;
+
+	if (buf_dblwr) {
+		/* Already inited */
+
+		return;
+	}
+
+start_again:
+	mtr_start(&mtr);
+	buf_dblwr_being_created = TRUE;
+
+	doublewrite = buf_dblwr_get(&mtr);
+
+	if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
+	    == TRX_SYS_DOUBLEWRITE_MAGIC_N) {
+		/* The doublewrite buffer has already been created:
+		just read in some numbers */
+
+		buf_dblwr_init(doublewrite);
+
+		mtr_commit(&mtr);
+		buf_dblwr_being_created = FALSE;
+		return;
+	}
+
+	ut_print_timestamp(stderr);
+	fprintf(stderr,
+		" InnoDB: Doublewrite buffer not found:"
+		" creating new\n");
+
+	if (buf_pool_get_curr_size()
+	    < ((2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
+		+ FSP_EXTENT_SIZE / 2 + 100)
+	       * UNIV_PAGE_SIZE)) {
+		fprintf(stderr,
+			"InnoDB: Cannot create doublewrite buffer:"
+			" you must\n"
+			"InnoDB: increase your buffer pool size.\n"
+			"InnoDB: Cannot continue operation.\n");
+
+		exit(1);
+	}
+
+	block2 = fseg_create(TRX_SYS_SPACE, TRX_SYS_PAGE_NO,
+			     TRX_SYS_DOUBLEWRITE
+			     + TRX_SYS_DOUBLEWRITE_FSEG, &mtr);
+
+	/* fseg_create acquires a second latch on the page,
+	therefore we must declare it: */
+
+	buf_block_dbg_add_level(block2, SYNC_NO_ORDER_CHECK);
+
+	if (block2 == NULL) {
+		fprintf(stderr,
+			"InnoDB: Cannot create doublewrite buffer:"
+			" you must\n"
+			"InnoDB: increase your tablespace size.\n"
+			"InnoDB: Cannot continue operation.\n");
+
+		/* We exit without committing the mtr to prevent
+		its modifications to the database getting to disk */
+
+		exit(1);
+	}
+
+	fseg_header = doublewrite + TRX_SYS_DOUBLEWRITE_FSEG;
+	prev_page_no = 0;
+
+	for (i = 0; i < 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
+		     + FSP_EXTENT_SIZE / 2; i++) {
+		page_no = fseg_alloc_free_page(fseg_header,
+					       prev_page_no + 1,
+					       FSP_UP, &mtr);
+		if (page_no == FIL_NULL) {
+			fprintf(stderr,
+				"InnoDB: Cannot create doublewrite"
+				" buffer: you must\n"
+				"InnoDB: increase your"
+				" tablespace size.\n"
+				"InnoDB: Cannot continue operation.\n"
+				);
+
+			exit(1);
+		}
+
+		/* We read the allocated pages to the buffer pool;
+		when they are written to disk in a flush, the space
+		id and page number fields are also written to the
+		pages. When we at database startup read pages
+		from the doublewrite buffer, we know that if the
+		space id and page number in them are the same as
+		the page position in the tablespace, then the page
+		has not been written to in doublewrite. */
+
+#ifdef UNIV_SYNC_DEBUG
+		new_block =
+#endif /* UNIV_SYNC_DEBUG */
+		buf_page_get(TRX_SYS_SPACE, 0, page_no,
+			     RW_X_LATCH, &mtr);
+		buf_block_dbg_add_level(new_block,
+					SYNC_NO_ORDER_CHECK);
+
+		if (i == FSP_EXTENT_SIZE / 2) {
+			ut_a(page_no == FSP_EXTENT_SIZE);
+			mlog_write_ulint(doublewrite
+					 + TRX_SYS_DOUBLEWRITE_BLOCK1,
+					 page_no, MLOG_4BYTES, &mtr);
+			mlog_write_ulint(doublewrite
+					 + TRX_SYS_DOUBLEWRITE_REPEAT
+					 + TRX_SYS_DOUBLEWRITE_BLOCK1,
+					 page_no, MLOG_4BYTES, &mtr);
+
+		} else if (i == FSP_EXTENT_SIZE / 2
+			   + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
+			ut_a(page_no == 2 * FSP_EXTENT_SIZE);
+			mlog_write_ulint(doublewrite
+					 + TRX_SYS_DOUBLEWRITE_BLOCK2,
+					 page_no, MLOG_4BYTES, &mtr);
+			mlog_write_ulint(doublewrite
+					 + TRX_SYS_DOUBLEWRITE_REPEAT
+					 + TRX_SYS_DOUBLEWRITE_BLOCK2,
+					 page_no, MLOG_4BYTES, &mtr);
+
+		} else if (i > FSP_EXTENT_SIZE / 2) {
+			ut_a(page_no == prev_page_no + 1);
+		}
+
+		if (((i + 1) & 15) == 0) {
+			/* rw_locks can only be recursively x-locked
+			2048 times. (on 32 bit platforms,
+			(lint) 0 - (X_LOCK_DECR * 2049)
+			is no longer a negative number, and thus
+			lock_word becomes like a shared lock).
+			For 4k page size this loop will
+			lock the fseg header too many times. Since
+			this code is not done while any other threads
+			are active, restart the MTR occasionally. */
+			mtr_commit(&mtr);
+			mtr_start(&mtr);
+			doublewrite = buf_dblwr_get(&mtr);
+			fseg_header = doublewrite
+				      + TRX_SYS_DOUBLEWRITE_FSEG;
+		}
+
+		prev_page_no = page_no;
+	}
+
+	mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC,
+			 TRX_SYS_DOUBLEWRITE_MAGIC_N,
+			 MLOG_4BYTES, &mtr);
+	mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC
+			 + TRX_SYS_DOUBLEWRITE_REPEAT,
+			 TRX_SYS_DOUBLEWRITE_MAGIC_N,
+			 MLOG_4BYTES, &mtr);
+
+	mlog_write_ulint(doublewrite
+			 + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED,
+			 TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
+			 MLOG_4BYTES, &mtr);
+	mtr_commit(&mtr);
+
+	/* Flush the modified pages to disk and make a checkpoint */
+	log_make_checkpoint_at(LSN_MAX, TRUE);
+
+	/* Remove doublewrite pages from LRU */
+	buf_pool_invalidate();
+
+	ut_print_timestamp(stderr);
+	fprintf(stderr, " InnoDB: Doublewrite buffer created\n");
+
+	goto start_again;
+}
+
+/****************************************************************//**
+At a database startup initializes the doublewrite buffer memory structure if
+we already have a doublewrite buffer created in the data files. If we are
+upgrading to an InnoDB version which supports multiple tablespaces, then this
+function performs the necessary update operations. If we are in a crash
+recovery, this function uses a possible doublewrite buffer to restore
+half-written pages in the data files. */
+UNIV_INTERN
+void
+buf_dblwr_init_or_restore_pages(
+/*============================*/
+	ibool	restore_corrupt_pages)	/*!< in: TRUE=restore pages */
+{
+	byte*	buf;
+	byte*	read_buf;
+	byte*	unaligned_read_buf;
+	ulint	block1;
+	ulint	block2;
+	byte*	page;
+	ibool	reset_space_ids = FALSE;
+	byte*	doublewrite;
+	ulint	space_id;
+	ulint	page_no;
+	ulint	i;
+
+	/* We do the file i/o past the buffer pool */
+
+	unaligned_read_buf = static_cast<byte*>(ut_malloc(2 * UNIV_PAGE_SIZE));
+
+	read_buf = static_cast<byte*>(
+		ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
+
+	/* Read the trx sys header to check if we are using the doublewrite
+	buffer */
+
+	fil_io(OS_FILE_READ, TRUE, TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO, 0,
+	       UNIV_PAGE_SIZE, read_buf, NULL);
+	doublewrite = read_buf + TRX_SYS_DOUBLEWRITE;
+
+	if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
+	    == TRX_SYS_DOUBLEWRITE_MAGIC_N) {
+		/* The doublewrite buffer has been created */
+
+		buf_dblwr_init(doublewrite);
+
+		block1 = buf_dblwr->block1;
+		block2 = buf_dblwr->block2;
+
+		buf = buf_dblwr->write_buf;
+	} else {
+		goto leave_func;
+	}
+
+	if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED)
+	!= TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N) {
+
+		/* We are upgrading from a version < 4.1.x to a version where
+		multiple tablespaces are supported. We must reset the space id
+		field in the pages in the doublewrite buffer because starting
+		from this version the space id is stored to
+		FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */
+
+		reset_space_ids = TRUE;
+
+		fprintf(stderr,
+			"InnoDB: Resetting space id's in the"
+			" doublewrite buffer\n");
+	}
+
+	/* Read the pages from the doublewrite buffer to memory */
+
+	fil_io(OS_FILE_READ, TRUE, TRX_SYS_SPACE, 0, block1, 0,
+	       TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE,
+	       buf, NULL);
+	fil_io(OS_FILE_READ, TRUE, TRX_SYS_SPACE, 0, block2, 0,
+	       TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE,
+	       buf + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE,
+	       NULL);
+	/* Check if any of these pages is half-written in data files, in the
+	intended position */
+
+	page = buf;
+
+	for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * 2; i++) {
+
+		ulint source_page_no;
+		page_no = mach_read_from_4(page + FIL_PAGE_OFFSET);
+
+		if (reset_space_ids) {
+
+			space_id = 0;
+			mach_write_to_4(page
+					+ FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0);
+			/* We do not need to calculate new checksums for the
+			pages because the field .._SPACE_ID does not affect
+			them. Write the page back to where we read it from. */
+
+			if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
+				source_page_no = block1 + i;
+			} else {
+				source_page_no = block2
+					+ i - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
+			}
+
+			fil_io(OS_FILE_WRITE, TRUE, 0, 0, source_page_no, 0,
+			       UNIV_PAGE_SIZE, page, NULL);
+		} else {
+
+			space_id = mach_read_from_4(
+				page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
+		}
+
+		if (!restore_corrupt_pages) {
+			/* The database was shut down gracefully: no need to
+			restore pages */
+
+		} else if (!fil_tablespace_exists_in_mem(space_id)) {
+			/* Maybe we have dropped the single-table tablespace
+			and this page once belonged to it: do nothing */
+
+		} else if (!fil_check_adress_in_tablespace(space_id,
+							   page_no)) {
+			fprintf(stderr,
+				"InnoDB: Warning: a page in the"
+				" doublewrite buffer is not within space\n"
+				"InnoDB: bounds; space id %lu"
+				" page number %lu, page %lu in"
+				" doublewrite buf.\n",
+				(ulong) space_id, (ulong) page_no, (ulong) i);
+
+		} else if (space_id == TRX_SYS_SPACE
+			   && ((page_no >= block1
+				&& page_no
+				< block1 + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
+			       || (page_no >= block2
+				   && page_no
+				   < (block2
+				      + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)))) {
+
+			/* It is an unwritten doublewrite buffer page:
+			do nothing */
+		} else {
+			ulint	zip_size = fil_space_get_zip_size(space_id);
+
+			/* Read in the actual page from the file */
+			fil_io(OS_FILE_READ, TRUE, space_id, zip_size,
+			       page_no, 0,
+			       zip_size ? zip_size : UNIV_PAGE_SIZE,
+			       read_buf, NULL);
+
+			/* Check if the page is corrupt */
+
+			if (UNIV_UNLIKELY
+			    (buf_page_is_corrupted(read_buf, zip_size))) {
+
+				fprintf(stderr,
+					"InnoDB: Warning: database page"
+					" corruption or a failed\n"
+					"InnoDB: file read of"
+					" space %lu page %lu.\n"
+					"InnoDB: Trying to recover it from"
+					" the doublewrite buffer.\n",
+					(ulong) space_id, (ulong) page_no);
+
+				if (buf_page_is_corrupted(page, zip_size)) {
+					fprintf(stderr,
+						"InnoDB: Dump of the page:\n");
+					buf_page_print(read_buf, zip_size);
+					fprintf(stderr,
+						"InnoDB: Dump of"
+						" corresponding page"
+						" in doublewrite buffer:\n");
+					buf_page_print(page, zip_size);
+
+					fprintf(stderr,
+						"InnoDB: Also the page in the"
+						" doublewrite buffer"
+						" is corrupt.\n"
+						"InnoDB: Cannot continue"
+						" operation.\n"
+						"InnoDB: You can try to"
+						" recover the database"
+						" with the my.cnf\n"
+						"InnoDB: option:\n"
+						"InnoDB:"
+						" innodb_force_recovery=6\n");
+					exit(1);
+				}
+
+				/* Write the good page from the
+				doublewrite buffer to the intended
+				position */
+
+				fil_io(OS_FILE_WRITE, TRUE, space_id,
+				       zip_size, page_no, 0,
+				       zip_size ? zip_size : UNIV_PAGE_SIZE,
+				       page, NULL);
+				fprintf(stderr,
+					"InnoDB: Recovered the page from"
+					" the doublewrite buffer.\n");
+			}
+		}
+
+		page += UNIV_PAGE_SIZE;
+	}
+
+	fil_flush_file_spaces(FIL_TABLESPACE);
+
+leave_func:
+	ut_free(unaligned_read_buf);
+}
+
+/****************************************************************//**
+Frees doublewrite buffer. */
+UNIV_INTERN
+void
+buf_dblwr_free(void)
+/*================*/
+{
+	/* Free the double write data structures. */
+	ut_a(buf_dblwr != NULL);
+	ut_ad(buf_dblwr->s_reserved == 0);
+	ut_ad(buf_dblwr->b_reserved == 0);
+
+	ut_free(buf_dblwr->write_buf_unaligned);
+	buf_dblwr->write_buf_unaligned = NULL;
+
+	mem_free(buf_dblwr->buf_block_arr);
+	buf_dblwr->buf_block_arr = NULL;
+
+	mem_free(buf_dblwr->in_use);
+	buf_dblwr->in_use = NULL;
+
+	mutex_free(&buf_dblwr->mutex);
+	mem_free(buf_dblwr);
+	buf_dblwr = NULL;
+}
+
+/********************************************************************//**
+Updates the doublewrite buffer when an IO request that is part of an
+LRU or flush batch is completed. */
+UNIV_INTERN
+void
+buf_dblwr_update(void)
+/*==================*/
+{
+	if (!srv_use_doublewrite_buf || buf_dblwr == NULL) {
+		return;
+	}
+
+	mutex_enter(&buf_dblwr->mutex);
+
+	ut_ad(buf_dblwr->batch_running);
+	ut_ad(buf_dblwr->b_reserved > 0);
+
+	buf_dblwr->b_reserved--;
+	if (buf_dblwr->b_reserved == 0) {
+
+		mutex_exit(&buf_dblwr->mutex);
+		/* This will finish the batch. Sync data files
+		to the disk. */
+		fil_flush_file_spaces(FIL_TABLESPACE);
+		mutex_enter(&buf_dblwr->mutex);
+
+		/* We can now reuse the doublewrite memory buffer: */
+		buf_dblwr->first_free = 0;
+		buf_dblwr->batch_running = FALSE;
+	}
+
+	mutex_exit(&buf_dblwr->mutex);
+}
+
+/********************************************************************//**
+Flush a batch of writes to the datafiles that have already been
+written by the OS. */
+static
+void
+buf_dblwr_sync_datafiles(void)
+/*==========================*/
+{
+	/* Wake possible simulated aio thread to actually post the
+	writes to the operating system */
+	os_aio_simulated_wake_handler_threads();
+
+	/* Wait that all async writes to tablespaces have been posted to
+	the OS */
+	os_aio_wait_until_no_pending_writes();
+
+	/* Now we flush the data to disk (for example, with fsync) */
+	fil_flush_file_spaces(FIL_TABLESPACE);
+
+	return;
+}
+
+/********************************************************************//**
+Check the LSN values on the page. */
+static
+void
+buf_dblwr_check_page_lsn(
+/*=====================*/
+	const page_t*	page)		/*!< in: page to check */
+{
+	if (memcmp(page + (FIL_PAGE_LSN + 4),
+		   page + (UNIV_PAGE_SIZE
+			   - FIL_PAGE_END_LSN_OLD_CHKSUM + 4),
+		   4)) {
+
+		ut_print_timestamp(stderr);
+		fprintf(stderr,
+			" InnoDB: ERROR: The page to be written"
+			" seems corrupt!\n"
+			"InnoDB: The low 4 bytes of LSN fields do not match "
+			"(" ULINTPF " != " ULINTPF ")!"
+			" Noticed in the buffer pool.\n",
+			mach_read_from_4(
+				page + FIL_PAGE_LSN + 4),
+			mach_read_from_4(
+				page + UNIV_PAGE_SIZE
+				- FIL_PAGE_END_LSN_OLD_CHKSUM + 4));
+	}
+}
+
+/********************************************************************//**
+Asserts when a corrupt block is find during writing out data to the
+disk. */
+static
+void
+buf_dblwr_assert_on_corrupt_block(
+/*==============================*/
+	const buf_block_t*	block)	/*!< in: block to check */
+{
+	buf_page_print(block->frame, 0);
+
+	ut_print_timestamp(stderr);
+	fprintf(stderr,
+		"  InnoDB: Apparent corruption of an"
+		" index page n:o %lu in space %lu\n"
+		"InnoDB: to be written to data file."
+		" We intentionally crash server\n"
+		"InnoDB: to prevent corrupt data"
+		" from ending up in data\n"
+		"InnoDB: files.\n",
+		(ulong) buf_block_get_page_no(block),
+		(ulong) buf_block_get_space(block));
+
+	ut_error;
+}
+
+/********************************************************************//**
+Check the LSN values on the page with which this block is associated.
+Also validate the page if the option is set. */
+static
+void
+buf_dblwr_check_block(
+/*==================*/
+	const buf_block_t*	block)	/*!< in: block to check */
+{
+	if (buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
+	    || block->page.zip.data) {
+		/* No simple validate for compressed pages exists. */
+		return;
+	}
+
+	buf_dblwr_check_page_lsn(block->frame);
+
+	if (!block->check_index_page_at_flush) {
+		return;
+	}
+
+	if (page_is_comp(block->frame)) {
+		if (!page_simple_validate_new(block->frame)) {
+			buf_dblwr_assert_on_corrupt_block(block);
+		}
+	} else if (!page_simple_validate_old(block->frame)) {
+
+		buf_dblwr_assert_on_corrupt_block(block);
+	}
+}
+
+/********************************************************************//**
+Writes a page that has already been written to the doublewrite buffer
+to the datafile. It is the job of the caller to sync the datafile. */
+static
+void
+buf_dblwr_write_block_to_datafile(
+/*==============================*/
+	const buf_block_t*	block)	/*!< in: block to write */
+{
+	ut_a(block);
+	ut_a(buf_page_in_file(&block->page));
+
+	if (block->page.zip.data) {
+		fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
+		       FALSE, buf_page_get_space(&block->page),
+		       buf_page_get_zip_size(&block->page),
+		       buf_page_get_page_no(&block->page), 0,
+		       buf_page_get_zip_size(&block->page),
+		       (void*) block->page.zip.data,
+		       (void*) block);
+
+		goto exit;
+	}
+
+	ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
+	buf_dblwr_check_page_lsn(block->frame);
+
+	fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
+	       FALSE, buf_block_get_space(block), 0,
+	       buf_block_get_page_no(block), 0, UNIV_PAGE_SIZE,
+	       (void*) block->frame, (void*) block);
+
+exit:
+	/* Increment the counter of I/O operations used
+	for selecting LRU policy. */
+	buf_LRU_stat_inc_io();
+}
+
+/********************************************************************//**
+Flushes possible buffered writes from the doublewrite memory buffer to disk,
+and also wakes up the aio thread if simulated aio is used. It is very
+important to call this function after a batch of writes has been posted,
+and also when we may have to wait for a page latch! Otherwise a deadlock
+of threads can occur. */
+UNIV_INTERN
+void
+buf_dblwr_flush_buffered_writes(void)
+/*=================================*/
+{
+	byte*		write_buf;
+	ulint		len;
+	ulint		len2;
+	ulint		i;
+
+	if (!srv_use_doublewrite_buf || buf_dblwr == NULL) {
+		/* Sync the writes to the disk. */
+		buf_dblwr_sync_datafiles();
+		return;
+	}
+
+try_again:
+	mutex_enter(&(buf_dblwr->mutex));
+
+	/* Write first to doublewrite buffer blocks. We use synchronous
+	aio and thus know that file write has been completed when the
+	control returns. */
+
+	if (buf_dblwr->first_free == 0) {
+
+		mutex_exit(&(buf_dblwr->mutex));
+
+		return;
+	}
+
+	if (buf_dblwr->batch_running) {
+		mutex_exit(&buf_dblwr->mutex);
+
+		/* Another thread is running the batch right now. Wait
+		for it to finish. */
+		os_thread_sleep(TRX_DOUBLEWRITE_BATCH_POLL_DELAY);
+		goto try_again;
+	}
+
+	ut_a(!buf_dblwr->batch_running);
+
+	/* Disallow anyone else to post to doublewrite buffer or to
+	start another batch of flushing. */
+	buf_dblwr->batch_running = TRUE;
+
+	/* Now safe to release the mutex. Note that though no other
+	thread is allowed to post to the doublewrite batch flushing
+	but any threads working on single page flushes are allowed
+	to proceed. */
+	mutex_exit(&buf_dblwr->mutex);
+
+	write_buf = buf_dblwr->write_buf;
+
+	for (len2 = 0, i = 0;
+	     i < buf_dblwr->first_free;
+	     len2 += UNIV_PAGE_SIZE, i++) {
+
+		const buf_block_t*	block;
+
+		block = (buf_block_t*) buf_dblwr->buf_block_arr[i];
+
+		if (buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
+		    || block->page.zip.data) {
+			/* No simple validate for compressed
+			pages exists. */
+			continue;
+		}
+
+		/* Check that the actual page in the buffer pool is
+		not corrupt and the LSN values are sane. */
+		buf_dblwr_check_block(block);
+
+		/* Check that the page as written to the doublewrite
+		buffer has sane LSN values. */
+		buf_dblwr_check_page_lsn(write_buf + len2);
+	}
+
+	/* Write out the first block of the doublewrite buffer */
+	len = ut_min(TRX_SYS_DOUBLEWRITE_BLOCK_SIZE,
+		     buf_dblwr->first_free) * UNIV_PAGE_SIZE;
+
+	fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
+	       buf_dblwr->block1, 0, len,
+	       (void*) write_buf, NULL);
+
+	if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
+		/* No unwritten pages in the second block. */
+		goto flush;
+	}
+
+	/* Write out the second block of the doublewrite buffer. */
+	len = (buf_dblwr->first_free - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
+	       * UNIV_PAGE_SIZE;
+
+	write_buf = buf_dblwr->write_buf
+		    + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE;
+
+	fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
+	       buf_dblwr->block2, 0, len,
+	       (void*) write_buf, NULL);
+
+flush:
+	/* increment the doublewrite flushed pages counter */
+	srv_dblwr_pages_written += buf_dblwr->first_free;
+	srv_dblwr_writes++;
+
+	/* Now flush the doublewrite buffer data to disk */
+	fil_flush(TRX_SYS_SPACE);
+
+	/* We know that the writes have been flushed to disk now
+	and in recovery we will find them in the doublewrite buffer
+	blocks. Next do the writes to the intended positions. */
+
+	for (i = 0; i < buf_dblwr->first_free; i++) {
+		const buf_block_t* block = (buf_block_t*)
+			buf_dblwr->buf_block_arr[i];
+
+		buf_dblwr_write_block_to_datafile(block);
+	}
+
+	/* Wake possible simulated aio thread to actually post the
+	writes to the operating system. We don't flush the files
+	at this point. We leave it to the IO helper thread to flush
+	datafiles when the whole batch has been processed. */
+	os_aio_simulated_wake_handler_threads();
+}
+
+/********************************************************************//**
+Posts a buffer page for writing. If the doublewrite memory buffer is
+full, calls buf_dblwr_flush_buffered_writes and waits for for free
+space to appear. */
+UNIV_INTERN
+void
+buf_dblwr_add_to_batch(
+/*====================*/
+	buf_page_t*	bpage)	/*!< in: buffer block to write */
+{
+	ulint	zip_size;
+
+	ut_a(buf_page_in_file(bpage));
+
+try_again:
+	mutex_enter(&(buf_dblwr->mutex));
+
+	ut_a(buf_dblwr->first_free <= srv_doublewrite_batch_size);
+
+	if (buf_dblwr->batch_running) {
+		mutex_exit(&buf_dblwr->mutex);
+
+		/* This not nearly as bad as it looks. There is only
+		page_cleaner thread which does background flushing
+		in batches therefore it is unlikely to be a contention
+		point. The only exception is when a user thread is
+		forced to do a flush batch because of a sync
+		checkpoint. */
+		os_thread_sleep(TRX_DOUBLEWRITE_BATCH_POLL_DELAY);
+		goto try_again;
+	}
+
+	if (buf_dblwr->first_free == srv_doublewrite_batch_size) {
+		mutex_exit(&(buf_dblwr->mutex));
+
+		buf_dblwr_flush_buffered_writes();
+
+		goto try_again;
+	}
+
+	zip_size = buf_page_get_zip_size(bpage);
+
+	if (zip_size) {
+		UNIV_MEM_ASSERT_RW(bpage->zip.data, zip_size);
+		/* Copy the compressed page and clear the rest. */
+		memcpy(buf_dblwr->write_buf
+		       + UNIV_PAGE_SIZE * buf_dblwr->first_free,
+		       bpage->zip.data, zip_size);
+		memset(buf_dblwr->write_buf
+		       + UNIV_PAGE_SIZE * buf_dblwr->first_free
+		       + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
+	} else {
+		ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
+		UNIV_MEM_ASSERT_RW(((buf_block_t*) bpage)->frame,
+				   UNIV_PAGE_SIZE);
+
+		memcpy(buf_dblwr->write_buf
+		       + UNIV_PAGE_SIZE * buf_dblwr->first_free,
+		       ((buf_block_t*) bpage)->frame, UNIV_PAGE_SIZE);
+	}
+
+	buf_dblwr->buf_block_arr[buf_dblwr->first_free] = bpage;
+
+	buf_dblwr->first_free++;
+	buf_dblwr->b_reserved++;
+
+	ut_ad(buf_dblwr->b_reserved <= srv_doublewrite_batch_size);
+
+	if (buf_dblwr->first_free == srv_doublewrite_batch_size) {
+		mutex_exit(&(buf_dblwr->mutex));
+
+		buf_dblwr_flush_buffered_writes();
+
+		return;
+	}
+
+	mutex_exit(&(buf_dblwr->mutex));
+}
+
+/********************************************************************//**
+Writes a page to the doublewrite buffer on disk, sync it, then write
+the page to the datafile and sync the datafile. This function is used
+for single page flushes. If all the buffers allocated for single page
+flushes in the doublewrite buffer are in use we wait here for one to
+become free. We are guaranteed that a slot will become free because any
+thread that is using a slot must also release the slot before leaving
+this function. */
+UNIV_INTERN
+void
+buf_dblwr_write_single_page(
+/*========================*/
+	buf_page_t*	bpage)	/*!< in: buffer block to write */
+{
+	ulint		n_slots;
+	ulint		size;
+	ulint		zip_size;
+	ulint		offset;
+	ulint		i;
+
+	ut_a(buf_page_in_file(bpage));
+	ut_a(srv_use_doublewrite_buf);
+	ut_a(buf_dblwr != NULL);
+
+	/* total number of slots available for single page flushes
+	starts from srv_doublewrite_batch_size to the end of the
+	buffer. */
+	size = 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
+	ut_a(size > srv_doublewrite_batch_size);
+	n_slots = size - srv_doublewrite_batch_size;
+
+	if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
+
+		/* Check that the actual page in the buffer pool is
+		not corrupt and the LSN values are sane. */
+		buf_dblwr_check_block((buf_block_t*) bpage);
+
+		/* Check that the page as written to the doublewrite
+		buffer has sane LSN values. */
+		if (!bpage->zip.data) {
+			buf_dblwr_check_page_lsn(
+				((buf_block_t*) bpage)->frame);
+		}
+	}
+
+retry:
+	mutex_enter(&buf_dblwr->mutex);
+	if (buf_dblwr->s_reserved == n_slots) {
+
+		mutex_exit(&buf_dblwr->mutex);
+		/* All slots are reserved. Since it involves two IOs
+		during the processing a sleep of 10ms should be
+		enough. */
+		os_thread_sleep(TRX_DOUBLEWRITE_BATCH_POLL_DELAY);
+		goto retry;
+	}
+
+	for (i = srv_doublewrite_batch_size; i < size; ++i) {
+
+		if (!buf_dblwr->in_use[i]) {
+			break;
+		}
+	}
+
+	/* We are guaranteed to find a slot. */
+	ut_a(i < size);
+	buf_dblwr->in_use[i] = TRUE;
+	buf_dblwr->s_reserved++;
+	buf_dblwr->buf_block_arr[i] = bpage;
+	mutex_exit(&buf_dblwr->mutex);
+
+	/* Lets see if we are going to write in the first or second
+	block of the doublewrite buffer. */
+	if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
+		offset = buf_dblwr->block1 + i;
+	} else {
+		offset = buf_dblwr->block2 + i
+			 - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
+	}
+
+	/* We deal with compressed and uncompressed pages a little
+	differently here. In case of uncompressed pages we can
+	directly write the block to the allocated slot in the
+	doublewrite buffer in the system tablespace and then after
+	syncing the system table space we can proceed to write the page
+	in the datafile.
+	In case of compressed page we first do a memcpy of the block
+	to the in-memory buffer of doublewrite before proceeding to
+	write it. This is so because we want to pad the remaining
+	bytes in the doublewrite page with zeros. */
+
+	zip_size = buf_page_get_zip_size(bpage);
+	if (zip_size) {
+		memcpy(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i,
+		       bpage->zip.data, zip_size);
+		memset(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i
+		       + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
+
+		fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
+		       offset, 0, UNIV_PAGE_SIZE,
+		       (void*) (buf_dblwr->write_buf
+				+ UNIV_PAGE_SIZE * i), NULL);
+	} else {
+		/* It is a regular page. Write it directly to the
+		doublewrite buffer */
+		fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
+		       offset, 0, UNIV_PAGE_SIZE,
+		       (void*) ((buf_block_t*) bpage)->frame,
+		       NULL);
+	}
+
+	/* Now flush the doublewrite buffer data to disk */
+	fil_flush(TRX_SYS_SPACE);
+
+	/* We know that the write has been flushed to disk now
+	and during recovery we will find it in the doublewrite buffer
+	blocks. Next do the write to the intended position. */
+	buf_dblwr_write_block_to_datafile((buf_block_t*) bpage);
+
+	/* Sync the writes to the disk. */
+	buf_dblwr_sync_datafiles();
+
+	mutex_enter(&buf_dblwr->mutex);
+
+	buf_dblwr->s_reserved--;
+	buf_dblwr->buf_block_arr[i] = NULL;
+	buf_dblwr->in_use[i] = FALSE;
+
+	/* increment the doublewrite flushed pages counter */
+	srv_dblwr_pages_written += buf_dblwr->first_free;
+	srv_dblwr_writes++;
+
+	mutex_exit(&(buf_dblwr->mutex));
+
+}
+#endif /* !UNIV_HOTBACKUP */

=== modified file 'storage/innobase/buf/buf0flu.cc'
--- a/storage/innobase/buf/buf0flu.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/buf/buf0flu.cc	2011-12-23 13:17:36 +0000
@@ -62,11 +62,6 @@ Each interval is 1 second, defined by th
 srv_error_monitor_thread() calls buf_flush_stat_update(). */
 #define BUF_FLUSH_STAT_N_INTERVAL 20
 
-/** Time in milliseconds that we sleep when unable to find a slot in
-the doublewrite buffer or when we have to wait for a running batch
-to end. */
-#define TRX_DOUBLEWRITE_BATCH_POLL_DELAY	10000
-
 /** Sampled values buf_flush_stat_cur.
 Not protected by any mutex.  Updated by buf_flush_stat_update(). */
 static buf_flush_stat_t	buf_flush_stat_arr[BUF_FLUSH_STAT_N_INTERVAL];
@@ -697,501 +692,19 @@ buf_flush_write_complete(
 
 		os_event_set(buf_pool->no_flush[flush_type]);
 	}
-}
-
-/********************************************************************//**
-Flush a batch of writes to the datafiles that have already been
-written by the OS. */
-static
-void
-buf_flush_sync_datafiles(void)
-/*==========================*/
-{
-	/* Wake possible simulated aio thread to actually post the
-	writes to the operating system */
-	os_aio_simulated_wake_handler_threads();
-
-	/* Wait that all async writes to tablespaces have been posted to
-	the OS */
-	os_aio_wait_until_no_pending_writes();
-
-	/* Now we flush the data to disk (for example, with fsync) */
-	fil_flush_file_spaces(FIL_TABLESPACE);
-
-	return;
-}
-
-/********************************************************************//**
-Check the LSN values on the page. */
-static
-void
-buf_flush_doublewrite_check_page_lsn(
-/*=================================*/
-	const page_t*	page)		/*!< in: page to check */
-{
-	if (memcmp(page + (FIL_PAGE_LSN + 4),
-		   page + (UNIV_PAGE_SIZE
-			   - FIL_PAGE_END_LSN_OLD_CHKSUM + 4),
-		   4)) {
-
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: ERROR: The page to be written"
-			" seems corrupt!\n"
-			"InnoDB: The low 4 bytes of LSN fields do not match "
-			"(" ULINTPF " != " ULINTPF ")!"
-			" Noticed in the buffer pool.\n",
-			mach_read_from_4(
-				page + FIL_PAGE_LSN + 4),
-			mach_read_from_4(
-				page + UNIV_PAGE_SIZE
-				- FIL_PAGE_END_LSN_OLD_CHKSUM + 4));
-	}
-}
-
-/********************************************************************//**
-Asserts when a corrupt block is find during writing out data to the
-disk. */
-static
-void
-buf_flush_doublewrite_assert_on_corrupt_block(
-/*==========================================*/
-	const buf_block_t*	block)	/*!< in: block to check */
-{
-	buf_page_print(block->frame, 0);
-
-	ut_print_timestamp(stderr);
-	fprintf(stderr,
-		"  InnoDB: Apparent corruption of an"
-		" index page n:o %lu in space %lu\n"
-		"InnoDB: to be written to data file."
-		" We intentionally crash server\n"
-		"InnoDB: to prevent corrupt data"
-		" from ending up in data\n"
-		"InnoDB: files.\n",
-		(ulong) buf_block_get_page_no(block),
-		(ulong) buf_block_get_space(block));
-
-	ut_error;
-}
-
-/********************************************************************//**
-Check the LSN values on the page with which this block is associated.
-Also validate the page if the option is set. */
-static
-void
-buf_flush_doublewrite_check_block(
-/*==============================*/
-	const buf_block_t*	block)	/*!< in: block to check */
-{
-	if (buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
-	    || block->page.zip.data) {
-		/* No simple validate for compressed pages exists. */
-		return;
-	}
-
-	buf_flush_doublewrite_check_page_lsn(block->frame);
-
-	if (!block->check_index_page_at_flush) {
-		return;
-	}
-
-	if (page_is_comp(block->frame)) {
-		if (!page_simple_validate_new(block->frame)) {
-			buf_flush_doublewrite_assert_on_corrupt_block(block);
-		}
-	} else if (!page_simple_validate_old(block->frame)) {
-
-		buf_flush_doublewrite_assert_on_corrupt_block(block);
-	}
-}
-
-/********************************************************************//**
-Writes a page that has already been written to the doublewrite buffer
-to the datafile. It is the job of the caller to sync the datafile. */
-static
-void
-buf_flush_write_block_to_datafile(
-/*==============================*/
-	const buf_block_t*	block)	/*!< in: block to write */
-{
-	ut_a(block);
-	ut_a(buf_page_in_file(&block->page));
-
-	if (block->page.zip.data) {
-		fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
-		       FALSE, buf_page_get_space(&block->page),
-		       buf_page_get_zip_size(&block->page),
-		       buf_page_get_page_no(&block->page), 0,
-		       buf_page_get_zip_size(&block->page),
-		       (void*) block->page.zip.data,
-		       (void*) block);
-
-		goto exit;
-	}
-
-	ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
-	buf_flush_doublewrite_check_page_lsn(block->frame);
-
-	fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
-	       FALSE, buf_block_get_space(block), 0,
-	       buf_block_get_page_no(block), 0, UNIV_PAGE_SIZE,
-	       (void*) block->frame, (void*) block);
-
-exit:
-	/* Increment the counter of I/O operations used
-	for selecting LRU policy. */
-	buf_LRU_stat_inc_io();
-}
-
-/********************************************************************//**
-Flushes possible buffered writes from the doublewrite memory buffer to disk,
-and also wakes up the aio thread if simulated aio is used. It is very
-important to call this function after a batch of writes has been posted,
-and also when we may have to wait for a page latch! Otherwise a deadlock
-of threads can occur. */
-static
-void
-buf_flush_buffered_writes(void)
-/*===========================*/
-{
-	byte*		write_buf;
-	ulint		len;
-	ulint		len2;
-	ulint		i;
-
-	if (!srv_use_doublewrite_buf || trx_doublewrite == NULL) {
-		/* Sync the writes to the disk. */
-		buf_flush_sync_datafiles();
-		return;
-	}
-
-try_again:
-	mutex_enter(&(trx_doublewrite->mutex));
-
-	/* Write first to doublewrite buffer blocks. We use synchronous
-	aio and thus know that file write has been completed when the
-	control returns. */
-
-	if (trx_doublewrite->first_free == 0) {
-
-		mutex_exit(&(trx_doublewrite->mutex));
-
-		return;
-	}
-
-	if (trx_doublewrite->batch_running) {
-		mutex_exit(&trx_doublewrite->mutex);
-
-		/* Another thread is running the batch right now. Wait
-		for it to finish. */
-		os_thread_sleep(TRX_DOUBLEWRITE_BATCH_POLL_DELAY);
-		goto try_again;
-	}
-
-	ut_a(!trx_doublewrite->batch_running);
-
-	/* Disallow anyone else to post to doublewrite buffer or to
-	start another batch of flushing. */
-	trx_doublewrite->batch_running = TRUE;
-
-	/* Now safe to release the mutex. Note that though no other
-	thread is allowed to post to the doublewrite batch flushing
-	but any threads working on single page flushes are allowed
-	to proceed. */
-	mutex_exit(&trx_doublewrite->mutex);
-
-	write_buf = trx_doublewrite->write_buf;
-
-	for (len2 = 0, i = 0;
-	     i < trx_doublewrite->first_free;
-	     len2 += UNIV_PAGE_SIZE, i++) {
-
-		const buf_block_t*	block;
-
-		block = (buf_block_t*) trx_doublewrite->buf_block_arr[i];
-
-		if (buf_block_get_state(block) != BUF_BLOCK_FILE_PAGE
-		    || block->page.zip.data) {
-			/* No simple validate for compressed
-			pages exists. */
-			continue;
-		}
-
-		/* Check that the actual page in the buffer pool is
-		not corrupt and the LSN values are sane. */
-		buf_flush_doublewrite_check_block(block);
-
-		/* Check that the page as written to the doublewrite
-		buffer has sane LSN values. */
-		buf_flush_doublewrite_check_page_lsn(write_buf + len2);
-	}
 
-	/* Write out the first block of the doublewrite buffer */
-	len = ut_min(TRX_SYS_DOUBLEWRITE_BLOCK_SIZE,
-		     trx_doublewrite->first_free) * UNIV_PAGE_SIZE;
-
-	fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
-	       trx_doublewrite->block1, 0, len,
-	       (void*) write_buf, NULL);
-
-	if (trx_doublewrite->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
-		/* No unwritten pages in the second block. */
-		goto flush;
-	}
-
-	/* Write out the second block of the doublewrite buffer. */
-	len = (trx_doublewrite->first_free - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
-	       * UNIV_PAGE_SIZE;
-
-	write_buf = trx_doublewrite->write_buf
-		    + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE;
-
-	fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
-	       trx_doublewrite->block2, 0, len,
-	       (void*) write_buf, NULL);
-
-flush:
-	/* increment the doublewrite flushed pages counter */
-	srv_dblwr_pages_written += trx_doublewrite->first_free;
-	srv_dblwr_writes++;
-
-	/* Now flush the doublewrite buffer data to disk */
-	fil_flush(TRX_SYS_SPACE);
-
-	/* We know that the writes have been flushed to disk now
-	and in recovery we will find them in the doublewrite buffer
-	blocks. Next do the writes to the intended positions. */
-
-	for (i = 0; i < trx_doublewrite->first_free; i++) {
-		const buf_block_t* block = (buf_block_t*)
-			trx_doublewrite->buf_block_arr[i];
-
-		buf_flush_write_block_to_datafile(block);
-	}
-
-	/* Sync the writes to the disk. */
-	buf_flush_sync_datafiles();
-
-	mutex_enter(&trx_doublewrite->mutex);
-
-	/* We can now reuse the doublewrite memory buffer: */
-	trx_doublewrite->first_free = 0;
-	trx_doublewrite->batch_running = FALSE;
-
-	mutex_exit(&(trx_doublewrite->mutex));
-}
-
-/********************************************************************//**
-Posts a buffer page for writing. If the doublewrite memory buffer is
-full, calls buf_flush_buffered_writes and waits for for free space to
-appear. */
-static
-void
-buf_flush_post_to_doublewrite_buf(
-/*==============================*/
-	buf_page_t*	bpage)	/*!< in: buffer block to write */
-{
-	ulint	zip_size;
-
-	ut_a(buf_page_in_file(bpage));
-
-try_again:
-	mutex_enter(&(trx_doublewrite->mutex));
-
-	ut_a(trx_doublewrite->first_free <= srv_doublewrite_batch_size);
-
-	if (trx_doublewrite->batch_running) {
-		mutex_exit(&trx_doublewrite->mutex);
-
-		/* This not nearly as bad as it looks. There is only
-		page_cleaner thread which does background flushing
-		in batches therefore it is unlikely to be a contention
-		point. The only exception is when a user thread is
-		forced to do a flush batch because of a sync
-		checkpoint. */
-		os_thread_sleep(TRX_DOUBLEWRITE_BATCH_POLL_DELAY);
-		goto try_again;
-	}
-
-	if (trx_doublewrite->first_free == srv_doublewrite_batch_size) {
-		mutex_exit(&(trx_doublewrite->mutex));
-
-		buf_flush_buffered_writes();
-
-		goto try_again;
-	}
-
-	zip_size = buf_page_get_zip_size(bpage);
-
-	if (zip_size) {
-		UNIV_MEM_ASSERT_RW(bpage->zip.data, zip_size);
-		/* Copy the compressed page and clear the rest. */
-		memcpy(trx_doublewrite->write_buf
-		       + UNIV_PAGE_SIZE * trx_doublewrite->first_free,
-		       bpage->zip.data, zip_size);
-		memset(trx_doublewrite->write_buf
-		       + UNIV_PAGE_SIZE * trx_doublewrite->first_free
-		       + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
-	} else {
-		ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
-		UNIV_MEM_ASSERT_RW(((buf_block_t*) bpage)->frame,
-				   UNIV_PAGE_SIZE);
-
-		memcpy(trx_doublewrite->write_buf
-		       + UNIV_PAGE_SIZE * trx_doublewrite->first_free,
-		       ((buf_block_t*) bpage)->frame, UNIV_PAGE_SIZE);
-	}
-
-	trx_doublewrite->buf_block_arr[trx_doublewrite->first_free] = bpage;
-
-	trx_doublewrite->first_free++;
-
-	if (trx_doublewrite->first_free == srv_doublewrite_batch_size) {
-		mutex_exit(&(trx_doublewrite->mutex));
-
-		buf_flush_buffered_writes();
-
-		return;
-	}
-
-	mutex_exit(&(trx_doublewrite->mutex));
-}
-
-/********************************************************************//**
-Writes a page to the doublewrite buffer on disk, sync it, then write
-the page to the datafile and sync the datafile. This function is used
-for single page flushes. If all the buffers allocated for single page
-flushes in the doublewrite buffer are in use we wait here for one to
-become free. We are guaranteed that a slot will become free because any
-thread that is using a slot must also release the slot before leaving
-this function. */
-static
-void
-buf_flush_write_to_dblwr_and_datafile(
-/*==================================*/
-	buf_page_t*	bpage)	/*!< in: buffer block to write */
-{
-	ulint		n_slots;
-	ulint		size;
-	ulint		zip_size;
-	ulint		offset;
-	ulint		i;
-
-	ut_a(buf_page_in_file(bpage));
-	ut_a(srv_use_doublewrite_buf);
-	ut_a(trx_doublewrite != NULL);
-
-	/* total number of slots available for single page flushes
-	starts from srv_doublewrite_batch_size to the end of the
-	buffer. */
-	size = 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
-	ut_a(size > srv_doublewrite_batch_size);
-	n_slots = size - srv_doublewrite_batch_size;
-
-	if (buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE) {
-
-		/* Check that the actual page in the buffer pool is
-		not corrupt and the LSN values are sane. */
-		buf_flush_doublewrite_check_block((buf_block_t*) bpage);
-
-		/* Check that the page as written to the doublewrite
-		buffer has sane LSN values. */
-		if (!bpage->zip.data) {
-			buf_flush_doublewrite_check_page_lsn(
-				((buf_block_t*) bpage)->frame);
-		}
-	}
-
-retry:
-	mutex_enter(&trx_doublewrite->mutex);
-	if (trx_doublewrite->n_reserved == n_slots) {
-
-		mutex_exit(&trx_doublewrite->mutex);
-		/* All slots are reserved. Since it involves two IOs
-		during the processing a sleep of 10ms should be
-		enough. */
-		os_thread_sleep(TRX_DOUBLEWRITE_BATCH_POLL_DELAY);
-		goto retry;
-	}
-
-	for (i = srv_doublewrite_batch_size; i < size; ++i) {
-
-		if (!trx_doublewrite->in_use[i]) {
-			break;
-		}
-	}
-
-	/* We are guaranteed to find a slot. */
-	ut_a(i < size);
-	trx_doublewrite->in_use[i] = TRUE;
-	trx_doublewrite->n_reserved++;
-	trx_doublewrite->buf_block_arr[i] = bpage;
-	mutex_exit(&trx_doublewrite->mutex);
-
-	/* Lets see if we are going to write in the first or second
-	block of the doublewrite buffer. */
-	if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
-		offset = trx_doublewrite->block1 + i;
-	} else {
-		offset = trx_doublewrite->block2 + i
-			 - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
-	}
-
-	/* We deal with compressed and uncompressed pages a little
-	differently here. In case of uncompressed pages we can
-	directly write the block to the allocated slot in the
-	doublewrite buffer in the system tablespace and then after
-	syncing the system table space we can proceed to write the page
-	in the datafile.
-	In case of compressed page we first do a memcpy of the block
-	to the in-memory buffer of doublewrite before proceeding to
-	write it. This is so because we want to pad the remaining
-	bytes in the doublewrite page with zeros. */
-
-	zip_size = buf_page_get_zip_size(bpage);
-	if (zip_size) {
-		memcpy(trx_doublewrite->write_buf + UNIV_PAGE_SIZE * i,
-		       bpage->zip.data, zip_size);
-		memset(trx_doublewrite->write_buf + UNIV_PAGE_SIZE * i
-		       + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
-
-		fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
-		       offset, 0, UNIV_PAGE_SIZE,
-		       (void*) (trx_doublewrite->write_buf
-				+ UNIV_PAGE_SIZE * i), NULL);
-	} else {
-		/* It is a regular page. Write it directly to the
-		doublewrite buffer */
-		fil_io(OS_FILE_WRITE, TRUE, TRX_SYS_SPACE, 0,
-		       offset, 0, UNIV_PAGE_SIZE,
-		       (void*) ((buf_block_t*) bpage)->frame,
-		       NULL);
+	switch (flush_type) {
+	case BUF_FLUSH_LIST:
+	case BUF_FLUSH_LRU:
+		buf_dblwr_update();
+		break;
+	case BUF_FLUSH_SINGLE_PAGE:
+		/* Single page flushes are synchronous. No need
+		to update doublewrite */
+		break;
+	case BUF_FLUSH_N_TYPES:
+		ut_error;
 	}
-
-	/* Now flush the doublewrite buffer data to disk */
-	fil_flush(TRX_SYS_SPACE);
-
-	/* We know that the write has been flushed to disk now
-	and during recovery we will find it in the doublewrite buffer
-	blocks. Next do the write to the intended position. */
-	buf_flush_write_block_to_datafile((buf_block_t*) bpage);
-
-	/* Sync the writes to the disk. */
-	buf_flush_sync_datafiles();
-
-	mutex_enter(&trx_doublewrite->mutex);
-
-	trx_doublewrite->n_reserved--;
-	trx_doublewrite->buf_block_arr[i] = NULL;
-	trx_doublewrite->in_use[i] = FALSE;
-
-	/* increment the doublewrite flushed pages counter */
-	srv_dblwr_pages_written += trx_doublewrite->first_free;
-	srv_dblwr_writes++;
-
-	mutex_exit(&(trx_doublewrite->mutex));
-
 }
 #endif /* !UNIV_HOTBACKUP */
 
@@ -1311,7 +824,8 @@ buf_flush_init_for_writing(
 /********************************************************************//**
 Does an asynchronous write of a buffer page. NOTE: in simulated aio and
 also when the doublewrite buffer is used, we must call
-buf_flush_buffered_writes after we have posted a batch of writes! */
+buf_dblwr_flush_buffered_writes after we have posted a batch of
+writes! */
 static
 void
 buf_flush_write_block_low(
@@ -1392,16 +906,16 @@ buf_flush_write_block_low(
 		break;
 	}
 
-	if (!srv_use_doublewrite_buf || !trx_doublewrite) {
+	if (!srv_use_doublewrite_buf || !buf_dblwr) {
 		fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
 		       FALSE, buf_page_get_space(bpage), zip_size,
 		       buf_page_get_page_no(bpage), 0,
 		       zip_size ? zip_size : UNIV_PAGE_SIZE,
 		       frame, bpage);
 	} else if (flush_type == BUF_FLUSH_SINGLE_PAGE) {
-		buf_flush_write_to_dblwr_and_datafile(bpage);
+		buf_dblwr_write_single_page(bpage);
 	} else {
-		buf_flush_post_to_doublewrite_buf(bpage);
+		buf_dblwr_add_to_batch(bpage);
 	}
 }
 
@@ -1469,7 +983,7 @@ buf_flush_page(
 		flush_list or LRU_list. */
 
 		if (!is_s_latched) {
-			buf_flush_buffered_writes();
+			buf_dblwr_flush_buffered_writes();
 
 			if (is_uncompressed) {
 				rw_lock_s_lock_gen(&((buf_block_t*) bpage)
@@ -2083,7 +1597,7 @@ buf_flush_batch(
 
 	buf_pool_mutex_exit(buf_pool);
 
-	buf_flush_buffered_writes();
+	buf_dblwr_flush_buffered_writes();
 
 #ifdef UNIV_DEBUG
 	if (buf_debug_prints && count > 0) {
@@ -2108,7 +1622,7 @@ buf_flush_common(
 	enum buf_flush	flush_type,	/*!< in: type of flush */
 	ulint		page_count)	/*!< in: number of pages flushed */
 {
-	buf_flush_buffered_writes();
+	buf_dblwr_flush_buffered_writes();
 
 	ut_a(flush_type == BUF_FLUSH_LRU || flush_type == BUF_FLUSH_LIST);
 

=== modified file 'storage/innobase/buf/buf0lru.cc'
--- a/storage/innobase/buf/buf0lru.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/buf/buf0lru.cc	2011-12-23 13:17:36 +0000
@@ -41,6 +41,7 @@ Created 11/5/1995 Heikki Tuuri
 #include "btr0btr.h"
 #include "buf0buddy.h"
 #include "buf0buf.h"
+#include "buf0dblwr.h"
 #include "buf0flu.h"
 #include "buf0rea.h"
 #include "btr0sea.h"
@@ -866,7 +867,7 @@ loop:
 
 	if (buf_pool->init_flush[BUF_FLUSH_LRU]
 	    && srv_use_doublewrite_buf
-	    && trx_doublewrite != NULL) {
+	    && buf_dblwr != NULL) {
 
 		/* If there is an LRU flush happening in the background
 		then we wait for it to end instead of trying a single

=== modified file 'storage/innobase/buf/buf0rea.cc'
--- a/storage/innobase/buf/buf0rea.cc	2011-11-30 10:27:10 +0000
+++ b/storage/innobase/buf/buf0rea.cc	2011-12-23 13:17:36 +0000
@@ -31,6 +31,7 @@ Created 11/5/1995 Heikki Tuuri
 #include "buf0buf.h"
 #include "buf0flu.h"
 #include "buf0lru.h"
+#include "buf0dblwr.h"
 #include "ibuf0ibuf.h"
 #include "log0recv.h"
 #include "trx0sys.h"
@@ -93,13 +94,7 @@ buf_read_page_low(
 	ignore_nonexistent_pages = mode & BUF_READ_IGNORE_NONEXISTENT_PAGES;
 	mode &= ~BUF_READ_IGNORE_NONEXISTENT_PAGES;
 
-	if (trx_doublewrite && space == TRX_SYS_SPACE
-	    && (   (offset >= trx_doublewrite->block1
-		    && offset < trx_doublewrite->block1
-		    + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
-		   || (offset >= trx_doublewrite->block2
-		       && offset < trx_doublewrite->block2
-		       + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE))) {
+	if (space == TRX_SYS_SPACE && buf_dblwr_page_inside(offset)) {
 		ut_print_timestamp(stderr);
 		fprintf(stderr,
 			"  InnoDB: Warning: trying to read"

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2011-12-15 14:18:46 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2011-12-23 13:17:36 +0000
@@ -49,6 +49,7 @@ this program; if not, write to the Free
 #include "buf0dump.h"
 #include "buf0lru.h"
 #include "buf0flu.h"
+#include "buf0dblwr.h"
 #include "btr0sea.h"
 #include "os0file.h"
 #include "os0thread.h"
@@ -324,7 +325,7 @@ static PSI_mutex_info all_innodb_mutexes
 #  ifdef UNIV_SYNC_DEBUG
 	{&sync_thread_mutex_key, "sync_thread_mutex", 0},
 #  endif /* UNIV_SYNC_DEBUG */
-	{&trx_doublewrite_mutex_key, "trx_doublewrite_mutex", 0},
+	{&buf_dblwr_mutex_key, "buf_dblwr_mutex", 0},
 	{&trx_undo_mutex_key, "trx_undo_mutex", 0},
 	{&srv_sys_mutex_key, "srv_sys_mutex", 0},
 	{&lock_sys_mutex_key, "lock_mutex", 0},

=== modified file 'storage/innobase/ibuf/ibuf0ibuf.cc'
--- a/storage/innobase/ibuf/ibuf0ibuf.cc	2011-11-30 10:27:10 +0000
+++ b/storage/innobase/ibuf/ibuf0ibuf.cc	2011-12-23 13:17:36 +0000
@@ -1255,17 +1255,9 @@ ibuf_rec_get_page_no_func(
 
 	field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_MARKER, &len);
 
-	if (len == 1) {
-		/* This is of the >= 4.1.x record format */
-		ut_a(trx_sys_multiple_tablespace_format);
-
-		field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_PAGE, &len);
-	} else {
-		ut_a(trx_doublewrite_must_reset_space_ids);
-		ut_a(!trx_sys_multiple_tablespace_format);
+	ut_a(len == 1);
 
-		field = rec_get_nth_field_old(rec, 0, &len);
-	}
+	field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_PAGE, &len);
 
 	ut_a(len == 4);
 
@@ -1301,20 +1293,13 @@ ibuf_rec_get_space_func(
 
 	field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_MARKER, &len);
 
-	if (len == 1) {
-		/* This is of the >= 4.1.x record format */
-
-		ut_a(trx_sys_multiple_tablespace_format);
-		field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_SPACE, &len);
-		ut_a(len == 4);
+	ut_a(len == 1);
 
-		return(mach_read_from_4(field));
-	}
+	field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_SPACE, &len);
 
-	ut_a(trx_doublewrite_must_reset_space_ids);
-	ut_a(!trx_sys_multiple_tablespace_format);
+	ut_a(len == 4);
 
-	return(0);
+	return(mach_read_from_4(field));
 }
 
 #ifdef UNIV_DEBUG
@@ -1584,58 +1569,6 @@ ibuf_dummy_index_free(
 	dict_mem_table_free(table);
 }
 
-/*********************************************************************//**
-Builds the entry to insert into a non-clustered index when we have the
-corresponding record in an ibuf index.
-
-NOTE that as we copy pointers to fields in ibuf_rec, the caller must
-hold a latch to the ibuf_rec page as long as the entry is used!
-
-@return own: entry to insert to a non-clustered index */
-UNIV_INLINE
-dtuple_t*
-ibuf_build_entry_pre_4_1_x(
-/*=======================*/
-	const rec_t*	ibuf_rec,	/*!< in: record in an insert buffer */
-	mem_heap_t*	heap,		/*!< in: heap where built */
-	dict_index_t**	pindex)		/*!< out, own: dummy index that
-					describes the entry */
-{
-	ulint		i;
-	ulint		len;
-	const byte*	types;
-	dtuple_t*	tuple;
-	ulint		n_fields;
-
-	ut_a(trx_doublewrite_must_reset_space_ids);
-	ut_a(!trx_sys_multiple_tablespace_format);
-
-	n_fields = rec_get_n_fields_old(ibuf_rec) - 2;
-	tuple = dtuple_create(heap, n_fields);
-	types = rec_get_nth_field_old(ibuf_rec, 1, &len);
-
-	ut_a(len == n_fields * DATA_ORDER_NULL_TYPE_BUF_SIZE);
-
-	for (i = 0; i < n_fields; i++) {
-		const byte*	data;
-		dfield_t*	field;
-
-		field = dtuple_get_nth_field(tuple, i);
-
-		data = rec_get_nth_field_old(ibuf_rec, i + 2, &len);
-
-		dfield_set_data(field, data, len);
-
-		dtype_read_for_order_and_null_size(
-			dfield_get_type(field),
-			types + i * DATA_ORDER_NULL_TYPE_BUF_SIZE);
-	}
-
-	*pindex = ibuf_dummy_index_create(n_fields, FALSE);
-
-	return(tuple);
-}
-
 #ifdef UNIV_DEBUG
 # define ibuf_build_entry_from_ibuf_rec(mtr,ibuf_rec,heap,pindex)	\
 	ibuf_build_entry_from_ibuf_rec_func(mtr,ibuf_rec,heap,pindex)
@@ -1689,15 +1622,7 @@ ibuf_build_entry_from_ibuf_rec_func(
 
 	data = rec_get_nth_field_old(ibuf_rec, IBUF_REC_FIELD_MARKER, &len);
 
-	if (len > 1) {
-		/* This a < 4.1.x format record */
-
-		return(ibuf_build_entry_pre_4_1_x(ibuf_rec, heap, pindex));
-	}
-
-	/* This a >= 4.1.x format record */
-
-	ut_a(trx_sys_multiple_tablespace_format);
+	ut_a(len == 1);
 	ut_a(*data == 0);
 	ut_a(rec_get_n_fields_old(ibuf_rec) > IBUF_REC_FIELD_USER);
 
@@ -1753,8 +1678,6 @@ ibuf_rec_get_size(
 	const rec_t*	rec,			/*!< in: ibuf record */
 	const byte*	types,			/*!< in: fields */
 	ulint		n_fields,		/*!< in: number of fields */
-	ibool		pre_4_1,		/*!< in: TRUE=pre-4.1 format,
-						FALSE=newer */
 	ulint		comp)			/*!< in: 0=ROW_FORMAT=REDUNDANT,
 						nonzero=ROW_FORMAT=COMPACT */
 {
@@ -1763,13 +1686,8 @@ ibuf_rec_get_size(
 	ulint	types_offset;
 	ulint	size = 0;
 
-	if (pre_4_1) {
-		field_offset = 2;
-		types_offset = DATA_ORDER_NULL_TYPE_BUF_SIZE;
-	} else {
-		field_offset = IBUF_REC_FIELD_USER;
-		types_offset = DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE;
-	}
+	field_offset = IBUF_REC_FIELD_USER;
+	types_offset = DATA_NEW_ORDER_NULL_TYPE_BUF_SIZE;
 
 	for (i = 0; i < n_fields; i++) {
 		ulint		len;
@@ -1779,10 +1697,6 @@ ibuf_rec_get_size(
 
 		if (len != UNIV_SQL_NULL) {
 			size += len;
-		} else if (pre_4_1) {
-			dtype_read_for_order_and_null_size(&dtype, types);
-
-			size += dtype_get_sql_null_size(&dtype, comp);
 		} else {
 			dtype_new_read_for_order_and_null_size(&dtype, types);
 
@@ -1820,8 +1734,9 @@ ibuf_rec_get_volume_func(
 	const byte*	types;
 	ulint		n_fields;
 	ulint		data_size;
-	ibool		pre_4_1;
 	ulint		comp;
+	ibuf_op_t	op;
+	ulint		info_len;
 
 	ut_ad(mtr_memo_contains_page(mtr, ibuf_rec, MTR_MEMO_PAGE_X_FIX)
 	      || mtr_memo_contains_page(mtr, ibuf_rec, MTR_MEMO_PAGE_S_FIX));
@@ -1829,64 +1744,44 @@ ibuf_rec_get_volume_func(
 	ut_ad(rec_get_n_fields_old(ibuf_rec) > 2);
 
 	data = rec_get_nth_field_old(ibuf_rec, IBUF_REC_FIELD_MARKER, &len);
-	pre_4_1 = (len > 1);
-
-	if (pre_4_1) {
-		/* < 4.1.x format record */
-
-		ut_a(trx_doublewrite_must_reset_space_ids);
-		ut_a(!trx_sys_multiple_tablespace_format);
-
-		n_fields = rec_get_n_fields_old(ibuf_rec) - 2;
-
-		types = rec_get_nth_field_old(ibuf_rec, 1, &len);
-
-		ut_ad(len == n_fields * DATA_ORDER_NULL_TYPE_BUF_SIZE);
-		comp = 0;
-	} else {
-		/* >= 4.1.x format record */
-		ibuf_op_t	op;
-		ulint		info_len;
-
-		ut_a(trx_sys_multiple_tablespace_format);
-		ut_a(*data == 0);
+	ut_a(len == 1);
+	ut_a(*data == 0);
 
-		types = rec_get_nth_field_old(
-			ibuf_rec, IBUF_REC_FIELD_METADATA, &len);
+	types = rec_get_nth_field_old(
+		ibuf_rec, IBUF_REC_FIELD_METADATA, &len);
 
-		ibuf_rec_get_info(mtr, ibuf_rec, &op, &comp, &info_len, NULL);
-
-		if (op == IBUF_OP_DELETE_MARK || op == IBUF_OP_DELETE) {
-			/* Delete-marking a record doesn't take any
-			additional space, and while deleting a record
-			actually frees up space, we have to play it safe and
-			pretend it takes no additional space (the record
-			might not exist, etc.).  */
+	ibuf_rec_get_info(mtr, ibuf_rec, &op, &comp, &info_len, NULL);
 
-			return(0);
-		} else if (comp) {
-			dtuple_t*	entry;
-			ulint		volume;
-			dict_index_t*	dummy_index;
-			mem_heap_t*	heap = mem_heap_create(500);
+	if (op == IBUF_OP_DELETE_MARK || op == IBUF_OP_DELETE) {
+		/* Delete-marking a record doesn't take any
+		additional space, and while deleting a record
+		actually frees up space, we have to play it safe and
+		pretend it takes no additional space (the record
+		might not exist, etc.).  */
 
-			entry = ibuf_build_entry_from_ibuf_rec(
-				mtr, ibuf_rec, heap, &dummy_index);
+		return(0);
+	} else if (comp) {
+		dtuple_t*	entry;
+		ulint		volume;
+		dict_index_t*	dummy_index;
+		mem_heap_t*	heap = mem_heap_create(500);
 
-			volume = rec_get_converted_size(dummy_index, entry, 0);
+		entry = ibuf_build_entry_from_ibuf_rec(mtr, ibuf_rec,
+			heap, &dummy_index);
 
-			ibuf_dummy_index_free(dummy_index);
-			mem_heap_free(heap);
+		volume = rec_get_converted_size(dummy_index, entry, 0);
 
-			return(volume + page_dir_calc_reserved_space(1));
-		}
+		ibuf_dummy_index_free(dummy_index);
+		mem_heap_free(heap);
 
-		types += info_len;
-		n_fields = rec_get_n_fields_old(ibuf_rec)
-			- IBUF_REC_FIELD_USER;
+		return(volume + page_dir_calc_reserved_space(1));
 	}
 
-	data_size = ibuf_rec_get_size(ibuf_rec, types, n_fields, pre_4_1, comp);
+	types += info_len;
+	n_fields = rec_get_n_fields_old(ibuf_rec)
+		- IBUF_REC_FIELD_USER;
+
+	data_size = ibuf_rec_get_size(ibuf_rec, types, n_fields, comp);
 
 	return(data_size + rec_get_converted_extra_size(data_size, n_fields, 0)
 	       + page_dir_calc_reserved_space(1));
@@ -2060,7 +1955,7 @@ ibuf_entry_build(
 
 /*********************************************************************//**
 Builds a search tuple used to search buffered inserts for an index page.
-This is for < 4.1.x format records
+This is for >= 4.1.x format records.
 @return	own: search tuple */
 static
 dtuple_t*
@@ -2074,45 +1969,6 @@ ibuf_search_tuple_build(
 	dfield_t*	field;
 	byte*		buf;
 
-	ut_a(space == 0);
-	ut_a(trx_doublewrite_must_reset_space_ids);
-	ut_a(!trx_sys_multiple_tablespace_format);
-
-	tuple = dtuple_create(heap, 1);
-
-	/* Store the page number in tuple */
-
-	field = dtuple_get_nth_field(tuple, 0);
-
-	buf = static_cast<byte*>(mem_heap_alloc(heap, 4));
-
-	mach_write_to_4(buf, page_no);
-
-	dfield_set_data(field, buf, 4);
-
-	dtuple_set_types_binary(tuple, 1);
-
-	return(tuple);
-}
-
-/*********************************************************************//**
-Builds a search tuple used to search buffered inserts for an index page.
-This is for >= 4.1.x format records.
-@return	own: search tuple */
-static
-dtuple_t*
-ibuf_new_search_tuple_build(
-/*========================*/
-	ulint		space,	/*!< in: space id */
-	ulint		page_no,/*!< in: index page number */
-	mem_heap_t*	heap)	/*!< in: heap into which to build */
-{
-	dtuple_t*	tuple;
-	dfield_t*	field;
-	byte*		buf;
-
-	ut_a(trx_sys_multiple_tablespace_format);
-
 	tuple = dtuple_create(heap, IBUF_REC_FIELD_METADATA);
 
 	/* Store the space id in tuple */
@@ -2834,8 +2690,7 @@ ibuf_get_volume_buffered_hash(
 
 	len = ibuf_rec_get_size(
 		rec, types,
-		rec_get_n_fields_old(rec) - IBUF_REC_FIELD_USER,
-		FALSE, comp);
+		rec_get_n_fields_old(rec) - IBUF_REC_FIELD_USER, comp);
 	fold = ut_fold_binary(data, len);
 
 	hash += (fold / (CHAR_BIT * sizeof *hash)) % size;
@@ -2895,7 +2750,6 @@ ibuf_get_volume_buffered_count_func(
 	operations.  All pre-4.1 records should have been merged
 	when the database was started up. */
 	ut_a(len == 1);
-	ut_ad(trx_sys_multiple_tablespace_format);
 
 	types = rec_get_nth_field_old(rec, IBUF_REC_FIELD_METADATA, &len);
 
@@ -2909,7 +2763,7 @@ ibuf_get_volume_buffered_count_func(
 		because deletes cannot be buffered if there are
 		old-style inserts buffered for the page. */
 
-		len = ibuf_rec_get_size(rec, types, n_fields, FALSE, 0);
+		len = ibuf_rec_get_size(rec, types, n_fields, 0);
 
 		return(len
 		       + rec_get_converted_extra_size(len, n_fields, 0)
@@ -3014,8 +2868,6 @@ ibuf_get_volume_buffered(
 	/* bitmap of buffered recs */
 	ulint		hash_bitmap[128 / sizeof(ulint)];
 
-	ut_a(trx_sys_multiple_tablespace_format);
-
 	ut_ad((pcur->latch_mode == BTR_MODIFY_PREV)
 	      || (pcur->latch_mode == BTR_MODIFY_TREE));
 
@@ -3259,18 +3111,11 @@ ibuf_get_entry_counter_low_func(
 
 	field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_MARKER, &len);
 
-	if (UNIV_UNLIKELY(len != 1)) {
-		/* pre-4.1 format */
-		ut_a(trx_doublewrite_must_reset_space_ids);
-		ut_a(!trx_sys_multiple_tablespace_format);
-
-		return(ULINT_UNDEFINED);
-	}
-
-	ut_a(trx_sys_multiple_tablespace_format);
+	ut_a(len == 1);
 
 	/* Check the tablespace identifier. */
 	field = rec_get_nth_field_old(rec, IBUF_REC_FIELD_SPACE, &len);
+
 	ut_a(len == 4);
 
 	if (mach_read_from_4(field) != space) {
@@ -3411,8 +3256,6 @@ ibuf_insert_low(
 	ut_ad(!no_counter || op == IBUF_OP_INSERT);
 	ut_a(op < IBUF_OP_COUNT);
 
-	ut_a(trx_sys_multiple_tablespace_format);
-
 	do_merge = FALSE;
 
 	/* Perform dirty reads of ibuf->size and ibuf->max_size, to
@@ -3712,7 +3555,6 @@ ibuf_insert(
 	this function, so that we will have a consistent view of it. */
 	ibuf_use_t	use		= ibuf_use;
 
-	ut_a(trx_sys_multiple_tablespace_format);
 	ut_ad(dtuple_check_typed(entry));
 	ut_ad(ut_is_2pow(zip_size));
 
@@ -4465,13 +4307,7 @@ ibuf_merge_or_delete_for_page(
 
 	heap = mem_heap_create(512);
 
-	if (UNIV_UNLIKELY(!trx_sys_multiple_tablespace_format)) {
-		ut_a(trx_doublewrite_must_reset_space_ids);
-		search_tuple = ibuf_search_tuple_build(space, page_no, heap);
-	} else {
-		search_tuple = ibuf_new_search_tuple_build(space, page_no,
-							   heap);
-	}
+	search_tuple = ibuf_search_tuple_build(space, page_no, heap);
 
 	if (block) {
 		/* Move the ownership of the x-latch on the page to this OS
@@ -4780,7 +4616,7 @@ ibuf_delete_for_discarded_space(
 	/* Use page number 0 to build the search tuple so that we get the
 	cursor positioned at the first entry for this space id */
 
-	search_tuple = ibuf_new_search_tuple_build(space, 0, heap);
+	search_tuple = ibuf_search_tuple_build(space, 0, heap);
 
 	memset(dops, 0, sizeof(dops));
 loop:

=== added file 'storage/innobase/include/buf0dblwr.h'
--- a/storage/innobase/include/buf0dblwr.h	1970-01-01 00:00:00 +0000
+++ b/storage/innobase/include/buf0dblwr.h	2011-12-23 13:17:36 +0000
@@ -0,0 +1,147 @@
+/*****************************************************************************
+
+Copyright (c) 1995, 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 Street, Suite 500, Boston, MA 02110-1335 USA
+
+*****************************************************************************/
+
+/**************************************************//**
+@file include/buf0dblwr.h
+Doublewrite buffer module
+
+Created 2011/12/19 Inaam Rana
+*******************************************************/
+
+#ifndef buf0dblwr_h
+#define buf0dblwr_h
+
+#include "univ.i"
+#include "ut0byte.h"
+#include "log0log.h"
+
+#ifndef UNIV_HOTBACKUP
+
+/** Doublewrite system */
+extern buf_dblwr_t*	buf_dblwr;
+/** Set to TRUE when the doublewrite buffer is being created */
+extern ibool		buf_dblwr_being_created;
+
+/****************************************************************//**
+Creates the doublewrite buffer to a new InnoDB installation. The header of the
+doublewrite buffer is placed on the trx system header page. */
+UNIV_INTERN
+void
+buf_dblwr_create(void);
+/*==================*/
+/****************************************************************//**
+At a database startup initializes the doublewrite buffer memory structure if
+we already have a doublewrite buffer created in the data files. If we are
+upgrading to an InnoDB version which supports multiple tablespaces, then this
+function performs the necessary update operations. If we are in a crash
+recovery, this function uses a possible doublewrite buffer to restore
+half-written pages in the data files. */
+UNIV_INTERN
+void
+buf_dblwr_init_or_restore_pages(
+/*============================*/
+	ibool	restore_corrupt_pages);	/*!< in: TRUE=restore pages */
+/****************************************************************//**
+frees doublewrite buffer. */
+UNIV_INTERN
+void
+buf_dblwr_free(void);
+/*================*/
+/********************************************************************//**
+Updates the doublewrite buffer when an IO request that is part of an
+LRU or flush batch is completed. */
+UNIV_INTERN
+void
+buf_dblwr_update(void);
+/*==================*/
+/****************************************************************//**
+Determines if a page number is located inside the doublewrite buffer.
+@return TRUE if the location is inside the two blocks of the
+doublewrite buffer */
+UNIV_INTERN
+ibool
+buf_dblwr_page_inside(
+/*==================*/
+	ulint	page_no);	/*!< in: page number */
+/********************************************************************//**
+Posts a buffer page for writing. If the doublewrite memory buffer is
+full, calls buf_dblwr_flush_buffered_writes and waits for for free
+space to appear. */
+UNIV_INTERN
+void
+buf_dblwr_add_to_batch(
+/*====================*/
+	buf_page_t*	bpage);	/*!< in: buffer block to write */
+/********************************************************************//**
+Flushes possible buffered writes from the doublewrite memory buffer to disk,
+and also wakes up the aio thread if simulated aio is used. It is very
+important to call this function after a batch of writes has been posted,
+and also when we may have to wait for a page latch! Otherwise a deadlock
+of threads can occur. */
+UNIV_INTERN
+void
+buf_dblwr_flush_buffered_writes(void);
+/*=================================*/
+/********************************************************************//**
+Writes a page to the doublewrite buffer on disk, sync it, then write
+the page to the datafile and sync the datafile. This function is used
+for single page flushes. If all the buffers allocated for single page
+flushes in the doublewrite buffer are in use we wait here for one to
+become free. We are guaranteed that a slot will become free because any
+thread that is using a slot must also release the slot before leaving
+this function. */
+UNIV_INTERN
+void
+buf_dblwr_write_single_page(
+/*========================*/
+	buf_page_t*	bpage);	/*!< in: buffer block to write */
+
+/** Doublewrite control struct */
+struct buf_dblwr_struct{
+	mutex_t	mutex;		/*!< mutex protecting the first_free field and
+				write_buf */
+	ulint	block1;		/*!< the page number of the first
+				doublewrite block (64 pages) */
+	ulint	block2;		/*!< page number of the second block */
+	ulint	first_free;	/*!< first free position in write_buf measured
+				in units of UNIV_PAGE_SIZE */
+	ulint	s_reserved;	/*!< number of slots currently reserved
+				for single page flushes. */
+	ulint	b_reserved;	/*!< number of slots currently reserved
+				for batch flush. */
+	ibool*	in_use;		/*!< flag used to indicate if a slot is
+				in use. Only used for single page
+				flushes. */
+	ibool	batch_running;	/*!< set to TRUE if currently a batch
+				is being written from the doublewrite
+				buffer. */
+	byte*	write_buf;	/*!< write buffer used in writing to the
+				doublewrite buffer, aligned to an
+				address divisible by UNIV_PAGE_SIZE
+				(which is required by Windows aio) */
+	byte*	write_buf_unaligned;
+				/*!< pointer to write_buf, but unaligned */
+	buf_page_t**
+		buf_block_arr;	/*!< array to store pointers to the buffer
+				blocks which have been cached to write_buf */
+};
+
+
+#endif /* UNIV_HOTBACKUP */
+
+#endif

=== modified file 'storage/innobase/include/buf0types.h'
--- a/storage/innobase/include/buf0types.h	2011-12-07 15:21:53 +0000
+++ b/storage/innobase/include/buf0types.h	2011-12-23 13:17:36 +0000
@@ -38,6 +38,8 @@ typedef	struct buf_pool_struct		buf_pool
 typedef	struct buf_pool_stat_struct	buf_pool_stat_t;
 /** Buffer pool buddy statistics struct */
 typedef	struct buf_buddy_stat_struct	buf_buddy_stat_t;
+/** Doublewrite memory struct */
+typedef struct buf_dblwr_struct		buf_dblwr_t;
 
 /** A buffer frame. @see page_t */
 typedef	byte	buf_frame_t;

=== modified file 'storage/innobase/include/mtr0log.ic'
--- a/storage/innobase/include/mtr0log.ic	2011-11-08 10:32:23 +0000
+++ b/storage/innobase/include/mtr0log.ic	2011-12-23 13:17:36 +0000
@@ -26,6 +26,7 @@ Created 12/7/1995 Heikki Tuuri
 #include "mach0data.h"
 #include "ut0lst.h"
 #include "buf0buf.h"
+#include "buf0dblwr.h"
 #include "fsp0types.h"
 #include "trx0sys.h"
 
@@ -203,7 +204,7 @@ mlog_write_initial_log_record_fast(
 	system tablespace */
 	if (space == TRX_SYS_SPACE
 	    && offset >= FSP_EXTENT_SIZE && offset < 3 * FSP_EXTENT_SIZE) {
-		if (trx_doublewrite_buf_is_being_created) {
+		if (buf_dblwr_being_created) {
 			/* Do nothing: we only come to this branch in an
 			InnoDB database creation. We do not redo log
 			anything for the doublewrite buffer pages. */

=== modified file 'storage/innobase/include/os0file.h'
--- a/storage/innobase/include/os0file.h	2011-11-24 07:15:35 +0000
+++ b/storage/innobase/include/os0file.h	2011-12-21 19:35:09 +0000
@@ -46,9 +46,6 @@ Created 10/21/1995 Heikki Tuuri
 /** File node of a tablespace or the log data space */
 typedef	struct fil_node_struct	fil_node_t;
 
-#ifdef UNIV_DO_FLUSH
-extern ibool	os_do_not_call_flush_at_each_write;
-#endif /* UNIV_DO_FLUSH */
 extern ibool	os_has_said_disk_full;
 /** Flag: enable debug printout for asynchronous i/o */
 extern ibool	os_aio_print_debug;

=== modified file 'storage/innobase/include/sync0sync.h'
--- a/storage/innobase/include/sync0sync.h	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/include/sync0sync.h	2011-12-23 13:17:36 +0000
@@ -109,7 +109,7 @@ extern mysql_pfs_key_t	srv_monitor_file_
 # ifdef UNIV_SYNC_DEBUG
 extern mysql_pfs_key_t	sync_thread_mutex_key;
 # endif /* UNIV_SYNC_DEBUG */
-extern mysql_pfs_key_t	trx_doublewrite_mutex_key;
+extern mysql_pfs_key_t	buf_dblwr_mutex_key;
 extern mysql_pfs_key_t	trx_undo_mutex_key;
 extern mysql_pfs_key_t	trx_mutex_key;
 extern mysql_pfs_key_t	lock_sys_mutex_key;

=== modified file 'storage/innobase/include/trx0sys.h'
--- a/storage/innobase/include/trx0sys.h	2011-11-30 10:09:12 +0000
+++ b/storage/innobase/include/trx0sys.h	2011-12-23 13:17:36 +0000
@@ -69,53 +69,6 @@ extern ib_int64_t	trx_sys_mysql_bin_log_
 /** The transaction system */
 extern trx_sys_t*	trx_sys;
 
-/** Doublewrite system */
-extern trx_doublewrite_t*	trx_doublewrite;
-/** The following is set to TRUE when we are upgrading from pre-4.1
-format data files to the multiple tablespaces format data files */
-extern ibool			trx_doublewrite_must_reset_space_ids;
-/** Set to TRUE when the doublewrite buffer is being created */
-extern ibool			trx_doublewrite_buf_is_being_created;
-/** The following is TRUE when we are using the database in the
-post-4.1 format, i.e., we have successfully upgraded, or have created
-a new database installation */
-extern ibool			trx_sys_multiple_tablespace_format;
-
-/****************************************************************//**
-Creates the doublewrite buffer to a new InnoDB installation. The header of the
-doublewrite buffer is placed on the trx system header page. */
-UNIV_INTERN
-void
-trx_sys_create_doublewrite_buf(void);
-/*================================*/
-/****************************************************************//**
-At a database startup initializes the doublewrite buffer memory structure if
-we already have a doublewrite buffer created in the data files. If we are
-upgrading to an InnoDB version which supports multiple tablespaces, then this
-function performs the necessary update operations. If we are in a crash
-recovery, this function uses a possible doublewrite buffer to restore
-half-written pages in the data files. */
-UNIV_INTERN
-void
-trx_sys_doublewrite_init_or_restore_pages(
-/*======================================*/
-	ibool	restore_corrupt_pages);	/*!< in: TRUE=restore pages */
-/****************************************************************//**
-Marks the trx sys header when we have successfully upgraded to the >= 4.1.x
-multiple tablespace format. */
-UNIV_INTERN
-void
-trx_sys_mark_upgraded_to_multiple_tablespaces(void);
-/*===============================================*/
-/****************************************************************//**
-Determines if a page number is located inside the doublewrite buffer.
-@return TRUE if the location is inside the two blocks of the
-doublewrite buffer */
-UNIV_INTERN
-ibool
-trx_doublewrite_page_inside(
-/*========================*/
-	ulint	page_no);	/*!< in: page number */
 /***************************************************************//**
 Checks if a page address is the trx sys header page.
 @return	TRUE if trx sys header page */
@@ -642,34 +595,6 @@ identifier is added to this 64-bit const
 /* @} */
 
 #ifndef UNIV_HOTBACKUP
-/** Doublewrite control struct */
-struct trx_doublewrite_struct{
-	mutex_t	mutex;		/*!< mutex protecting the first_free field and
-				write_buf */
-	ulint	block1;		/*!< the page number of the first
-				doublewrite block (64 pages) */
-	ulint	block2;		/*!< page number of the second block */
-	ulint	first_free;	/*!< first free position in write_buf measured
-				in units of UNIV_PAGE_SIZE */
-	ulint	n_reserved;	/*!< number of slots currently reserved
-				for single page flushes. */
-	ibool*	in_use;		/*!< flag used to indicate if a slot is
-				in use. Only used for single page
-				flushes. */
-	ibool	batch_running;	/*!< set to TRUE if currently a batch
-				is being written from the doublewrite
-				buffer. */
-	byte*	write_buf;	/*!< write buffer used in writing to the
-				doublewrite buffer, aligned to an
-				address divisible by UNIV_PAGE_SIZE
-				(which is required by Windows aio) */
-	byte*	write_buf_unaligned;
-				/*!< pointer to write_buf, but unaligned */
-	buf_page_t**
-		buf_block_arr;	/*!< array to store pointers to the buffer
-				blocks which have been cached to write_buf */
-};
-
 /** The transaction system central memory data structure. */
 struct trx_sys_struct{
 

=== modified file 'storage/innobase/include/trx0types.h'
--- a/storage/innobase/include/trx0types.h	2011-11-08 10:32:23 +0000
+++ b/storage/innobase/include/trx0types.h	2011-12-23 13:17:36 +0000
@@ -60,8 +60,6 @@ typedef struct trx_struct	trx_t;
 typedef struct trx_lock_struct	trx_lock_t;
 /** Transaction system */
 typedef struct trx_sys_struct	trx_sys_t;
-/** Doublewrite information */
-typedef struct trx_doublewrite_struct	trx_doublewrite_t;
 /** Signal */
 typedef struct trx_sig_struct	trx_sig_t;
 /** Rollback segment */

=== modified file 'storage/innobase/include/ut0rnd.ic'
--- a/storage/innobase/include/ut0rnd.ic	2011-11-21 04:58:23 +0000
+++ b/storage/innobase/include/ut0rnd.ic	2011-12-22 02:47:18 +0000
@@ -117,7 +117,7 @@ ut_rnd_interval(
 
 	rnd = ut_rnd_gen_ulint();
 
-	return(low + (rnd % (high - low + 1)));
+	return(low + (rnd % (high - low)));
 }
 
 /*********************************************************//**

=== modified file 'storage/innobase/log/log0recv.cc'
--- a/storage/innobase/log/log0recv.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/log/log0recv.cc	2011-12-23 13:17:36 +0000
@@ -2866,7 +2866,7 @@ recv_init_crash_recovery(void)
 			" half-written data pages from"
 			" the doublewrite\n"
 			"InnoDB: buffer...\n");
-		trx_sys_doublewrite_init_or_restore_pages(TRUE);
+		buf_dblwr_init_or_restore_pages(TRUE);
 	}
 }
 
@@ -3139,7 +3139,7 @@ recv_recovery_from_checkpoint_start_func
 
 		if (!recv_needed_recovery) {
 			/* Init the doublewrite buffer memory structure */
-			trx_sys_doublewrite_init_or_restore_pages(FALSE);
+			buf_dblwr_init_or_restore_pages(FALSE);
 		}
 	}
 

=== modified file 'storage/innobase/os/os0file.cc'
--- a/storage/innobase/os/os0file.cc	2011-12-01 10:04:44 +0000
+++ b/storage/innobase/os/os0file.cc	2011-12-21 19:35:09 +0000
@@ -73,14 +73,6 @@ UNIV_INTERN ulint	os_innodb_umask
 UNIV_INTERN ulint	os_innodb_umask		= 0;
 #endif
 
-#ifdef UNIV_DO_FLUSH
-/* If the following is set to TRUE, we do not call os_file_flush in every
-os_file_write. We can set this TRUE when the doublewrite buffer is used. */
-UNIV_INTERN ibool	os_do_not_call_flush_at_each_write	= FALSE;
-#else
-/* We do not call os_file_flush in every os_file_write. */
-#endif /* UNIV_DO_FLUSH */
-
 #ifndef UNIV_HOTBACKUP
 /* We use these mutexes to protect lseek + file i/o operation, if the
 OS does not provide an atomic pread or pwrite, or similar */
@@ -2355,19 +2347,6 @@ os_file_pwrite(
 	MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_WRITES);
 #endif /* !HAVE_ATOMIC_BUILTINS || UNIV_WORD < 8 */
 
-# ifdef UNIV_DO_FLUSH
-	if (srv_unix_file_flush_method != SRV_UNIX_LITTLESYNC
-	    && srv_unix_file_flush_method != SRV_UNIX_NOSYNC
-	    && !os_do_not_call_flush_at_each_write) {
-
-		/* Always do fsync to reduce the probability that when
-		the OS crashes, a database page is only partially
-		physically written to disk. */
-
-		ut_a(TRUE == os_file_flush(file));
-	}
-# endif /* UNIV_DO_FLUSH */
-
 	return(ret);
 #else
 	{
@@ -2398,19 +2377,6 @@ os_file_pwrite(
 
 		ret = write(file, buf, (ssize_t) n);
 
-# ifdef UNIV_DO_FLUSH
-		if (srv_unix_file_flush_method != SRV_UNIX_LITTLESYNC
-		    && srv_unix_file_flush_method != SRV_UNIX_NOSYNC
-		    && !os_do_not_call_flush_at_each_write) {
-
-			/* Always do fsync to reduce the probability that when
-			the OS crashes, a database page is only partially
-			physically written to disk. */
-
-			ut_a(TRUE == os_file_flush(file));
-		}
-# endif /* UNIV_DO_FLUSH */
-
 func_exit:
 # ifndef UNIV_HOTBACKUP
 		os_mutex_exit(os_file_seek_mutexes[i]);
@@ -2773,15 +2739,6 @@ retry:
 
 	ret = WriteFile(file, buf, (DWORD) n, &len, NULL);
 
-	/* Always do fsync to reduce the probability that when the OS crashes,
-	a database page is only partially physically written to disk. */
-
-# ifdef UNIV_DO_FLUSH
-	if (!os_do_not_call_flush_at_each_write) {
-		ut_a(TRUE == os_file_flush(file));
-	}
-# endif /* UNIV_DO_FLUSH */
-
 #ifndef UNIV_HOTBACKUP
 	os_mutex_exit(os_file_seek_mutexes[i]);
 #endif /* !UNIV_HOTBACKUP */
@@ -4312,16 +4269,8 @@ os_aio_windows_handle(
 	*type = slot->type;
 
 	if (ret && len == slot->len) {
-		ret_val = TRUE;
 
-#ifdef UNIV_DO_FLUSH
-		if (slot->type == OS_FILE_WRITE
-		    && !os_do_not_call_flush_at_each_write) {
-			if (!os_file_flush(slot->file)) {
-				ut_error;
-			}
-		}
-#endif /* UNIV_DO_FLUSH */
+		ret_val = TRUE;
 	} else if (os_file_handle_error(slot->name, "Windows aio")) {
 
 		retry = TRUE;
@@ -4613,15 +4562,8 @@ found:
 	*type = slot->type;
 
 	if ((slot->ret == 0) && (slot->n_bytes == (long) slot->len)) {
-		ret = TRUE;
 
-#ifdef UNIV_DO_FLUSH
-		if (slot->type == OS_FILE_WRITE
-		    && !os_do_not_call_flush_at_each_write)
-		    && !os_file_flush(slot->file) {
-			ut_error;
-		}
-#endif /* UNIV_DO_FLUSH */
+		ret = TRUE;
 	} else {
 		errno = -slot->ret;
 

=== modified file 'storage/innobase/row/row0sel.cc'
--- a/storage/innobase/row/row0sel.cc	2011-12-05 08:30:46 +0000
+++ b/storage/innobase/row/row0sel.cc	2011-12-21 13:01:49 +0000
@@ -4208,10 +4208,12 @@ rec_loop:
 #ifdef UNIV_SEARCH_DEBUG
 	/*
 	fputs("Using ", stderr);
-	dict_index_name_print(stderr, index);
+	dict_index_name_print(stderr, trx, index);
 	fprintf(stderr, " cnt %lu ; Page no %lu\n", cnt,
 	page_get_page_no(page_align(rec)));
-	rec_print(rec);
+	rec_print(stderr, rec, index);
+	printf("delete-mark: %lu\n",
+	       rec_get_deleted_flag(rec, page_rec_is_comp(rec)));
 	*/
 #endif /* UNIV_SEARCH_DEBUG */
 
@@ -4392,8 +4394,10 @@ wrong_offs:
 			btr_pcur_store_position(pcur, &mtr);
 
 			err = DB_RECORD_NOT_FOUND;
-			/* ut_print_name(stderr, index->name);
-			fputs(" record not found 3\n", stderr); */
+#if 0
+			ut_print_name(stderr, trx, FALSE, index->name);
+			fputs(" record not found 3\n", stderr);
+#endif
 
 			goto normal_return;
 		}
@@ -4431,8 +4435,10 @@ wrong_offs:
 			btr_pcur_store_position(pcur, &mtr);
 
 			err = DB_RECORD_NOT_FOUND;
-			/* ut_print_name(stderr, index->name);
-			fputs(" record not found 4\n", stderr); */
+#if 0
+			ut_print_name(stderr, trx, FALSE, index->name);
+			fputs(" record not found 4\n", stderr);
+#endif
 
 			goto normal_return;
 		}

=== modified file 'storage/innobase/srv/srv0start.cc'
--- a/storage/innobase/srv/srv0start.cc	2011-12-08 20:20:49 +0000
+++ b/storage/innobase/srv/srv0start.cc	2011-12-23 13:17:36 +0000
@@ -2148,10 +2148,10 @@ innobase_start_or_create_for_mysql(void)
 	/* fprintf(stderr, "Max allowed record size %lu\n",
 	page_get_free_space_of_empty() / 2); */
 
-	if (trx_doublewrite == NULL) {
+	if (buf_dblwr == NULL) {
 		/* Create the doublewrite buffer to a new tablespace */
 
-		trx_sys_create_doublewrite_buf();
+		buf_dblwr_create();
 	}
 
 	/* Here the double write buffer has already been created and so
@@ -2388,67 +2388,6 @@ innobase_start_or_create_for_mysql(void)
 
 	fflush(stderr);
 
-	if (trx_doublewrite_must_reset_space_ids) {
-		/* Actually, we did not change the undo log format between
-		4.0 and 4.1.1, and we would not need to run purge to
-		completion. Note also that the purge algorithm in 4.1.1
-		can process the history list again even after a full
-		purge, because our algorithm does not cut the end of the
-		history list in all cases so that it would become empty
-		after a full purge. That mean that we may purge 4.0 type
-		undo log even after this phase.
-
-		The insert buffer record format changed between 4.0 and
-		4.1.1. It is essential that the insert buffer is emptied
-		here! */
-
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: You are upgrading to an"
-			" InnoDB version which allows multiple\n");
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: tablespaces. Wait that purge"
-			" and insert buffer merge run to\n");
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: completion...\n");
-		for (;;) {
-			os_thread_sleep(1000000);
-
-			if (0 == strcmp(srv_main_thread_op_info,
-					"waiting for server activity")) {
-
-				ut_a(ibuf_is_empty());
-
-				break;
-			}
-		}
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: Full purge and insert buffer merge"
-			" completed.\n");
-
-		trx_sys_mark_upgraded_to_multiple_tablespaces();
-
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: You have now successfully upgraded"
-			" to the multiple tablespaces\n");
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: format. You should NOT DOWNGRADE"
-			" to an earlier version of\n");
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: InnoDB! But if you absolutely need to"
-			" downgrade, see\n");
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: " REFMAN "multiple-tablespaces.html\n"
-			" InnoDB: for instructions.\n");
-	}
-
 	if (srv_force_recovery == 0) {
 		/* In the insert buffer we may have even bigger tablespace
 		id's, because we may have dropped those tablespaces, but

=== modified file 'storage/innobase/trx/trx0sys.cc'
--- a/storage/innobase/trx/trx0sys.cc	2011-12-19 08:43:28 +0000
+++ b/storage/innobase/trx/trx0sys.cc	2011-12-23 13:17:36 +0000
@@ -58,19 +58,6 @@ typedef struct file_format_struct	file_f
 
 /** The transaction system */
 UNIV_INTERN trx_sys_t*		trx_sys		= NULL;
-/** The doublewrite buffer */
-UNIV_INTERN trx_doublewrite_t*	trx_doublewrite = NULL;
-
-/** The following is set to TRUE when we are upgrading from pre-4.1
-format data files to the multiple tablespaces format data files */
-UNIV_INTERN ibool	trx_doublewrite_must_reset_space_ids	= FALSE;
-/** Set to TRUE when the doublewrite buffer is being created */
-UNIV_INTERN ibool	trx_doublewrite_buf_is_being_created = FALSE;
-
-/** The following is TRUE when we are using the database in the
-post-4.1 format, i.e., we have successfully upgraded, or have created
-a new database installation */
-UNIV_INTERN ibool	trx_sys_multiple_tablespace_format	= FALSE;
 
 /** In a MySQL replication slave, in crash recovery we store the master log
 file name and position here. */
@@ -130,7 +117,6 @@ static const ulint	FILE_FORMAT_NAME_N
 
 #ifdef UNIV_PFS_MUTEX
 /* Key to register the mutex with performance schema */
-UNIV_INTERN mysql_pfs_key_t	trx_doublewrite_mutex_key;
 UNIV_INTERN mysql_pfs_key_t	file_format_max_mutex_key;
 UNIV_INTERN mysql_pfs_key_t	trx_sys_mutex_key;
 #endif /* UNIV_PFS_RWLOCK */
@@ -141,546 +127,6 @@ updated via SET GLOBAL innodb_file_forma
 or create a table. */
 static	file_format_t	file_format_max;
 
-/****************************************************************//**
-Determines if a page number is located inside the doublewrite buffer.
-@return TRUE if the location is inside the two blocks of the
-doublewrite buffer */
-UNIV_INTERN
-ibool
-trx_doublewrite_page_inside(
-/*========================*/
-	ulint	page_no)	/*!< in: page number */
-{
-	if (trx_doublewrite == NULL) {
-
-		return(FALSE);
-	}
-
-	if (page_no >= trx_doublewrite->block1
-	    && page_no < trx_doublewrite->block1
-	    + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
-		return(TRUE);
-	}
-
-	if (page_no >= trx_doublewrite->block2
-	    && page_no < trx_doublewrite->block2
-	    + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
-		return(TRUE);
-	}
-
-	return(FALSE);
-}
-
-/****************************************************************//**
-Creates or initialializes the doublewrite buffer at a database start. */
-static
-void
-trx_doublewrite_init(
-/*=================*/
-	byte*	doublewrite)	/*!< in: pointer to the doublewrite buf
-				header on trx sys page */
-{
-	ulint	buf_size;
-
-	trx_doublewrite = static_cast<trx_doublewrite_t*>(
-		mem_zalloc(sizeof(trx_doublewrite_t)));
-
-	/* There are two blocks of same size in the doublewrite
-	buffer. */
-	buf_size = 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
-
-	/* There must be atleast one buffer for single page writes
-	and one buffer for batch writes. */
-	ut_a(srv_doublewrite_batch_size > 0
-	     && srv_doublewrite_batch_size < buf_size);
-
-	/* Since we now start to use the doublewrite buffer, no need to call
-	fsync() after every write to a data file */
-#ifdef UNIV_DO_FLUSH
-	os_do_not_call_flush_at_each_write = TRUE;
-#endif /* UNIV_DO_FLUSH */
-
-	mutex_create(trx_doublewrite_mutex_key,
-		     &trx_doublewrite->mutex, SYNC_DOUBLEWRITE);
-
-	trx_doublewrite->first_free = 0;
-	trx_doublewrite->n_reserved = 0;
-
-	trx_doublewrite->block1 = mach_read_from_4(
-		doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK1);
-	trx_doublewrite->block2 = mach_read_from_4(
-		doublewrite + TRX_SYS_DOUBLEWRITE_BLOCK2);
-
-	trx_doublewrite->in_use = static_cast<ibool*>(
-		mem_zalloc(buf_size * sizeof(ibool)));
-
-	trx_doublewrite->write_buf_unaligned = static_cast<byte*>(
-		ut_malloc((1 + buf_size) * UNIV_PAGE_SIZE));
-
-	trx_doublewrite->write_buf = static_cast<byte*>(
-		ut_align(trx_doublewrite->write_buf_unaligned,
-			 UNIV_PAGE_SIZE));
-
-	trx_doublewrite->buf_block_arr = static_cast<buf_page_t**>(
-		mem_zalloc(buf_size * sizeof(void*)));
-}
-
-/****************************************************************//**
-Calls buf_page_get() on the TRX_SYS_PAGE and returns a pointer to the
-doublewrite buffer within it.
-@return	pointer to the doublewrite buffer within the filespace header
-page. */
-UNIV_INLINE
-byte*
-trx_sys_doublewrite_get(
-/*====================*/
-	mtr_t*	mtr)	/*!< in/out: MTR to hold the page latch */
-{
-	buf_block_t*	block;
-
-	block = buf_page_get(TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO,
-			     RW_X_LATCH, mtr);
-	buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
-
-	return(buf_block_get_frame(block) + TRX_SYS_DOUBLEWRITE);
-}
-
-/****************************************************************//**
-Marks the trx sys header when we have successfully upgraded to the >= 4.1.x
-multiple tablespace format. */
-UNIV_INTERN
-void
-trx_sys_mark_upgraded_to_multiple_tablespaces(void)
-/*===============================================*/
-{
-	byte*		doublewrite;
-	mtr_t		mtr;
-
-	/* We upgraded to 4.1.x and reset the space id fields in the
-	doublewrite buffer. Let us mark to the trx_sys header that the upgrade
-	has been done. */
-
-	mtr_start(&mtr);
-
-	doublewrite = trx_sys_doublewrite_get(&mtr);
-
-	mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED,
-			 TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
-			 MLOG_4BYTES, &mtr);
-	mtr_commit(&mtr);
-
-	/* Flush the modified pages to disk and make a checkpoint */
-	log_make_checkpoint_at(LSN_MAX, TRUE);
-
-	trx_sys_multiple_tablespace_format = TRUE;
-}
-
-/****************************************************************//**
-Creates the doublewrite buffer to a new InnoDB installation. The header of the
-doublewrite buffer is placed on the trx system header page. */
-UNIV_INTERN
-void
-trx_sys_create_doublewrite_buf(void)
-/*================================*/
-{
-	buf_block_t*	block2;
-#ifdef UNIV_SYNC_DEBUG
-	buf_block_t*	new_block;
-#endif /* UNIV_SYNC_DEBUG */
-	byte*	doublewrite;
-	byte*	fseg_header;
-	ulint	page_no;
-	ulint	prev_page_no;
-	ulint	i;
-	mtr_t	mtr;
-
-	if (trx_doublewrite) {
-		/* Already inited */
-
-		return;
-	}
-
-start_again:
-	mtr_start(&mtr);
-	trx_doublewrite_buf_is_being_created = TRUE;
-
-	doublewrite = trx_sys_doublewrite_get(&mtr);
-
-	if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
-	    == TRX_SYS_DOUBLEWRITE_MAGIC_N) {
-		/* The doublewrite buffer has already been created:
-		just read in some numbers */
-
-		trx_doublewrite_init(doublewrite);
-
-		mtr_commit(&mtr);
-		trx_doublewrite_buf_is_being_created = FALSE;
-	} else {
-		ut_print_timestamp(stderr);
-		fprintf(stderr,
-			" InnoDB: Doublewrite buffer not found:"
-			" creating new\n");
-
-		if (buf_pool_get_curr_size()
-		    < ((2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
-			+ FSP_EXTENT_SIZE / 2 + 100)
-		       * UNIV_PAGE_SIZE)) {
-			fprintf(stderr,
-				"InnoDB: Cannot create doublewrite buffer:"
-				" you must\n"
-				"InnoDB: increase your buffer pool size.\n"
-				"InnoDB: Cannot continue operation.\n");
-
-			exit(1);
-		}
-
-		block2 = fseg_create(TRX_SYS_SPACE, TRX_SYS_PAGE_NO,
-				     TRX_SYS_DOUBLEWRITE
-				     + TRX_SYS_DOUBLEWRITE_FSEG, &mtr);
-
-		/* fseg_create acquires a second latch on the page,
-		therefore we must declare it: */
-
-		buf_block_dbg_add_level(block2, SYNC_NO_ORDER_CHECK);
-
-		if (block2 == NULL) {
-			fprintf(stderr,
-				"InnoDB: Cannot create doublewrite buffer:"
-				" you must\n"
-				"InnoDB: increase your tablespace size.\n"
-				"InnoDB: Cannot continue operation.\n");
-
-			/* We exit without committing the mtr to prevent
-			its modifications to the database getting to disk */
-
-			exit(1);
-		}
-
-		fseg_header = doublewrite + TRX_SYS_DOUBLEWRITE_FSEG;
-		prev_page_no = 0;
-
-		for (i = 0; i < 2 * TRX_SYS_DOUBLEWRITE_BLOCK_SIZE
-			     + FSP_EXTENT_SIZE / 2; i++) {
-			page_no = fseg_alloc_free_page(fseg_header,
-						       prev_page_no + 1,
-						       FSP_UP, &mtr);
-			if (page_no == FIL_NULL) {
-				fprintf(stderr,
-					"InnoDB: Cannot create doublewrite"
-					" buffer: you must\n"
-					"InnoDB: increase your"
-					" tablespace size.\n"
-					"InnoDB: Cannot continue operation.\n"
-					);
-
-				exit(1);
-			}
-
-			/* We read the allocated pages to the buffer pool;
-			when they are written to disk in a flush, the space
-			id and page number fields are also written to the
-			pages. When we at database startup read pages
-			from the doublewrite buffer, we know that if the
-			space id and page number in them are the same as
-			the page position in the tablespace, then the page
-			has not been written to in doublewrite. */
-
-#ifdef UNIV_SYNC_DEBUG
-			new_block =
-#endif /* UNIV_SYNC_DEBUG */
-			buf_page_get(TRX_SYS_SPACE, 0, page_no,
-				     RW_X_LATCH, &mtr);
-			buf_block_dbg_add_level(new_block,
-						SYNC_NO_ORDER_CHECK);
-
-			if (i == FSP_EXTENT_SIZE / 2) {
-				ut_a(page_no == FSP_EXTENT_SIZE);
-				mlog_write_ulint(doublewrite
-						 + TRX_SYS_DOUBLEWRITE_BLOCK1,
-						 page_no, MLOG_4BYTES, &mtr);
-				mlog_write_ulint(doublewrite
-						 + TRX_SYS_DOUBLEWRITE_REPEAT
-						 + TRX_SYS_DOUBLEWRITE_BLOCK1,
-						 page_no, MLOG_4BYTES, &mtr);
-
-			} else if (i == FSP_EXTENT_SIZE / 2
-				   + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
-				ut_a(page_no == 2 * FSP_EXTENT_SIZE);
-				mlog_write_ulint(doublewrite
-						 + TRX_SYS_DOUBLEWRITE_BLOCK2,
-						 page_no, MLOG_4BYTES, &mtr);
-				mlog_write_ulint(doublewrite
-						 + TRX_SYS_DOUBLEWRITE_REPEAT
-						 + TRX_SYS_DOUBLEWRITE_BLOCK2,
-						 page_no, MLOG_4BYTES, &mtr);
-
-			} else if (i > FSP_EXTENT_SIZE / 2) {
-				ut_a(page_no == prev_page_no + 1);
-			}
-
-			if (((i + 1) & 15) == 0) {
-				/* rw_locks can only be recursively x-locked
-				2048 times. (on 32 bit platforms,
-				(lint) 0 - (X_LOCK_DECR * 2049)
-				is no longer a negative number, and thus
-				lock_word becomes like a shared lock).
-				For 4k page size this loop will
-				lock the fseg header too many times. Since
-				this code is not done while any other threads
-				are active, restart the MTR occasionally. */
-				mtr_commit(&mtr);
-				mtr_start(&mtr);
-				doublewrite = trx_sys_doublewrite_get(&mtr);
-				fseg_header = doublewrite
-					      + TRX_SYS_DOUBLEWRITE_FSEG;
-			}
-
-			prev_page_no = page_no;
-		}
-
-		mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC,
-				 TRX_SYS_DOUBLEWRITE_MAGIC_N,
-				 MLOG_4BYTES, &mtr);
-		mlog_write_ulint(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC
-				 + TRX_SYS_DOUBLEWRITE_REPEAT,
-				 TRX_SYS_DOUBLEWRITE_MAGIC_N,
-				 MLOG_4BYTES, &mtr);
-
-		mlog_write_ulint(doublewrite
-				 + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED,
-				 TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
-				 MLOG_4BYTES, &mtr);
-		mtr_commit(&mtr);
-
-		/* Flush the modified pages to disk and make a checkpoint */
-		log_make_checkpoint_at(LSN_MAX, TRUE);
-
-		/* Remove doublewrite pages from LRU */
-		buf_pool_invalidate();
-
-		ut_print_timestamp(stderr);
-		fprintf(stderr, " InnoDB: Doublewrite buffer created\n");
-
-		trx_sys_multiple_tablespace_format = TRUE;
-
-		goto start_again;
-	}
-}
-
-/****************************************************************//**
-At a database startup initializes the doublewrite buffer memory structure if
-we already have a doublewrite buffer created in the data files. If we are
-upgrading to an InnoDB version which supports multiple tablespaces, then this
-function performs the necessary update operations. If we are in a crash
-recovery, this function uses a possible doublewrite buffer to restore
-half-written pages in the data files. */
-UNIV_INTERN
-void
-trx_sys_doublewrite_init_or_restore_pages(
-/*======================================*/
-	ibool	restore_corrupt_pages)	/*!< in: TRUE=restore pages */
-{
-	byte*	buf;
-	byte*	read_buf;
-	byte*	unaligned_read_buf;
-	ulint	block1;
-	ulint	block2;
-	ulint	source_page_no;
-	byte*	page;
-	byte*	doublewrite;
-	ulint	space_id;
-	ulint	page_no;
-	ulint	i;
-
-	/* We do the file i/o past the buffer pool */
-
-	unaligned_read_buf = static_cast<byte*>(ut_malloc(2 * UNIV_PAGE_SIZE));
-
-	read_buf = static_cast<byte*>(
-		ut_align(unaligned_read_buf, UNIV_PAGE_SIZE));
-
-	/* Read the trx sys header to check if we are using the doublewrite
-	buffer */
-
-	fil_io(OS_FILE_READ, TRUE, TRX_SYS_SPACE, 0, TRX_SYS_PAGE_NO, 0,
-	       UNIV_PAGE_SIZE, read_buf, NULL);
-	doublewrite = read_buf + TRX_SYS_DOUBLEWRITE;
-
-	if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_MAGIC)
-	    == TRX_SYS_DOUBLEWRITE_MAGIC_N) {
-		/* The doublewrite buffer has been created */
-
-		trx_doublewrite_init(doublewrite);
-
-		block1 = trx_doublewrite->block1;
-		block2 = trx_doublewrite->block2;
-
-		buf = trx_doublewrite->write_buf;
-	} else {
-		goto leave_func;
-	}
-
-	if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED)
-	    != TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N) {
-
-		/* We are upgrading from a version < 4.1.x to a version where
-		multiple tablespaces are supported. We must reset the space id
-		field in the pages in the doublewrite buffer because starting
-		from this version the space id is stored to
-		FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */
-
-		trx_doublewrite_must_reset_space_ids = TRUE;
-
-		fprintf(stderr,
-			"InnoDB: Resetting space id's in the"
-			" doublewrite buffer\n");
-	} else {
-		trx_sys_multiple_tablespace_format = TRUE;
-	}
-
-	/* Read the pages from the doublewrite buffer to memory */
-
-	fil_io(OS_FILE_READ, TRUE, TRX_SYS_SPACE, 0, block1, 0,
-	       TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE,
-	       buf, NULL);
-	fil_io(OS_FILE_READ, TRUE, TRX_SYS_SPACE, 0, block2, 0,
-	       TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE,
-	       buf + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE,
-	       NULL);
-	/* Check if any of these pages is half-written in data files, in the
-	intended position */
-
-	page = buf;
-
-	for (i = 0; i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * 2; i++) {
-
-		page_no = mach_read_from_4(page + FIL_PAGE_OFFSET);
-
-		if (trx_doublewrite_must_reset_space_ids) {
-
-			space_id = 0;
-			mach_write_to_4(page
-					+ FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 0);
-			/* We do not need to calculate new checksums for the
-			pages because the field .._SPACE_ID does not affect
-			them. Write the page back to where we read it from. */
-
-			if (i < TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
-				source_page_no = block1 + i;
-			} else {
-				source_page_no = block2
-					+ i - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE;
-			}
-
-			fil_io(OS_FILE_WRITE, TRUE, 0, 0, source_page_no, 0,
-			       UNIV_PAGE_SIZE, page, NULL);
-			/* printf("Resetting space id in page %lu\n",
-			source_page_no); */
-		} else {
-			space_id = mach_read_from_4(
-				page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
-		}
-
-		if (!restore_corrupt_pages) {
-			/* The database was shut down gracefully: no need to
-			restore pages */
-
-		} else if (!fil_tablespace_exists_in_mem(space_id)) {
-			/* Maybe we have dropped the single-table tablespace
-			and this page once belonged to it: do nothing */
-
-		} else if (!fil_check_adress_in_tablespace(space_id,
-							   page_no)) {
-			fprintf(stderr,
-				"InnoDB: Warning: a page in the"
-				" doublewrite buffer is not within space\n"
-				"InnoDB: bounds; space id %lu"
-				" page number %lu, page %lu in"
-				" doublewrite buf.\n",
-				(ulong) space_id, (ulong) page_no, (ulong) i);
-
-		} else if (space_id == TRX_SYS_SPACE
-			   && ((page_no >= block1
-				&& page_no
-				< block1 + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)
-			       || (page_no >= block2
-				   && page_no
-				   < (block2
-				      + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE)))) {
-
-			/* It is an unwritten doublewrite buffer page:
-			do nothing */
-		} else {
-			ulint	zip_size = fil_space_get_zip_size(space_id);
-
-			/* Read in the actual page from the file */
-			fil_io(OS_FILE_READ, TRUE, space_id, zip_size,
-			       page_no, 0,
-			       zip_size ? zip_size : UNIV_PAGE_SIZE,
-			       read_buf, NULL);
-
-			/* Check if the page is corrupt */
-
-			if (UNIV_UNLIKELY
-			    (buf_page_is_corrupted(read_buf, zip_size))) {
-
-				fprintf(stderr,
-					"InnoDB: Warning: database page"
-					" corruption or a failed\n"
-					"InnoDB: file read of"
-					" space %lu page %lu.\n"
-					"InnoDB: Trying to recover it from"
-					" the doublewrite buffer.\n",
-					(ulong) space_id, (ulong) page_no);
-
-				if (buf_page_is_corrupted(page, zip_size)) {
-					fprintf(stderr,
-						"InnoDB: Dump of the page:\n");
-					buf_page_print(read_buf, zip_size);
-					fprintf(stderr,
-						"InnoDB: Dump of"
-						" corresponding page"
-						" in doublewrite buffer:\n");
-					buf_page_print(page, zip_size);
-
-					fprintf(stderr,
-						"InnoDB: Also the page in the"
-						" doublewrite buffer"
-						" is corrupt.\n"
-						"InnoDB: Cannot continue"
-						" operation.\n"
-						"InnoDB: You can try to"
-						" recover the database"
-						" with the my.cnf\n"
-						"InnoDB: option:\n"
-						"InnoDB:"
-						" innodb_force_recovery=6\n");
-					exit(1);
-				}
-
-				/* Write the good page from the
-				doublewrite buffer to the intended
-				position */
-
-				fil_io(OS_FILE_WRITE, TRUE, space_id,
-				       zip_size, page_no, 0,
-				       zip_size ? zip_size : UNIV_PAGE_SIZE,
-				       page, NULL);
-				fprintf(stderr,
-					"InnoDB: Recovered the page from"
-					" the doublewrite buffer.\n");
-			}
-		}
-
-		page += UNIV_PAGE_SIZE;
-	}
-
-	fil_flush_file_spaces(FIL_TABLESPACE);
-
-leave_func:
-	ut_free(unaligned_read_buf);
-}
-
 #ifdef UNIV_DEBUG
 /****************************************************************//**
 Checks whether a trx is in one of rw_trx_list or ro_trx_list.
@@ -1735,21 +1181,7 @@ trx_sys_close(void)
 	trx_purge_sys_close();
 
 	/* Free the double write data structures. */
-	ut_a(trx_doublewrite != NULL);
-	ut_ad(trx_doublewrite->n_reserved == 0);
-
-	ut_free(trx_doublewrite->write_buf_unaligned);
-	trx_doublewrite->write_buf_unaligned = NULL;
-
-	mem_free(trx_doublewrite->buf_block_arr);
-	trx_doublewrite->buf_block_arr = NULL;
-
-	mem_free(trx_doublewrite->in_use);
-	trx_doublewrite->in_use = NULL;
-
-	mutex_free(&trx_doublewrite->mutex);
-	mem_free(trx_doublewrite);
-	trx_doublewrite = NULL;
+	buf_dblwr_free();
 
 	mutex_enter(&trx_sys->mutex);
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-wl5767 branch (mayank.prasad:3406 to 3407) WL#5767Mayank Prasad26 Dec