Skip to content

Commit 725e47b

Browse files
committed
Merge branch '5.5' into 10.0
2 parents eb30230 + 7d57ba6 commit 725e47b

File tree

11 files changed

+314
-9
lines changed

11 files changed

+314
-9
lines changed

mysql-test/r/derived_view.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,5 +2629,26 @@ id select_type table type possible_keys key key_len ref rows Extra
26292629
1 PRIMARY t2 ref idx idx 5 test.t1.a 140 Using index; FirstMatch(t1)
26302630
drop view v1;
26312631
drop table t1,t2;
2632+
#
2633+
# Bug mdev-12812: mergeable derived / view with subqueries
2634+
# NOT subject to semi-join optimizations
2635+
#
2636+
CREATE TABLE t1 (c1 varchar(3)) ENGINE=MyISAM;
2637+
INSERT INTO t1 VALUES ('foo'),('foo');
2638+
CREATE TABLE t2 (c2 varchar(3)) ENGINE=MyISAM;
2639+
INSERT INTO t2 VALUES ('bar'),('qux'),('foo');
2640+
SELECT STRAIGHT_JOIN *
2641+
FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq;
2642+
c1
2643+
foo
2644+
foo
2645+
EXPLAIN EXTENDED SELECT STRAIGHT_JOIN *
2646+
FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq;
2647+
id select_type table type possible_keys key key_len ref rows filtered Extra
2648+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
2649+
3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
2650+
Warnings:
2651+
Note 1003 select straight_join `test`.`t1`.`c1` AS `c1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t2`.`c2` from `test`.`t2` where (<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c2`)))
2652+
DROP TABLE t1, t2;
26322653
set optimizer_switch=@exit_optimizer_switch;
26332654
set join_cache_level=@exit_join_cache_level;

mysql-test/r/subselect_sj.result

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,4 +3101,58 @@ id select_type table type possible_keys key key_len ref rows Extra
31013101
1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
31023102
drop table t1,t2;
31033103
set optimizer_switch= @tmp_mdev12675;
3104+
#
3105+
# MDEV-12817: subquery NOT subject to semi-join optimizations
3106+
# in ON expression of INNER JOIN
3107+
#
3108+
CREATE TABLE t1 (c1 int) ENGINE=MyISAM;
3109+
INSERT INTO t1 VALUES (1),(2);
3110+
CREATE TABLE t2 (c2 int) ENGINE=MyISAM;
3111+
INSERT INTO t2 VALUES (3),(4);
3112+
CREATE TABLE t3 (c3 int) ENGINE=MyISAM;
3113+
INSERT INTO t3 VALUES (5),(6);
3114+
CREATE TABLE t4 (c4 int) ENGINE=MyISAM;
3115+
INSERT INTO t4 VALUES (7),(8);
3116+
SELECT c1
3117+
FROM t1
3118+
LEFT JOIN
3119+
( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) )
3120+
ON (c1 = c3);
3121+
c1
3122+
1
3123+
2
3124+
EXPLAIN EXTENDED SELECT c1
3125+
FROM t1
3126+
LEFT JOIN
3127+
( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) )
3128+
ON (c1 = c3);
3129+
id select_type table type possible_keys key key_len ref rows filtered Extra
3130+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
3131+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3132+
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
3133+
2 SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where
3134+
Warnings:
3135+
Note 1003 select `test`.`t1`.`c1` AS `c1` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t3`.`c3` = `test`.`t1`.`c1`) and <cache>(<in_optimizer>(1,<exists>(select `test`.`t4`.`c4` from `test`.`t4` where (1 = `test`.`t4`.`c4`)))))) where 1
3136+
# mdev-12820
3137+
SELECT *
3138+
FROM t1
3139+
LEFT JOIN
3140+
( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 )
3141+
ON (c1 = c2);
3142+
c1 c2 c4
3143+
1 NULL NULL
3144+
2 NULL NULL
3145+
EXPLAIN EXTENDED SELECT *
3146+
FROM t1
3147+
LEFT JOIN
3148+
( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 )
3149+
ON (c1 = c2);
3150+
id select_type table type possible_keys key key_len ref rows filtered Extra
3151+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
3152+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
3153+
1 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00
3154+
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
3155+
Warnings:
3156+
Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2`,`test`.`t4`.`c4` AS `c4` from `test`.`t1` left join (`test`.`t2` join `test`.`t4`) on(((`test`.`t2`.`c2` = `test`.`t1`.`c1`) and <in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t3`.`c3` from `test`.`t3` where (<cache>(`test`.`t2`.`c2`) = `test`.`t3`.`c3`))))) where 1
3157+
DROP TABLE t1,t2,t3,t4;
31043158
set optimizer_switch=@subselect_sj_tmp;

