List:Commits« Previous MessageNext Message »
From:Daniel Fischer Date:August 2 2012 12:26pm
Subject:bzr push into mysql-5.5 branch (daniel.fischer:3818 to 3823)
View as plain text  
 3823 Georgi Kodinov	2012-05-15 [merge]
      merge 5.1->5.5

    modified:
      extra/yassl/taocrypt/src/asn.cpp
      vio/viosslfactories.c
 3822 Bjorn Munch	2012-05-15 [merge]
      Upmerge optional testsuite path

    modified:
      mysql-test/lib/My/Find.pm
      mysql-test/lib/mtr_cases.pm
 3821 Joerg Bruehe	2012-05-14
      Raise version after cloning 5.5.25

    modified:
      VERSION
 3820 Annamalai Gurusami	2012-05-10 {clone-5.5.25-build, mysql-5.5.25} [merge]
      Merging from mysql-5.1 to mysql-5.5. 

    added:
      mysql-test/suite/innodb/r/innodb_bug14007649.result
      mysql-test/suite/innodb/t/innodb_bug14007649.test
    modified:
      storage/innobase/btr/btr0cur.c
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/handler/ha_innodb.h
 3819 Georgi Kodinov	2012-05-09 [merge]
      merge

 3818 Joerg Bruehe	2012-05-07 [merge]
      Merge 5.5.24 back into main 5.5.
      This is a weave merge, but without any conflicts.
      In 14 source files, the copyright year needed to be updated to 2012.

    added:
      mysql-test/r/blackhole.result
      mysql-test/suite/innodb/r/innodb_bug13635833.result
      mysql-test/suite/innodb/t/innodb_bug13635833.test
      mysql-test/suite/rpl/r/rpl_row_merge_engine.result
      mysql-test/suite/rpl/t/rpl_row_merge_engine.test
      mysql-test/t/blackhole.test
    modified:
      include/my_base.h
      include/violite.h
      mysql-test/r/cast.result
      mysql-test/r/errors.result
      mysql-test/r/gis.result
      mysql-test/r/subselect.result
      mysql-test/r/subselect_innodb.result
      mysql-test/r/user_var.result
      mysql-test/t/cast.test
      mysql-test/t/errors.test
      mysql-test/t/gis.test
      mysql-test/t/subselect.test
      mysql-test/t/subselect_innodb.test
      mysql-test/t/user_var.test
      mysys/my_handler_errors.h
      sql/field.cc
      sql/field.h
      sql/field_conv.cc
      sql/handler.cc
      sql/item.cc
      sql/item_subselect.cc
      sql/item_timefunc.cc
      sql/log_event.cc
      sql/log_event_old.cc
      sql/mysqld.cc
      sql/password.c
      sql/rpl_rli.cc
      sql/share/errmsg-utf8.txt
      sql/spatial.cc
      sql/sql_class.cc
      sql/sql_class.h
      sql/sql_select.cc
      storage/blackhole/ha_blackhole.cc
      storage/innobase/dict/dict0dict.c
      storage/innobase/handler/ha_innodb.cc
      storage/innobase/include/db0err.h
      storage/innobase/include/univ.i
      storage/innobase/row/row0ins.c
      storage/innobase/row/row0mysql.c
      storage/innobase/ut/ut0ut.c
      vio/viosocket.c
=== modified file '.bzr-mysql/default.conf'
--- a/.bzr-mysql/default.conf	2012-03-21 13:06:25 +0000
+++ b/.bzr-mysql/default.conf	2012-05-09 14:08:44 +0000
@@ -1,4 +1,4 @@
 [MYSQL]
-post_commit_to = "MYSQL_COMMITS_SECURITY_WW@stripped"
-post_push_to = "MYSQL_COMMITS_SECURITY_WW@stripped"
-tree_name = "mysql-5.5-security"
+post_commit_to = "commits@stripped"
+post_push_to = "commits@stripped"
+tree_name = "mysql-5.5"

=== modified file 'VERSION'
--- a/VERSION	2012-04-10 11:23:17 +0000
+++ b/VERSION	2012-06-28 18:03:53 +0000
@@ -1,4 +1,4 @@
 MYSQL_VERSION_MAJOR=5
 MYSQL_VERSION_MINOR=5
-MYSQL_VERSION_PATCH=24
+MYSQL_VERSION_PATCH=25a
 MYSQL_VERSION_EXTRA=

=== modified file 'client/mysqldump.c'
--- a/client/mysqldump.c	2012-03-02 12:23:52 +0000
+++ b/client/mysqldump.c	2012-05-09 14:08:44 +0000
@@ -85,6 +85,15 @@
 #define IGNORE_DATA 0x01 /* don't dump data for this table */
 #define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */
 
+/* general_log or slow_log tables under mysql database */
+static inline my_bool general_log_or_slow_log_tables(const char *db, 
+                                                     const char *table)
+{
+  return (strcmp(db, "mysql") == 0) &&
+         ((strcmp(table, "general_log") == 0) ||
+          (strcmp(table, "slow_log") == 0));
+}
+
 static void add_load_option(DYNAMIC_STRING *str, const char *option,
                              const char *option_value);
 static ulong find_set(TYPELIB *lib, const char *x, uint length,
@@ -2451,6 +2460,7 @@ static uint get_table_structure(char *ta
                                 "TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'";
   FILE       *sql_file= md_result_file;
   int        len;
+  my_bool    is_log_table;
   MYSQL_RES  *result;
   MYSQL_ROW  row;
   DBUG_ENTER("get_table_structure");
@@ -2535,9 +2545,12 @@ static uint get_table_structure(char *ta
       /*
         Even if the "table" is a view, we do a DROP TABLE here.  The
         view-specific code below fills in the DROP VIEW.
+        We will skip the DROP TABLE for general_log and slow_log, since
+        those stmts will fail, in case we apply dump by enabling logging.
        */
-        fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
-                opt_quoted_table);
+        if (!general_log_or_slow_log_tables(db, table))
+          fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
+                  opt_quoted_table);
         check_io(sql_file);
       }
 
@@ -2649,12 +2662,25 @@ static uint get_table_structure(char *ta
 
       row= mysql_fetch_row(result);
 
-      fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" :
-              "/*!40101 SET @saved_cs_client     = @@character_set_client */;\n"
-              "/*!40101 SET character_set_client = utf8 */;\n"
-              "%s;\n"
-              "/*!40101 SET character_set_client = @saved_cs_client */;\n",
-              row[1]);
+      is_log_table= general_log_or_slow_log_tables(db, table);
+      if (is_log_table)
+        row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */
+      if (opt_compatible_mode & 3)
+      {
+        fprintf(sql_file,
+                is_log_table ? "CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n",
+                row[1]);
+      }
+      else
+      {
+        fprintf(sql_file,
+                "/*!40101 SET @saved_cs_client     = @@character_set_client */;\n"
+                "/*!40101 SET character_set_client = utf8 */;\n"
+                "%s%s;\n"
+                "/*!40101 SET character_set_client = @saved_cs_client */;\n",
+                is_log_table ? "CREATE TABLE IF NOT EXISTS " : "",
+                row[1]);
+      }
 
       check_io(sql_file);
       mysql_free_result(result);
@@ -4263,6 +4289,22 @@ static int dump_all_tables_in_db(char *d
   if (opt_xml)
     print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
 
+  if (strcmp(database, "mysql") == 0)
+  {
+    char table_type[NAME_LEN];
+    char ignore_flag;
+    uint num_fields;
+    num_fields= get_table_structure((char *) "general_log", 
+                                    database, table_type, &ignore_flag);
+    if (num_fields == 0)
+      verbose_msg("-- Warning: get_table_structure() failed with some internal "
+                  "error for 'general_log' table\n");
+    num_fields= get_table_structure((char *) "slow_log", 
+                                    database, table_type, &ignore_flag);
+    if (num_fields == 0)
+      verbose_msg("-- Warning: get_table_structure() failed with some internal "
+                  "error for 'slow_log' table\n");
+  }
   if (lock_tables)
   {
     DYNAMIC_STRING query;

=== modified file 'configure.cmake'
--- a/configure.cmake	2011-08-09 08:03:29 +0000
+++ b/configure.cmake	2012-04-23 14:18:55 +0000
@@ -149,7 +149,10 @@ IF(UNIX)
   SET(CMAKE_REQUIRED_LIBRARIES 
     ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT})
 
-  LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
+  LIST(LENGTH CMAKE_REQUIRED_LIBRARIES required_libs_length)
+  IF(${required_libs_length} GREATER 0)
+    LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
+  ENDIF()  
   LINK_LIBRARIES(${CMAKE_THREAD_LIBS_INIT})
   
   OPTION(WITH_LIBWRAP "Compile with tcp wrappers support" OFF)

=== modified file 'include/violite.h'
--- a/include/violite.h	2012-02-19 09:00:52 +0000
+++ b/include/violite.h	2012-05-07 20:20:42 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2012, 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
@@ -10,8 +10,8 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+   along with this program; if not, write to the Free Software Foundation, Inc.,
+   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
 
 /*
  * Vio Lite.

=== modified file 'mysql-test/lib/My/Find.pm'
--- a/mysql-test/lib/My/Find.pm	2011-07-03 23:48:19 +0000
+++ b/mysql-test/lib/My/Find.pm	2012-07-02 11:09:33 +0000
@@ -126,9 +126,9 @@ sub my_find_file {
 #
 #
 sub my_find_dir {
-  my ($base, $paths, $dirs, $required)= @_;
-  croak "usage: my_find_dir(<base>, <paths>[, <dirs>])"
-    unless (@_ == 3 or @_ == 2);
+  my ($base, $paths, $dirs, $optional)= @_;
+  croak "usage: my_find_dir(<base>, <paths>[, <dirs>[, <optional>]])"
+    unless (@_ == 3 or @_ == 2 or @_ == 4);
 
   # -------------------------------------------------------
   # Find and return the first directory
@@ -136,6 +136,7 @@ sub my_find_dir {
   foreach my $path (my_find_paths($base, $paths, $dirs)) {
     return $path if ( -d $path );
   }
+  return "" if $optional;
   find_error($base, $paths, $dirs);
 }
 

=== modified file 'mysql-test/lib/mtr_cases.pm'
--- a/mysql-test/lib/mtr_cases.pm	2012-02-16 09:48:16 +0000
+++ b/mysql-test/lib/mtr_cases.pm	2012-07-02 11:09:33 +0000
@@ -137,6 +137,7 @@ sub collect_test_cases ($$$$) {
     {
       push(@$cases, collect_one_suite($suite, $opt_cases, $opt_skip_test_list));
       last if $some_test_found;
+      push(@$cases, collect_one_suite("i_".$suite, $opt_cases, $opt_skip_test_list));
     }
   }
 
@@ -288,13 +289,15 @@ sub collect_one_suite($)
       $suitedir= my_find_dir($::basedir,
 			     ["share/mysql-test/suite",
 			      "mysql-test/suite",
+			      "internal/mysql-test/suite",
 			      "mysql-test",
 			      # Look in storage engine specific suite dirs
 			      "storage/*/mtr",
 			      # Look in plugin specific suite dir
 			      "plugin/$suite/tests",
 			     ],
