List:Commits« Previous MessageNext Message »
From:Marc Alff Date:March 28 2012 10:12am
Subject:bzr push into mysql-trunk-pfs-tuning branch (marc.alff:3483 to 3484)
View as plain text  
 3484 Marc Alff	2012-03-28 [merge]
      Merge mysql-trunk --> mysql-trunk-pfs-tuning

    added:
      mysql-test/suite/rpl/r/rpl_gtid_sql_until_before_after.result
      mysql-test/suite/rpl/t/rpl_gtid_sql_until_before_after.test
    modified:
      include/my_md5.h
      mysql-test/collections/default.experimental
      mysql-test/include/subquery_sj.inc
      mysql-test/r/sp-bugs.result
      mysql-test/r/sp-code.result
      mysql-test/r/sp_notembedded.result
      mysql-test/r/subquery_sj_all.result
      mysql-test/r/subquery_sj_all_bka.result
      mysql-test/r/subquery_sj_all_bka_nixbnl.result
      mysql-test/r/subquery_sj_all_bkaunique.result
      mysql-test/r/subquery_sj_dupsweed.result
      mysql-test/r/subquery_sj_dupsweed_bka.result
      mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result
      mysql-test/r/subquery_sj_dupsweed_bkaunique.result
      mysql-test/r/subquery_sj_firstmatch.result
      mysql-test/r/subquery_sj_firstmatch_bka.result
      mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result
      mysql-test/r/subquery_sj_firstmatch_bkaunique.result
      mysql-test/r/subquery_sj_loosescan.result
      mysql-test/r/subquery_sj_loosescan_bka.result
      mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result
      mysql-test/r/subquery_sj_loosescan_bkaunique.result
      mysql-test/r/subquery_sj_mat.result
      mysql-test/r/subquery_sj_mat_bka.result
      mysql-test/r/subquery_sj_mat_bka_nixbnl.result
      mysql-test/r/subquery_sj_mat_bkaunique.result
      mysql-test/r/subquery_sj_mat_nosj.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/subquery_sj_none_bka.result
      mysql-test/r/subquery_sj_none_bka_nixbnl.result
      mysql-test/r/subquery_sj_none_bkaunique.result
      mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result
      mysql-test/suite/binlog/t/binlog_row_mysqlbinlog_verbose.test
      mysql-test/suite/engines/funcs/t/se_string_having.test
      mysql-test/suite/engines/funcs/t/ta_add_column.test
      mysql-test/suite/engines/funcs/t/ta_add_column_first.test
      mysql-test/suite/engines/funcs/t/ta_add_column_middle.test
      mysql-test/suite/engines/funcs/t/tc_multicolumn_different.test
      mysql-test/suite/funcs_2/t/innodb_charset.test
      mysql-test/suite/innodb/r/innodb-index-online-purge.result
      mysql-test/suite/innodb/r/innodb-index-online.result
      mysql-test/suite/innodb/t/disabled.def
      mysql-test/suite/innodb/t/innodb-index-online.test
      mysql-test/suite/innodb/t/innodb_bug11766634.test
      mysql-test/suite/innodb/t/innodb_mysql.test
      mysql-test/suite/parts/t/partition_alter1_1_innodb.test
      mysql-test/suite/parts/t/partition_alter2_2_1_innodb.test
      mysql-test/suite/parts/t/partition_basic_innodb.test
      mysql-test/suite/parts/t/partition_decimal_myisam.test
      mysql-test/suite/parts/t/partition_int_myisam.test
      mysql-test/t/sp-bugs.test
      mysql-test/t/sp-code.test
      mysql-test/t/sp_notembedded.test
      sql/log_event.cc
      sql/rpl_gtid.h
      sql/rpl_gtid_set.cc
      sql/rpl_rli.cc
      sql/rpl_rli.h
      sql/rpl_slave.cc
      sql/rpl_slave.h
      sql/sql_executor.cc
      sql/sql_lex.h
      sql/sql_show.cc
      sql/sql_yacc.yy
      storage/innobase/api/api0api.cc
      storage/innobase/api/api0misc.cc
      storage/innobase/buf/buf0lru.cc
      storage/innobase/fil/fil0fil.cc
      storage/innobase/handler/handler0alter.cc
      storage/innobase/include/api0api.h
      storage/innobase/include/buf0lru.h
      storage/innobase/include/buf0types.h
      storage/innobase/include/fil0fil.h
      storage/innobase/row/row0mysql.cc
      storage/perfschema/pfs_instr.cc
 3483 Marc Alff	2012-03-28
      Performance tuning, in progress

    modified:
      config.h.cmake
      configure.cmake
      storage/perfschema/pfs_account.cc
      storage/perfschema/pfs_account.h
      storage/perfschema/pfs_digest.cc
      storage/perfschema/pfs_digest.h
      storage/perfschema/pfs_engine_table.cc
      storage/perfschema/pfs_global.cc
      storage/perfschema/pfs_global.h
      storage/perfschema/pfs_host.cc
      storage/perfschema/pfs_host.h
      storage/perfschema/pfs_instr.cc
      storage/perfschema/pfs_instr.h
      storage/perfschema/pfs_instr_class.cc
      storage/perfschema/pfs_instr_class.h
      storage/perfschema/pfs_setup_actor.cc
      storage/perfschema/pfs_setup_actor.h
      storage/perfschema/pfs_setup_object.cc
      storage/perfschema/pfs_setup_object.h
      storage/perfschema/pfs_user.cc
      storage/perfschema/pfs_user.h
      strings/ctype-bin.c