mysql-test/r/subselect_sj_jcl6.result

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,6 +3115,60 @@ id select_type table type possible_keys key key_len ref rows Extra
31153115
1 PRIMARY t2 range idx idx 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
31163116
drop table t1,t2;
31173117
set optimizer_switch= @tmp_mdev12675;
3118+
#
3119+
# MDEV-12817: subquery NOT subject to semi-join optimizations
3120+
# in ON expression of INNER JOIN
3121+
#
3122+
CREATE TABLE t1 (c1 int) ENGINE=MyISAM;
3123+
INSERT INTO t1 VALUES (1),(2);
3124+
CREATE TABLE t2 (c2 int) ENGINE=MyISAM;
3125+
INSERT INTO t2 VALUES (3),(4);
3126+
CREATE TABLE t3 (c3 int) ENGINE=MyISAM;
3127+
INSERT INTO t3 VALUES (5),(6);
3128+
CREATE TABLE t4 (c4 int) ENGINE=MyISAM;
3129+
INSERT INTO t4 VALUES (7),(8);
3130+
SELECT c1
3131+
FROM t1
3132+
LEFT JOIN
3133+
( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) )
3134+
ON (c1 = c3);
3135+
c1
3136+
1
3137+
2
3138+
EXPLAIN EXTENDED SELECT c1
3139+
FROM t1
3140+
LEFT JOIN
3141+
( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) )
3142+
ON (c1 = c3);
3143+
id select_type table type possible_keys key key_len ref rows filtered Extra
3144+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
3145+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
3146+
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join)
3147+
2 SUBQUERY t4 ALL NULL NULL NULL NULL 2 100.00 Using where
3148+
Warnings:
3149+
Note 1003 select `test`.`t1`.`c1` AS `c1` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t3`.`c3` = `test`.`t1`.`c1`) and <cache>(<in_optimizer>(1,<exists>(select `test`.`t4`.`c4` from `test`.`t4` where (1 = `test`.`t4`.`c4`)))))) where 1
3150+
# mdev-12820
3151+
SELECT *
3152+
FROM t1
3153+
LEFT JOIN
3154+
( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 )
3155+
ON (c1 = c2);
3156+
c1 c2 c4
3157+
1 NULL NULL
3158+
2 NULL NULL
3159+
EXPLAIN EXTENDED SELECT *
3160+
FROM t1
3161+
LEFT JOIN
3162+
( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 )
3163+
ON (c1 = c2);
3164+
id select_type table type possible_keys key key_len ref rows filtered Extra
3165+
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
3166+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
3167+
1 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join)
3168+
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
3169+
Warnings:
3170+
Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2`,`test`.`t4`.`c4` AS `c4` from `test`.`t1` left join (`test`.`t2` join `test`.`t4`) on(((`test`.`t2`.`c2` = `test`.`t1`.`c1`) and <in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t3`.`c3` from `test`.`t3` where (<cache>(`test`.`t2`.`c2`) = `test`.`t3`.`c3`))))) where 1
3171+
DROP TABLE t1,t2,t3,t4;
31183172
set optimizer_switch=@subselect_sj_tmp;
31193173
#
31203174
# BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include/master-slave.inc
2+
[connection master]
3+
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
4+
call mtr.add_suppression("Slave SQL: The incident LOST_EVENTS occured on the master. .*");
5+
SET GLOBAL max_binlog_cache_size = 4096;
6+
SET GLOBAL binlog_cache_size = 4096;
7+
SET GLOBAL max_binlog_stmt_cache_size = 4096;
8+
SET GLOBAL binlog_stmt_cache_size = 4096;
9+
CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MYISAM;
10+
ERROR HY000: Writing one row to the row-based binary log failed
11+
include/wait_for_slave_sql_error_and_skip.inc [errno=1590]
12+
SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE;
13+
SET GLOBAL binlog_cache_size= ORIGINAL_VALUE;
14+
SET GLOBAL max_binlog_stmt_cache_size= ORIGINAL_VALUE;
15+
SET GLOBAL binlog_stmt_cache_size= ORIGINAL_VALUE;
16+
DROP TABLE t1;
17+
include/rpl_end.inc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--binlog_checksum=1 --binlog-annotate-row-events=1
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--source include/have_innodb.inc
2+
--source include/master-slave.inc
3+
--source include/not_embedded.inc
4+
--source include/not_windows.inc
5+
--source include/have_binlog_format_row.inc
6+
7+
########################################################################################
8+
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT");
9+
call mtr.add_suppression("Slave SQL: The incident LOST_EVENTS occured on the master. .*");
10+
11+
let $old_max_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_cache_size", Value, 1);
12+
let $old_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_cache_size", Value, 1);
13+
let $old_max_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_stmt_cache_size", Value, 1);
14+
let $old_binlog_stmt_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_stmt_cache_size", Value, 1);
15+
16+
SET GLOBAL max_binlog_cache_size = 4096;
17+
SET GLOBAL binlog_cache_size = 4096;
18+
SET GLOBAL max_binlog_stmt_cache_size = 4096;
19+
SET GLOBAL binlog_stmt_cache_size = 4096;
20+
disconnect master;
21+
connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
22+
23+
CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MYISAM;
24+
25+
let $data = `select concat('"', repeat('a',2000), '"')`;
26+
27+
connection master;
28+
29+
--disable_query_log
30+
--error ER_BINLOG_ROW_LOGGING_FAILED
31+
eval INSERT INTO t1 (a, data) VALUES (2,
32+
CONCAT($data, $data, $data, $data, $data, $data));
33+
--enable_query_log
34+
35+
# Incident event
36+
# 1590=ER_SLAVE_INCIDENT
37+
--let $slave_sql_errno= 1590
38+
--source include/wait_for_slave_sql_error_and_skip.inc
39+
40+
connection master;
41+
42+
--replace_result $old_max_binlog_cache_size ORIGINAL_VALUE
43+
--eval SET GLOBAL max_binlog_cache_size= $old_max_binlog_cache_size
44+
--replace_result $old_binlog_cache_size ORIGINAL_VALUE
45+
--eval SET GLOBAL binlog_cache_size= $old_binlog_cache_size
46+
--replace_result $old_max_binlog_stmt_cache_size ORIGINAL_VALUE
47+
--eval SET GLOBAL max_binlog_stmt_cache_size= $old_max_binlog_stmt_cache_size
48+
--replace_result $old_binlog_stmt_cache_size ORIGINAL_VALUE
49+
--eval SET GLOBAL binlog_stmt_cache_size= $old_binlog_stmt_cache_size
50+
51+
DROP TABLE t1;
52+
53+
--source include/rpl_end.inc

mysql-test/t/derived_view.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,26 @@ explain select * from v1;
19111911
drop view v1;
19121912
drop table t1,t2;
19131913

1914+
--echo #
1915+
--echo # Bug mdev-12812: mergeable derived / view with subqueries
1916+
--echo # NOT subject to semi-join optimizations
1917+
--echo #
1918+
1919+
CREATE TABLE t1 (c1 varchar(3)) ENGINE=MyISAM;
1920+
INSERT INTO t1 VALUES ('foo'),('foo');
1921+
1922+
CREATE TABLE t2 (c2 varchar(3)) ENGINE=MyISAM;
1923+
INSERT INTO t2 VALUES ('bar'),('qux'),('foo');
1924+
1925+
let $q=
1926+
SELECT STRAIGHT_JOIN *
1927+
FROM ( SELECT * FROM t1 WHERE c1 IN ( SELECT c2 FROM t2 ) ) AS sq;
1928+
1929+
eval $q;
1930+
eval EXPLAIN EXTENDED $q;
1931+
1932+
DROP TABLE t1, t2;
1933+
19141934
# The following command must be the last one the file
19151935
set optimizer_switch=@exit_optimizer_switch;
19161936
set join_cache_level=@exit_join_cache_level;

mysql-test/t/subselect_sj.test

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,5 +2805,45 @@ select a from t1 join t2 on b between 1 and 2 and a in (select b from t2);
28052805
drop table t1,t2;
28062806
set optimizer_switch= @tmp_mdev12675;
28072807

2808+
--echo #
2809+
--echo # MDEV-12817: subquery NOT subject to semi-join optimizations
2810+
--echo # in ON expression of INNER JOIN
2811+
--echo #
2812+
2813+
CREATE TABLE t1 (c1 int) ENGINE=MyISAM;
2814+
INSERT INTO t1 VALUES (1),(2);
2815+
2816+
CREATE TABLE t2 (c2 int) ENGINE=MyISAM;
2817+
INSERT INTO t2 VALUES (3),(4);
2818+
2819+
CREATE TABLE t3 (c3 int) ENGINE=MyISAM;
2820+
INSERT INTO t3 VALUES (5),(6);
2821+
2822+
CREATE TABLE t4 (c4 int) ENGINE=MyISAM;
2823+
INSERT INTO t4 VALUES (7),(8);
2824+
2825+
let $q1=
2826+
SELECT c1
2827+
FROM t1
2828+
LEFT JOIN
2829+
( t2 INNER JOIN t3 ON ( 1 IN ( SELECT c4 FROM t4 ) ) )
2830+
ON (c1 = c3);
2831+
2832+
eval $q1;
2833+
eval EXPLAIN EXTENDED $q1;
2834+
2835+
let $q2=
2836+
SELECT *
2837+
FROM t1
2838+
LEFT JOIN
2839+
( ( SELECT * FROM t2 WHERE c2 IN ( SELECT c3 FROM t3 ) ) AS sq INNER JOIN t4 )
2840+
ON (c1 = c2);
2841+
2842+
--echo # mdev-12820
2843+
eval $q2;
2844+
eval EXPLAIN EXTENDED $q2;
2845+
2846+
DROP TABLE t1,t2,t3,t4;
2847+
28082848
# The following command must be the last one the file
28092849
set optimizer_switch=@subselect_sj_tmp;

sql/log.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5401,13 +5401,20 @@ int THD::binlog_write_table_map(TABLE *table, bool is_transactional,
54015401

54025402
IO_CACHE *file=
54035403
cache_mngr->get_binlog_cache_log(use_trans_cache(this, is_transactional));
5404+
binlog_cache_data *cache_data=
5405+
cache_mngr->get_binlog_cache_data(use_trans_cache(this, is_transactional));
5406+
54045407
if (with_annotate && *with_annotate)
54055408
{
54065409
Annotate_rows_log_event anno(table->in_use, is_transactional, false);
54075410
/* Annotate event should be written not more than once */
54085411
*with_annotate= 0;
54095412
if ((error= anno.write(file)))
5413+
{
5414+
if (my_errno == EFBIG)
5415+
cache_data->set_incident();
54105416
DBUG_RETURN(error);
5417+
}
54115418
}
54125419
if ((error= the_event.write(file)))
54135420
DBUG_RETURN(error);

sql/opt_subselect.cc

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,26 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
11031103
do
11041104
{
11051105
embedded= embedding;
1106-
if (MY_TEST(embedded->outer_join))
1106+
bool block_conversion_to_sj= false;
1107+
if (embedded->on_expr)
1108+
{
1109+
/*
1110+
Conversion of an IN subquery predicate into semi-join
1111+
is blocked now if the predicate occurs:
1112+
- in the ON expression of an outer join
1113+
- in the ON expression of an inner join embedded directly
1114+
or indirectly in the inner nest of an outer join
1115+
*/
1116+
for (TABLE_LIST *tl= embedded; tl; tl= tl->embedding)
1117+
{
1118+
if (tl->outer_join)
1119+
{
1120+
block_conversion_to_sj= true;
1121+
break;
1122+
}
1123+
}
1124+
}
1125+
if (block_conversion_to_sj)
11071126
{
11081127
Item *cond= embedded->on_expr;
11091128
if (!cond)
@@ -1142,6 +1161,16 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
11421161
in_subq->block_conversion_to_sj();
11431162
}
11441163
}
1164+
1165+
if (join->select_options & SELECT_STRAIGHT_JOIN)
1166+
{
1167+
/* Block conversion to semijoins for all candidates */
1168+
li.rewind();
1169+
while ((in_subq= li++))
1170+
{
1171+
in_subq->block_conversion_to_sj();
1172+
}
1173+
}
11451174

11461175
li.rewind();
11471176
/* First, convert child join's subqueries. We proceed bottom-up here */

0 commit comments

Comments
 (0)