-			     [$suite, "mtr"]);
+			     [$suite, "mtr"], ($suite =~ /^i_/));
+      return unless $suitedir;
     }
     mtr_verbose("suitedir: $suitedir");
   }

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2012-02-16 09:48:16 +0000
+++ b/mysql-test/mysql-test-run.pl	2012-04-23 10:52:14 +0000
@@ -1442,7 +1442,7 @@ sub command_line_setup {
 
   # We make the path absolute, as the server will do a chdir() before usage
   unless ( $opt_vardir =~ m,^/, or
-           (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:/,i) )
+           (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:[/\\],i) )
   {
     # Make absolute path, relative test dir
     $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";

=== added file 'mysql-test/r/bug12427262.result'
--- a/mysql-test/r/bug12427262.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/bug12427262.result	2012-04-20 23:53:09 +0000
@@ -0,0 +1,56 @@
+#
+# Bug#12427262 : 60961: SHOW TABLES VERY SLOW WHEN NOT IN SYSTEM DISK CACHE. 
+#
+create database show_table_lw_db;
+use show_table_lw_db;
+create table t1 (c1 int);
+create table t2 (c1 int);
+create table t3 (c1 int);
+create table t4 (c1 int);
+create table t5 (c1 int);
+create table t6 (c1 int);
+create table t7 (c1 int);
+create table t8 (c1 int);
+create table t9 (c1 int);
+create table t10 (c1 int);
+select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME 
+like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
+into @count_read_before;
+show tables;
+Tables_in_show_table_lw_db
+t1
+t10
+t2
+t3
+t4
+t5
+t6
+t7
+t8
+t9
+select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME 
+like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
+into @count_read_after;
+select @count_read_after-@count_read_before;
+@count_read_after-@count_read_before
+0.000000000000000000000000000000
+show full tables;
+Tables_in_show_table_lw_db	Table_type
+t1	BASE TABLE
+t10	BASE TABLE
+t2	BASE TABLE
+t3	BASE TABLE
+t4	BASE TABLE
+t5	BASE TABLE
+t6	BASE TABLE
+t7	BASE TABLE
+t8	BASE TABLE
+t9	BASE TABLE
+select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME 
+like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
+into @count_read_after;
+select @count_read_after-@count_read_before;
+@count_read_after-@count_read_before
+10.000000000000000000000000000000
+drop table t1;
+drop database show_table_lw_db;

=== modified file 'mysql-test/r/mysqldump.result'
--- a/mysql-test/r/mysqldump.result	2012-01-10 10:40:48 +0000
+++ b/mysql-test/r/mysqldump.result	2012-05-09 14:08:44 +0000
@@ -5205,3 +5205,48 @@ DROP DATABASE b12809202_db;
 # Delete all existing binary logs.
 #
 RESET MASTER;
+#
+# Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM
+#
+SET @old_log_output_state=       @@global.log_output;
+SET @old_general_log_state=      @@global.general_log;
+SET @old_slow_query_log_state=   @@global.slow_query_log;
+call mtr.add_suppression("Failed to write to mysql.general_log");
+SET @@global.log_output="TABLE";
+SET @@global.general_log='OFF';
+SET @@global.slow_query_log='OFF';
+DROP DATABASE mysql;
+Warnings:
+Error	1146	Table 'mysql.proc' doesn't exist
+Error	1146	Table 'mysql.event' doesn't exist
+SHOW CREATE TABLE mysql.general_log;
+Table	Create Table
+general_log	CREATE TABLE `general_log` (
+  `event_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `user_host` mediumtext NOT NULL,
+  `thread_id` int(11) NOT NULL,
+  `server_id` int(10) unsigned NOT NULL,
+  `command_type` varchar(64) NOT NULL,
+  `argument` mediumtext NOT NULL
+) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log'
+SHOW CREATE TABLE mysql.slow_log;
+Table	Create Table
+slow_log	CREATE TABLE `slow_log` (
+  `start_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `user_host` mediumtext NOT NULL,
+  `query_time` time NOT NULL,
+  `lock_time` time NOT NULL,
+  `rows_sent` int(11) NOT NULL,
+  `rows_examined` int(11) NOT NULL,
+  `db` varchar(512) NOT NULL,
+  `last_insert_id` int(11) NOT NULL,
+  `insert_id` int(11) NOT NULL,
+  `server_id` int(10) unsigned NOT NULL,
+  `sql_text` mediumtext NOT NULL
+) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
+SET @@global.log_output=       @old_log_output_state;
+SET @@global.slow_query_log=   @old_slow_query_log_state;
+SET @@global.general_log=      @old_general_log_state;
+#
+# End of 5.1 tests
+#

=== modified file 'mysql-test/r/select.result'
--- a/mysql-test/r/select.result	2011-12-15 11:18:40 +0000
+++ b/mysql-test/r/select.result	2012-04-18 06:04:36 +0000
@@ -4988,3 +4988,30 @@ f1
 DROP TABLE t1;
 DROP VIEW view_t1;
 # End of test  BUG#63020
+#
+# Bug#12713907: STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY 
+# COUNT(*) LIMIT.
+#
+CREATE TABLE t1 (
+id BIGINT(20) ,
+member_id_to INT(11) ,
+r_date DATE ,
+PRIMARY KEY (id,r_date),
+KEY r_date_idx (r_date),
+KEY t1_idx01 (member_id_to)
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES 
+(107924526,518491,'2011-05-01'),
+(107924527,518491,'2011-05-01'),
+(107924534,518491,'2011-06-21'),
+(107924535,518491,'2011-06-21'),
+(107924542,1601319,'2011-06-21'),
+(107924543,1601319,'2011-06-21'),
+(107924544,1601319,'2011-06-21'),
+(107924545,1601319,'2011-06-21');
+SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date =
+'2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1;
+member_id_to	COUNT(*)
+518491	2
+DROP TABLE t1;
+# End of test  BUG#12713907

=== modified file 'mysql-test/suite/binlog/r/binlog_grant.result'
--- a/mysql-test/suite/binlog/r/binlog_grant.result	2009-12-22 09:35:56 +0000
+++ b/mysql-test/suite/binlog/r/binlog_grant.result	2012-04-18 09:12:19 +0000
@@ -22,3 +22,7 @@ ERROR 42000: Access denied; you need (at
 **** Clean up ****
 set global binlog_format = @saved_binlog_format;
 drop user mysqltest_1@localhost;
+GRANT REPLICATION CLIENT ON *.* TO 'mysqltest_1'@'localhost';
+SHOW MASTER LOGS;
+SHOW BINARY LOGS;
+DROP USER 'mysqltest_1'@'localhost';

=== modified file 'mysql-test/suite/binlog/t/binlog_grant.test'
--- a/mysql-test/suite/binlog/t/binlog_grant.test	2009-12-22 09:35:56 +0000
+++ b/mysql-test/suite/binlog/t/binlog_grant.test	2012-04-18 09:12:19 +0000
@@ -54,3 +54,22 @@ disconnect root;
 connection default;
 set global binlog_format = @saved_binlog_format;
 drop user mysqltest_1@localhost;
+
+
+# Testing if REPLICATION CLIENT privilege is enough to execute
+# SHOW MASTER LOGS and SHOW BINARY.
+GRANT REPLICATION CLIENT ON *.* TO 'mysqltest_1'@'localhost';
+--connect(rpl,localhost,mysqltest_1,,)
+
+--connection rpl
+# We are only interested if the following commands succeed and not on
+# their output.
+--disable_result_log
+SHOW MASTER LOGS;
+SHOW BINARY LOGS;
+--enable_result_log
+
+# clean up
+--disconnect rpl
+connection default;
+DROP USER 'mysqltest_1'@'localhost';

=== added file 'mysql-test/suite/innodb/r/innodb_bug12902967.result'
--- a/mysql-test/suite/innodb/r/innodb_bug12902967.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/r/innodb_bug12902967.result	2012-04-17 11:24:02 +0000
@@ -0,0 +1,6 @@
+create table t1 (f1 integer primary key) engine innodb;
+alter table t1 add constraint c1 foreign key (f1) references t1(f1);
+ERROR HY000: Error on rename of '#sql-temporary' to './test/t1' (errno: 150)
+InnoDB: which are not compatible with the new table definition.
+InnoDB: has or is referenced in foreign key constraints
+drop table t1;

=== added file 'mysql-test/suite/innodb/r/innodb_bug14007649.result'
--- a/mysql-test/suite/innodb/r/innodb_bug14007649.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/r/innodb_bug14007649.result	2012-05-10 04:48:31 +0000
@@ -0,0 +1,56 @@
+create table t1 (
+rowid int,
+f1    int,
+f2    int,
+key i1 (f1, f2),
+key i2 (f2)) engine=innodb;
+show create table t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `rowid` int(11) DEFAULT NULL,
+  `f1` int(11) DEFAULT NULL,
+  `f2` int(11) DEFAULT NULL,
+  KEY `i1` (`f1`,`f2`),
+  KEY `i2` (`f2`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL);
+start transaction with consistent snapshot;
+start transaction;
+update t1 set f2 = 4  where f1 = 1 and f2 is null;
+(b) Number of rows updated:
+select row_count();
+row_count()
+1
+insert into t1 values (3, 1, null);
+(b) After update and insert query.
+select rowid, f1, f2 from t1;
+rowid	f1	f2
+1	1	10
+2	1	4
+3	1	NULL
+commit;
+(a) Before the update statement is executed.
+select rowid, f1, f2 from t1;
+rowid	f1	f2
+1	1	10
+2	1	NULL
+SET SESSION debug="+d,bug14007649";
+update t1 set f2 = 6 where f1 = 1 and f2 is null;
+(a) Number of rows updated:
+select row_count();
+row_count()
+1
+(a) After the update statement is executed.
+select rowid, f1, f2 from t1;
+rowid	f1	f2
+1	1	10
+2	1	NULL
+3	1	6
+commit;
+"The trx with consistent snapshot ended."
+select rowid, f1, f2 from t1;
+rowid	f1	f2
+1	1	10
+2	1	4
+3	1	6
+drop table t1;

=== added file 'mysql-test/suite/innodb/t/innodb_bug12902967.test'
--- a/mysql-test/suite/innodb/t/innodb_bug12902967.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/t/innodb_bug12902967.test	2012-05-04 06:59:49 +0000
@@ -0,0 +1,42 @@
+# Bug 12902967: Creating self referencing fk on same index unhandled,
+# confusing error
+#
+# Creating a self referencing foreign key on the same
+# column/index is an unhandled exception, it should throw a sensible
+# error but instead implies that your data dictionary may now be out
+# of sync:
+
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+let error_log= $MYSQLTEST_VARDIR/log/mysqld.1.err;
+--source include/restart_mysqld.inc
+
+create table t1 (f1 integer primary key) engine innodb;
+
+# The below statement should produce error message in error log.
+# This error message should mention problem with foreign keys
+# rather than with data dictionary.
+--replace_regex /'\.\/test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
+--error ER_ERROR_ON_RENAME
+alter table t1 add constraint c1 foreign key (f1) references t1(f1);
+--source include/restart_mysqld.inc
+perl;
+
+$file = "$ENV{'error_log'}";
+open ( FILE, $file) || die "can't open file! ($file)\n";
+@lines = <FILE>;
+close (FILE);
+$count = 0; 
+foreach $line (reverse @lines) {
+    if ($line =~ "^InnoDB:") { 
+       ++$count; 
+       print "$line"; 
+       if ($count == 2) {
+          last;
+       }
+    }
+}
+EOF
+
+drop table t1;

=== added file 'mysql-test/suite/innodb/t/innodb_bug14007649.test'
--- a/mysql-test/suite/innodb/t/innodb_bug14007649.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/innodb/t/innodb_bug14007649.test	2012-05-10 04:48:31 +0000
@@ -0,0 +1,58 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+create table t1 (
+  rowid int,
+  f1    int,
+  f2    int,
+  key i1 (f1, f2),
+  key i2 (f2)) engine=innodb;
+
+show create table t1;
+insert into `t1` (rowid, f1, f2) values (1, 1, 10), (2, 1, NULL);
+
+connect (a,localhost,root,,);
+connect (b,localhost,root,,);
+
+connection a;
+start transaction with consistent snapshot;
+
+connection b;
+start transaction;
+update t1 set f2 = 4  where f1 = 1 and f2 is null;
+
+-- echo (b) Number of rows updated:
+select row_count();
+
+insert into t1 values (3, 1, null);
+
+-- echo (b) After update and insert query.
+select rowid, f1, f2 from t1;
+
+commit;
+
+connection a;
+
+-- echo (a) Before the update statement is executed.
+select rowid, f1, f2 from t1;
+
+SET SESSION debug="+d,bug14007649";
+update t1 set f2 = 6 where f1 = 1 and f2 is null;
+
+-- echo (a) Number of rows updated:
+select row_count();
+
+-- echo (a) After the update statement is executed.
+select rowid, f1, f2 from t1;
+
+commit;
+
+--echo "The trx with consistent snapshot ended."
+
+select rowid, f1, f2 from t1;
+
+connection default;
+disconnect a;
+disconnect b;
+
+drop table t1;

=== added file 'mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result'
--- a/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_auto_increment_bug45679.result	2012-04-23 08:56:23 +0000
@@ -0,0 +1,41 @@
+include/master-slave.inc
+[connection master]
+call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.');
+create table tm (b int auto_increment, a int, primary key (a,b)) engine= myisam;
+create table ti (b int auto_increment, a int, primary key (a,b)) engine= innodb;
+ERROR 42000: Incorrect table definition; there can be only one auto column and it must be defined as a key
+create table ti (b int auto_increment, a int, primary key (b,a)) engine= innodb;
+set @@binlog_format=statement;
+*** autoincrement field is not the first in PK warning must be there: ***
+insert into tm set b=null, a=1;
+Warnings:
+Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
+show warnings;
+Level	Code	Message
+Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
+*** no warning when autoincrement is the first in PK
+insert into ti set b=null, a=1;
+show warnings;
+Level	Code	Message
+create function multi_part_pk_with_autoinc (arg int)
+returns int
+begin
+insert into tm set b=null, a=arg;
+return arg;
+end//
+select multi_part_pk_with_autoinc (3);
+multi_part_pk_with_autoinc (3)
+3
+Warnings:
+Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
+Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
+*** autoincrement field is not the first in PK warning must be there: ***
+show warnings;
+Level	Code	Message
+Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly.
+Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT into autoincrement field which is not the first part in the composed primary key is unsafe.
+set @@binlog_format=mixed;
+insert into tm set b=null, a=2;
+drop table tm, ti;
+drop function multi_part_pk_with_autoinc;
+include/rpl_end.inc

=== modified file 'mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result'
--- a/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result	2011-02-23 09:31:37 +0000
+++ b/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result	2012-04-21 11:19:06 +0000
@@ -114,4 +114,25 @@ id	c
 3	3
 [on master]
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT);
+CREATE TABLE test.t1 (a INT);
+INSERT INTO test.t1 VALUES(1);
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT);
+CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW
+INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c);
+SET INSERT_ID=2;
+SET @c=2;
+SET @@rand_seed1=10000000, @@rand_seed2=1000000;
+INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c);
+Warnings:
+Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
+SELECT b into @b FROM test.t5;
+UPDATE test.t1 SET a=2;
+SELECT a AS 'ONE' into @a FROM test.t_slave;
+SELECT c AS 'NULL' into @c FROM test.t_slave;
+SELECT b into @b FROM test.t_slave;
+drop table test.t5;
+drop table test.t1;
+drop table test.t_slave;
 include/rpl_end.inc