=== modified file 'include/my_md5.h'
--- a/include/my_md5.h	2012-03-23 14:32:09 +0000
+++ b/include/my_md5.h	2012-03-27 08:25:06 +0000
@@ -62,6 +62,8 @@ do { \
    bits instead of 64 is not important; speed is considerably more
    important.  ANSI guarantees that "unsigned long" will be big enough,
    and always using it seems to have few disadvantages.  */
+
+#include "my_global.h"
 typedef uint32 cvs_uint32;
 
 typedef struct {

=== modified file 'mysql-test/collections/default.experimental'
--- a/mysql-test/collections/default.experimental	2012-03-24 08:18:36 +0000
+++ b/mysql-test/collections/default.experimental	2012-03-27 09:55:06 +0000
@@ -24,6 +24,7 @@ rpl.rpl_seconds_behind_master
 rpl.rpl_show_slave_running               # BUG#12346048 2011-04-11 sven fails sporadically on pb2
 rpl.rpl_parallel_switch_sequential       # BUG#13626976 2012-02-07 dlenev Fails sporadically on pb2
 rpl.rpl_report_port                      # BUG#13812374 2012-03-22 Hemant Fails after the post fix for bug#13812374 
+rpl.rpl_gtid_stress_failover             # BUG#11938382,BUG#13779291 2012-03-26 Nuno Fails sporadically on pb2 (see also BUG#13813811)
 
 sys_vars.max_sp_recursion_depth_func @solaris # Bug#11753919 2010-01-20 alik Several test cases fail on Solaris with error Thread stack overrun
 
@@ -38,16 +39,6 @@ rpl.rpl_mixed_mts_rec_crash_safe @solari
 rpl.rpl_mixed_mts_rec_crash_safe_checksum @solaris # Bug#12902514 2011-08-19 andrei same as rpl_mixed_mts_rec_crash_safe
 rpl.rpl_mixed_mts_crash_safe @solaris              # Bug#12902514 2011-08-19 andrei same as rpl_mixed_mts_rec_crash_safe
 
-
 # All memcached tests are failing. This could be setup issues on PB2
 # Making experimental until the problems are resolved
-memcached.memc216_5_utf8
-memcached.memc212_2_cols
-memcached.memc213_2_intcols
-memcached.memc217_add
-memcached.memc218_decr
-memcached.memc214_5_cols
-memcached.memc219_delete
-memcached.memc215_50_cols
-memcached.memc220_fkey_1
-memcached.memc221_get
+memcached.*

=== modified file 'mysql-test/include/subquery_sj.inc'
--- a/mysql-test/include/subquery_sj.inc	2012-03-22 08:17:51 +0000
+++ b/mysql-test/include/subquery_sj.inc	2012-03-26 10:29:07 +0000
@@ -4916,4 +4916,39 @@ eval $query;
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
 
+--echo #
+--echo # BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+--echo #               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+--echo #
+
+CREATE TABLE t1 (
+  col_int_key INT,
+  col_varchar_key VARCHAR(1),
+  KEY col_int_key (col_int_key),
+  KEY col_varchar_key (col_varchar_key)
+);
+
+INSERT INTO t1 VALUES (8,'x');
+
+CREATE TABLE t2 (
+  col_varchar_key VARCHAR(1),
+  KEY col_varchar_key (col_varchar_key)
+);
+
+INSERT INTO t2 VALUES ('x'), ('y');
+
+let $query= SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+  SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+  FROM t1 as t1_inner JOIN t2
+    ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+
+
+--eval explain $query
+--eval $query
+
+DROP TABLE t1,t2;
+
 --echo # End of 5.6 tests

=== modified file 'mysql-test/r/sp-bugs.result'
--- a/mysql-test/r/sp-bugs.result	2012-03-21 14:27:34 +0000
+++ b/mysql-test/r/sp-bugs.result	2012-03-28 08:27:26 +0000
@@ -119,3 +119,92 @@ SELECT sf();
 sf()
 
 DROP FUNCTION sf;
+#
+# Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
+#
+SET @@SQL_MODE = '';
+CREATE FUNCTION testf_bug11763507() RETURNS INT
+BEGIN
+RETURN 0;
+END
+$
+CREATE PROCEDURE testp_bug11763507()
+BEGIN
+SELECT "PROCEDURE testp_bug11763507";
+END
+$
+SELECT testf_bug11763507();
+testf_bug11763507()
+0
+SELECT TESTF_bug11763507();
+TESTF_bug11763507()
+0
+SHOW FUNCTION STATUS LIKE  'testf_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testf_bug11763507	FUNCTION	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW FUNCTION STATUS WHERE NAME='testf_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testf_bug11763507	FUNCTION	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW FUNCTION STATUS LIKE  'TESTF_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testf_bug11763507	FUNCTION	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW FUNCTION STATUS WHERE NAME='TESTF_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testf_bug11763507	FUNCTION	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW CREATE FUNCTION testf_bug11763507;
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+testf_bug11763507		CREATE DEFINER=`root`@`localhost` FUNCTION `testf_bug11763507`() RETURNS int(11)
+BEGIN
+RETURN 0;
+END	latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW CREATE FUNCTION TESTF_bug11763507;
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+testf_bug11763507		CREATE DEFINER=`root`@`localhost` FUNCTION `testf_bug11763507`() RETURNS int(11)
+BEGIN
+RETURN 0;
+END	latin1	latin1_swedish_ci	latin1_swedish_ci
+CALL testp_bug11763507();
+PROCEDURE testp_bug11763507
+PROCEDURE testp_bug11763507
+CALL TESTP_bug11763507();
+PROCEDURE testp_bug11763507
+PROCEDURE testp_bug11763507
+SHOW PROCEDURE STATUS LIKE  'testp_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testp_bug11763507	PROCEDURE	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW PROCEDURE STATUS WHERE NAME='testp_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testp_bug11763507	PROCEDURE	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW PROCEDURE STATUS LIKE  'TESTP_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testp_bug11763507	PROCEDURE	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW PROCEDURE STATUS WHERE NAME='TESTP_bug11763507';
+Db	Name	Type	Definer	Modified	Created	Security_type	Comment	character_set_client	collation_connection	Database Collation
+test	testp_bug11763507	PROCEDURE	root@localhost	#	#	DEFINER		latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW CREATE PROCEDURE testp_bug11763507;
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+testp_bug11763507		CREATE DEFINER=`root`@`localhost` PROCEDURE `testp_bug11763507`()
+BEGIN
+SELECT "PROCEDURE testp_bug11763507";
+END	latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW CREATE PROCEDURE TESTP_bug11763507;
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+testp_bug11763507		CREATE DEFINER=`root`@`localhost` PROCEDURE `testp_bug11763507`()
+BEGIN
+SELECT "PROCEDURE testp_bug11763507";
+END	latin1	latin1_swedish_ci	latin1_swedish_ci
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'testf_bug11763507';
+specific_name
+testf_bug11763507
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'TESTF_bug11763507';
+specific_name
+testf_bug11763507
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='testf_bug11763507';
+specific_name
+testf_bug11763507
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='TESTF_bug11763507';
+specific_name
+testf_bug11763507
+DROP PROCEDURE testp_bug11763507;
+DROP FUNCTION testf_bug11763507;
+#END OF BUG#11763507 test.

=== modified file 'mysql-test/r/sp-code.result'
--- a/mysql-test/r/sp-code.result	2012-02-13 15:23:37 +0000
+++ b/mysql-test/r/sp-code.result	2012-03-28 08:27:26 +0000
@@ -941,3 +941,32 @@ Error	1329	No data - zero rows fetched,
 SET SESSION debug="-d,bug23032_emit_warning";
 DROP PROCEDURE p1;
 DROP TABLE t1;
+#
+# Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
+#
+SET @@SQL_MODE = '';
+CREATE FUNCTION testf_bug11763507() RETURNS INT
+BEGIN
+RETURN 0;
+END
+$
+CREATE PROCEDURE testp_bug11763507()
+BEGIN
+SELECT "PROCEDURE testp_bug11763507";
+END
+$
+SHOW FUNCTION CODE testf_bug11763507;
+Pos	Instruction
+0	freturn 3 0
+SHOW FUNCTION CODE TESTF_bug11763507;
+Pos	Instruction
+0	freturn 3 0
+SHOW PROCEDURE CODE testp_bug11763507;
+Pos	Instruction
+0	stmt 0 "SELECT "PROCEDURE testp_bug11763507""
+SHOW PROCEDURE CODE TESTP_bug11763507;
+Pos	Instruction
+0	stmt 0 "SELECT "PROCEDURE testp_bug11763507""
+DROP PROCEDURE testp_bug11763507;
+DROP FUNCTION testf_bug11763507;
+#END OF BUG#11763507 test.

=== modified file 'mysql-test/r/sp_notembedded.result'
--- a/mysql-test/r/sp_notembedded.result	2011-06-08 13:44:50 +0000
+++ b/mysql-test/r/sp_notembedded.result	2012-03-28 08:05:08 +0000
@@ -308,4 +308,25 @@ SELECT `my.db`.f1(2);
 2
 # Switching to default connection.
 DROP DATABASE `my.db`;
+USE test;
 set @@global.concurrent_insert= @old_concurrent_insert;
+#
+# Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
+#
+SET @@SQL_MODE = '';
+CREATE EVENT teste_bug11763507 ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR 
+DO SELECT 1 $
+SHOW EVENTS LIKE 'teste_bug11763507';
+Db	Name	Definer	Time zone	Type	Execute at	Interval value	Interval field	Starts	Ends	Status	Originator	character_set_client	collation_connection	Database Collation
+test	teste_bug11763507	root@localhost	SYSTEM	ONE TIME	#	#	#	#	NULL	ENABLED	1	latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW EVENTS LIKE 'TESTE_bug11763507';
+Db	Name	Definer	Time zone	Type	Execute at	Interval value	Interval field	Starts	Ends	Status	Originator	character_set_client	collation_connection	Database Collation
+test	teste_bug11763507	root@localhost	SYSTEM	ONE TIME	#	#	#	#	NULL	ENABLED	1	latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW CREATE EVENT teste_bug11763507;
+Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
+teste_bug11763507		SYSTEM	#	latin1	latin1_swedish_ci	latin1_swedish_ci
+SHOW CREATE EVENT TESTE_bug11763507;
+Event	sql_mode	time_zone	Create Event	character_set_client	collation_connection	Database Collation
+teste_bug11763507		SYSTEM	#	latin1	latin1_swedish_ci	latin1_swedish_ci
+DROP EVENT teste_bug11763507;
+#END OF BUG#11763507 test.

=== modified file 'mysql-test/r/subquery_sj_all.result'
--- a/mysql-test/r/subquery_sj_all.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_all.result	2012-03-26 10:29:07 +0000
@@ -8060,5 +8060,41 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_all_bka.result'
--- a/mysql-test/r/subquery_sj_all_bka.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_all_bka.result	2012-03-26 10:29:07 +0000
@@ -8065,6 +8065,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_all_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_all_bka_nixbnl.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_all_bka_nixbnl.result	2012-03-26 10:29:07 +0000
@@ -8066,6 +8066,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_all_bkaunique.result'
--- a/mysql-test/r/subquery_sj_all_bkaunique.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_all_bkaunique.result	2012-03-26 10:29:07 +0000
@@ -8066,6 +8066,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed.result'
--- a/mysql-test/r/subquery_sj_dupsweed.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed.result	2012-03-26 10:29:07 +0000
@@ -8044,5 +8044,41 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed_bka.result'
--- a/mysql-test/r/subquery_sj_dupsweed_bka.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed_bka.result	2012-03-26 10:29:07 +0000
@@ -8045,6 +8045,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result	2012-03-26 10:29:07 +0000
@@ -8053,6 +8053,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed_bkaunique.result'
--- a/mysql-test/r/subquery_sj_dupsweed_bkaunique.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed_bkaunique.result	2012-03-26 10:29:07 +0000
@@ -8046,6 +8046,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_firstmatch.result'
--- a/mysql-test/r/subquery_sj_firstmatch.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch.result	2012-03-26 10:29:07 +0000
@@ -8043,6 +8043,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_firstmatch_bka.result'
--- a/mysql-test/r/subquery_sj_firstmatch_bka.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch_bka.result	2012-03-26 10:29:07 +0000
@@ -8044,6 +8044,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result	2012-03-26 10:29:07 +0000
@@ -8052,6 +8052,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_firstmatch_bkaunique.result'
--- a/mysql-test/r/subquery_sj_firstmatch_bkaunique.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch_bkaunique.result	2012-03-26 10:29:07 +0000
@@ -8045,6 +8045,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_loosescan.result'
--- a/mysql-test/r/subquery_sj_loosescan.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_loosescan.result	2012-03-26 10:29:07 +0000
@@ -8045,5 +8045,41 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_loosescan_bka.result'
--- a/mysql-test/r/subquery_sj_loosescan_bka.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_loosescan_bka.result	2012-03-26 10:29:07 +0000
@@ -8046,6 +8046,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result	2012-03-26 10:29:07 +0000
@@ -8054,6 +8054,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_loosescan_bkaunique.result'
--- a/mysql-test/r/subquery_sj_loosescan_bkaunique.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_loosescan_bkaunique.result	2012-03-26 10:29:07 +0000
@@ -8047,6 +8047,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat.result'
--- a/mysql-test/r/subquery_sj_mat.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_mat.result	2012-03-26 10:29:07 +0000
@@ -8058,5 +8058,41 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_bka.result'
--- a/mysql-test/r/subquery_sj_mat_bka.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_mat_bka.result	2012-03-26 10:29:07 +0000
@@ -8059,6 +8059,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_mat_bka_nixbnl.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_mat_bka_nixbnl.result	2012-03-26 10:29:07 +0000
@@ -8060,6 +8060,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_bkaunique.result'
--- a/mysql-test/r/subquery_sj_mat_bkaunique.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_mat_bkaunique.result	2012-03-26 10:29:07 +0000
@@ -8060,6 +8060,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_nosj.result'
--- a/mysql-test/r/subquery_sj_mat_nosj.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_mat_nosj.result	2012-03-26 10:29:07 +0000
@@ -8126,5 +8126,41 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none.result'
--- a/mysql-test/r/subquery_sj_none.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_none.result	2012-03-26 10:29:07 +0000
@@ -8041,5 +8041,41 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none_bka.result'
--- a/mysql-test/r/subquery_sj_none_bka.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_none_bka.result	2012-03-26 10:29:07 +0000
@@ -8042,6 +8042,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_none_bka_nixbnl.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_none_bka_nixbnl.result	2012-03-26 10:29:07 +0000
@@ -8042,6 +8042,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none_bkaunique.result'
--- a/mysql-test/r/subquery_sj_none_bkaunique.result	2012-03-22 08:17:51 +0000
+++ b/mysql-test/r/subquery_sj_none_bkaunique.result	2012-03-26 10:29:07 +0000
@@ -8043,6 +8043,42 @@ col_datetime_key
 2008-09-27 00:34:58
 DROP TABLE t1,t2;
 SET @@optimizer_search_depth=@old_depth;
+#
+# BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT 
+#               SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
+#
+CREATE TABLE t1 (
+col_int_key INT,
+col_varchar_key VARCHAR(1),
+KEY col_int_key (col_int_key),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t1 VALUES (8,'x');
+CREATE TABLE t2 (
+col_varchar_key VARCHAR(1),
+KEY col_varchar_key (col_varchar_key)
+);
+INSERT INTO t2 VALUES ('x'), ('y');
+explain SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+2	DEPENDENT SUBQUERY	t1_inner	system	col_varchar_key	NULL	NULL	NULL	1	NULL
+2	DEPENDENT SUBQUERY	t2	ref	col_varchar_key	col_varchar_key	4	const	1	Using index
+SELECT MIN(col_int_key)
+FROM t1 as t1_outer
+HAVING (1, 2) IN (
+SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
+FROM t1 as t1_inner JOIN t2
+ON t2.col_varchar_key = t1_inner.col_varchar_key
+);
+MIN(col_int_key)
+DROP TABLE t1,t2;
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result'
--- a/mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result	2009-10-14 13:25:11 +0000
+++ b/mysql-test/suite/binlog/r/binlog_row_mysqlbinlog_verbose.result	2012-03-27 00:14:24 +0000
@@ -159,3 +159,9 @@ stmt
 ### WHERE
 ###   @1=2
 drop table raw_binlog_rows;
+SET @@SESSION.BINLOG_ROWS_QUERY_LOG_EVENTS = 1;
+CREATE TABLE t1 (a VARCHAR(50));
+INSERT INTO t1 VALUES ("
+  GRANT ALL ON *.* TO 'batman'/*!*/;
+  ")|
+DROP TABLE t1;

=== modified file 'mysql-test/suite/binlog/t/binlog_row_mysqlbinlog_verbose.test'
--- a/mysql-test/suite/binlog/t/binlog_row_mysqlbinlog_verbose.test	2009-10-14 13:25:11 +0000
+++ b/mysql-test/suite/binlog/t/binlog_row_mysqlbinlog_verbose.test	2012-03-27 00:14:24 +0000
@@ -32,9 +32,6 @@
 #  tool and the output is checked.
 #
 ########################################################
-
-# We require binlog_format_row as we're independent of binlog format
-# and there's no point running the same test 3 times
 -- source include/have_binlog_format_row.inc
 
 --disable_query_log
@@ -84,3 +81,63 @@ create table raw_binlog_rows (txt varcha
 # Output --verbose lines, with extra Windows CR's trimmed
 select replace(txt,'\r', '') as stmt from raw_binlog_rows where txt like '###%';
 drop table raw_binlog_rows;
+
+
+#######################################################################
+# BUG#13799555: ROWS_QUERY_LOG_EVENTS DOES NOT ESCAPE MULTI-LINE QUERIES PROPERLY
+#
+# Check that when mysqlbinlog is given the option --verbose --verbose,
+# the multi-line original statement are properly escaped to prevent from
+# being executed.
+SET @@SESSION.BINLOG_ROWS_QUERY_LOG_EVENTS = 1;
+CREATE TABLE t1 (a VARCHAR(50));
+--let $binlog_start_position= query_get_value("SHOW MASTER STATUS", Position, 1)
+
+--delimiter |
+INSERT INTO t1 VALUES ("
+  GRANT ALL ON *.* TO 'batman'/*!*/;
+  ")|
+--delimiter ;
+
+--let $binlog_stop_position= query_get_value("SHOW MASTER STATUS", Position, 1)
+--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
+--let $datadir= `SELECT @@datadir`
+
+--let $_prefix= `SELECT UUID()`
+--let $TMP_FILE= $MYSQLTEST_VARDIR/tmp/$_prefix.tmp
+--exec $MYSQL_BINLOG --force-if-open --verbose --verbose --start-position=$binlog_start_position --stop-position=$binlog_stop_position $datadir/$binlog_file > $TMP_FILE
+
+--let TMP_FILE= $TMP_FILE
+--perl END_OF_FILE
+my $tmp_file= $ENV{'TMP_FILE'};
+
+my $escaped_query = <<END;
+# INSERT INTO t1 VALUES ("
+#   GRANT ALL ON *.* TO 'batman'/*!*/;
+#   ")
+END
+
+open(FILE, $tmp_file) or die("Unable to open $tmp_file: $!\n");
+my $contents = do { local $/; <FILE> };
+close(FILE) or die("Unable to close file.");
+
+$match= index($contents, $escaped_query) > -1;
+if (!$match)
+{
+  print "\n====================================================\n";
+  print "ESCAPED STRING DID NOT MATCH:\n";
+  print "====================================================\n";
+  print "$escaped_query";
+  print "====================================================\n";
+
+  print "\n====================================================\n";
+  print "BINLOG CONTENTS\n";
+  print "====================================================\n";
+  print "$contents";
+  print "====================================================\n";
+}
+END_OF_FILE
+
+# Clean up
+DROP TABLE t1;
+--remove_file $TMP_FILE

=== modified file 'mysql-test/suite/engines/funcs/t/se_string_having.test'
--- a/mysql-test/suite/engines/funcs/t/se_string_having.test	2010-03-18 06:42:07 +0000
+++ b/mysql-test/suite/engines/funcs/t/se_string_having.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,5 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
 --disable_warnings
 DROP TABLE IF EXISTS t1;
 --enable_warnings

=== modified file 'mysql-test/suite/engines/funcs/t/ta_add_column.test'
--- a/mysql-test/suite/engines/funcs/t/ta_add_column.test	2010-03-18 06:42:07 +0000
+++ b/mysql-test/suite/engines/funcs/t/ta_add_column.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,6 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
+
 --disable_warnings
 DROP TABLE IF EXISTS t1;
 --enable_warnings

=== modified file 'mysql-test/suite/engines/funcs/t/ta_add_column_first.test'
--- a/mysql-test/suite/engines/funcs/t/ta_add_column_first.test	2010-03-18 06:42:07 +0000
+++ b/mysql-test/suite/engines/funcs/t/ta_add_column_first.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,6 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
+
 --disable_warnings
 DROP TABLE IF EXISTS t1;
 --enable_warnings

=== modified file 'mysql-test/suite/engines/funcs/t/ta_add_column_middle.test'
--- a/mysql-test/suite/engines/funcs/t/ta_add_column_middle.test	2010-03-18 06:42:07 +0000
+++ b/mysql-test/suite/engines/funcs/t/ta_add_column_middle.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,6 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
+
 --disable_warnings
 DROP TABLE IF EXISTS t1;
 --enable_warnings

=== modified file 'mysql-test/suite/engines/funcs/t/tc_multicolumn_different.test'
--- a/mysql-test/suite/engines/funcs/t/tc_multicolumn_different.test	2010-03-18 06:42:07 +0000
+++ b/mysql-test/suite/engines/funcs/t/tc_multicolumn_different.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,6 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
+
 --disable_warnings
 DROP TABLE IF EXISTS m3;
 --enable_warnings

=== modified file 'mysql-test/suite/funcs_2/t/innodb_charset.test'
--- a/mysql-test/suite/funcs_2/t/innodb_charset.test	2008-07-09 18:55:23 +0000
+++ b/mysql-test/suite/funcs_2/t/innodb_charset.test	2012-03-26 11:51:27 +0000
@@ -5,6 +5,8 @@
 #                                                                              #
 # Checking of other prerequisites is in charset_master.test                    #
 ################################################################################
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
 
 --source include/have_innodb.inc
 

=== modified file 'mysql-test/suite/innodb/r/innodb-index-online-purge.result'
--- a/mysql-test/suite/innodb/r/innodb-index-online-purge.result	2012-03-21 14:06:19 +0000
+++ b/mysql-test/suite/innodb/r/innodb-index-online-purge.result	2012-03-26 08:41:29 +0000
@@ -1,4 +1,3 @@
-SET DEBUG='+d,debug_sync_abort_on_timeout';
 CREATE TABLE t (a INT PRIMARY KEY, c TEXT) ENGINE=InnoDB;
 CREATE TABLE u (a INT PRIMARY KEY, b INT, c INT NOT NULL) ENGINE=InnoDB;
 INSERT INTO t VALUES (1,'aa');
@@ -16,7 +15,6 @@ INSERT INTO u SELECT a+256,NULL,a+64 FRO
 COMMIT;
 BEGIN;
 DELETE FROM u;
-SET DEBUG='+d,debug_sync_abort_on_timeout';
 SET DEBUG_SYNC='row_log_apply_before SIGNAL created_u WAIT_FOR dml_done_u';
 ALTER TABLE u ADD INDEX (c);
 COMMIT;
@@ -25,7 +23,6 @@ SELECT state FROM information_schema.pro
 WHERE info='ALTER TABLE u ADD INDEX (c)';
 state
 debug sync point: row_log_apply_before
-SET DEBUG='+d,debug_sync_abort_on_timeout';
 SET DEBUG_SYNC='row_log_apply_before SIGNAL created_t WAIT_FOR dml_done_t';
 CREATE INDEX c1 ON t (c(1));
 SET DEBUG_SYNC='now WAIT_FOR created_t';
@@ -36,5 +33,4 @@ SLEEP(10)
 SET DEBUG_SYNC='now SIGNAL dml_done_u';
 SET DEBUG_SYNC='now SIGNAL dml_done_t';
 SET DEBUG_SYNC='RESET';
-SET DEBUG='-d,debug_sync_abort_on_timeout';
 DROP TABLE t,u;

=== modified file 'mysql-test/suite/innodb/r/innodb-index-online.result'
--- a/mysql-test/suite/innodb/r/innodb-index-online.result	2012-03-22 16:13:46 +0000
+++ b/mysql-test/suite/innodb/r/innodb-index-online.result	2012-03-27 10:12:44 +0000
@@ -1,5 +1,3 @@
-SET GLOBAL DEBUG='d,query,debug_sync_exec:i:A,ds.trace';
-SET DEBUG='d,query,debug_sync_exec,debug_sync_abort_on_timeout:i:A,ds.trace';
 call mtr.add_suppression("InnoDB: Warning: Small buffer pool size");
 call mtr.add_suppression("Cannot find index .*c2 in InnoDB index translation table");
 call mtr.add_suppression("Find index .*c2 in InnoDB index list but not its MySQL index number");
@@ -15,7 +13,6 @@ ddl_pending_alter_table	0
 SET DEBUG_SYNC='RESET';
 SET DEBUG_SYNC='write_row_noreplace SIGNAL have_handle WAIT_FOR go_ahead';
 INSERT INTO t1 VALUES(1,2,3);
-SET DEBUG='d,query,debug_sync_exec,debug_sync_abort_on_timeout:i:A,ds.trace';
 SET DEBUG_SYNC='now WAIT_FOR have_handle';
 SET lock_wait_timeout=1;
 ALTER TABLE t1 ADD UNIQUE INDEX(c2);
@@ -169,6 +166,7 @@ t1	CREATE TABLE `t1` (
   KEY `c2d` (`c2`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 SET DEBUG_SYNC='row_log_apply_before SIGNAL c2e_created WAIT_FOR dml2_done';
+SET lock_wait_timeout=10;
 ALTER TABLE t1 DROP INDEX c2d, ADD INDEX c2e(c2);
 INSERT INTO t1 SELECT 80+c1,c2,c3 FROM t1;
 INSERT INTO t1 SELECT 160+c1,c2,c3 FROM t1;
@@ -255,9 +253,7 @@ CHECK TABLE t1;
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 SET DEBUG_SYNC='RESET';
-SET DEBUG='';
 SET GLOBAL innodb_monitor_disable=module_ddl;
 DROP TABLE t1;
-SET GLOBAL DEBUG='';
 SET GLOBAL innodb_monitor_enable=default;
 SET GLOBAL innodb_monitor_disable=default;

=== modified file 'mysql-test/suite/innodb/t/disabled.def'
--- a/mysql-test/suite/innodb/t/disabled.def	2012-03-24 08:23:10 +0000
+++ b/mysql-test/suite/innodb/t/disabled.def	2012-03-26 08:41:29 +0000
@@ -9,4 +9,3 @@
 #  Do not use any TAB characters for whitespace.
 #
 ##############################################################################
-innodb-index-online-purge : BUG#13875241 2012-03-24 Anitha Gopi Test failing after push of WL#5526

=== modified file 'mysql-test/suite/innodb/t/innodb-index-online.test'
--- a/mysql-test/suite/innodb/t/innodb-index-online.test	2012-03-22 16:13:46 +0000
+++ b/mysql-test/suite/innodb/t/innodb-index-online.test	2012-03-27 10:12:44 +0000
@@ -3,9 +3,6 @@
 # Temporarily prohibit Valgrind runs until Bug#13875241 is resolved
 --source include/not_valgrind.inc
 
-SET GLOBAL DEBUG='d,query,debug_sync_exec:i:A,ds.trace';
-SET DEBUG='d,query,debug_sync_exec,debug_sync_abort_on_timeout:i:A,ds.trace';
-
 call mtr.add_suppression("InnoDB: Warning: Small buffer pool size");
 # These will be triggered by INSERT INTO t1 VALUES(6,3,1);
 call mtr.add_suppression("Cannot find index .*c2 in InnoDB index translation table");
@@ -27,7 +24,6 @@ INSERT INTO t1 VALUES(1,2,3);
 
 connect (con1,localhost,root,,);
 connection con1;
-SET DEBUG='d,query,debug_sync_exec,debug_sync_abort_on_timeout:i:A,ds.trace';
 
 # This should block at the end because of the INSERT in connection default
 # is holding a metadata lock.
@@ -180,6 +176,8 @@ SHOW CREATE TABLE t1;
 # The actual limit is a multiple of innodb_sort_buf_size,
 # because that is the size of the in-memory log buffers.
 SET DEBUG_SYNC='row_log_apply_before SIGNAL c2e_created WAIT_FOR dml2_done';
+# Ensure that the ALTER TABLE will be executed even with some concurrent DML.
+SET lock_wait_timeout=10;
 --send
 ALTER TABLE t1 DROP INDEX c2d, ADD INDEX c2e(c2);
 
@@ -259,7 +257,6 @@ disconnect con1;
 connection default;
 
 SET DEBUG_SYNC='RESET';
-SET DEBUG='';
 SET GLOBAL innodb_monitor_disable=module_ddl;
 
 DROP TABLE t1;
@@ -268,7 +265,6 @@ DROP TABLE t1;
 # gone so execution of other tests won't be affected by their presence.
 --source include/wait_until_count_sessions.inc
 
-SET GLOBAL DEBUG='';
 -- disable_warnings
 SET GLOBAL innodb_monitor_enable=default;
 SET GLOBAL innodb_monitor_disable=default;

=== modified file 'mysql-test/suite/innodb/t/innodb_bug11766634.test'
--- a/mysql-test/suite/innodb/t/innodb_bug11766634.test	2012-03-16 06:36:29 +0000
+++ b/mysql-test/suite/innodb/t/innodb_bug11766634.test	2012-03-26 11:51:27 +0000
@@ -7,6 +7,9 @@
 # records.  The size of ibdata1 must not increase.
 #
 
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
+
 -- source include/not_embedded.inc
 -- source include/have_innodb.inc
 

=== modified file 'mysql-test/suite/innodb/t/innodb_mysql.test'
--- a/mysql-test/suite/innodb/t/innodb_mysql.test	2011-12-09 21:08:37 +0000
+++ b/mysql-test/suite/innodb/t/innodb_mysql.test	2012-03-26 11:51:27 +0000
@@ -5,6 +5,9 @@
 #               main testing code t/innodb_mysql.test -> include/mix1.inc
 #
 
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
+
 -- source include/have_innodb.inc
 let $engine_type= InnoDB;
 let $other_engine_type= MEMORY;

=== modified file 'mysql-test/suite/parts/t/partition_alter1_1_innodb.test'
--- a/mysql-test/suite/parts/t/partition_alter1_1_innodb.test	2010-06-17 17:17:17 +0000
+++ b/mysql-test/suite/parts/t/partition_alter1_1_innodb.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,5 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
 ################################################################################
 # t/partition_alter1_1_innodb.test                                             #
 #                                                                              #

=== modified file 'mysql-test/suite/parts/t/partition_alter2_2_1_innodb.test'
--- a/mysql-test/suite/parts/t/partition_alter2_2_1_innodb.test	2010-06-17 17:17:17 +0000
+++ b/mysql-test/suite/parts/t/partition_alter2_2_1_innodb.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,5 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
 ################################################################################
 # t/partition_alter2_2_1_innodb.test                                           #
 #                                                                              #

=== modified file 'mysql-test/suite/parts/t/partition_basic_innodb.test'
--- a/mysql-test/suite/parts/t/partition_basic_innodb.test	2010-06-17 17:17:17 +0000
+++ b/mysql-test/suite/parts/t/partition_basic_innodb.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,5 @@
+#Want to skip this test from daily Valgrind execution
+--source include/no_valgrind_without_big.inc
 ################################################################################
 # t/partition_basic_innodb.test                                                #
 #                                                                              #

=== modified file 'mysql-test/suite/parts/t/partition_decimal_myisam.test'
--- a/mysql-test/suite/parts/t/partition_decimal_myisam.test	2007-11-20 15:04:07 +0000
+++ b/mysql-test/suite/parts/t/partition_decimal_myisam.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,5 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
 ################################################################################
 # t/partition_decimal_myisam.test                                              #
 #                                                                              #

=== modified file 'mysql-test/suite/parts/t/partition_int_myisam.test'
--- a/mysql-test/suite/parts/t/partition_int_myisam.test	2007-11-20 15:04:07 +0000
+++ b/mysql-test/suite/parts/t/partition_int_myisam.test	2012-03-26 11:51:27 +0000
@@ -1,3 +1,5 @@
+#Want to skip this test from daily Valgrind execution.
+--source include/no_valgrind_without_big.inc
 ################################################################################
 # t/partition_int_myisam.test                                                  #
 #                                                                              #

=== added file 'mysql-test/suite/rpl/r/rpl_gtid_sql_until_before_after.result'
--- a/mysql-test/suite/rpl/r/rpl_gtid_sql_until_before_after.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_gtid_sql_until_before_after.result	2012-03-27 08:43:25 +0000
@@ -0,0 +1,112 @@
+include/master-slave.inc
+Warnings:
+Note	1756	Sending passwords in plain text without SSL/TLS is extremely insecure.
+Note	1757	Storing MySQL user name or password information in the master.info repository is not secure and is therefore not recommended. Please see the MySQL Manual for more about this issue and possible alternatives.
+[connection master]
+include/rpl_set_gtid_mode.inc
+CREATE TABLE t1(c1 INTEGER) ENGINE= Innodb;
+[connection slave]
+include/stop_slave.inc
+[connection master]
+INSERT INTO t1 VALUES(2);
+INSERT INTO t1 VALUES(3);
+INSERT INTO t1 VALUES(4);
+INSERT INTO t1 VALUES(5);
+INSERT INTO t1 VALUES(6);
+INSERT INTO t1 VALUES(7);
+INSERT INTO t1 VALUES(8);
+INSERT INTO t1 VALUES(9);
+INSERT INTO t1 VALUES(10);
+[connection slave]
+SQL thread must stop *before* INSERT 4
+START SLAVE UNTIL SQL_BEFORE_GTIDS= "MASTER_UUID:4-5";
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+c1
+2
+3
+SQL thread must stop *after* INSERT 5
+START SLAVE UNTIL SQL_AFTER_GTIDS= "MASTER_UUID:4-5";
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+c1
+2
+3
+4
+5
+SQL thread must stop *before* INSERT 6
+START SLAVE UNTIL SQL_BEFORE_GTIDS= "MASTER_UUID:2-7";
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+c1
+2
+3
+4
+5
+SQL thread must stop *after* INSERT 5
+1-5 are already applied so it will stop immediately
+START SLAVE UNTIL SQL_AFTER_GTIDS= "MASTER_UUID:1-5";
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+c1
+2
+3
+4
+5
+SQL thread must stop *before* INSERT 10
+START SLAVE UNTIL SQL_BEFORE_GTIDS= "MASTER_UUID:10";
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+c1
+2
+3
+4
+5
+6
+7
+8
+9
+SQL thread must stop *before* INSERT 3-6
+3-6 is already applied so it will stop immediately
+START SLAVE UNTIL SQL_BEFORE_GTIDS= "MASTER_UUID:3-6";
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+c1
+2
+3
+4
+5
+6
+7
+8
+9
+SQL thread must stop *before* INSERT 9
+9 is already applied so it will stop immediately
+START SLAVE UNTIL SQL_BEFORE_GTIDS= "MASTER_UUID:9";
+include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+c1
+2
+3
+4
+5
+6
+7
+8
+9
+Sync slave with master
+include/start_slave_sql.inc
+SELECT SQL_THREAD_WAIT_AFTER_GTIDS('MASTER_UUID:10', 300);
+SELECT * FROM t1;
+c1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+DROP TABLE t1;
+include/rpl_end.inc

=== added file 'mysql-test/suite/rpl/t/rpl_gtid_sql_until_before_after.test'
--- a/mysql-test/suite/rpl/t/rpl_gtid_sql_until_before_after.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_gtid_sql_until_before_after.test	2012-03-27 08:43:25 +0000
@@ -0,0 +1,107 @@
+# BUG#13810456: GTID: UNTIL_SQL_BEFORE_GTID DOES NOT WORK
+#
+# This test performs multiple invocations of
+# START SLAVE UNTIL SQL_BEFORE_GTIDS and START SLAVE UNTIL SQL_AFTER_GTIDS
+# to demonstrate its correct operation.
+#
+# Create a set of transactions on the master and applied them individually
+# by using START SLAVE UNTIL SQL_BEFORE_GTIDS and
+# START SLAVE UNTIL SQL_AFTER_GTIDS with different sets of missing and/or
+# already applied GTIDs.
+#
+--source include/master-slave.inc
+--source include/rpl_set_gtid_mode.inc
+
+--connection master
+--let $master_uuid= query_get_value(SELECT @@SERVER_UUID, @@SERVER_UUID, 1)
+CREATE TABLE t1(c1 INTEGER) ENGINE= Innodb;
+--sync_slave_with_master
+--echo [connection slave]
+--source include/stop_slave.inc
+
+# Generate a set of transactions on the master.
+# INSERT value is the equal to sequence number.
+--echo [connection master]
+--connection master
+--let $i=2
+while ($i != 11)
+{
+  --eval INSERT INTO t1 VALUES($i)
+  --inc $i
+}
+
+--connection slave
+--echo [connection slave]
+--echo SQL thread must stop *before* INSERT 4
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--eval START SLAVE UNTIL SQL_BEFORE_GTIDS= "$master_uuid:4-5"
+--source include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+
+--echo SQL thread must stop *after* INSERT 5
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--eval START SLAVE UNTIL SQL_AFTER_GTIDS= "$master_uuid:4-5"
+--source include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+
+--echo SQL thread must stop *before* INSERT 6
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--eval START SLAVE UNTIL SQL_BEFORE_GTIDS= "$master_uuid:2-7"
+--source include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+
+--echo SQL thread must stop *after* INSERT 5
+--echo 1-5 are already applied so it will stop immediately
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--eval START SLAVE UNTIL SQL_AFTER_GTIDS= "$master_uuid:1-5"
+--source include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+
+--echo SQL thread must stop *before* INSERT 10
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--eval START SLAVE UNTIL SQL_BEFORE_GTIDS= "$master_uuid:10"
+--source include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+
+--echo SQL thread must stop *before* INSERT 3-6
+--echo 3-6 is already applied so it will stop immediately
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--eval START SLAVE UNTIL SQL_BEFORE_GTIDS= "$master_uuid:3-6"
+--source include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+
+--echo SQL thread must stop *before* INSERT 9
+--echo 9 is already applied so it will stop immediately
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--eval START SLAVE UNTIL SQL_BEFORE_GTIDS= "$master_uuid:9"
+--source include/wait_for_slave_sql_to_stop.inc
+SELECT * FROM t1;
+
+--echo Sync slave with master
+--source include/start_slave_sql.inc
+--disable_query_log
+--replace_result $master_uuid MASTER_UUID
+--enable_query_log
+--disable_result_log
+--eval SELECT SQL_THREAD_WAIT_AFTER_GTIDS('$master_uuid:10', 300)
+--enable_result_log
+SELECT * FROM t1;
+
+# Cleanup
+--connection master
+DROP TABLE t1;
+--source include/rpl_end.inc

=== modified file 'mysql-test/t/sp-bugs.test'
--- a/mysql-test/t/sp-bugs.test	2012-03-21 06:42:54 +0000
+++ b/mysql-test/t/sp-bugs.test	2012-03-28 08:27:26 +0000
@@ -148,3 +148,66 @@ DROP DATABASE db2;
 CREATE FUNCTION sf() RETURNS BLOB RETURN "";
 SELECT sf();
 DROP FUNCTION sf;
+
+--echo #
+--echo # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
+--echo #
+SET @@SQL_MODE = '';
+DELIMITER $;
+CREATE FUNCTION testf_bug11763507() RETURNS INT
+BEGIN
+    RETURN 0;
+END
+$
+
+CREATE PROCEDURE testp_bug11763507()
+BEGIN
+    SELECT "PROCEDURE testp_bug11763507";
+END
+$
+
+DELIMITER ;$
+
+# STORED FUNCTIONS
+SELECT testf_bug11763507();
+SELECT TESTF_bug11763507();
+
+--replace_column 5 # 6 #
+SHOW FUNCTION STATUS LIKE  'testf_bug11763507';
+--replace_column 5 # 6 #
+SHOW FUNCTION STATUS WHERE NAME='testf_bug11763507';
+--replace_column 5 # 6 #
+SHOW FUNCTION STATUS LIKE  'TESTF_bug11763507';
+--replace_column 5 # 6 #
+SHOW FUNCTION STATUS WHERE NAME='TESTF_bug11763507';
+
+SHOW CREATE FUNCTION testf_bug11763507;
+SHOW CREATE FUNCTION TESTF_bug11763507;
+
+# STORED PROCEDURE
+CALL testp_bug11763507();
+CALL TESTP_bug11763507();
+
+--replace_column 5 # 6 #
+SHOW PROCEDURE STATUS LIKE  'testp_bug11763507';
+--replace_column 5 # 6 #
+SHOW PROCEDURE STATUS WHERE NAME='testp_bug11763507';
+--replace_column 5 # 6 #
+SHOW PROCEDURE STATUS LIKE  'TESTP_bug11763507';
+--replace_column 5 # 6 #
+SHOW PROCEDURE STATUS WHERE NAME='TESTP_bug11763507';
+
+SHOW CREATE PROCEDURE testp_bug11763507;
+SHOW CREATE PROCEDURE TESTP_bug11763507;
+
+# INFORMATION SCHEMA 
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'testf_bug11763507';
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'TESTF_bug11763507';
+
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='testf_bug11763507';
+SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='TESTF_bug11763507';
+
+DROP PROCEDURE testp_bug11763507;
+DROP FUNCTION testf_bug11763507;
+
+--echo #END OF BUG#11763507 test.

=== modified file 'mysql-test/t/sp-code.test'
--- a/mysql-test/t/sp-code.test	2010-07-30 15:28:36 +0000
+++ b/mysql-test/t/sp-code.test	2012-03-28 08:05:08 +0000
@@ -702,3 +702,35 @@ SET SESSION debug="-d,bug23032_emit_warn
 
 DROP PROCEDURE p1;
 DROP TABLE t1;
+
+--echo #
+--echo # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
+--echo #
+SET @@SQL_MODE = '';
+DELIMITER $;
+CREATE FUNCTION testf_bug11763507() RETURNS INT
+BEGIN
+    RETURN 0;
+END
+$
+
+CREATE PROCEDURE testp_bug11763507()
+BEGIN
+    SELECT "PROCEDURE testp_bug11763507";
+END
+$
+
+DELIMITER ;$
+
+# STORED FUNCTIONS
+SHOW FUNCTION CODE testf_bug11763507;
+SHOW FUNCTION CODE TESTF_bug11763507;
+
+# STORED PROCEDURE
+SHOW PROCEDURE CODE testp_bug11763507;
+SHOW PROCEDURE CODE TESTP_bug11763507;
+
+DROP PROCEDURE testp_bug11763507;
+DROP FUNCTION testf_bug11763507;
+
+--echo #END OF BUG#11763507 test.

=== modified file 'mysql-test/t/sp_notembedded.test'
--- a/mysql-test/t/sp_notembedded.test	2011-06-08 13:44:50 +0000
+++ b/mysql-test/t/sp_notembedded.test	2012-03-28 08:05:08 +0000
@@ -473,6 +473,7 @@ SELECT `my.db`.f1(2);
 connection default;
 disconnect addcon;
 DROP DATABASE `my.db`;
+USE test;
 
 #
 # Restore global concurrent_insert value. Keep in the end of the test file.
@@ -483,3 +484,26 @@ set @@global.concurrent_insert= @old_con
 # Wait till all disconnects are completed
 --source include/wait_until_count_sessions.inc
 
+--echo #
+--echo # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE
+--echo #
+SET @@SQL_MODE = '';
+DELIMITER $;
+
+CREATE EVENT teste_bug11763507 ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR 
+DO SELECT 1 $
+
+DELIMITER ;$
+# EVENTS
+--replace_column 6 # 7 # 8 # 9 #
+SHOW EVENTS LIKE 'teste_bug11763507';
+--replace_column 6 # 7 # 8 # 9 #
+SHOW EVENTS LIKE 'TESTE_bug11763507';
+
+--replace_column 4 # 
+SHOW CREATE EVENT teste_bug11763507;
+--replace_column 4 # 
+SHOW CREATE EVENT TESTE_bug11763507;
+
+DROP EVENT teste_bug11763507;
+--echo #END OF BUG#11763507 test.

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2012-03-22 17:33:57 +0000
+++ b/sql/log_event.cc	2012-03-27 00:14:24 +0000
@@ -11807,9 +11807,22 @@ Rows_query_log_event::print(FILE *file,
   {
     IO_CACHE *const head= &print_event_info->head_cache;
     IO_CACHE *const body= &print_event_info->body_cache;
+    char *token= NULL, *saveptr= NULL;
+    char *rows_query_copy= NULL;
+    if (!(rows_query_copy= my_strdup(m_rows_query, MYF(MY_WME))))
+      return;
+
     print_header(head, print_event_info, FALSE);
     my_b_printf(head, "\tRows_query\n");
-    my_b_printf(head, "# %s\n", m_rows_query);
+    /*
+      Prefix every line of a multi-line query with '#' to prevent the
+      statement from being executed when binary log will be processed
+      using 'mysqlbinlog --verbose --verbose'.
+    */
+    for (token= strtok_r(rows_query_copy, "\n", &saveptr); token;
+         token= strtok_r(NULL, "\n", &saveptr))
+      my_b_printf(head, "# %s\n", token);
+    my_free(rows_query_copy);
     print_base64(body, print_event_info, true);
   }
 }

=== modified file 'sql/rpl_gtid.h'
--- a/sql/rpl_gtid.h	2012-02-28 12:04:45 +0000
+++ b/sql/rpl_gtid.h	2012-03-27 08:43:25 +0000
@@ -1003,6 +1003,11 @@ public:
   enum_return_status ensure_sidno(rpl_sidno sidno);
   /// Returns true if this Gtid_set is a subset of the other Gtid_set.
   bool is_subset(const Gtid_set *super) const;
+  /// Returns true if there is a least one element of this Gtid_set in
+  /// the other Gtid_set.
+  bool is_intersection(const Gtid_set *other) const;
+  /// Result is the intersection of this Gtid_set and the other Gtid_set.
+  enum_return_status intersection(const Gtid_set *other, Gtid_set *result);
   /// Returns true if this Gtid_set is empty.
   bool is_empty() const
   {

=== modified file 'sql/rpl_gtid_set.cc'
--- a/sql/rpl_gtid_set.cc	2012-02-24 11:29:46 +0000
+++ b/sql/rpl_gtid_set.cc	2012-03-27 08:43:25 +0000
@@ -1087,6 +1087,49 @@ bool Gtid_set::is_subset(const Gtid_set
 }
 
 
+bool Gtid_set::is_intersection(const Gtid_set *other) const
+{
+  DBUG_ENTER("Gtid_set::is_intersection(Gtid_set *)");
+  if (sid_lock != NULL)
+    sid_lock->assert_some_wrlock();
+  Gtid_iterator git(this);
+  Gtid g= git.get();
+  while (g.sidno != 0)
+  {
+    if (other->contains_gtid(g.sidno, g.gno))
+      DBUG_RETURN(true);
+    git.next();
+    g= git.get();
+  }
+  DBUG_RETURN(false);
+}
+
+
+enum_return_status
+Gtid_set::intersection(const Gtid_set *other, Gtid_set *result)
+{
+  DBUG_ENTER("Gtid_set::intersection(Gtid_set *, Gtid_set *)");
+  if (sid_lock != NULL)
+    sid_lock->assert_some_wrlock();
+  DBUG_ASSERT(result != NULL);
+  result->clear();
+  Gtid_iterator git(this);
+  Gtid g= git.get();
+  while (g.sidno != 0)
+  {
+    if (other->contains_gtid(g.sidno, g.gno))
+    {
+      if (result->ensure_sidno(g.sidno) ||
+          result->_add_gtid(g.sidno, g.gno))
+        RETURN_REPORTED_ERROR;
+    }
+    git.next();
+    g= git.get();
+  }
+  RETURN_OK;
+}
+
+
 void Gtid_set::encode(uchar *buf) const
 {
   DBUG_ENTER("Gtid_set::encode(uchar *)");

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2012-03-14 09:52:49 +0000
+++ b/sql/rpl_rli.cc	2012-03-27 08:43:25 +0000
@@ -80,8 +80,9 @@ Relay_log_info::Relay_log_info(bool is_s
    last_master_timestamp(0), slave_skip_counter(0),
    abort_pos_wait(0), until_condition(UNTIL_NONE),
    until_log_pos(0),
-   until_gtids_obj(&global_sid_map),
-   request_gtids_obj(&global_sid_map),
+   until_sql_gtids(&global_sid_map),
+   until_sql_gtids_seen(&global_sid_map),
+   until_sql_gtids_first_event(true),
    retried_trans(0),
    tables_to_lock(0), tables_to_lock_count(0),
    rows_query_ev(NULL), last_event_start_time(0),
@@ -297,8 +298,9 @@ void Relay_log_info::clear_until_conditi
   until_condition= Relay_log_info::UNTIL_NONE;
   until_log_name[0]= 0;
   until_log_pos= 0;
-  request_gtids_obj.clear();
-  until_gtids_obj.clear();
+  until_sql_gtids.clear();
+  until_sql_gtids_seen.clear();
+  until_sql_gtids_first_event= true;
   DBUG_VOID_RETURN;
 }
 
@@ -1087,9 +1089,10 @@ bool Relay_log_info::is_until_satisfied(
                     "condition is bad.";
   DBUG_ENTER("Relay_log_info::is_until_satisfied");
 
-  DBUG_ASSERT(until_condition != UNTIL_NONE);
-
-  if (until_condition == UNTIL_MASTER_POS || until_condition == UNTIL_RELAY_POS)
+  switch (until_condition)
+  {
+  case UNTIL_MASTER_POS:
+  case UNTIL_RELAY_POS:
   {
     const char *log_name= NULL;
     ulonglong log_pos= 0;
@@ -1097,7 +1100,7 @@ bool Relay_log_info::is_until_satisfied(
     if (until_condition == UNTIL_MASTER_POS)
     {
       if (ev && ev->server_id == (uint32) ::server_id && !replicate_same_server_id)
-        DBUG_RETURN(FALSE);
+        DBUG_RETURN(false);
       log_name= group_master_log_name;
       log_pos= (!ev)? group_master_log_pos :
         ((thd->variables.option_bits & OPTION_BEGIN || !ev->log_pos) ?
@@ -1154,48 +1157,99 @@ bool Relay_log_info::is_until_satisfied(
         }
         else
         {
-          /* Probably error so we aborting */
+          /* Base names do not match, so we abort */
           sql_print_error("%s", error_msg);
-          DBUG_RETURN(TRUE);
+          DBUG_RETURN(true);
         }
       }
       else
         DBUG_RETURN(until_log_pos == 0);
     }
 
-    DBUG_RETURN(((until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_EQUAL &&
-             log_pos >= until_log_pos) ||
-            until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_GREATER));
-  }
-  else if (ev != NULL && ev->get_type_code() == GTID_LOG_EVENT)
-  {
-    global_sid_lock.wrlock();
-    if (until_gtids_obj._remove_gtid(((Gtid_log_event *)(ev))->get_sidno(false),
-                                     ((Gtid_log_event *)(ev))->get_gno())
-        != RETURN_STATUS_OK || until_gtids_obj.is_empty())
+    if (((until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_EQUAL &&
+          log_pos >= until_log_pos) ||
+         until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_GREATER))
     {
-      global_sid_lock.unlock();
+      char buf[22];
+      sql_print_information("Slave SQL thread stopped because it reached its"
+                            " UNTIL position %s", llstr(until_pos(), buf));
       DBUG_RETURN(true);
     }
+    DBUG_RETURN(false);
+  }
 
-#ifndef DBUG_OFF
-    char* buffer= NULL;
-    if (!(buffer= (char *) my_malloc(until_gtids_obj.get_string_length() + 1,
-                                     MYF(MY_WME))))
+  case UNTIL_SQL_BEFORE_GTIDS:
+    if (ev != NULL && ev->get_type_code() == GTID_LOG_EVENT)
     {
+      Gtid_log_event *gev= (Gtid_log_event *)ev;
+      global_sid_lock.rdlock();
+      if (until_sql_gtids.contains_gtid(gev->get_sidno(false), gev->get_gno()))
+      {
+        char *buffer= until_sql_gtids.to_string();
+        global_sid_lock.unlock();
+        sql_print_information("Slave SQL thread stopped because it reached "
+                              "UNTIL SQL_BEFORE_GTIDS %s", buffer);
+        my_free(buffer);
+        DBUG_RETURN(true);
+      }
       global_sid_lock.unlock();
-      DBUG_RETURN(true);
+      // We only need to check once if logged_gtids set contains any of the until_sql_gtids.
+      if (until_sql_gtids_first_event)
+      {
+        until_sql_gtids_first_event= false;
+        global_sid_lock.wrlock();
+        /* Check if until GTIDs were already applied. */
+        const Gtid_set* logged_gtids= gtid_state.get_logged_gtids();
+        if (until_sql_gtids.is_intersection(logged_gtids))
+        {
+          char *buffer= until_sql_gtids.to_string();
+          global_sid_lock.unlock();
+          sql_print_information("Slave SQL thread stopped because "
+                                "UNTIL SQL_BEFORE_GTIDS %s is already "
+                                "applied", buffer);
+          my_free(buffer);
+          DBUG_RETURN(true);
+        }
+        global_sid_lock.unlock();
+      }
     }
-    else
+    DBUG_RETURN(false);
+    break;
+
+  case UNTIL_SQL_AFTER_GTIDS:
+    if (ev != NULL && ev->get_type_code() == GTID_LOG_EVENT)
     {
-      until_gtids_obj.to_string(buffer);
-      DBUG_PRINT("info", ("Waiting for %s to be processed.", buffer));
-      my_free(buffer);
+      global_sid_lock.wrlock();
+      // We only need to compute until_sql_gtids_seen once.
+      if (until_sql_gtids_first_event)
+      {
+        until_sql_gtids_first_event= false;
+        const Gtid_set* logged_gtids= gtid_state.get_logged_gtids();
+        until_sql_gtids.intersection(logged_gtids, &until_sql_gtids_seen);
+      }
+      if (until_sql_gtids.is_subset(const_cast<Gtid_set *>(&until_sql_gtids_seen)))
+      {
+        char *buffer= until_sql_gtids.to_string();
+        global_sid_lock.unlock();
+        sql_print_information("Slave SQL thread stopped because it reached "
+                              "UNTIL SQL_AFTER_GTIDS %s", buffer);
+        my_free(buffer);
+        DBUG_RETURN(true);
+      }
+      Gtid_log_event *gev= (Gtid_log_event *)ev;
+      until_sql_gtids_seen.ensure_sidno(gev->get_sidno(false));
+      until_sql_gtids_seen._add_gtid(gev->get_sidno(false), gev->get_gno());
+      global_sid_lock.unlock();
     }
-#endif
-    global_sid_lock.unlock();
+    DBUG_RETURN(false);
+    break;
+
+  case UNTIL_NONE:
+    DBUG_ASSERT(0);
+    break;
   }
 
+  DBUG_ASSERT(0);
   DBUG_RETURN(false);
 }
 

=== modified file 'sql/rpl_rli.h'
--- a/sql/rpl_rli.h	2012-03-12 22:08:24 +0000
+++ b/sql/rpl_rli.h	2012-03-27 08:43:25 +0000
@@ -309,29 +309,29 @@ public:
      thread is running).
    */
   enum {UNTIL_NONE= 0, UNTIL_MASTER_POS, UNTIL_RELAY_POS,
-        UNTIL_SQL_BEFORE_GTIDS} until_condition;
+        UNTIL_SQL_BEFORE_GTIDS, UNTIL_SQL_AFTER_GTIDS} until_condition;
   char until_log_name[FN_REFLEN];
   ulonglong until_log_pos;
   /* extension extracted from log_name and converted to int */
   ulong until_log_name_extension;
   /**
-    The START SLAVE UNTIL SQL_BEFORE_GTIDS initializes both
-    the until_gtids_obj and request_gtids_obj. Each time a
-    gtid is about to be processed, it is removed from the
-    until_gtids_obj and when until_gtids_obj becomes empty,
-    the SQL Thread is stopped and a message saying that 
-    the condition was reached, i.e. request_gtids_obj, is
-    printed out.
-
-    This is used by the START SLAVE UNTIL SQL_BEFORE_GTIDS.
-    is issued.
+    The START SLAVE UNTIL SQL_*_GTIDS initializes until_sql_gtids.
+    Each time a gtid is about to be processed, we check if it is in the
+    set. Depending on until_condition, SQL thread is stopped before or
+    after applying the gtid.
   */
-  Gtid_set until_gtids_obj;
-  /**
-    This is used when the START SLAVE UNTIL SQL_BEFORE_GTIDS
-    is issued.
+  Gtid_set until_sql_gtids;
+  /*
+    On START SLAVE UNTIL SQL_AFTER_GTIDS this set contains the
+    intersection between logged gtids set and gtids scheduled on MTS
+    worker queues.
+  */
+  Gtid_set until_sql_gtids_seen;
+  /*
+    True if the current event is the first gtid event to be processed
+    after executing START SLAVE UNTIL SQL_*_GTIDS.
   */
-  Gtid_set request_gtids_obj;
+  bool until_sql_gtids_first_event;
   /* 
      Cached result of comparison of until_log_name and current log name
      -2 means unitialised, -1,0,1 are comarison results 

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	2012-03-22 06:25:38 +0000
+++ b/sql/rpl_slave.cc	2012-03-27 08:43:25 +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
@@ -3519,23 +3519,6 @@ static int exec_relay_log_event(THD* thd
     if (rli->until_condition != Relay_log_info::UNTIL_NONE &&
         rli->is_until_satisfied(thd, ev))
     {
-      char buf[22];
-      if (rli->until_condition == Relay_log_info::UNTIL_MASTER_POS ||
-          rli->until_condition == Relay_log_info::UNTIL_RELAY_POS)
-        sql_print_information("Slave SQL thread stopped because it reached its"
-                              " UNTIL position %s", llstr(rli->until_pos(), buf));
-      else
-      {
-        char *buffer;
-        global_sid_lock.wrlock();
-        if ((buffer= (char *) my_malloc(rli->request_gtids_obj.get_string_length() + 1,
-                                        MYF(MY_WME))))
-          rli->request_gtids_obj.to_string(buffer);
-        global_sid_lock.unlock();
-        sql_print_information("Slave SQL thread stopped because it reached its"
-                              " UNTIL SQL_BEFORE_GTIDS %s", buffer);
-        my_free(buffer);
-      }
       /*
         Setting abort_slave flag because we do not want additional message about
         error in query execution to be printed.
@@ -5257,23 +5240,6 @@ log '%s' at position %s, relay log '%s'
   if (rli->until_condition != Relay_log_info::UNTIL_NONE &&
       rli->is_until_satisfied(thd, NULL))
   {
-    char buf[22];
-    if (rli->until_condition == Relay_log_info::UNTIL_MASTER_POS ||
-        rli->until_condition == Relay_log_info::UNTIL_RELAY_POS)
-      sql_print_information("Slave SQL thread stopped because it reached its"
-                            " UNTIL position %s", llstr(rli->until_pos(), buf));
-    else
-    {
-      char* buffer= NULL;
-      global_sid_lock.rdlock();
-      if ((buffer= (char *) my_malloc(rli->request_gtids_obj.get_string_length() + 1,
-                                      MYF(MY_WME))))
-        rli->request_gtids_obj.to_string(buffer);
-      global_sid_lock.unlock();
-      sql_print_information("Slave SQL thread stopped because it reached its"
-                            " UNTIL SQL_BEFORE_GTIDS %s", buffer);
-      my_free(buffer);
-    }
     mysql_mutex_unlock(&rli->data_lock);
     goto err;
   }
@@ -7475,15 +7441,15 @@ int start_slave(THD* thd , Master_info*
         {
           global_sid_lock.wrlock();
           mi->rli->clear_until_condition();
-          if (mi->rli->until_gtids_obj.add_gtid_text(thd->lex->mi.gtid)
-              != RETURN_STATUS_OK ||
-              mi->rli->request_gtids_obj.add_gtid_text(thd->lex->mi.gtid)
+          if (mi->rli->until_sql_gtids.add_gtid_text(thd->lex->mi.gtid)
               != RETURN_STATUS_OK)
             slave_errno= ER_BAD_SLAVE_UNTIL_COND;
-          if (mi->rli->until_gtids_obj.remove_gtid_set(gtid_state.get_logged_gtids()) 
-              != RETURN_STATUS_OK)
-            slave_errno= ER_BAD_SLAVE_UNTIL_COND;
-          mi->rli->until_condition= Relay_log_info::UNTIL_SQL_BEFORE_GTIDS;
+          else {
+            mi->rli->until_condition=
+              LEX_MASTER_INFO::UNTIL_SQL_BEFORE_GTIDS == thd->lex->mi.gtid_until_condition
+              ? Relay_log_info::UNTIL_SQL_BEFORE_GTIDS
+              : Relay_log_info::UNTIL_SQL_AFTER_GTIDS;
+          }
           global_sid_lock.unlock();
         }
         else

=== modified file 'sql/rpl_slave.h'
--- a/sql/rpl_slave.h	2012-03-22 06:25:38 +0000
+++ b/sql/rpl_slave.h	2012-03-26 19:30:00 +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/sql_executor.cc'
--- a/sql/sql_executor.cc	2012-03-21 21:12:45 +0000
+++ b/sql/sql_executor.cc	2012-03-26 10:29:07 +0000
@@ -145,15 +145,13 @@ JOIN::exec()
       We have to test for 'conds' here as the WHERE may not be constant
       even if we don't have any tables for prepared statements or if
       conds uses something like 'rand()'.
-      If the HAVING clause is either impossible or always true, then
-      JOIN::having is set to NULL by optimize_cond.
-      In this case JOIN::exec must check for JOIN::having_value, in the
-      same way it checks for JOIN::cond_value.
+
+      Don't evaluate the having clause here. return_zero_rows() should
+      be called only for cases where there are no matching rows after
+      evaluating all conditions except the HAVING clause.
     */
     if (select_lex->cond_value != Item::COND_FALSE &&
-        select_lex->having_value != Item::COND_FALSE &&
-        (!conds || conds->val_int()) &&
-        (!having || having->val_int()))
+        (!conds || conds->val_int()))
     {
       if (result->send_result_set_metadata(*columns_list,
                                            Protocol::SEND_NUM_ROWS |
@@ -161,7 +159,16 @@ JOIN::exec()
       {
         DBUG_VOID_RETURN;
       }
-      if (do_send_rows &&
+
+      /*
+        If the HAVING clause is either impossible or always true, then
+        JOIN::having is set to NULL by optimize_cond.
+        In this case JOIN::exec must check for JOIN::having_value, in the
+        same way it checks for JOIN::cond_value.
+      */
+      if (((select_lex->having_value != Item::COND_FALSE) &&
+           (!having || having->val_int())) 
+          && do_send_rows &&
           (procedure ? (procedure->send_row(procedure_fields_list) ||
            procedure->end_of_records()) : result->send_data(fields_list)))
         error= 1;
@@ -1422,13 +1429,17 @@ static void update_const_equal_items(Ite
 }
 
 /**
-  For some reason (impossible WHERE clause etc), the tables cannot
+  For some reason, e.g. due to an impossible WHERE clause, the tables cannot
   possibly contain any rows that will be in the result. This function
   is used to return with a result based on no matching rows (i.e., an
   empty result or one row with aggregates calculated without using
   rows in the case of implicit grouping) before the execution of
   nested loop join.
 
+  This function may evaluate the HAVING clause and is only meant for
+  result sets that are empty due to an impossible HAVING clause. Do
+  not use it if HAVING has already been evaluated.
+
   @param join    The join that does not produce a row
   @param fields  Fields in result
 */

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2012-03-14 13:12:36 +0000
+++ b/sql/sql_lex.h	2012-03-27 08:43:25 +0000
@@ -213,6 +213,7 @@ typedef struct st_lex_master_info
   ulonglong pos;
   ulong server_id, retry_count;
   char *gtid;
+  enum {UNTIL_SQL_BEFORE_GTIDS= 0, UNTIL_SQL_AFTER_GTIDS} gtid_until_condition;
 
   /*
     Enum is used for making it possible to detect if the user

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2012-03-13 13:27:02 +0000
+++ b/sql/sql_show.cc	2012-03-27 11:50:38 +0000
@@ -5082,7 +5082,8 @@ bool store_schema_proc(THD *thd, TABLE *
       (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0)
   {
     restore_record(table, s->default_values);
-    if (!wild || !wild[0] || !wild_compare(sp_name.c_ptr_safe(), wild, 0))
+    if (!wild || !wild[0] || !wild_case_compare(system_charset_info,
+                                                sp_name.c_ptr_safe(), wild))
     {
       int enum_idx= (int) proc_table->field[MYSQL_PROC_FIELD_ACCESS]->val_int();
       table->field[IS_ROUTINES_ROUTINE_NAME]->store(sp_name.ptr(),
@@ -6239,7 +6240,7 @@ copy_event_to_schema_table(THD *thd, TAB
     DBUG_RETURN(1);
   }
 
-  if (!(!wild || !wild[0] || !wild_compare(et.name.str, wild, 0)))
+  if (!(!wild || !wild[0] || !wild_case_compare(scs, et.name.str, wild)))
     DBUG_RETURN(0);
 
   /*

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2012-03-21 14:27:34 +0000
+++ b/sql/sql_yacc.yy	2012-03-27 08:43:25 +0000
@@ -1510,7 +1510,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %token  SQLEXCEPTION_SYM              /* SQL-2003-R */
 %token  SQLSTATE_SYM                  /* SQL-2003-R */
 %token  SQLWARNING_SYM                /* SQL-2003-R */
-%token  SQL_AFTER_GTIDS               /* MYSQL, FUTURE-USE */
+%token  SQL_AFTER_GTIDS               /* MYSQL */
 %token  SQL_BEFORE_GTIDS              /* MYSQL */
 %token  SQL_BIG_RESULT
 %token  SQL_BUFFER_RESULT
@@ -7700,6 +7700,12 @@ slave_until_opts:
         | SQL_BEFORE_GTIDS EQ TEXT_STRING_sys
           {
             Lex->mi.gtid= $3.str;
+            Lex->mi.gtid_until_condition= LEX_MASTER_INFO::UNTIL_SQL_BEFORE_GTIDS;
+          }
+        | SQL_AFTER_GTIDS EQ TEXT_STRING_sys
+          {
+            Lex->mi.gtid= $3.str;
+            Lex->mi.gtid_until_condition= LEX_MASTER_INFO::UNTIL_SQL_AFTER_GTIDS;
           }
         ;
 

=== modified file 'storage/innobase/api/api0api.cc'
--- a/storage/innobase/api/api0api.cc	2012-03-22 08:01:37 +0000
+++ b/storage/innobase/api/api0api.cc	2012-03-27 08:08:04 +0000
@@ -20,6 +20,7 @@ this program; if not, write to the Free
 @file api/api0api.cc
 InnoDB Native API
 
+2008-08-01 Created Sunny Bains
 3/20/2011 Jimmy Yang extracted from Embedded InnoDB
 *******************************************************/
 

=== modified file 'storage/innobase/api/api0misc.cc'
--- a/storage/innobase/api/api0misc.cc	2011-12-13 11:26:37 +0000
+++ b/storage/innobase/api/api0misc.cc	2012-03-27 08:08:04 +0000
@@ -20,8 +20,8 @@ this program; if not, write to the Free
 @file api/api0misc.cc
 InnoDB Native API
 
+2008-08-01 Created by Sunny Bains
 3/20/2011 Jimmy Yang extracted from Embedded InnoDB
-2008 Created by Sunny Bains
 *******************************************************/
 
 #include <errno.h>

=== modified file 'storage/innobase/buf/buf0lru.cc'
--- a/storage/innobase/buf/buf0lru.cc	2011-12-23 13:17:36 +0000
+++ b/storage/innobase/buf/buf0lru.cc	2012-03-26 18:33:20 +0000
@@ -342,39 +342,276 @@ next_page:
 }
 
 /******************************************************************//**
+While flushing (or removing dirty) pages from a tablespace we don't
+want to hog the CPU and resources. Release the buffer pool and block
+mutex and try to force a context switch. Then reacquire the same mutexes.
+The current page is "fixed" before the release of the mutexes and then
+"unfixed" again once we have reacquired the mutexes. */
+static
+void
+buf_flush_yield(
+/*============*/
+	buf_pool_t*	buf_pool,	/*!< in/out: buffer pool instance */
+	buf_page_t*	bpage)		/*!< in/out: current page */
+{
+	mutex_t*	block_mutex;
+
+	ut_ad(buf_pool_mutex_own(buf_pool));
+	ut_ad(buf_page_in_file(bpage));
+
+	block_mutex = buf_page_get_mutex(bpage);
+
+	mutex_enter(block_mutex);
+	/* "Fix" the block so that the position cannot be
+	changed after we release the buffer pool and
+	block mutexes. */
+	buf_page_set_sticky(bpage);
+
+	/* Now it is safe to release the buf_pool->mutex. */
+	buf_pool_mutex_exit(buf_pool);
+
+	mutex_exit(block_mutex);
+	/* Try and force a context switch. */
+	os_thread_yield();
+
+	buf_pool_mutex_enter(buf_pool);
+
+	mutex_enter(block_mutex);
+	/* "Unfix" the block now that we have both the
+	buffer pool and block mutex again. */
+	buf_page_unset_sticky(bpage);
+	mutex_exit(block_mutex);
+}
+
+/******************************************************************//**
+If we have hogged the resources for too long then release the buffer
+pool and flush list mutex and do a thread yield. Set the current page
+to "sticky" so that it is not relocated during the yield.
+@return TRUE if yielded */
+static
+ibool
+buf_flush_try_yield(
+/*================*/
+	buf_pool_t*	buf_pool,	/*!< in/out: buffer pool instance */
+	buf_page_t*	bpage,		/*!< in/out: bpage to remove */
+	ulint		processed)	/*!< in: number of pages processed */
+{
+	/* Every BUF_LRU_DROP_SEARCH_SIZE iterations in the
+	loop we release buf_pool->mutex to let other threads
+	do their job but only if the block is not IO fixed. This
+	ensures that the block stays in its position in the
+	flush_list. */
+
+	if (bpage != NULL
+	    && processed >= BUF_LRU_DROP_SEARCH_SIZE
+	    && buf_page_get_io_fix(bpage) == BUF_IO_NONE) {
+
+		buf_flush_list_mutex_exit(buf_pool);
+
+		/* Release the buffer pool and block mutex
+		to give the other threads a go. */
+
+		buf_flush_yield(buf_pool, bpage);
+
+		buf_flush_list_mutex_enter(buf_pool);
+
+		/* Should not have been removed from the flush
+		list during the yield. However, this check is
+		not sufficient to catch a remove -> add. */
+
+		ut_ad(bpage->in_flush_list);
+
+		return(TRUE);
+	}
+
+	return(FALSE);
+}
+
+/******************************************************************//**
+Removes a single page from a given tablespace inside a specific
+buffer pool instance.
+@return TRUE if page was removed. */
+static
+ibool
+buf_flush_or_remove_page(
+/*=====================*/
+	buf_pool_t*	buf_pool,	/*!< in/out: buffer pool instance */
+	buf_page_t*	bpage)		/*!< in/out: bpage to remove */
+{
+	mutex_t*	block_mutex;
+	ibool		processed = FALSE;
+
+	ut_ad(buf_pool_mutex_own(buf_pool));
+	ut_ad(buf_flush_list_mutex_own(buf_pool));
+
+	block_mutex = buf_page_get_mutex(bpage);
+
+	/* bpage->space and bpage->io_fix are protected by
+	buf_pool->mutex and block_mutex. It is safe to check
+	them while holding buf_pool->mutex only. */
+
+	if (buf_page_get_io_fix(bpage) != BUF_IO_NONE) {
+
+		/* We cannot remove this page during this scan
+		yet; maybe the system is currently reading it
+		in, or flushing the modifications to the file */
+
+	} else {
+
+		/* We have to release the flush_list_mutex to obey the
+		latching order. We are however guaranteed that the page
+		will stay in the flush_list because buf_flush_remove()
+		needs buf_pool->mutex as well (for the non-flush case). */
+
+		buf_flush_list_mutex_exit(buf_pool);
+
+		mutex_enter(block_mutex);
+
+		ut_ad(bpage->oldest_modification != 0);
+
+		if (bpage->buf_fix_count == 0) {
+
+			buf_flush_remove(bpage);
+
+			processed = TRUE;
+		}
+
+		mutex_exit(block_mutex);
+
+		buf_flush_list_mutex_enter(buf_pool);
+	}
+
+	ut_ad(!mutex_own(block_mutex));
+
+	return(processed);
+}
+
+/******************************************************************//**
 Remove all dirty pages belonging to a given tablespace inside a specific
 buffer pool instance when we are deleting the data file(s) of that
 tablespace. The pages still remain a part of LRU and are evicted from
-the list as they age towards the tail of the LRU. */
+the list as they age towards the tail of the LRU.
+@return TRUE if all freed. */
+static
+ibool
+buf_flush_or_remove_pages(
+/*======================*/
+	buf_pool_t*	buf_pool,	/*!< buffer pool instance */
+	ulint		id)		/*!< in: target space id for which
+					to remove or flush pages */
+{
+	buf_page_t*	prev;
+	buf_page_t*	bpage;
+	ulint		processed = 0;
+	ibool		all_freed = TRUE;
+
+	buf_flush_list_mutex_enter(buf_pool);
+
+	for (bpage = UT_LIST_GET_LAST(buf_pool->flush_list);
+	     bpage != NULL;
+	     bpage = prev) {
+
+		ut_a(buf_page_in_file(bpage));
+		ut_ad(bpage->in_flush_list);
+
+		/* Save the previous link because once we free the
+		page we can't rely on the links. */
+
+		prev = UT_LIST_GET_PREV(list, bpage);
+
+		if (buf_page_get_space(bpage) != id) {
+
+			/* Skip this block, as it does not belong to
+			the target space. */
+
+		} else if (!buf_flush_or_remove_page(buf_pool, bpage)) {
+
+			/* Remove was unsuccessful, we have to try again
+			by scanning the entire list from the end. */
+
+			all_freed = FALSE;
+		}
+
+		++processed;
+
+		/* Yield if we have hogged the CPU and mutexes for too long. */
+		if (buf_flush_try_yield(buf_pool, prev, processed)) {
+
+			/* Reset the batch size counter if we had to yield. */
+
+			processed = 0;
+		}
+
+	}
+
+	buf_flush_list_mutex_exit(buf_pool);
+
+	return(all_freed);
+}
+
+/******************************************************************//**
+Remove or flush all the dirty pages that belong to a given tablespace
+inside a specific buffer pool instance. The pages will remain in the LRU
+list and will be evicted from the LRU list as they age and move towards
+the tail of the LRU list. */
+static
+void
+buf_flush_dirty_pages(
+/*==================*/
+	buf_pool_t*	buf_pool,	/*!< buffer pool instance */
+	ulint		id)		/*!< in: space id */
+{
+	ibool	all_freed;
+
+	do {
+		buf_pool_mutex_enter(buf_pool);
+
+		all_freed = buf_flush_or_remove_pages(buf_pool, id);
+
+		buf_pool_mutex_exit(buf_pool);
+
+		ut_ad(buf_flush_validate(buf_pool));
+
+		if (!all_freed) {
+			os_thread_sleep(20000);
+		}
+
+	} while (!all_freed);
+}
+
+/******************************************************************//**
+Remove all pages that belong to a given tablespace inside a specific
+buffer pool instance when we are DISCARDing the tablespace. */
 static
 void
-buf_LRU_remove_dirty_pages_for_tablespace(
-/*======================================*/
+buf_LRU_remove_all_pages(
+/*=====================*/
 	buf_pool_t*	buf_pool,	/*!< buffer pool instance */
 	ulint		id)		/*!< in: space id */
 {
 	buf_page_t*	bpage;
 	ibool		all_freed;
-	ulint		i;
 
 scan_again:
 	buf_pool_mutex_enter(buf_pool);
-	buf_flush_list_mutex_enter(buf_pool);
 
 	all_freed = TRUE;
 
-	for (bpage = UT_LIST_GET_LAST(buf_pool->flush_list), i = 0;
-	     bpage != NULL; ++i) {
+	for (bpage = UT_LIST_GET_LAST(buf_pool->LRU);
+	     bpage != NULL;
+	     /* No op */) {
 
+		rw_lock_t*      hash_lock;
 		buf_page_t*	prev_bpage;
 		mutex_t*	block_mutex = NULL;
 
 		ut_a(buf_page_in_file(bpage));
+		ut_ad(bpage->in_LRU_list);
 
-		prev_bpage = UT_LIST_GET_PREV(list, bpage);
+		prev_bpage = UT_LIST_GET_PREV(LRU, bpage);
 
 		/* bpage->space and bpage->io_fix are protected by
-		buf_pool->mutex and block_mutex. It is safe to check
+		buf_pool->mutex and the block_mutex. It is safe to check
 		them while holding buf_pool->mutex only. */
 
 		if (buf_page_get_space(bpage) != id) {
@@ -388,83 +625,101 @@ scan_again:
 
 			all_freed = FALSE;
 			goto next_page;
-		}
+		} else {
 
-		/* We have to release the flush_list_mutex to obey the
-		latching order. We are however guaranteed that the page
-		will stay in the flush_list because buf_flush_remove()
-		needs buf_pool->mutex as well. */
-		buf_flush_list_mutex_exit(buf_pool);
-		block_mutex = buf_page_get_mutex(bpage);
-		mutex_enter(block_mutex);
+			ulint	fold = buf_page_address_fold(
+				bpage->space, bpage->offset);
 
-		if (bpage->buf_fix_count > 0) {
-			mutex_exit(block_mutex);
-			buf_flush_list_mutex_enter(buf_pool);
+			hash_lock = buf_page_hash_lock_get(buf_pool, fold);
 
-			/* We cannot remove this page during
-			this scan yet; maybe the system is
-			currently reading it in, or flushing
-			the modifications to the file */
+			rw_lock_x_lock(hash_lock);
 
-			all_freed = FALSE;
-			goto next_page;
-		}
+			block_mutex = buf_page_get_mutex(bpage);
+			mutex_enter(block_mutex);
 
-		ut_ad(bpage->oldest_modification != 0);
+			if (bpage->buf_fix_count > 0) {
 
-		buf_flush_remove(bpage);
+				mutex_exit(block_mutex);
 
-		mutex_exit(block_mutex);
-		buf_flush_list_mutex_enter(buf_pool);
-next_page:
-		bpage = prev_bpage;
+				/* We cannot remove this page during
+				this scan yet; maybe the system is
+				currently reading it in, or flushing
+				the modifications to the file */
 
-		if (!bpage) {
-			break;
+				all_freed = FALSE;
+
+				goto next_page;
+			}
 		}
 
-		/* Every BUF_LRU_DROP_SEARCH_SIZE iterations in the
-		loop we release buf_pool->mutex to let other threads
-		do their job. */
-		if (i < BUF_LRU_DROP_SEARCH_SIZE) {
-			continue;
+		ut_ad(mutex_own(block_mutex));
+
+#ifdef UNIV_DEBUG
+		if (buf_debug_prints) {
+			fprintf(stderr,
+				"Dropping space %lu page %lu\n",
+				(ulong) buf_page_get_space(bpage),
+				(ulong) buf_page_get_page_no(bpage));
 		}
+#endif
+		if (buf_page_get_state(bpage) != BUF_BLOCK_FILE_PAGE) {
+			/* Do nothing, because the adaptive hash index
+			covers uncompressed pages only. */
+		} else if (((buf_block_t*) bpage)->index) {
+			ulint	page_no;
+			ulint	zip_size;
+
+			buf_pool_mutex_exit(buf_pool);
+
+			zip_size = buf_page_get_zip_size(bpage);
+			page_no = buf_page_get_page_no(bpage);
 
-		/* We IO-fix the block to make sure that the block
-		stays in its position in the flush_list. */
-		if (buf_page_get_io_fix(bpage) != BUF_IO_NONE) {
-			/* Block is already IO-fixed. We don't
-			want to change the value. Lets leave
-			this block alone. */
-			continue;
+			rw_lock_x_unlock(hash_lock);
+
+			mutex_exit(block_mutex);
+
+			/* Note that the following call will acquire
+			and release block->lock X-latch. */
+
+			btr_search_drop_page_hash_when_freed(
+				id, zip_size, page_no);
+
+			goto scan_again;
 		}
 
-		buf_flush_list_mutex_exit(buf_pool);
-		block_mutex = buf_page_get_mutex(bpage);
-		mutex_enter(block_mutex);
-		buf_page_set_sticky(bpage);
-		mutex_exit(block_mutex);
+		if (bpage->oldest_modification != 0) {
+			buf_flush_remove(bpage);
+		}
 
-		/* Now it is safe to release the buf_pool->mutex. */
-		buf_pool_mutex_exit(buf_pool);
-		os_thread_yield();
-		buf_pool_mutex_enter(buf_pool);
+		ut_ad(!bpage->in_flush_list);
 
-		mutex_enter(block_mutex);
-		buf_page_unset_sticky(bpage);
-		mutex_exit(block_mutex);
+		/* Remove from the LRU list. */
 
-		buf_flush_list_mutex_enter(buf_pool);
-		ut_ad(bpage->in_flush_list);
+		if (buf_LRU_block_remove_hashed_page(bpage, TRUE)
+		    != BUF_BLOCK_ZIP_FREE) {
+
+			buf_LRU_block_free_hashed_page((buf_block_t*) bpage);
+
+		} else {
+			/* The block_mutex should have been released
+			by buf_LRU_block_remove_hashed_page() when it
+			returns BUF_BLOCK_ZIP_FREE. */
+			ut_ad(block_mutex == &buf_pool->zip_mutex);
+		}
+
+		ut_ad(!mutex_own(block_mutex));
+
+#ifdef UNIV_SYNC_DEBUG
+                /* buf_LRU_block_remove_hashed_page() releases the hash_lock */
+                ut_ad(!rw_lock_own(hash_lock, RW_LOCK_EX));
+                ut_ad(!rw_lock_own(hash_lock, RW_LOCK_SHARED));
+#endif /* UNIV_SYNC_DEBUG */
 
-		i = 0;
+next_page:
+		bpage = prev_bpage;
 	}
 
 	buf_pool_mutex_exit(buf_pool);
-	buf_flush_list_mutex_exit(buf_pool);
-
-	ut_ad(buf_flush_validate(buf_pool));
 
 	if (!all_freed) {
 		os_thread_sleep(20000);
@@ -474,28 +729,46 @@ next_page:
 }
 
 /******************************************************************//**
-Invalidates all pages belonging to a given tablespace when we are deleting
-the data file(s) of that tablespace. */
+Removes all pages belonging to a given tablespace. */
 UNIV_INTERN
 void
-buf_LRU_invalidate_tablespace(
+buf_LRU_flush_or_remove_pages(
 /*==========================*/
-	ulint	id)	/*!< in: space id */
+	ulint			id,	/*!< in: space id */
+	enum buf_remove_t	buf_remove)/*!< in: remove or flush
+					strategy */
 {
-	ulint	i;
+	ulint		i;
 
-	/* Before we attempt to drop pages one by one we first
-	attempt to drop page hash index entries in batches to make
-	it more efficient. The batching attempt is a best effort
-	attempt and does not guarantee that all pages hash entries
-	will be dropped. We get rid of remaining page hash entries
-	one by one below. */
 	for (i = 0; i < srv_buf_pool_instances; i++) {
 		buf_pool_t*	buf_pool;
 
 		buf_pool = buf_pool_from_array(i);
-		buf_LRU_drop_page_hash_for_tablespace(buf_pool, id);
-		buf_LRU_remove_dirty_pages_for_tablespace(buf_pool, id);
+
+		switch (buf_remove) {
+		case BUF_REMOVE_ALL_NO_WRITE:
+			/* A DISCARD tablespace case. Remove AHI entries
+			and evict all pages from LRU. */
+
+			/* Before we attempt to drop pages hash entries
+			one by one we first attempt to drop page hash
+			index entries in batches to make it more
+			efficient. The batching attempt is a best effort
+			attempt and does not guarantee that all pages
+			hash entries will be dropped. We get rid of
+			remaining page hash entries one by one below. */
+			buf_LRU_drop_page_hash_for_tablespace(buf_pool, id);
+			buf_LRU_remove_all_pages(buf_pool, id);
+			break;
+
+		case BUF_REMOVE_FLUSH_NO_WRITE:
+			/* A DROP table case. AHI entries are already
+			removed. No need to evict all pages from LRU
+			list. Just evict pages from flush list without
+			writing. */
+			buf_flush_dirty_pages(buf_pool, id);
+			break;
+		}
 	}
 }
 

=== modified file 'storage/innobase/fil/fil0fil.cc'
--- a/storage/innobase/fil/fil0fil.cc	2012-03-15 17:49:27 +0000
+++ b/storage/innobase/fil/fil0fil.cc	2012-03-26 14:16:26 +0000
@@ -2195,7 +2195,7 @@ fil_op_log_parse_or_replay(
 	switch (type) {
 	case MLOG_FILE_DELETE:
 		if (fil_tablespace_exists_in_mem(space_id)) {
-			ut_a(fil_delete_tablespace(space_id));
+			ut_a(fil_delete_tablespace(space_id, TRUE));
 		}
 
 		break;
@@ -2266,7 +2266,9 @@ UNIV_INTERN
 ibool
 fil_delete_tablespace(
 /*==================*/
-	ulint	id)	/*!< in: space id */
+	ulint	id,		/*!< in: space id */
+	ibool	evict_all)	/*!< in: TRUE if we want all pages
+				evicted from LRU. */
 {
 	ibool		success;
 	fil_space_t*	space;
@@ -2393,7 +2395,10 @@ try_again:
 	completely and permanently. The flag is_being_deleted also prevents
 	fil_flush() from being applied to this tablespace. */
 
-	buf_LRU_invalidate_tablespace(id);
+	buf_LRU_flush_or_remove_pages(
+		id, evict_all
+		? BUF_REMOVE_ALL_NO_WRITE
+		: BUF_REMOVE_FLUSH_NO_WRITE);
 #endif
 	/* printf("Deleting tablespace %s id %lu\n", space->name, id); */
 
@@ -2481,7 +2486,7 @@ fil_discard_tablespace(
 {
 	ibool	success;
 
-	success = fil_delete_tablespace(id);
+	success = fil_delete_tablespace(id, TRUE);
 
 	if (!success) {
 		fprintf(stderr,

=== modified file 'storage/innobase/handler/handler0alter.cc'
--- a/storage/innobase/handler/handler0alter.cc	2012-03-21 12:45:40 +0000
+++ b/storage/innobase/handler/handler0alter.cc	2012-03-26 09:54:31 +0000
@@ -677,7 +677,9 @@ innobase_create_index_def(
 		index->ind_type |= DICT_CLUSTERED;
 	} else if (key->flags & HA_FULLTEXT) {
 		DBUG_ASSERT(!(key->flags & HA_KEYFLAG_MASK
-			      & ~(HA_FULLTEXT | HA_BINARY_PACK_KEY)));
+			      & ~(HA_FULLTEXT
+				  | HA_PACK_KEY
+				  | HA_BINARY_PACK_KEY)));
 		DBUG_ASSERT(!(key->flags & HA_NOSAME));
 		DBUG_ASSERT(!index->ind_type);
 		index->ind_type |= DICT_FTS;
@@ -1873,7 +1875,9 @@ err_exit_no_heap:
 			fulltext indexes are not supported. */
 			DBUG_ASSERT(!(key->flags & HA_NOSAME));
 			DBUG_ASSERT(!(key->flags & HA_KEYFLAG_MASK
-				      & ~(HA_FULLTEXT | HA_BINARY_PACK_KEY)));
+				      & ~(HA_FULLTEXT
+					  | HA_PACK_KEY
+					  | HA_BINARY_PACK_KEY)));
 			continue;
 		}
 
@@ -2014,7 +2018,9 @@ func_exit:
 
 		if (key->flags & HA_FULLTEXT) {
 			DBUG_ASSERT(!(key->flags & HA_KEYFLAG_MASK
-				      & ~(HA_FULLTEXT | HA_BINARY_PACK_KEY)));
+				      & ~(HA_FULLTEXT
+					  | HA_PACK_KEY
+					  | HA_BINARY_PACK_KEY)));
 			num_fts_index++;
 		}
 	}

=== modified file 'storage/innobase/include/api0api.h'
--- a/storage/innobase/include/api0api.h	2012-03-19 05:39:58 +0000
+++ b/storage/innobase/include/api0api.h	2012-03-27 08:08:04 +0000
@@ -20,6 +20,7 @@ this program; if not, write to the Free
 @file include/api0api.h
 InnoDB Native API
 
+2008-08-01 Created by Sunny Bains.
 3/20/2011 Jimmy Yang extracted from Embedded InnoDB
 *******************************************************/
 

=== modified file 'storage/innobase/include/buf0lru.h'
--- a/storage/innobase/include/buf0lru.h	2011-11-08 10:32:23 +0000
+++ b/storage/innobase/include/buf0lru.h	2012-03-26 14:16:26 +0000
@@ -49,15 +49,14 @@ These are low-level functions
 #define BUF_LRU_OLD_MIN_LEN	512	/* 8 megabytes of 16k pages */
 
 /******************************************************************//**
-Invalidates all pages belonging to a given tablespace when we are deleting
-the data file(s) of that tablespace. A PROBLEM: if readahead is being started,
-what guarantees that it will not try to read in pages after this operation has
-completed? */
+Removes all pages belonging to a given tablespace. */
 UNIV_INTERN
 void
-buf_LRU_invalidate_tablespace(
+buf_LRU_flush_or_remove_pages(
 /*==========================*/
-	ulint	id);	/*!< in: space id */
+	ulint			id,	/*!< in: space id */
+	enum buf_remove_t	buf_remove);/*!< in: remove or flush
+					strategy */
 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
 /********************************************************************//**
 Insert a compressed block into buf_pool->zip_clean in the LRU order. */

=== modified file 'storage/innobase/include/buf0types.h'
--- a/storage/innobase/include/buf0types.h	2011-12-23 13:17:36 +0000
+++ b/storage/innobase/include/buf0types.h	2012-03-26 14:16:26 +0000
@@ -80,9 +80,17 @@ enum srv_checksum_algorithm_enum {
 	SRV_CHECKSUM_ALGORITHM_STRICT_NONE	/*!< Write none, allow none
 						when reading */
 };
-
 typedef enum srv_checksum_algorithm_enum	srv_checksum_algorithm_t;
 
+/** Algorithm to remove the pages for a tablespace from the buffer pool.
+@See buf_LRU_flush_or_remove_pages(). */
+enum buf_remove_t {
+	BUF_REMOVE_ALL_NO_WRITE,	/*!< Remove all pages from the buffer
+					pool, don't write or sync to disk */
+	BUF_REMOVE_FLUSH_NO_WRITE,	/*!< Remove only, from the flush list,
+					don't write or sync to disk */
+};
+
 /** Parameters of binary buddy system for compressed pages (buf0buddy.h) */
 /* @{ */
 /** Zip shift value for the smallest page size */

=== modified file 'storage/innobase/include/fil0fil.h'
--- a/storage/innobase/include/fil0fil.h	2012-03-15 17:49:27 +0000
+++ b/storage/innobase/include/fil0fil.h	2012-03-26 14:16:26 +0000
@@ -408,7 +408,9 @@ UNIV_INTERN
 ibool
 fil_delete_tablespace(
 /*==================*/
-	ulint	id);	/*!< in: space id */
+	ulint	id,		/*!< in: space id */
+	ibool	evict_all);	/*!< in: TRUE if we want all pages
+				evicted from LRU. */
 #ifndef UNIV_HOTBACKUP
 /*******************************************************************//**
 Discards a single-table tablespace. The tablespace must be cached in the

=== modified file 'storage/innobase/row/row0mysql.cc'
--- a/storage/innobase/row/row0mysql.cc	2012-03-20 15:09:23 +0000
+++ b/storage/innobase/row/row0mysql.cc	2012-03-26 14:16:26 +0000
@@ -2209,7 +2209,8 @@ err_exit:
 	case DB_TOO_MANY_CONCURRENT_TRXS:
 		/* We already have .ibd file here. it should be deleted. */
 
-		if (table->space && !fil_delete_tablespace(table->space)) {
+		if (table->space && !fil_delete_tablespace(table->space,
+							   FALSE)) {
 			ut_print_timestamp(stderr);
 			fprintf(stderr,
 				"  InnoDB: Error: not able to"
@@ -3855,7 +3856,7 @@ check_next_foreign:
 					"InnoDB: of table ");
 				ut_print_name(stderr, trx, TRUE, name);
 				fprintf(stderr, ".\n");
-			} else if (!fil_delete_tablespace(space_id)) {
+			} else if (!fil_delete_tablespace(space_id, FALSE)) {
 				fprintf(stderr,
 					"InnoDB: We removed now the InnoDB"
 					" internal data dictionary entry\n"

=== modified file 'storage/perfschema/pfs_instr.cc'
--- a/storage/perfschema/pfs_instr.cc	2012-03-28 08:29:33 +0000
+++ b/storage/perfschema/pfs_instr.cc	2012-03-28 10:09:04 +0000
@@ -1143,8 +1143,8 @@ find_or_create_file(PFS_thread *thread,
   /* Append the unresolved file name to the resolved path */
   char *ptr= buffer + strlen(buffer);
   char *buf_end= &buffer[sizeof(buffer)-1];
-  if (buf_end > ptr)
-    *ptr++= FN_LIBCHAR;
+  if (buf_end > ptr && *(ptr-1) != FN_LIBCHAR)
+      *ptr++= FN_LIBCHAR;
   if (buf_end > ptr)
     strncpy(ptr, safe_filename + dirlen, buf_end - ptr);
   *buf_end= '\0';

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-pfs-tuning branch (marc.alff:3483 to 3484) Marc Alff28 Mar