=== added file 'mysql-test/suite/rpl/r/rpl_parallel_show_binlog_events_purge_logs.result'
--- a/mysql-test/suite/rpl/r/rpl_parallel_show_binlog_events_purge_logs.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_parallel_show_binlog_events_purge_logs.result	2012-04-20 21:25:59 +0000
@@ -0,0 +1,13 @@
+include/master-slave.inc
+[connection master]
+[connection slave]
+SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end';
+SHOW BINLOG EVENTS;
+[connection slave1]
+SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events';
+FLUSH LOGS;
+SET DEBUG_SYNC= 'now SIGNAL end';
+SET DEBUG_SYNC= 'RESET';
+[connection slave]
+SET DEBUG_SYNC= 'RESET';
+include/rpl_end.inc

=== modified file 'mysql-test/suite/rpl/r/rpl_report_port.result'
--- a/mysql-test/suite/rpl/r/rpl_report_port.result	2012-04-10 06:14:17 +0000
+++ b/mysql-test/suite/rpl/r/rpl_report_port.result	2012-04-26 14:04:03 +0000
@@ -3,8 +3,8 @@ include/master-slave.inc
 include/rpl_restart_server.inc [server_number=2 parameters: --report-port=9000]
 include/start_slave.inc
 [Slave restarted with the report-port set to some value]
-include/assert.inc [The value shown for the slave's port number is 9000 which is the value set for report-port.]
-include/rpl_restart_server.inc [server_number=2 parameters: --report-port=]
+include/assert.inc [The value shown for the slave's port number is user specified port number which is the value set for report-port.]
+include/rpl_restart_server.inc [server_number=2]
 include/start_slave.inc
 [Slave restarted with the report-port set to the value of slave's port number]
 include/assert.inc [The default value shown for the slave's port number is the actual port number of the slave.]

=== added file 'mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test'
--- a/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_auto_increment_bug45679.test	2012-04-23 08:56:23 +0000
@@ -0,0 +1,62 @@
+# Test of auto-increment.
+#
+# BUG#11754117-45670 
+# Multipart primary key with the autoincrement part not first in it
+# is replication unsafe.
+#
+
+source include/master-slave.inc;
+source include/have_binlog_format_mixed.inc;
+source include/have_innodb.inc;
+
+call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.');
+
+--connection master
+create table tm (b int auto_increment, a int, primary key (a,b)) engine= myisam;
+--error ER_WRONG_AUTO_KEY
+create table ti (b int auto_increment, a int, primary key (a,b)) engine= innodb;
+create table ti (b int auto_increment, a int, primary key (b,a)) engine= innodb;
+
+set @@binlog_format=statement;
+--echo *** autoincrement field is not the first in PK warning must be there: ***
+insert into tm set b=null, a=1;
+show warnings;
+--echo *** no warning when autoincrement is the first in PK
+insert into ti set b=null, a=1;
+show warnings;
+
+delimiter //;
+create function multi_part_pk_with_autoinc (arg int)
+returns int
+begin
+  insert into tm set b=null, a=arg;
+  return arg;
+end//
+delimiter ;//
+
+select multi_part_pk_with_autoinc (3);
+--echo *** autoincrement field is not the first in PK warning must be there: ***
+show warnings;
+
+set @@binlog_format=mixed;
+insert into tm set b=null, a=2;
+
+sync_slave_with_master;
+
+if (`select count(*) <> 3 from tm`)
+{
+  --echo Wrong result from SELECT on the slave side.
+  select * from tm;
+  --die
+}
+
+# cleanup
+
+--connection master
+
+drop table tm, ti;
+drop function multi_part_pk_with_autoinc;
+
+sync_slave_with_master;
+
+--source include/rpl_end.inc

=== modified file 'mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test'
--- a/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test	2011-02-23 09:31:37 +0000
+++ b/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test	2012-04-20 16:41:20 +0000
@@ -206,4 +206,64 @@ SELECT * FROM t3;
 connection master;
 echo [on master];
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+
+--sync_slave_with_master
+
+#
+# BUG#11754117 - 45670: INTVAR_EVENTS FOR FILTERED-OUT QUERY_LOG_EVENTS ARE EXECUTED
+# Int-, Rand- and User- var events accompaning a filtered out Query-log-event should
+# be filtered as well.
+#
+connection master;
+CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); # ignored on slave
+CREATE TABLE test.t1 (a INT); # accepted on slave
+INSERT INTO test.t1 VALUES(1);
+
+--sync_slave_with_master
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
+CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT);
+CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW
+                               INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c);
+
+connection master;
+SET INSERT_ID=2;
+SET @c=2;
+SET @@rand_seed1=10000000, @@rand_seed2=1000000;
+INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c); # to be ignored
+SELECT b into @b FROM test.t5;
+--let $b_master=`select @b`
+UPDATE test.t1 SET a=2; # to run trigger on slave
+
+--sync_slave_with_master
+
+# The proof:
+SELECT a AS 'ONE' into @a FROM test.t_slave;
+SELECT c AS 'NULL' into @c FROM test.t_slave;
+
+let $count= 1;
+let $table= test.t_slave;
+source include/wait_until_rows_count.inc;
+
+if (`SELECT @a != 2 and @c != NULL`)
+{
+    SELECT * FROM test.t_slave;
+    --die Intvar or user var from replication events unexpetedly escaped out to screw a following query applying context.
+}
+
+SELECT b into @b FROM test.t_slave;
+--let $b_slave=`select @b`
+
+if (`SELECT $b_slave = $b_master`)
+{
+    --echo Might be pure coincidence of two randoms from master and slave table. Don not panic yet.
+}
+
+# cleanup BUG#11754117
+connection master;
+drop table test.t5;
+drop table test.t1;
+
+--sync_slave_with_master
+drop table test.t_slave;
+
 --source include/rpl_end.inc

=== added file 'mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test'
--- a/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_parallel_show_binlog_events_purge_logs.test	2012-04-20 21:25:59 +0000
@@ -0,0 +1,35 @@
+# BUG#13979418: SHOW BINLOG EVENTS MAY CRASH THE SERVER
+#
+# The function mysql_show_binlog_events has a local stack variable
+# 'LOG_INFO linfo;', which is assigned to thd->current_linfo, however
+# this variable goes out of scope and is destroyed before clean
+# thd->current_linfo.
+#
+# This test case runs SHOW BINLOG EVENTS and FLUSH LOGS to make sure
+# that with the fix local variable linfo is valid along all
+# mysql_show_binlog_events function scope.
+#
+--source include/have_debug_sync.inc
+--source include/master-slave.inc
+
+--echo [connection slave]
+--connection slave
+SET DEBUG_SYNC= 'after_show_binlog_events SIGNAL on_show_binlog_events WAIT_FOR end';
+--send SHOW BINLOG EVENTS
+
+--connection slave1
+--echo [connection slave1]
+SET DEBUG_SYNC= 'now WAIT_FOR on_show_binlog_events';
+FLUSH LOGS;
+SET DEBUG_SYNC= 'now SIGNAL end';
+SET DEBUG_SYNC= 'RESET';
+
+--echo [connection slave]
+--connection slave
+--disable_result_log
+--reap
+--enable_result_log
+SET DEBUG_SYNC= 'RESET';
+
+--connection master
+--source include/rpl_end.inc

=== added file 'mysql-test/suite/rpl/t/rpl_report_port-master.opt'
--- a/mysql-test/suite/rpl/t/rpl_report_port-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_report_port-master.opt	2012-04-26 14:04:03 +0000
@@ -0,0 +1 @@
+--force-restart

=== modified file 'mysql-test/suite/rpl/t/rpl_report_port.test'
--- a/mysql-test/suite/rpl/t/rpl_report_port.test	2012-04-10 06:14:17 +0000
+++ b/mysql-test/suite/rpl/t/rpl_report_port.test	2012-04-26 14:04:03 +0000
@@ -38,21 +38,23 @@ connection master;
 
 # 9000 is the value of the port we should get.
 --let $report_port= query_get_value(SHOW SLAVE HOSTS, Port, 1)
---let assert_text= The value shown for the slave's port number is 9000 which is the value set for report-port.
+--let assert_text= The value shown for the slave's port number is user specified port number which is the value set for report-port.
 --let assert_cond= $report_port = "9000"
 --source include/assert.inc
 
-
 # Start the server with the report-port being passed with no value. So on SHOW SLAVE HOSTS
 # on the master the value of slave's port should be the actual value of the slave port.
+connection master;
 
 --let $rpl_server_number= 2
---let $rpl_server_parameters= --report-port=
+--let $rpl_server_parameters= 
 --source include/rpl_restart_server.inc
 
 connection slave;
 --source include/start_slave.inc
 
+connection master;
+sync_slave_with_master;
 --echo [Slave restarted with the report-port set to the value of slave's port number]
 
 connection master;

=== added file 'mysql-test/t/bug12427262.test'
--- a/mysql-test/t/bug12427262.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/bug12427262.test	2012-04-20 23:53:09 +0000
@@ -0,0 +1,51 @@
+--echo #
+--echo # Bug#12427262 : 60961: SHOW TABLES VERY SLOW WHEN NOT IN SYSTEM DISK CACHE. 
+--echo #
+
+--source include/not_embedded.inc
+--source include/have_perfschema.inc
+
+--disable_warnings
+create database show_table_lw_db;
+use show_table_lw_db;
+create table t1 (c1 int);
+create table t2 (c1 int);
+create table t3 (c1 int);
+create table t4 (c1 int);
+create table t5 (c1 int);
+create table t6 (c1 int);
+create table t7 (c1 int);
+create table t8 (c1 int);
+create table t9 (c1 int);
+create table t10 (c1 int);
+--enable_warnings
+
+# Query PS to know initial read count for frm file.
+select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME 
+like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
+into @count_read_before;
+
+show tables;
+
+# Query PS to know read count for frm file after above query. It should
+# not be changed as FRM file will not be opened for above query.
+select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME 
+like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
+into @count_read_after;
+
+select @count_read_after-@count_read_before;
+
+show full tables;
+
+# Query PS to know read count for frm file after above query. COUNT_READ
+# will be incremented by 1 as FRM file will be opened for above query.
+select Sum(ALL(COUNT_READ)) from performance_schema.file_summary_by_instance where FILE_NAME 
+like "%show_table_lw_db%" AND FILE_NAME like "%.frm%" AND EVENT_NAME='wait/io/file/sql/FRM'
+into @count_read_after;
+
+select @count_read_after-@count_read_before;
+
+--disable_warnings
+drop table t1;
+drop database show_table_lw_db;
+--enable_warnings

=== modified file 'mysql-test/t/mysql_plugin.test'
--- a/mysql-test/t/mysql_plugin.test	2012-02-28 08:32:27 +0000
+++ b/mysql-test/t/mysql_plugin.test	2012-06-29 12:19:31 +0000
@@ -372,11 +372,11 @@ let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n
 --echo # Show the help.
 --echo #
 replace_result $MYSQL_PLUGIN mysql_plugin;
---replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/
+--replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/ /XX[a-z]/XX/
 --exec $MYSQL_PLUGIN --help
 
 replace_result $MYSQL_PLUGIN mysql_plugin;
---replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/
+--replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/ /XX[a-z]/XX/
 --exec $MYSQL_PLUGIN --version
 
 #

=== modified file 'mysql-test/t/mysqldump.test'
--- a/mysql-test/t/mysqldump.test	2012-01-10 10:40:48 +0000
+++ b/mysql-test/t/mysqldump.test	2012-05-09 14:08:44 +0000
@@ -2367,3 +2367,30 @@ RESET MASTER;
 
 # Wait till we reached the initial number of concurrent sessions
 --source include/wait_until_count_sessions.inc
+
+--echo #
+--echo # Bug#45740 MYSQLDUMP DOESN'T DUMP GENERAL_LOG AND SLOW_QUERY CAUSES RESTORE PROBLEM
+--echo #
+SET @old_log_output_state=       @@global.log_output;
+SET @old_general_log_state=      @@global.general_log;
+SET @old_slow_query_log_state=   @@global.slow_query_log;
+
+call mtr.add_suppression("Failed to write to mysql.general_log");
+--exec $MYSQL_DUMP -uroot --all-databases > $MYSQLTEST_VARDIR/tmp/bug45740.sql
+# Make log_output as table and disabling general_log and slow_log
+SET @@global.log_output="TABLE";
+SET @@global.general_log='OFF';
+SET @@global.slow_query_log='OFF';
+DROP DATABASE mysql; 
+--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug45740.sql
+SHOW CREATE TABLE mysql.general_log;
+SHOW CREATE TABLE mysql.slow_log;
+--remove_file $MYSQLTEST_VARDIR/tmp/bug45740.sql
+
+SET @@global.log_output=       @old_log_output_state;
+SET @@global.slow_query_log=   @old_slow_query_log_state;
+SET @@global.general_log=      @old_general_log_state;
+ 
+--echo #
+--echo # End of 5.1 tests
+--echo #

=== modified file 'mysql-test/t/select.test'
--- a/mysql-test/t/select.test	2011-12-15 11:18:40 +0000
+++ b/mysql-test/t/select.test	2012-04-18 06:04:36 +0000
@@ -4253,3 +4253,35 @@ DROP VIEW view_t1;
 
 --echo # End of test  BUG#63020
 
+
+--echo #
+--echo # Bug#12713907: STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY 
+--echo # COUNT(*) LIMIT.
+--echo #
+
+CREATE TABLE t1 (
+id BIGINT(20) ,
+member_id_to INT(11) ,
+r_date DATE ,
+PRIMARY KEY (id,r_date),
+KEY r_date_idx (r_date),
+KEY t1_idx01 (member_id_to)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES 
+(107924526,518491,'2011-05-01'),
+(107924527,518491,'2011-05-01'),
+(107924534,518491,'2011-06-21'),
+(107924535,518491,'2011-06-21'),
+(107924542,1601319,'2011-06-21'),
+(107924543,1601319,'2011-06-21'),
+(107924544,1601319,'2011-06-21'),
+(107924545,1601319,'2011-06-21');
+
+SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date =
+  '2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1;
+
+DROP TABLE t1;
+
+--echo # End of test  BUG#12713907
+

=== modified file 'sql/field.cc'
--- a/sql/field.cc	2012-04-12 13:04:22 +0000
+++ b/sql/field.cc	2012-05-07 20:20:42 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2000, 2012, 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

=== modified file 'sql/field.h'
--- a/sql/field.h	2012-04-12 13:04:22 +0000
+++ b/sql/field.h	2012-05-07 20:20:42 +0000
@@ -1,7 +1,7 @@
 #ifndef FIELD_INCLUDED
 #define FIELD_INCLUDED
 
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2012, 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

=== modified file 'sql/field_conv.cc'
--- a/sql/field_conv.cc	2012-04-12 13:04:22 +0000
+++ b/sql/field_conv.cc	2012-05-07 20:20:42 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2012, 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

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2012-04-10 11:46:21 +0000
+++ b/sql/item_subselect.cc	2012-05-07 20:20:42 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2002, 2012, 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

=== modified file 'sql/log.h'
--- a/sql/log.h	2011-11-24 17:15:58 +0000
+++ b/sql/log.h	2012-04-20 22:35:53 +0000
@@ -151,6 +151,11 @@ class Relay_log_info;
 extern PSI_mutex_key key_LOG_INFO_lock;
 #endif
 
+/*
+  Note that we destroy the lock mutex in the desctructor here.
+  This means that object instances cannot be destroyed/go out of scope,
+  until we have reset thd->current_linfo to NULL;
+ */
 typedef struct st_log_info
 {
   char log_file_name[FN_REFLEN];

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2012-04-12 11:04:12 +0000
+++ b/sql/log_event.cc	2012-05-07 20:20:42 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2000, 2012, 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
@@ -5372,11 +5372,12 @@ void Intvar_log_event::print(FILE* file,
 #endif
 
 
+#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
+
 /*
   Intvar_log_event::do_apply_event()
 */
 
-#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
 int Intvar_log_event::do_apply_event(Relay_log_info const *rli)
 {
   /*
@@ -5385,6 +5386,9 @@ int Intvar_log_event::do_apply_event(Rel
    */
   const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT);
 
+  if (rli->deferred_events_collecting)
+    return rli->deferred_events->add(this);
+
   switch (type) {
   case LAST_INSERT_ID_EVENT:
     thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1;
@@ -5490,6 +5494,9 @@ int Rand_log_event::do_apply_event(Relay
    */
   const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT);
 
+  if (rli->deferred_events_collecting)
+    return rli->deferred_events->add(this);
+
   thd->rand.seed1= (ulong) seed1;
   thd->rand.seed2= (ulong) seed2;
   return 0;
@@ -5516,6 +5523,29 @@ Rand_log_event::do_shall_skip(Relay_log_
   return continue_group(rli);
 }
 
+/**
+   Exec deferred Int-, Rand- and User- var events prefixing
+   a Query-log-event event.
+
+   @param thd THD handle
+
+   @return false on success, true if a failure in an event applying occurred.
+*/
+bool slave_execute_deferred_events(THD *thd)
+{
+  bool res= false;
+  Relay_log_info *rli= thd->rli_slave;
+
+  DBUG_ASSERT(rli && (!rli->deferred_events_collecting || rli->deferred_events));
+
+  if (!rli->deferred_events_collecting || rli->deferred_events->is_empty())
+    return res;
+
+  res= rli->deferred_events->execute(rli);
+
+  return res;
+}
+
 #endif /* !MYSQL_CLIENT */
 
 
@@ -5939,6 +5969,10 @@ int User_var_log_event::do_apply_event(R
 {
   Item *it= 0;
   CHARSET_INFO *charset;
+
+  if (rli->deferred_events_collecting)
+    return rli->deferred_events->add(this);
+
   if (!(charset= get_charset(charset_number, MYF(MY_WME))))
     return 1;
   LEX_STRING user_var_name;

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2012-02-29 08:45:15 +0000
+++ b/sql/log_event.h	2012-04-21 10:24:39 +0000
@@ -4080,11 +4080,18 @@ private:
   const char* log_ident;
   uint ident_len;
 };
+
+/**
+   The function is called by slave applier in case there are
+   active table filtering rules to force gathering events associated
+   with Query-log-event into an array to execute
+   them once the fate of the Query is determined for execution.
+*/
+bool slave_execute_deferred_events(THD *thd);
 #endif
 
 int append_query_string(THD *thd, CHARSET_INFO *csinfo,
                         String const *from, String *to);
-
 /**
   @} (end of group Replication)
 */

=== modified file 'sql/log_event_old.cc'
--- a/sql/log_event_old.cc	2012-02-24 16:07:43 +0000
+++ b/sql/log_event_old.cc	2012-05-07 20:20:42 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2007, 2012, 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

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2012-04-12 11:04:12 +0000
+++ b/sql/mysqld.cc	2012-05-07 20:20:42 +0000
@@ -1840,9 +1840,13 @@ static void network_init(void)
   {
     struct addrinfo *ai, *a;
     struct addrinfo hints;
+    const char *bind_address= my_bind_addr_str;
+
+    if (!bind_address)
+      bind_address= "0.0.0.0";
 
     sql_print_information("Server hostname (bind-address): '%s'; port: %d",
-                          my_bind_addr_str, mysqld_port);
+                          bind_address, mysqld_port);
 
     // Get list of IP-addresses associated with the server hostname.
     bzero(&hints, sizeof (hints));
@@ -1851,7 +1855,7 @@ static void network_init(void)
     hints.ai_family= AF_UNSPEC;
 
     my_snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
-    if (getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai))
+    if (getaddrinfo(bind_address, port_buf, &hints, &ai))
     {
       sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR));  /* purecov: tested */
       sql_print_error("Can't start server: cannot resolve hostname!");
@@ -1871,7 +1875,7 @@ static void network_init(void)
       }
 
       sql_print_information("  - '%s' resolves to '%s';",
-                            my_bind_addr_str, ip_addr);
+                            bind_address, ip_addr);
     }
 
     /*

=== modified file 'sql/password.c'
--- a/sql/password.c	2012-04-06 10:20:33 +0000
+++ b/sql/password.c	2012-05-07 20:20:42 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2000, 2012, 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

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2012-02-24 16:32:46 +0000
+++ b/sql/rpl_rli.cc	2012-05-07 20:20:42 +0000
@@ -52,8 +52,8 @@ Relay_log_info::Relay_log_info(bool is_s
    inited(0), abort_slave(0), slave_running(0), until_condition(UNTIL_NONE),
    until_log_pos(0), retried_trans(0),
    tables_to_lock(0), tables_to_lock_count(0),
-   last_event_start_time(0), m_flags(0), row_stmt_start_timestamp(0),
-   long_find_row_note_printed(false)
+   last_event_start_time(0), deferred_events(NULL),m_flags(0),
+   row_stmt_start_timestamp(0), long_find_row_note_printed(false)
 {
   DBUG_ENTER("Relay_log_info::Relay_log_info");
 

=== modified file 'sql/rpl_rli.h'
--- a/sql/rpl_rli.h	2012-03-12 22:02:50 +0000
+++ b/sql/rpl_rli.h	2012-04-21 10:24:39 +0000
@@ -388,6 +388,41 @@ public:
   */
   time_t last_event_start_time;
 
+  /*
+    A container to hold on Intvar-, Rand-, Uservar- log-events in case
+    the slave is configured with table filtering rules.
+    The withhold events are executed when their parent Query destiny is
+    determined for execution as well.
+  */
+  Deferred_log_events *deferred_events;
+
+  /*
+    State of the container: true stands for IRU events gathering, 
+    false does for execution, either deferred or direct.
+  */
+  bool deferred_events_collecting;
+
+  /* 
+     Returns true if the argument event resides in the containter;
+     more specifically, the checking is done against the last added event.
+  */
+  bool is_deferred_event(Log_event * ev)
+  {
+    return deferred_events_collecting ? deferred_events->is_last(ev) : false;
+  };
+  /* The general cleanup that slave applier may need at the end of query. */
+  inline void cleanup_after_query()
+  {
+    if (deferred_events)
+      deferred_events->rewind();
+  };
+  /* The general cleanup that slave applier may need at the end of session. */
+  void cleanup_after_session()
+  {
+    if (deferred_events)
+      delete deferred_events;
+  };
+   
   /**
     Helper function to do after statement completion.
 

=== modified file 'sql/rpl_utility.cc'
--- a/sql/rpl_utility.cc	2011-06-30 15:46:53 +0000
+++ b/sql/rpl_utility.cc	2012-04-21 10:24:39 +0000
@@ -18,6 +18,7 @@
 #ifndef MYSQL_CLIENT
 #include "unireg.h"                      // REQUIRED by later includes
 #include "rpl_rli.h"
+#include "log_event.h"
 #include "sql_select.h"
 
 /**
@@ -1056,3 +1057,65 @@ table_def::~table_def()
 #endif
 }
 
+
+#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
+
+Deferred_log_events::Deferred_log_events(Relay_log_info *rli) : last_added(NULL)
+{
+  my_init_dynamic_array(&array, sizeof(Log_event *), 32, 16);
+}
+
+Deferred_log_events::~Deferred_log_events() 
+{
+  delete_dynamic(&array);
+}
+
+int Deferred_log_events::add(Log_event *ev)
+{
+  last_added= ev;
+  insert_dynamic(&array, (uchar*) &ev);
+  return 0;
+}
+
+bool Deferred_log_events::is_empty()
+{  
+  return array.elements == 0;
+}
+
+bool Deferred_log_events::execute(Relay_log_info *rli)
+{
+  bool res= false;
+
+  DBUG_ASSERT(rli->deferred_events_collecting);
+
+  rli->deferred_events_collecting= false;
+  for (uint i=  0; !res && i < array.elements; i++)
+  {
+    Log_event *ev= (* (Log_event **)
+                    dynamic_array_ptr(&array, i));
+    res= ev->apply_event(rli);
+  }
+  rli->deferred_events_collecting= true;
+  return res;
+}
+
+void Deferred_log_events::rewind()
+{
+  /*
+    Reset preceeding Query log event events which execution was
+    deferred because of slave side filtering.
+  */
+  if (!is_empty())
+  {
+    for (uint i=  0; i < array.elements; i++)
+    {
+      Log_event *ev= *(Log_event **) dynamic_array_ptr(&array, i);
+      delete ev;
+    }
+    if (array.elements > array.max_element)
+      freeze_size(&array);
+    reset_dynamic(&array);
+  }
+}
+
+#endif

=== modified file 'sql/rpl_utility.h'
--- a/sql/rpl_utility.h	2011-06-30 15:46:53 +0000
+++ b/sql/rpl_utility.h	2012-04-21 10:24:39 +0000
@@ -28,7 +28,7 @@
 #include "mysql_com.h"
 
 class Relay_log_info;
-
+class Log_event;
 
 /**
   A table definition from the master.
@@ -261,6 +261,24 @@ CPP_UNNAMED_NS_START
   };
 
 CPP_UNNAMED_NS_END
+
+class Deferred_log_events
+{
+private:
+  DYNAMIC_ARRAY array;
+  Log_event *last_added;
+
+public:
+  Deferred_log_events(Relay_log_info *rli);
+  ~Deferred_log_events();
+  /* queue for exection at Query-log-event time prior the Query */;
+  int add(Log_event *ev);
+  bool is_empty();
+  bool execute(Relay_log_info *rli);
+  void rewind();
+  bool is_last(Log_event *ev) { return ev == last_added; };
+};
+
 #endif
 
 // NB. number of printed bit values is limited to sizeof(buf) - 1

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2012-04-12 11:04:12 +0000
+++ b/sql/share/errmsg-utf8.txt	2012-05-07 20:20:42 +0000
@@ -6503,6 +6503,9 @@ ER_TABLE_IN_FK_CHECK
 ER_UNSUPPORTED_ENGINE
   eng "Storage engine '%s' does not support system tables. [%s.%s]"
 
+ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST
+  eng "INSERT into autoincrement field which is not the first part in the composed primary key is unsafe."
+
 #
 #  End of 5.5 error messages.
 #

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2012-03-12 22:02:50 +0000
+++ b/sql/slave.cc	2012-04-21 10:24:39 +0000
@@ -2557,7 +2557,8 @@ static int exec_relay_log_event(THD* thd
       used to read info about the relay log's format; it will be deleted when
       the SQL thread does not need it, i.e. when this thread terminates.
     */
-    if (ev->get_type_code() != FORMAT_DESCRIPTION_EVENT)
+    if (ev->get_type_code() != FORMAT_DESCRIPTION_EVENT &&
+        !rli->is_deferred_event(ev))
     {
       DBUG_PRINT("info", ("Deleting the event after it has been executed"));
       delete ev;
@@ -3219,6 +3220,12 @@ pthread_handler_t handle_slave_sql(void
     goto err;
   }
   thd->init_for_queries();
+  thd->rli_slave= rli;
+  if ((rli->deferred_events_collecting= rpl_filter->is_on()))
+  {
+    rli->deferred_events= new Deferred_log_events(rli);
+  }
+
   thd->temporary_tables = rli->save_temporary_tables; // restore temp tables
   set_thd_in_use_temporary_tables(rli);   // (re)set sql_thd in use for saved temp tables
   mysql_mutex_lock(&LOCK_thread_count);

=== modified file 'sql/spatial.cc'
--- a/sql/spatial.cc	2012-03-05 18:36:56 +0000
+++ b/sql/spatial.cc	2012-05-07 20:20:42 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2002, 2012, 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

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2012-04-02 19:05:43 +0000
+++ b/sql/sql_base.cc	2012-04-21 10:24:39 +0000
@@ -216,6 +216,7 @@ static bool
 has_write_table_with_auto_increment(TABLE_LIST *tables);
 static bool
 has_write_table_with_auto_increment_and_select(TABLE_LIST *tables);
+static bool has_write_table_auto_increment_not_first_in_pk(TABLE_LIST *tables);
 
 uint cached_open_tables(void)
 {
@@ -5690,6 +5691,12 @@ bool lock_tables(THD *thd, TABLE_LIST *t
     if (thd->variables.binlog_format != BINLOG_FORMAT_ROW && tables &&
         has_write_table_with_auto_increment_and_select(tables))
       thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT);
+    /* Todo: merge all has_write_table_auto_inc with decide_logging_format */
+    if (thd->variables.binlog_format != BINLOG_FORMAT_ROW && tables)
+    {
+      if (has_write_table_auto_increment_not_first_in_pk(tables))
+        thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST);
+    }
 
     /* 
      INSERT...ON DUPLICATE KEY UPDATE on a table with more than one unique keys
@@ -9152,6 +9159,32 @@ has_write_table_with_auto_increment_and_
   return(has_select && has_auto_increment_tables);
 }
 
+/*
+  Tells if there is a table whose auto_increment column is a part
+  of a compound primary key while is not the first column in
+  the table definition.
+
+  @param tables Table list
+
+  @return true if the table exists, fais if does not.
+*/
+
+static bool
+has_write_table_auto_increment_not_first_in_pk(TABLE_LIST *tables)
+{
+  for (TABLE_LIST *table= tables; table; table= table->next_global)
+  {
+    /* we must do preliminary checks as table->table may be NULL */
+    if (!table->placeholder() &&
+        table->table->found_next_number_field &&
+        (table->lock_type >= TL_WRITE_ALLOW_WRITE)
+        && table->table->s->next_number_keypart != 0)
+      return 1;
+  }
+
+  return 0;
+}
+
 
 
 /*

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2012-03-09 13:04:49 +0000
+++ b/sql/sql_class.cc	2012-05-07 20:20:42 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2000, 2012, 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
@@ -744,7 +744,7 @@ bool Drop_table_error_handler::handle_co
 THD::THD()
    :Statement(&main_lex, &main_mem_root, STMT_CONVENTIONAL_EXECUTION,
               /* statement id */ 0),
-   rli_fake(0),
+   rli_fake(0), rli_slave(NULL),
    user_time(0), in_sub_stmt(0),
    binlog_unsafe_warning_flags(0),
    binlog_table_maps(0),
@@ -1359,6 +1359,8 @@ THD::~THD()
   }
   
   mysql_audit_free_thd(this);
+  if (rli_slave)
+    rli_slave->cleanup_after_session();
 #endif
 
   free_root(&main_mem_root, MYF(0));
@@ -1678,6 +1680,10 @@ void THD::cleanup_after_query()
   {
     delete_dynamic(&lex->mi.repl_ignore_server_ids);
   }
+#ifndef EMBEDDED_LIBRARY
+  if (rli_slave)
+    rli_slave->cleanup_after_query();
+#endif
 }
 
 

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2012-03-09 13:04:49 +0000
+++ b/sql/sql_class.h	2012-05-07 20:20:42 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2012, 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
@@ -1445,6 +1445,8 @@ public:
 
   /* Used to execute base64 coded binlog events in MySQL server */
   Relay_log_info* rli_fake;
+  /* Slave applier execution context */
+  Relay_log_info* rli_slave;
 
   void reset_for_next_command();
   /*

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2012-03-30 13:05:53 +0000
+++ b/sql/sql_lex.cc	2012-04-21 10:24:39 +0000
@@ -67,7 +67,8 @@ Query_tables_list::binlog_stmt_unsafe_er
   ER_BINLOG_UNSAFE_CREATE_REPLACE_SELECT,
   ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC,
   ER_BINLOG_UNSAFE_UPDATE_IGNORE,
-  ER_BINLOG_UNSAFE_INSERT_TWO_KEYS
+  ER_BINLOG_UNSAFE_INSERT_TWO_KEYS,
+  ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST
 };
 
 

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2012-03-30 13:05:53 +0000
+++ b/sql/sql_lex.h	2012-04-21 12:06:06 +0000
@@ -1329,6 +1329,12 @@ public:
     */
     BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS,
 
+    /**
+       INSERT into auto-inc field which is not the first part of composed
+       primary key.
+    */
+    BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST,
+
     /* The last element of this enumeration type. */
     BINLOG_STMT_UNSAFE_COUNT
   };

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2012-02-19 04:11:08 +0000
+++ b/sql/sql_parse.cc	2012-04-21 10:24:39 +0000
@@ -2025,6 +2025,11 @@ mysql_execute_command(THD *thd)
       }
       DBUG_RETURN(0);
     }
+    /* 
+       Execute deferred events first
+    */
+    if (slave_execute_deferred_events(thd))
+      DBUG_RETURN(-1);
   }
   else
   {
@@ -2677,7 +2682,7 @@ end_with_restore_list:
     goto error;
 #else
     {
-      if (check_global_access(thd, SUPER_ACL))
+      if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL))
 	goto error;
       res = show_binlogs(thd);
       break;

=== modified file 'sql/sql_repl.cc'
--- a/sql/sql_repl.cc	2012-02-16 09:48:16 +0000
+++ b/sql/sql_repl.cc	2012-04-20 22:35:53 +0000
@@ -1737,6 +1737,8 @@ bool mysql_show_binlog_events(THD* thd)
   File file = -1;
   MYSQL_BIN_LOG *binary_log= NULL;
   int old_max_allowed_packet= thd->variables.max_allowed_packet;
+  LOG_INFO linfo;
+
   DBUG_ENTER("mysql_show_binlog_events");
 
   Log_event::init_show_field_list(&field_list);
@@ -1779,7 +1781,6 @@ bool mysql_show_binlog_events(THD* thd)
     char search_file_name[FN_REFLEN], *name;
     const char *log_file_name = lex_mi->log_file_name;
     mysql_mutex_t *log_lock = binary_log->get_log_lock();
-    LOG_INFO linfo;
     Log_event* ev;
 
     unit->set_limit(thd->lex->current_select);
@@ -1871,6 +1872,8 @@ bool mysql_show_binlog_events(THD* thd)
 
     mysql_mutex_unlock(log_lock);
   }
+  // Check that linfo is still on the function scope.
+  DEBUG_SYNC(thd, "after_show_binlog_events");
 
   ret= FALSE;
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2012-04-04 10:19:00 +0000
+++ b/sql/sql_select.cc	2012-05-09 14:08:44 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2012, 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
@@ -13930,8 +13930,6 @@ check_reverse_order:
                                 join_read_first:join_read_last;
         tab->type=JT_NEXT;           // Read with index_first(), index_next()
 
-        if (table->covering_keys.is_set(best_key))
-          table->set_keyread(TRUE);
         table->file->ha_index_or_rnd_end();
         if (tab->join->select_options & SELECT_DESCRIBE)
         {

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2012-03-27 09:50:14 +0000
+++ b/sql/sql_show.cc	2012-04-19 10:29:46 +0000
@@ -3192,39 +3192,44 @@ end:
 
 static int fill_schema_table_names(THD *thd, TABLE *table,
                                    LEX_STRING *db_name, LEX_STRING *table_name,
-                                   bool with_i_schema)
+                                   bool with_i_schema,
+                                   bool need_table_type)
 {
-  if (with_i_schema)
+  /* Avoid opening FRM files if table type is not needed. */
+  if (need_table_type)
   {
-    table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"),
-                           system_charset_info);
-  }
-  else
-  {
-    enum legacy_db_type not_used;
-    char path[FN_REFLEN + 1];
-    (void) build_table_filename(path, sizeof(path) - 1, db_name->str, 
-                                table_name->str, reg_ext, 0);
-    switch (dd_frm_type(thd, path, &not_used)) {
-    case FRMTYPE_ERROR:
-      table->field[3]->store(STRING_WITH_LEN("ERROR"),
-                             system_charset_info);
-      break;
-    case FRMTYPE_TABLE:
-      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
-                             system_charset_info);
-      break;
-    case FRMTYPE_VIEW:
-      table->field[3]->store(STRING_WITH_LEN("VIEW"),
+    if (with_i_schema)
+    {
+      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"),
                              system_charset_info);
-      break;
-    default:
-      DBUG_ASSERT(0);
     }
-    if (thd->is_error() && thd->stmt_da->sql_errno() == ER_NO_SUCH_TABLE)
+    else
     {
-      thd->clear_error();
-      return 0;
+      enum legacy_db_type not_used;
+      char path[FN_REFLEN + 1];
+      (void) build_table_filename(path, sizeof(path) - 1, db_name->str, 
+                                  table_name->str, reg_ext, 0);
+      switch (dd_frm_type(thd, path, &not_used)) {
+      case FRMTYPE_ERROR:
+        table->field[3]->store(STRING_WITH_LEN("ERROR"),
+                               system_charset_info);
+        break;
+      case FRMTYPE_TABLE:
+        table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
+                               system_charset_info);
+        break;
+      case FRMTYPE_VIEW:
+        table->field[3]->store(STRING_WITH_LEN("VIEW"),
+                               system_charset_info);
+        break;
+      default:
+        DBUG_ASSERT(0);
+      }
+      if (thd->is_error() && thd->stmt_da->sql_errno() == ER_NO_SUCH_TABLE)
+      {
+        thd->clear_error();
+        return 0;
+      }
     }
   }
   if (schema_table_store_record(thd, table))
@@ -3763,7 +3768,8 @@ int get_all_tables(THD *thd, TABLE_LIST
           if (schema_table_idx == SCH_TABLE_NAMES)
           {
             if (fill_schema_table_names(thd, tables->table, db_name,
-                                        table_name, with_i_schema))
+                                        table_name, with_i_schema,
+                                        lex->verbose))
               continue;
           }
           else

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2012-04-11 10:23:17 +0000
+++ b/sql/sql_table.cc	2012-04-17 11:24:02 +0000
@@ -246,10 +246,17 @@ uint explain_filename(THD* thd,
       {
         part_name_len= tmp_p - part_name - 1;
         subpart_name= tmp_p + 3;
+	tmp_p+= 3;
+      }
+      else if ((tmp_p[1] == 'Q' || tmp_p[1] == 'q') &&
+               (tmp_p[2] == 'L' || tmp_p[2] == 'l') &&
+                tmp_p[3] == '-')
+      {
+        name_type= TEMP;
+        tmp_p+= 4; /* sql- prefix found */
       }
       else
         res= 2;
-      tmp_p+= 3;
       break;
     case 'T':
     case 't':
@@ -6718,21 +6725,47 @@ bool mysql_alter_table(THD *thd,char *ne
     (void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
   }
   else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db,
-                              new_alias, FN_FROM_IS_TMP) ||
-           ((new_name != table_name || new_db != db) && // we also do rename
-           (need_copy_table != ALTER_TABLE_METADATA_ONLY ||
-            mysql_rename_table(save_old_db_type, db, table_name, new_db,
-                               new_alias, NO_FRM_RENAME)) &&
-           Table_triggers_list::change_table_name(thd, db, alias, table_name,
-                                                  new_db, new_alias)))
+                              new_alias, FN_FROM_IS_TMP))
   {
     /* Try to get everything back. */
-    error=1;
-    (void) quick_rm_table(new_db_type,new_db,new_alias, 0);
+    error= 1;
     (void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
     (void) mysql_rename_table(old_db_type, db, old_name, db, alias,
                             FN_FROM_IS_TMP);
   }
+  else if (new_name != table_name || new_db != db)
+  {
+    if (need_copy_table == ALTER_TABLE_METADATA_ONLY &&
+        mysql_rename_table(save_old_db_type, db, table_name, new_db,
+                           new_alias, NO_FRM_RENAME))
+    {
+      /* Try to get everything back. */
+      error= 1;
+      (void) quick_rm_table(new_db_type, new_db, new_alias, 0);
+      (void) mysql_rename_table(old_db_type, db, old_name, db, alias,
+                                FN_FROM_IS_TMP);
+    }
+    else if (Table_triggers_list::change_table_name(thd, db, alias, 
+                                                    table_name, new_db, 
+                                                    new_alias))
+    {
+      /* Try to get everything back. */
+      error= 1;
+      (void) quick_rm_table(new_db_type, new_db, new_alias, 0);
+      (void) mysql_rename_table(old_db_type, db, old_name, db,
+                                alias, FN_FROM_IS_TMP);
+      /*
+        If we were performing "fast"/in-place ALTER TABLE we also need
+        to restore old name of table in storage engine as a separate
+        step, as the above rename affects .FRM only.
+      */
+      if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
+      {
+        (void) mysql_rename_table(save_old_db_type, new_db, new_alias,
+                                  db, table_name, NO_FRM_RENAME); 
+      }
+    }
+  }
 
   if (! error)
     (void) quick_rm_table(old_db_type, db, old_name, FN_IS_TMP);

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2011-07-03 23:25:49 +0000
+++ b/sql/sql_update.cc	2012-06-28 18:03:53 +0000
@@ -450,6 +450,15 @@ int mysql_update(THD *thd,
   { // Check if we are modifying a key that we are used to search with:
     used_key_is_modified= is_key_used(table, used_index, table->write_set);
   }
+  else if (select && select->quick)
+  {
+    /*
+      select->quick != NULL and used_index == MAX_KEY happens for index
+      merge and should be handled in a different way.
+    */
+    used_key_is_modified= (!select->quick->unique_key_range() &&
+                           select->quick->is_keys_used(table->write_set));
+  }
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   if (used_key_is_modified || order ||

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2012-03-28 08:22:31 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2012-05-07 20:20:42 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2005, 2012, 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

=== modified file 'storage/innobase/btr/btr0cur.c'
--- a/storage/innobase/btr/btr0cur.c	2012-02-17 09:52:51 +0000
+++ b/storage/innobase/btr/btr0cur.c	2012-05-10 05:03:16 +0000
@@ -3463,6 +3463,8 @@ btr_estimate_n_rows_in_range(
 				n_rows = n_rows * 2;
 			}
 
+			DBUG_EXECUTE_IF("bug14007649", return(n_rows););
+
 			/* Do not estimate the number of rows in the range
 			to over 1 / 2 of the estimated rows in the whole
 			table */

=== modified file 'storage/innobase/buf/buf0flu.c'
--- a/storage/innobase/buf/buf0flu.c	2012-02-02 10:31:57 +0000
+++ b/storage/innobase/buf/buf0flu.c	2012-04-24 02:15:29 +0000
@@ -1750,8 +1750,6 @@ buf_flush_batch(
 	}
 #endif /* UNIV_DEBUG */
 
-	srv_buf_pool_flushed += count;
-
 	return(count);
 }
 
@@ -1778,13 +1776,6 @@ buf_flush_common(
 #endif /* UNIV_DEBUG */
 
 	srv_buf_pool_flushed += page_count;
-
-	if (flush_type == BUF_FLUSH_LRU) {
-		/* We keep track of all flushes happening as part of LRU
-		flush. When estimating the desired rate at which flush_list
-		should be flushed we factor in this value. */
-		buf_lru_flush_page_count += page_count;
-	}
 }
 
 /******************************************************************//**

=== modified file 'storage/innobase/dict/dict0load.c'
--- a/storage/innobase/dict/dict0load.c	2011-12-29 14:14:45 +0000
+++ b/storage/innobase/dict/dict0load.c	2012-04-27 10:40:12 +0000
@@ -177,7 +177,7 @@ dict_print(void)
 	monitor printout */
 
 	mutex_enter(&kernel_mutex);
-	srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */
+	srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION;
 	mutex_exit(&kernel_mutex);
 
 	heap = mem_heap_create(1000);
@@ -214,7 +214,7 @@ dict_print(void)
 
 	/* Restore the fatal semaphore wait timeout */
 	mutex_enter(&kernel_mutex);
-	srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */
+	srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION;
 	mutex_exit(&kernel_mutex);
 }
 

=== modified file 'storage/innobase/fil/fil0fil.c'
--- a/storage/innobase/fil/fil0fil.c	2012-03-26 13:45:01 +0000
+++ b/storage/innobase/fil/fil0fil.c	2012-04-26 15:21:25 +0000
@@ -1908,7 +1908,7 @@ fil_inc_pending_ops(
 
 	if (space == NULL) {
 		fprintf(stderr,
-			"InnoDB: Error: trying to do ibuf merge to a"
+			"InnoDB: Error: trying to do an operation on a"
 			" dropped tablespace %lu\n",
 			(ulong) id);
 	}

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2012-04-10 11:23:17 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2012-05-10 05:03:16 +0000
@@ -4145,6 +4145,31 @@ table_opened:
 }
 
 UNIV_INTERN
+handler*
+ha_innobase::clone(
+/*===============*/
+	const char*	name,		/*!< in: table name */
+	MEM_ROOT*	mem_root)	/*!< in: memory context */
+{
+	ha_innobase* new_handler;
+
+	DBUG_ENTER("ha_innobase::clone");
+
+	new_handler = static_cast<ha_innobase*>(handler::clone(name,
+							       mem_root));
+	if (new_handler) {
+		DBUG_ASSERT(new_handler->prebuilt != NULL);
+		DBUG_ASSERT(new_handler->user_thd == user_thd);
+		DBUG_ASSERT(new_handler->prebuilt->trx == prebuilt->trx);
+
+		new_handler->prebuilt->select_lock_type
+			= prebuilt->select_lock_type;
+	}
+
+	DBUG_RETURN(new_handler);
+}
+
+UNIV_INTERN
 uint
 ha_innobase::max_supported_key_part_length() const
 {
@@ -8470,7 +8495,7 @@ ha_innobase::check(
 
 	/* Enlarge the fatal lock wait timeout during CHECK TABLE. */
 	mutex_enter(&kernel_mutex);
-	srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */
+	srv_fatal_semaphore_wait_threshold += SRV_SEMAPHORE_WAIT_EXTENSION;
 	mutex_exit(&kernel_mutex);
 
 	for (index = dict_table_get_first_index(prebuilt->table);
@@ -8611,7 +8636,7 @@ ha_innobase::check(
 
 	/* Restore the fatal lock wait timeout after CHECK TABLE. */
 	mutex_enter(&kernel_mutex);
-	srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */
+	srv_fatal_semaphore_wait_threshold -= SRV_SEMAPHORE_WAIT_EXTENSION;
 	mutex_exit(&kernel_mutex);
 
 	prebuilt->trx->op_info = "";

=== modified file 'storage/innobase/handler/ha_innodb.h'
--- a/storage/innobase/handler/ha_innodb.h	2011-12-29 14:19:33 +0000
+++ b/storage/innobase/handler/ha_innodb.h	2012-05-10 05:03:16 +0000
@@ -133,6 +133,7 @@ class ha_innobase: public handler
 	const key_map* keys_to_use_for_scanning();
 
 	int open(const char *name, int mode, uint test_if_locked);
+	handler* clone(const char *name, MEM_ROOT *mem_root);
 	int close(void);
 	double scan_time();
 	double read_time(uint index, uint ranges, ha_rows rows);

=== modified file 'storage/innobase/include/srv0srv.h'
--- a/storage/innobase/include/srv0srv.h	2012-03-21 03:48:12 +0000
+++ b/storage/innobase/include/srv0srv.h	2012-04-27 10:40:12 +0000
@@ -262,6 +262,7 @@ extern	ibool	srv_print_latch_waits;
 
 extern ulint	srv_activity_count;
 extern ulint	srv_fatal_semaphore_wait_threshold;
+#define SRV_SEMAPHORE_WAIT_EXTENSION	7200
 extern ulint	srv_dml_needed_delay;
 
 extern mutex_t*	kernel_mutex_temp;/* mutex protecting the server, trx structs,

=== modified file 'storage/innobase/srv/srv0start.c'
--- a/storage/innobase/srv/srv0start.c	2012-02-16 18:13:08 +0000
+++ b/storage/innobase/srv/srv0start.c	2012-04-23 10:39:16 +0000
@@ -1364,10 +1364,18 @@ innobase_start_or_create_for_mysql(void)
 	}
 # endif /* __WIN__ */
 
-	os_aio_init(io_limit,
-		    srv_n_read_io_threads,
-		    srv_n_write_io_threads,
-		    SRV_MAX_N_PENDING_SYNC_IOS);
+	if (!os_aio_init(io_limit,
+			 srv_n_read_io_threads,
+			 srv_n_write_io_threads,
+			 SRV_MAX_N_PENDING_SYNC_IOS)) {
+
+		ut_print_timestamp(stderr);
+		fprintf(stderr,
+			" InnoDB: Fatal error: cannot initialize AIO"
+			" sub-system\n");
+
+		return(DB_ERROR);
+	}
 
 	fil_init(srv_file_per_table ? 50000 : 5000,
 		 srv_max_n_open_files);

=== modified file 'storage/innobase/sync/sync0arr.c'
--- a/storage/innobase/sync/sync0arr.c	2011-03-30 11:52:26 +0000
+++ b/storage/innobase/sync/sync0arr.c	2012-04-27 10:40:12 +0000
@@ -928,6 +928,11 @@ sync_array_print_long_waits(
 	ibool		fatal = FALSE;
 	double		longest_diff = 0;
 
+	/* For huge tables, skip the check during CHECK TABLE etc... */
+	if (fatal_timeout > SRV_SEMAPHORE_WAIT_EXTENSION) {
+		return(FALSE);
+	}
+
 #ifdef UNIV_DEBUG_VALGRIND
 	/* Increase the timeouts if running under valgrind because it executes
 	extremely slowly. UNIV_DEBUG_VALGRIND does not necessary mean that

=== modified file 'vio/viosocket.c'
--- a/vio/viosocket.c	2012-02-19 09:00:52 +0000
+++ b/vio/viosocket.c	2012-05-07 20:20:42 +0000
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+   Copyright (c) 2001, 2012, 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

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5 branch (daniel.fischer:3818 to 3823) Daniel Fischer5 Aug