summaryrefslogtreecommitdiff
path: root/mysql-test/r
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2012-02-15 18:08:08 +0100
committerSergei Golubchik <sergii@pisem.net>2012-02-15 18:08:08 +0100
commit25609313ffbd9205e921d0793cf423f711d10ced (patch)
treef04a1c26fabcc5463aca51a860f03131e02d94f7 /mysql-test/r
parent47a54a2e087a7c1fc861bcbc114c14987f492cfe (diff)
parent764eeeee74f999fe2107fc362236563be0025093 (diff)
downloadmariadb-git-25609313ffbd9205e921d0793cf423f711d10ced.tar.gz
5.3.4 merge
Diffstat (limited to 'mysql-test/r')
-rw-r--r--mysql-test/r/create.result1
-rw-r--r--mysql-test/r/derived_opt.result9
-rw-r--r--mysql-test/r/derived_view.result58
-rw-r--r--mysql-test/r/func_group.result64
-rw-r--r--mysql-test/r/handler_read_last.result4
-rw-r--r--mysql-test/r/insert_select.result1
-rw-r--r--mysql-test/r/join.result2
-rw-r--r--mysql-test/r/join_cache.result180
-rw-r--r--mysql-test/r/join_outer.result3
-rw-r--r--mysql-test/r/join_outer_innodb.result8
-rw-r--r--mysql-test/r/join_outer_jcl6.result3
-rw-r--r--mysql-test/r/myisam_mrr.result62
-rw-r--r--mysql-test/r/null_key.result1
-rw-r--r--mysql-test/r/order_by.result54
-rw-r--r--mysql-test/r/partition.result6
-rw-r--r--mysql-test/r/partition_pruning.result10
-rw-r--r--mysql-test/r/ps.result4
-rw-r--r--mysql-test/r/ps_11bugs.result4
-rw-r--r--mysql-test/r/select.result9
-rw-r--r--mysql-test/r/select_jcl6.result11
-rw-r--r--mysql-test/r/select_pkeycache.result9
-rw-r--r--mysql-test/r/single_delete_update.result42
-rw-r--r--mysql-test/r/status.result31
-rw-r--r--mysql-test/r/status_user.result1
-rw-r--r--mysql-test/r/subselect.result244
-rw-r--r--mysql-test/r/subselect3.result1
-rw-r--r--mysql-test/r/subselect3_jcl6.result3
-rw-r--r--mysql-test/r/subselect4.result8
-rw-r--r--mysql-test/r/subselect_cache.result34
-rw-r--r--mysql-test/r/subselect_mat.result39
-rw-r--r--mysql-test/r/subselect_no_mat.result242
-rw-r--r--mysql-test/r/subselect_no_opts.result242
-rw-r--r--mysql-test/r/subselect_no_scache.result244
-rw-r--r--mysql-test/r/subselect_no_semijoin.result242
-rw-r--r--mysql-test/r/subselect_sj.result459
-rw-r--r--mysql-test/r/subselect_sj2.result14
-rw-r--r--mysql-test/r/subselect_sj2_jcl6.result23
-rw-r--r--mysql-test/r/subselect_sj2_mat.result14
-rw-r--r--mysql-test/r/subselect_sj_jcl6.result488
-rw-r--r--mysql-test/r/subselect_sj_mat.result36
-rw-r--r--mysql-test/r/sum_distinct.result12
-rw-r--r--mysql-test/r/update.result12
-rw-r--r--mysql-test/r/view.result64
43 files changed, 2822 insertions, 176 deletions
diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result
index b63131fcca6..fbc8e3d28e2 100644
--- a/mysql-test/r/create.result
+++ b/mysql-test/r/create.result
@@ -1562,6 +1562,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 7
drop table t1,t2;
CREATE TABLE t1(c1 VARCHAR(33), KEY USING BTREE (c1));
diff --git a/mysql-test/r/derived_opt.result b/mysql-test/r/derived_opt.result
index 721d4277775..c5376bee756 100644
--- a/mysql-test/r/derived_opt.result
+++ b/mysql-test/r/derived_opt.result
@@ -273,4 +273,13 @@ ON alias3.f4 != 0
) ON alias3.f4 != 0;
f4 f4 f2 f4
drop table t1,t2,t3,t4;
+#
+# LP BUG#910123 MariaDB 5.3.3 causes 1093 error on Drupal
+# Fix: force materialization in case of conflict
+#
+SET optimizer_switch='derived_merge=on';
+CREATE TABLE t1 ( i INT );
+INSERT INTO t1 VALUES ( (SELECT 1 FROM ( SELECT * FROM t1 ) as a) );
+drop table t1;
+set optimizer_switch=@save_optimizer_switch;
set optimizer_switch=@exit_optimizer_switch;
diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result
index 587a1dd9e31..4756daaf687 100644
--- a/mysql-test/r/derived_view.result
+++ b/mysql-test/r/derived_view.result
@@ -80,6 +80,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
select * from (select * from t1 where f1 in (2,3)) tt where f11=2;
@@ -93,6 +94,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 12
for merged views
create view v1 as select * from t1;
@@ -165,6 +167,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
select * from v4 where f2 in (1,3);
@@ -178,6 +181,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 12
for materialized derived tables
explain for simple derived
@@ -229,6 +233,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
select * from t1 join (select * from t2 group by f2) tt on f1=f2;
@@ -244,6 +249,7 @@ Handler_read_last 0
Handler_read_next 3
Handler_read_prev 0
Handler_read_rnd 11
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 36
for materialized views
drop view v1,v2,v3;
@@ -318,6 +324,7 @@ Handler_read_last 0
Handler_read_next 22
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 60
explain showing late materialization
flush status;
@@ -334,6 +341,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
select * from t1 join v2 on f1=f2;
@@ -349,6 +357,7 @@ Handler_read_last 0
Handler_read_next 3
Handler_read_prev 0
Handler_read_rnd 11
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 36
explain extended select * from v1 join v4 on f1=f2;
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -443,6 +452,7 @@ Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 8
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 39
flush status;
merged in merged derived join merged in merged derived
@@ -1089,7 +1099,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where (not(<expr_cache><6,5>(<in_optimizer>((6,5),<exists>(select 7,5 having (trigcond(((<cache>(6) = 7) or isnull(7))) and trigcond(((<cache>(5) = 5) or isnull(5))) and trigcond(<is_not_null_test>(7)) and trigcond(<is_not_null_test>(5))))))))
SELECT t.a,t.b FROM t3 RIGHT JOIN ((SELECT * FROM t1) AS t, t2) ON t2.b != 0
@@ -1103,7 +1113,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
-3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where (not(<expr_cache><6,5>(<in_optimizer>((6,5),<exists>(select 7,5 having (trigcond(((<cache>(6) = 7) or isnull(7))) and trigcond(((<cache>(5) = 5) or isnull(5))) and trigcond(<is_not_null_test>(7)) and trigcond(<is_not_null_test>(5))))))))
SELECT t.a,t.b FROM t3 RIGHT JOIN (v1 AS t, t2) ON t2.b != 0
@@ -1117,7 +1127,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select 6 AS `a`,5 AS `b` from `test`.`t3` where (not(<expr_cache><6,5>(<in_optimizer>((6,5),<exists>(select 7,5 having (trigcond(((<cache>(6) = 7) or isnull(7))) and trigcond(((<cache>(5) = 5) or isnull(5))) and trigcond(<is_not_null_test>(7)) and trigcond(<is_not_null_test>(5))))))))
DROP VIEW v1;
@@ -1800,6 +1810,7 @@ INSERT INTO t2 VALUES (7), (4);
CREATE TABLE t1 (b int NOT NULL);
INSERT INTO t1 VALUES (5), (7);
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
+SET @save_optimizer_switch=@@optimizer_switch;
SET SESSION optimizer_switch='derived_merge=off';
PREPARE st1 FROM
'SELECT * FROM (SELECT * FROM t2 LEFT JOIN v1 ON t2.a = v1.b) AS t';
@@ -1812,9 +1823,9 @@ a b
7 7
4 NULL
DEALLOCATE PREPARE st1;
+set SESSION optimizer_switch= @save_optimizer_switch;
DROP VIEW v1;
DROP TABLE t1,t2;
-SET SESSION optimizer_switch='derived_merge=on';
#
# LP bug #879939: assertion in ha_maria::enable_indexes
# with derived_with_keys=on
@@ -1832,6 +1843,7 @@ INSERT INTO t1 VALUES
('USA','Mesquite'), ('USA','Metairie'), ('USA','Miami');
CREATE TABLE t3 (a varchar(35));
INSERT INTO t3 VALUES ('Miami');
+SET @save_optimizer_switch=@@optimizer_switch;
SET optimizer_switch = 'derived_with_keys=on';
SET @@tmp_table_size=1024*4;
explain SELECT * FROM (SELECT t1.* FROM t1, t2) AS t JOIN t3 ON t3.a = t.b;
@@ -1855,6 +1867,7 @@ USA Miami Miami
USA Miami Miami
USA Miami Miami
SET @@tmp_table_size=default;
+set SESSION optimizer_switch= @save_optimizer_switch;
drop table t1,t2,t3;
#
# BUG#882994: Crash in QUICK_RANGE_SELECT::reset with derived_with_keys
@@ -1889,5 +1902,42 @@ ORDER BY CONCAT(alias2.col_varchar_nokey);
col_varchar_key pk col_varchar_key col_varchar_nokey
set max_heap_table_size= @tmp_882994;
drop table t1,t2,t3;
+#
+# LP bug #917990: Bad estimate of #rows for derived table with LIMIT
+#
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES
+(8), (3), (4), (7), (9), (5), (1), (2);
+SELECT * FROM (SELECT * FROM t1 LIMIT 3) t;
+a
+8
+3
+4
+EXPLAIN
+SELECT * FROM (SELECT * FROM t1 LIMIT 3) t;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3
+2 DERIVED t1 ALL NULL NULL NULL NULL 8
+DROP TABLE t1;
+#
+# LP BUG#921878 incorrect check of items during columns union types
+# aggregation for merged derived tables
+#
+SET @save_optimizer_switch=@@optimizer_switch;
+SET SESSION optimizer_switch='derived_merge=on';
+CREATE TABLE t1 ( a ENUM( 'x', 'y' ) );
+insert into t1 values ('x');
+CREATE TABLE t2 LIKE t1;
+insert into t1 values ('y');
+CREATE TABLE t3 LIKE t1;
+INSERT INTO t3
+SELECT * FROM ( SELECT * FROM t1 ) AS A
+UNION SELECT * FROM t2;
+select * from t3;
+a
+x
+y
+drop table t1,t2,t3;
+set SESSION optimizer_switch= @save_optimizer_switch;
set optimizer_switch=@exit_optimizer_switch;
set join_cache_level=@exit_join_cache_level;
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index c39a226303b..aa93424f2ae 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -1825,6 +1825,70 @@ drop table t1;
#
End of 5.1 tests
#
+# Bug #904345: MIN/MAX optimization with constant FALSE condition
+#
+CREATE TABLE t1 (a int NOT NULL, KEY(a));
+INSERT INTO t1 VALUES (10), (8), (11), (7), (15), (12), (9);
+CREATE TABLE t2 (a int, b int);
+INSERT INTO t2 VALUES
+(8,2), (6,9), (8,4), (5,3), (9,1);
+EXPLAIN EXTENDED
+SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT 3,4) AND a<10;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 range a a 4 NULL 4 100.00 Using where; Using index
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+Warnings:
+Note 1003 select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1` where (<expr_cache><<cache>(1),<cache>(2)>(<in_optimizer>(<cache>((1,2)),<exists>(select 3,4 having (((1 = 3) or isnull(3)) and ((2 = 4) or isnull(4)) and <is_not_null_test>(3) and <is_not_null_test>(4))))) and (`test`.`t1`.`a` < 10))
+SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT 3,4) AND a<10;
+MAX(a)
+NULL
+EXPLAIN EXTENDED
+SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 10 func,func 1 100.00
+1 PRIMARY t1 range a a 4 NULL 4 100.00 Using where; Using index; Using join buffer (flat, BNL join)
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where
+Warnings:
+Note 1003 select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`b` = 2) and (`test`.`t2`.`a` = 1) and (`test`.`t1`.`a` < 10))
+SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10;
+MAX(a)
+NULL
+EXPLAIN EXTENDED
+SELECT MAX(a) FROM t1 WHERE RAND()*0<>0 AND a<10;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 range a a 4 NULL 4 100.00 Using where; Using index
+Warnings:
+Note 1003 select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1` where (((rand() * 0) <> 0) and (`test`.`t1`.`a` < 10))
+SELECT MAX(a) FROM t1 WHERE RAND()*0<>0 AND a<10;
+MAX(a)
+NULL
+DROP TABLE t1,t2;
+#
+# Bug #879860: MIN/MAX for subquery returning empty set
+#
+CREATE TABLE t1 (a int PRIMARY KEY);
+INSERT INTO t1 VALUES (1);
+CREATE TABLE t2 (a int NOT NULL);
+INSERT INTO t2 VALUES (10);
+CREATE TABLE t3 ( a int, b int);
+INSERT INTO t3 VALUES (19,1), (20,5);
+EXPLAIN EXTENDED
+SELECT (SELECT MIN(t1.a) FROM t1,t2 WHERE t2.a = t3.b) FROM t3;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00
+2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00
+2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1 100.00
+Warnings:
+Note 1276 Field or reference 'test.t3.b' of SELECT #2 was resolved in SELECT #1
+Note 1003 select <expr_cache><`test`.`t3`.`b`>((select min(1) from dual where (10 = `test`.`t3`.`b`))) AS `(SELECT MIN(t1.a) FROM t1,t2 WHERE t2.a = t3.b)` from `test`.`t3`
+SELECT (SELECT MIN(t1.a) FROM t1,t2 WHERE t2.a = t3.b) FROM t3;
+(SELECT MIN(t1.a) FROM t1,t2 WHERE t2.a = t3.b)
+NULL
+NULL
+DROP TABLE t1,t2,t3;
+#
+End of 5.2 tests
+#
# BUG#46680 - Assertion failed in file item_subselect.cc,
# line 305 crashing on HAVING subquery
#
diff --git a/mysql-test/r/handler_read_last.result b/mysql-test/r/handler_read_last.result
index a21e9ed9564..574c3c25ab1 100644
--- a/mysql-test/r/handler_read_last.result
+++ b/mysql-test/r/handler_read_last.result
@@ -13,6 +13,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
SELECT a FROM t1 ORDER BY a DESC LIMIT 1;
@@ -26,6 +27,7 @@ Handler_read_last 1
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
SELECT a FROM t1 ORDER BY a LIMIT 3;
@@ -41,6 +43,7 @@ Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
SELECT a FROM t1 ORDER BY a DESC LIMIT 3;
@@ -56,5 +59,6 @@ Handler_read_last 1
Handler_read_next 0
Handler_read_prev 2
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
DROP TABLE t1;
diff --git a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result
index 538d6ddd0fd..04754375103 100644
--- a/mysql-test/r/insert_select.result
+++ b/mysql-test/r/insert_select.result
@@ -698,6 +698,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 1
DROP TABLE t1;
CREATE TABLE t1 (
diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result
index d8230826048..d826fbe2aa7 100644
--- a/mysql-test/r/join.result
+++ b/mysql-test/r/join.result
@@ -861,6 +861,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 5
drop table t1, t2, t3;
create table t1 (a int);
@@ -1271,6 +1272,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 1
DROP TABLE t1, t2;
End of 5.1 tests
diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result
index 07ceb573f85..19de0fb0a5a 100644
--- a/mysql-test/r/join_cache.result
+++ b/mysql-test/r/join_cache.result
@@ -5392,4 +5392,184 @@ x 5 5 4
SET join_cache_level = DEFAULT;
SET optimizer_switch=@tmp_optimizer_switch;
DROP TABLE t1,t2,t3,t4;
+#
+# Bug#53305 Duplicate weedout + join buffer (join cache --level=7,8)
+#
+create table t1 (uid int, fid int, index(uid));
+insert into t1 values
+(1,1), (1,2), (1,3), (1,4),
+(2,5), (2,6), (2,7), (2,8),
+(3,1), (3,2), (3,9);
+create table t2 (uid int primary key, name varchar(128), index(name));
+insert into t2 values
+(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
+(6, "F"), (7, "G"), (8, "H"), (9, "I");
+create table t3 (uid int, fid int, index(uid));
+insert into t3 values
+(1,1), (1,2), (1,3),(1,4),
+(2,5), (2,6), (2,7), (2,8),
+(3,1), (3,2), (3,9);
+set @tmp_optimizer_switch=@@optimizer_switch;
+set @@optimizer_switch='semijoin=on';
+set optimizer_switch='materialization=off';
+set optimizer_switch='loosescan=off,firstmatch=off';
+set optimizer_switch='mrr_sort_keys=off';
+set join_cache_level=7;
+create table t4 (uid int primary key, name varchar(128), index(name));
+insert into t4 values
+(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
+(6, "F"), (7, "G"), (8, "H"), (9, "I");
+explain select name from t2, t1
+where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
+and t2.uid=t1.fid;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t3 ref uid uid 5 const 4 Using where; Start temporary
+1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t3.fid 1 Using index
+1 PRIMARY t1 ALL uid NULL NULL NULL 11 Using where; End temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.fid 1 Using join buffer (flat, BKAH join); Rowid-ordered scan
+select name from t2, t1
+where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
+and t2.uid=t1.fid;
+name
+A
+A
+B
+B
+C
+D
+E
+F
+G
+H
+I
+set join_cache_level = default;
+set optimizer_switch=@tmp_optimizer_switch;
+drop table t1,t2,t3,t4;
+#
+# Bug#50358 - semijoin execution of subquery with outerjoin
+# emplying join buffer
+#
+CREATE TABLE t1 (i int);
+CREATE TABLE t2 (i int);
+CREATE TABLE t3 (i int);
+INSERT INTO t1 VALUES (1), (2);
+INSERT INTO t2 VALUES (6);
+INSERT INTO t3 VALUES (1), (2);
+set @tmp_optimizer_switch=@@optimizer_switch;
+set @@optimizer_switch='semijoin=on';
+set optimizer_switch='materialization=on';
+set join_cache_level=0;
+EXPLAIN
+SELECT * FROM t1 WHERE t1.i IN
+(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 1 Using where
+SELECT * FROM t1 WHERE t1.i IN
+(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
+i
+1
+2
+set join_cache_level=2;
+EXPLAIN
+SELECT * FROM t1 WHERE t1.i IN
+(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
+SELECT * FROM t1 WHERE t1.i IN
+(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
+i
+1
+2
+set join_cache_level = default;
+set optimizer_switch=@tmp_optimizer_switch;
+DROP TABLE t1,t2,t3;
+#
+# Bug #12546542: missing row with semijoin=off + join cache
+# (LP bug #922971)
+#
+CREATE TABLE t1 (a varchar(1024));
+INSERT INTO t1 VALUES ('v'), ('we');
+CREATE TABLE t2 (
+a varchar(1024) CHARACTER SET utf8 DEFAULT NULL, b int, c int
+);
+INSERT INTO t2 VALUES ('we',4,NULL), ('v',1305673728,6);
+CREATE TABLE t3 (b int, c int);
+INSERT INTO t3 VALUES (4,4);
+set @tmp_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=off';
+set optimizer_switch='materialization=off';
+set join_cache_level=0;
+EXPLAIN
+SELECT * FROM t1
+WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
+WHERE t2.c < 10 OR t3.c > 1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 1 Using where
+SELECT * FROM t1
+WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
+WHERE t2.c < 10 OR t3.c > 1);
+a
+v
+we
+set join_cache_level=2;
+EXPLAIN
+SELECT * FROM t1
+WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
+WHERE t2.c < 10 OR t3.c > 1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
+SELECT * FROM t1
+WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
+WHERE t2.c < 10 OR t3.c > 1);
+a
+v
+we
+set join_cache_level = default;
+set optimizer_switch=@tmp_optimizer_switch;
+DROP TABLE t1,t2,t3;
+#
+# Bug #925985: LEFT JOIN with optimize_join_buffer_size=off +
+# join_buffer_size > join_buffer_space_limit
+#
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES (5), (3);
+CREATE TABLE t2 (a int, b int);
+INSERT INTO t2 VALUES
+(3,30), (1,10), (7,70), (2,20),
+(3,31), (1,11), (7,71), (2,21),
+(3,32), (1,12), (7,72), (2,22);
+CREATE TABLE t3 (b int, c int);
+INSERT INTO t3 VALUES (32, 302), (42,400), (30,300);
+set @tmp_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='optimize_join_buffer_size=off';
+set join_buffer_space_limit=4096;
+set join_buffer_size=4096*2;
+set join_cache_level=2;
+set optimizer_switch='outer_join_with_cache=on';
+EXPLAIN
+SELECT * FROM t1, t2 LEFT JOIN t3 ON t2.b=t3.b WHERE t1.a=t2.a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2
+1 SIMPLE t2 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
+1 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (incremental, BNL join)
+SELECT * FROM t1, t2 LEFT JOIN t3 ON t2.b=t3.b WHERE t1.a=t2.a;
+a a b b c
+3 3 30 30 300
+3 3 31 NULL NULL
+3 3 32 32 302
+set join_buffer_space_limit=default;
+set join_buffer_size=default;
+set join_cache_level=default;
+set optimizer_switch=@tmp_optimizer_switch;
+DROP TABLE t1,t2,t3;
set @@optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result
index 16913864f5d..842ac2e81cd 100644
--- a/mysql-test/r/join_outer.result
+++ b/mysql-test/r/join_outer.result
@@ -1245,6 +1245,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 6
DROP TABLE t1,t2;
CREATE TABLE t1 (c int PRIMARY KEY, e int NOT NULL);
@@ -1747,6 +1748,7 @@ Handler_read_last 0
Handler_read_next 5
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 1048581
flush status;
select sum(t3.b) from t2 left join t3 on t3.a=t2.a and t2.a <> 10;
@@ -1760,6 +1762,7 @@ Handler_read_last 0
Handler_read_next 5
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 1048581
drop table t1,t2,t3;
#
diff --git a/mysql-test/r/join_outer_innodb.result b/mysql-test/r/join_outer_innodb.result
index 749cb2ab212..5a99cb83b90 100644
--- a/mysql-test/r/join_outer_innodb.result
+++ b/mysql-test/r/join_outer_innodb.result
@@ -52,3 +52,11 @@ pk
DROP TABLE t1,t2;
# End BUG#58456
+CREATE TABLE t1(a int, b int, KEY (a), PRIMARY KEY (b)) ENGINE=InnoDB;
+CREATE TABLE t2 (b int, PRIMARY KEY (b));
+INSERT INTO t2 VALUES (4),(9);
+SELECT STRAIGHT_JOIN t1.a FROM t1 RIGHT JOIN t2 ON t1.b = t2.b
+WHERE (t1.b NOT BETWEEN 1 AND 7 OR t1.a IS NULL AND t1.b = t2.b) AND t2.b = 4
+GROUP BY 1;
+a
+DROP TABLE t1,t2;
diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result
index 7605af40a6f..046c758a751 100644
--- a/mysql-test/r/join_outer_jcl6.result
+++ b/mysql-test/r/join_outer_jcl6.result
@@ -1256,6 +1256,7 @@ Handler_read_last 0
Handler_read_next 9
Handler_read_prev 0
Handler_read_rnd 3
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 6
DROP TABLE t1,t2;
CREATE TABLE t1 (c int PRIMARY KEY, e int NOT NULL);
@@ -1758,6 +1759,7 @@ Handler_read_last 0
Handler_read_next 5
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 1048581
flush status;
select sum(t3.b) from t2 left join t3 on t3.a=t2.a and t2.a <> 10;
@@ -1771,6 +1773,7 @@ Handler_read_last 0
Handler_read_next 5
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 1048581
drop table t1,t2,t3;
#
diff --git a/mysql-test/r/myisam_mrr.result b/mysql-test/r/myisam_mrr.result
index 9dd3602bab7..01d3e6aeb5d 100644
--- a/mysql-test/r/myisam_mrr.result
+++ b/mysql-test/r/myisam_mrr.result
@@ -557,4 +557,66 @@ COUNT(alias2.f2)
set @@join_cache_level= @tmp_730133_jcl;
set @@optimizer_switch= @tmp_730133_os;
drop table t1;
+#
+# Test of MRR handler counters
+#
+flush status;
+show status like 'Handler_mrr%';
+Variable_name Value
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int, b int, filler char(200), key(a));
+insert into t1
+select A.a+10*B.a+100*C.a+1000*D.a, 123,'filler' from t0 A, t0 B, t0 C, t0 D;
+explain select sum(b) from t1 where a < 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range a a 5 NULL 8 Using index condition; Rowid-ordered scan
+# This should show one MRR scan and no re-fills:
+flush status;
+select sum(b) from t1 where a < 10;
+sum(b)
+1230
+show status like 'handler_mrr%';
+Variable_name Value
+set @mrr_buffer_size_save= @@mrr_buffer_size;
+set mrr_buffer_size=128;
+explain select sum(b) from t1 where a < 1600;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range a a 5 NULL 1380 Using index condition; Rowid-ordered scan
+# This should show one MRR scan and one extra rowid sort:
+flush status;
+select sum(b) from t1 where a < 1600;
+sum(b)
+196800
+show status like 'handler_mrr%';
+Variable_name Value
+set @@mrr_buffer_size= @mrr_buffer_size_save;
+#Now, let's check BKA:
+set @join_cache_level_save= @@join_cache_level;
+set @join_buffer_size_save= @@join_buffer_size;
+set join_cache_level=6;
+explain select sum(t1.b) from t0,t1 where t0.a=t1.a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where
+1 SIMPLE t1 ref a a 5 test.t0.a 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+flush status;
+select sum(t1.b) from t0,t1 where t0.a=t1.a;
+sum(t1.b)
+1230
+show status like 'handler_mrr%';
+Variable_name Value
+set join_buffer_size=10;
+explain select sum(t1.b) from t0,t1 where t0.a=t1.a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where
+1 SIMPLE t1 ref a a 5 test.t0.a 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+flush status;
+select sum(t1.b) from t0,t1 where t0.a=t1.a;
+sum(t1.b)
+1230
+show status like 'handler_mrr%';
+Variable_name Value
+set join_cache_level= @join_cache_level_save;
+set join_buffer_size= @join_buffer_size_save;
+drop table t0, t1;
set optimizer_switch= @myisam_mrr_tmp;
diff --git a/mysql-test/r/null_key.result b/mysql-test/r/null_key.result
index 4e28f73caad..35c6ebe1442 100644
--- a/mysql-test/r/null_key.result
+++ b/mysql-test/r/null_key.result
@@ -428,6 +428,7 @@ Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 5
DROP TABLE t1,t2,t3,t4;
CREATE TABLE t1 (
diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result
index 270e74ddf52..d320b5b669f 100644
--- a/mysql-test/r/order_by.result
+++ b/mysql-test/r/order_by.result
@@ -1759,3 +1759,57 @@ i1 i2
4 4
5 5
DROP TABLE t1, t2, t3;
+#
+# Fix of LP BUG#793589 Wrong result with double ORDER BY
+#
+CREATE TABLE t1 ( b int) ;
+INSERT INTO t1 VALUES (8),(9);
+CREATE TABLE t2 ( a int, b int, PRIMARY KEY (a)) ;
+INSERT INTO t2 VALUES (6,7),(7,7),(8,1),(9,7),(10,1),(11,5),(12,2),(13,0),(14,1),(15,8),(16,1),(17,1),(18,9),(19,1),(20,5);
+SELECT t2.b AS field1 FROM t1, t2 WHERE t1.b = t2.a GROUP BY field1 ORDER BY t1.b, field1;
+field1
+1
+7
+SELECT t2.b, t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b, t2.b;
+b b
+1 8
+7 9
+SELECT t2.b,t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
+b b
+1 8
+7 9
+SELECT t2.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
+b
+1
+7
+# field1 removed from ORDER BY
+explain extended
+SELECT t2.b AS field1 FROM t1, t2 WHERE t1.b = t2.a GROUP BY field1 ORDER BY t1.b, field1;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary; Using filesort
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
+Warnings:
+Note 1003 select `test`.`t2`.`b` AS `field1` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
+explain extended
+SELECT t2.b, t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b, t2.b;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary; Using filesort
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
+Warnings:
+Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
+explain extended
+SELECT t2.b,t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary; Using filesort
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
+Warnings:
+Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
+explain extended
+SELECT t2.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary; Using filesort
+1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
+Warnings:
+Note 1003 select `test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
+drop table t1,t2;
+End of 5.2 tests
diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result
index 2e90bf8e27b..7c38fa18faa 100644
--- a/mysql-test/r/partition.result
+++ b/mysql-test/r/partition.result
@@ -521,6 +521,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
EXPLAIN PARTITIONS SELECT c1 FROM t2 WHERE (c1 > 10 AND c1 < 13) OR (c1 > 17 AND c1 < 20);
id select_type table partitions type possible_keys key key_len ref rows Extra
@@ -540,6 +541,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
DROP TABLE t1,t2;
CREATE TABLE `t1` (
@@ -571,6 +573,7 @@ Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
EXPLAIN PARTITIONS SELECT c1 FROM t2 WHERE (c1 > 2 AND c1 < 5);
id select_type table partitions type possible_keys key key_len ref rows Extra
@@ -588,6 +591,7 @@ Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
EXPLAIN PARTITIONS SELECT c1 FROM t1 WHERE (c1 > 12 AND c1 < 15);
id select_type table partitions type possible_keys key key_len ref rows Extra
@@ -605,6 +609,7 @@ Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
EXPLAIN PARTITIONS SELECT c1 FROM t2 WHERE (c1 > 12 AND c1 < 15);
id select_type table partitions type possible_keys key key_len ref rows Extra
@@ -622,6 +627,7 @@ Handler_read_last 0
Handler_read_next 2
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
DROP TABLE t1,t2;
create table t1 (a int) partition by list ((a/3)*10 div 1)
diff --git a/mysql-test/r/partition_pruning.result b/mysql-test/r/partition_pruning.result
index eb0849e2cad..32c0cd34942 100644
--- a/mysql-test/r/partition_pruning.result
+++ b/mysql-test/r/partition_pruning.result
@@ -2968,7 +2968,10 @@ flush status;
delete from t2 where b > 5;
show status like 'Handler_read_rnd_next';
Variable_name Value
-Handler_read_rnd_next 1215
+Handler_read_rnd_next 815
+show status like 'Handler_read_rnd_deleted';
+Variable_name Value
+Handler_read_rnd_deleted 400
show status like 'Handler_read_key';
Variable_name Value
Handler_read_key 0
@@ -2982,7 +2985,10 @@ flush status;
delete from t2 where b < 5 or b > 3;
show status like 'Handler_read_rnd_next';
Variable_name Value
-Handler_read_rnd_next 1215
+Handler_read_rnd_next 515
+show status like 'Handler_read_rnd_deleted';
+Variable_name Value
+Handler_read_rnd_deleted 700
show status like 'Handler_read_key';
Variable_name Value
Handler_read_key 0
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result
index 7d793f16c1a..b4a09091aa6 100644
--- a/mysql-test/r/ps.result
+++ b/mysql-test/r/ps.result
@@ -3790,6 +3790,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
execute st;
@@ -3803,6 +3804,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
select * from t1 use index() where a=3;
@@ -3816,6 +3818,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 8
flush status;
execute st;
@@ -3829,6 +3832,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
deallocate prepare st;
drop table t1;
diff --git a/mysql-test/r/ps_11bugs.result b/mysql-test/r/ps_11bugs.result
index f9f0525646d..56894302505 100644
--- a/mysql-test/r/ps_11bugs.result
+++ b/mysql-test/r/ps_11bugs.result
@@ -121,8 +121,8 @@ insert into t1 values (1);
explain select * from t1 where 3 in (select (1+1) union select 1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
-3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
+3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
select * from t1 where 3 in (select (1+1) union select 1);
a
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index 7f035ca749a..d2e3594dfc6 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -2783,10 +2783,10 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+1 SIMPLE t1 index key1 key1 5 NULL 4 Using where; Using index
explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+1 SIMPLE t1 range key1 key1 5 NULL 3 Using where; Using index
select max(key1) from t1 where key1 <= 0.6158;
max(key1)
0.6158000230789185
@@ -2805,10 +2805,10 @@ max(key1) min(key2)
0.6158000230789185 1.3761999607086182
select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
max(key1)
-0.6158000230789185
+0.38449999690055847
select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
min(key1)
-0.37619999051094055
+0.38449999690055847
DROP TABLE t1,t2;
CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
INSERT INTO t1 VALUES (10);
@@ -4346,6 +4346,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 6
DROP TABLE t1, t2;
CREATE TABLE t1 (f1 bigint(20) NOT NULL default '0',
diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result
index 54eed1ebaae..f5aa02fe94c 100644
--- a/mysql-test/r/select_jcl6.result
+++ b/mysql-test/r/select_jcl6.result
@@ -2794,10 +2794,10 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+1 SIMPLE t1 index key1 key1 5 NULL 4 Using where; Using index
explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+1 SIMPLE t1 range key1 key1 5 NULL 3 Using where; Using index
select max(key1) from t1 where key1 <= 0.6158;
max(key1)
0.6158000230789185
@@ -2816,10 +2816,10 @@ max(key1) min(key2)
0.6158000230789185 1.3761999607086182
select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
max(key1)
-0.6158000230789185
+0.38449999690055847
select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
min(key1)
-0.37619999051094055
+0.38449999690055847
DROP TABLE t1,t2;
CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
INSERT INTO t1 VALUES (10);
@@ -4357,7 +4357,8 @@ Handler_read_last 0
Handler_read_next 10
Handler_read_prev 0
Handler_read_rnd 10
-Handler_read_rnd_next 7
+Handler_read_rnd_deleted 1
+Handler_read_rnd_next 6
DROP TABLE t1, t2;
CREATE TABLE t1 (f1 bigint(20) NOT NULL default '0',
f2 int(11) NOT NULL default '0',
diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result
index 7f035ca749a..d2e3594dfc6 100644
--- a/mysql-test/r/select_pkeycache.result
+++ b/mysql-test/r/select_pkeycache.result
@@ -2783,10 +2783,10 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+1 SIMPLE t1 index key1 key1 5 NULL 4 Using where; Using index
explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+1 SIMPLE t1 range key1 key1 5 NULL 3 Using where; Using index
select max(key1) from t1 where key1 <= 0.6158;
max(key1)
0.6158000230789185
@@ -2805,10 +2805,10 @@ max(key1) min(key2)
0.6158000230789185 1.3761999607086182
select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
max(key1)
-0.6158000230789185
+0.38449999690055847
select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
min(key1)
-0.37619999051094055
+0.38449999690055847
DROP TABLE t1,t2;
CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
INSERT INTO t1 VALUES (10);
@@ -4346,6 +4346,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 6
DROP TABLE t1, t2;
CREATE TABLE t1 (f1 bigint(20) NOT NULL default '0',
diff --git a/mysql-test/r/single_delete_update.result b/mysql-test/r/single_delete_update.result
index 72419c6ec9d..d4534a2c2d8 100644
--- a/mysql-test/r/single_delete_update.result
+++ b/mysql-test/r/single_delete_update.result
@@ -29,6 +29,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
@@ -46,6 +47,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i;
a i
@@ -80,6 +82,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
@@ -97,6 +100,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i;
a i
@@ -128,6 +132,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -145,6 +150,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
## should be 5 (previous LIMIT)
SELECT 1 - COUNT(*) FROM t2 WHERE b = 10;
@@ -180,6 +186,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -197,6 +204,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
## should be 5 (previous LIMIT)
SELECT 257 - COUNT(*) FROM t2 WHERE b = 10;
@@ -226,6 +234,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -243,6 +252,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 WHERE b = 10 ORDER BY a, c;
a b c d
@@ -270,6 +280,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -287,6 +298,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 WHERE b = 10 ORDER BY a, c;
a b c d
@@ -317,6 +329,7 @@ Handler_read_last 0
Handler_read_next 7
Handler_read_prev 0
Handler_read_rnd 4
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -339,6 +352,7 @@ Handler_read_last 0
Handler_read_next 7
Handler_read_prev 0
Handler_read_rnd 8
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
i key1 key2
@@ -375,6 +389,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
@@ -392,6 +407,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i;
a i
@@ -426,6 +442,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
DELETE FROM t2 ORDER BY a, b DESC LIMIT 5;
@@ -443,6 +460,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 ORDER BY a, b DESC;
a b c
@@ -486,6 +504,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
@@ -509,6 +528,7 @@ Handler_read_last 1
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
@@ -526,6 +546,7 @@ Handler_read_last 1
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE c = 10 ORDER BY a DESC, b DESC;
a b c
@@ -561,6 +582,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
@@ -578,6 +600,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i;
a i
@@ -617,6 +640,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
@@ -634,6 +658,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i;
a i
@@ -670,6 +695,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -687,6 +713,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
## should be 5 (previous LIMIT)
SELECT COUNT(*) FROM t2 WHERE b = 10 AND d = 10 ORDER BY a, c;
@@ -722,6 +749,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -739,6 +767,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
## should be 5 (previous LIMIT)
SELECT COUNT(*) FROM t2 WHERE b = 10 AND d = 10 ORDER BY a, c;
@@ -768,6 +797,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -785,6 +815,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 WHERE b = 10 ORDER BY a, c;
a b c d
@@ -813,6 +844,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
@@ -830,6 +862,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 WHERE b = 10 ORDER BY a, c;
a b c d
@@ -861,6 +894,7 @@ Handler_read_last 0
Handler_read_next 7
Handler_read_prev 0
Handler_read_rnd 4
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -883,6 +917,7 @@ Handler_read_last 0
Handler_read_next 7
Handler_read_prev 0
Handler_read_rnd 8
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
i key1 key2
@@ -923,6 +958,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
@@ -940,6 +976,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i;
a i
@@ -979,6 +1016,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
FLUSH STATUS;
UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
@@ -996,6 +1034,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
SELECT * FROM t2 WHERE c = 10 ORDER BY a, b DESC;
a b c
@@ -1033,6 +1072,7 @@ Handler_read_last 0
Handler_read_next 4
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
@@ -1056,6 +1096,7 @@ Handler_read_last 1
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
FLUSH STATUS;
UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
@@ -1073,6 +1114,7 @@ Handler_read_last 1
Handler_read_next 0
Handler_read_prev 4
Handler_read_rnd 5
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT * FROM t2 WHERE c = 10 ORDER BY a DESC, b DESC;
a b c
diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result
index 91a120313ae..0182ffac880 100644
--- a/mysql-test/r/status.result
+++ b/mysql-test/r/status.result
@@ -282,6 +282,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 7
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 23
Handler_rollback 0
Handler_savepoint 0
@@ -297,7 +298,35 @@ Created_tmp_files 0
Created_tmp_tables 2
Handler_tmp_update 2
Handler_tmp_write 7
-Rows_tmp_read 35
+Rows_tmp_read 36
+drop table t1;
+CREATE TABLE t1 (i int(11) DEFAULT NULL, KEY i (i) ) ENGINE=MyISAM;
+insert into t1 values (1),(2),(3),(4),(5);
+flush status;
+select * from t1 where i=5 union select * from t1 where i=5;
+i
+5
+show status like "handler%";
+Variable_name Value
+Handler_commit 0
+Handler_delete 0
+Handler_discover 0
+Handler_prepare 0
+Handler_read_first 0
+Handler_read_key 2
+Handler_read_last 0
+Handler_read_next 2
+Handler_read_prev 0
+Handler_read_rnd 0
+Handler_read_rnd_deleted 1
+Handler_read_rnd_next 2
+Handler_rollback 0
+Handler_savepoint 0
+Handler_savepoint_rollback 0
+Handler_tmp_update 0
+Handler_tmp_write 2
+Handler_update 0
+Handler_write 0
drop table t1;
set @@global.concurrent_insert= @old_concurrent_insert;
SET GLOBAL log_output = @old_log_output;
diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result
index cd8e5af3004..96edd1c4207 100644
--- a/mysql-test/r/status_user.result
+++ b/mysql-test/r/status_user.result
@@ -107,6 +107,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 5
Handler_rollback 2
Handler_savepoint 0
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 7d3877e678d..e7883c5801e 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -4620,6 +4620,13 @@ CREATE TABLE t1(a1 int);
INSERT INTO t1 VALUES (1),(2);
SELECT @@session.sql_mode INTO @old_sql_mode;
SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+EXPLAIN EXTENDED
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1)))
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1
1
@@ -5322,7 +5329,6 @@ EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
WHERE t1.a = d1.a;
ERROR 42S22: Unknown column 'd1.a' in 'where clause'
DROP TABLE t1;
-End of 5.1 tests.
Set up test tables.
CREATE TABLE t1 (
t1_id INT UNSIGNED,
@@ -5847,10 +5853,161 @@ NULL
NULL
5
DROP TABLE t1, t2, t3;
+#
+# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
+#
+CREATE TABLE t1(a1 int);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2(a1 int);
+INSERT INTO t2 VALUES (3);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
+1
+1
+1
+SET SESSION sql_mode=@old_sql_mode;
+DROP TABLE t1, t2;
+create table t2(i int);
+insert into t2 values(0);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+CREATE VIEW v1 AS
+SELECT 'f' FROM t2 UNION SELECT 'x' FROM t2
+;
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key)
+);
+SELECT t1.pk
+FROM t1
+WHERE t1.col_varchar_key < ALL ( SELECT * FROM v1 )
+;
+pk
+SET SESSION sql_mode=@old_sql_mode;
+drop table t2, t1;
+drop view v1;
+#
+# BUG#50257: Missing info in REF column of the EXPLAIN
+# lines for subselects
+#
+CREATE TABLE t1 (a INT, b INT, INDEX (a));
+INSERT INTO t1 VALUES (3, 10), (2, 20), (7, 10), (5, 20);
+EXPLAIN SELECT * FROM (SELECT * FROM t1 WHERE a=7) t;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref a a 5 const 1
+EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+2 SUBQUERY t1 ref a a 5 const 1 Using index
+DROP TABLE t1;
+#
+# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
+# (duplicate of LP bug #888456)
+#
+CREATE TABLE t1 (f1 varchar(1));
+INSERT INTO t1 VALUES ('v'),('s');
+CREATE TABLE t2 (f1_key varchar(1), KEY (f1_key));
+INSERT INTO t2 VALUES ('j'),('v'),('c'),('m'),('d'),
+('d'),('y'),('t'),('d'),('s');
+EXPLAIN
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY table1 ALL NULL NULL NULL NULL 2
+1 PRIMARY table2 index NULL f1_key 4 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t2 index f1_key f1_key 4 NULL 10 Using where; Using index
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+f1 f1_key
+v j
+s j
+v v
+s v
+v c
+s c
+v m
+s m
+v d
+s d
+v d
+s d
+v y
+s y
+v t
+s t
+v d
+s d
+v s
+s s
+DROP TABLE t1,t2;
+#
+# LP bug 919427: EXPLAIN for a query over a single-row table
+# with IN subquery in WHERE condition
+#
+CREATE TABLE ot (
+col_int_nokey int(11),
+col_varchar_nokey varchar(1)
+) ;
+INSERT INTO ot VALUES (1,'x');
+CREATE TABLE it1(
+col_int_key int(11),
+col_varchar_key varchar(1),
+KEY idx_cvk_cik (col_varchar_key,col_int_key)
+);
+INSERT INTO it1 VALUES (NULL,'x'), (NULL,'f');
+CREATE TABLE it2 (
+col_int_key int(11),
+col_varchar_key varchar(1),
+col_varchar_key2 varchar(1),
+KEY idx_cvk_cvk2_cik (col_varchar_key, col_varchar_key2, col_int_key),
+KEY idx_cvk_cik (col_varchar_key, col_int_key)
+);
+INSERT INTO it2 VALUES (NULL,'x','x'), (NULL,'f','f');
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
+2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+col_int_nokey
+1
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 10 func,func 1
+2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+col_int_nokey
+1
+DROP TABLE ot,it1,it2;
End of 5.2 tests
#
# BUG#779885: Crash in eliminate_item_equal with materialization=on in
-# maria-5.3
#
CREATE TABLE t1 ( f1 int );
INSERT INTO t1 VALUES (19), (20);
@@ -5897,32 +6054,6 @@ b c
9 NULL
SET optimizer_switch=@save_optimizer_switch;
drop table t1, t2, t3;
-End of 5.3 tests
-#
-# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
-#
-CREATE TABLE t1(a1 int);
-INSERT INTO t1 VALUES (1),(2);
-CREATE TABLE t2(a1 int);
-INSERT INTO t2 VALUES (3);
-SELECT @@session.sql_mode INTO @old_sql_mode;
-SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
-1
-1
-1
-SET SESSION sql_mode=@old_sql_mode;
-DROP TABLE t1, t2;
#
# BUG#50257: Missing info in REF column of the EXPLAIN
# lines for subselects
@@ -5945,6 +6076,54 @@ id select_type table type possible_keys key key_len ref rows Extra
DROP TABLE t1;
#
+# Bug#11764086: Null left operand to NOT IN in WHERE clause
+# behaves differently than real NULL
+#
+CREATE TABLE parent (id int);
+INSERT INTO parent VALUES (1), (2);
+CREATE TABLE child (parent_id int, other int);
+INSERT INTO child VALUES (1,NULL);
+# Offending query (c.parent_id is NULL for null-complemented rows only)
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id NOT IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+);
+id parent_id
+1 1
+2 NULL
+# Some syntactic variations with IS FALSE and IS NOT TRUE
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS NOT TRUE;
+id parent_id
+1 1
+2 NULL
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS FALSE;
+id parent_id
+1 1
+2 NULL
+DROP TABLE parent, child;
+# End of test for bug#11764086.
+#
# Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
# BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
#
@@ -6283,5 +6462,14 @@ SELECT ( SELECT b FROM t2 WHERE b = a OR rand() * 0) FROM t1;
1
NULL
drop table t1,t2,t3;
+#
+# LP BUG#905353 Wrong non-empty result with a constant table,
+# aggregate function in subquery, MyISAM or Aria
+#
+CREATE TABLE t1 ( a INT ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 );
+a
+drop table t1;
# return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp;
diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result
index 833d6f203c2..d5d75b68628 100644
--- a/mysql-test/r/subselect3.result
+++ b/mysql-test/r/subselect3.result
@@ -125,6 +125,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 50
select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
Z
diff --git a/mysql-test/r/subselect3_jcl6.result b/mysql-test/r/subselect3_jcl6.result
index 5d7fee48d87..d794d35cf1a 100644
--- a/mysql-test/r/subselect3_jcl6.result
+++ b/mysql-test/r/subselect3_jcl6.result
@@ -135,6 +135,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 50
select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
Z
@@ -1153,7 +1154,7 @@ insert into t4 select a from t3;
explain select * from t3 where a in (select t1.kp1 from t1,t4 where kp1<20
and t4.pk=t1.c);
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY t1 range kp1 kp1 5 NULL 48 Using index condition; Using where; Rowid-ordered scan; LooseScan
+1 PRIMARY t1 range kp1 kp1 5 NULL 48 Using index condition; Using where; LooseScan
1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 Using index; FirstMatch(t1)
1 PRIMARY t3 ALL NULL NULL NULL NULL 100 Using where; Using join buffer (flat, BNL join)
drop table t1, t3, t4;
diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result
index 1fd638fd42c..14c4254028d 100644
--- a/mysql-test/r/subselect4.result
+++ b/mysql-test/r/subselect4.result
@@ -711,7 +711,7 @@ EXPLAIN
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2);
f1 f2
SET @@optimizer_switch = 'materialization=off,in_to_exists=on,semijoin=off';
@@ -802,7 +802,7 @@ EXPLAIN
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2);
f1 f2
INSERT INTO t1 VALUES (1, 2);
@@ -897,7 +897,7 @@ EXPLAIN
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2 WHERE f3 > 10);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2 WHERE f3 > 10);
f1 f2
SET @@optimizer_switch = 'materialization=off,in_to_exists=on,semijoin=off';
@@ -988,7 +988,7 @@ EXPLAIN
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2 WHERE f3 > 10);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No matching min/max row
SELECT * FROM t1 WHERE (2, 0) NOT IN (SELECT min(f3)+f3, min(f4)+f3+max(f4) FROM t2 WHERE f3 > 10);
f1 f2
set @@optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/r/subselect_cache.result b/mysql-test/r/subselect_cache.result
index d8ac44005f9..e38e8b42e9a 100644
--- a/mysql-test/r/subselect_cache.result
+++ b/mysql-test/r/subselect_cache.result
@@ -37,6 +37,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 31
set optimizer_switch='subquery_cache=off';
flush status;
@@ -64,6 +65,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 61
set optimizer_switch='subquery_cache=on';
#single value subquery test (where)
@@ -90,6 +92,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 31
set optimizer_switch='subquery_cache=off';
flush status;
@@ -115,6 +118,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 61
set optimizer_switch='subquery_cache=on';
#single value subquery test (having)
@@ -141,6 +145,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 31
set optimizer_switch='subquery_cache=off';
flush status;
@@ -166,6 +171,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 61
set optimizer_switch='subquery_cache=on';
#single value subquery test (OUTER JOIN ON)
@@ -264,6 +270,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 442
set optimizer_switch='subquery_cache=off';
flush status;
@@ -361,6 +368,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 472
set optimizer_switch='subquery_cache=on';
#single value subquery test (GROUP BY)
@@ -383,6 +391,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 4
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 36
set optimizer_switch='subquery_cache=off';
flush status;
@@ -404,6 +413,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 4
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 86
set optimizer_switch='subquery_cache=on';
#single value subquery test (distinct GROUP BY)
@@ -426,6 +436,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 4
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 41
set optimizer_switch='subquery_cache=off';
flush status;
@@ -447,6 +458,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 4
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 91
set optimizer_switch='subquery_cache=on';
#single value subquery test (ORDER BY)
@@ -475,6 +487,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 10
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 42
set optimizer_switch='subquery_cache=off';
flush status;
@@ -502,6 +515,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 10
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 72
set optimizer_switch='subquery_cache=on';
#single value subquery test (distinct ORDER BY)
@@ -524,7 +538,8 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 4
-Handler_read_rnd_next 37
+Handler_read_rnd_deleted 1
+Handler_read_rnd_next 36
set optimizer_switch='subquery_cache=off';
flush status;
select distinct a from t1 ORDER BY (select d from t2 where b=c);
@@ -545,7 +560,8 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 4
-Handler_read_rnd_next 67
+Handler_read_rnd_deleted 1
+Handler_read_rnd_next 66
set optimizer_switch='subquery_cache=on';
#single value subquery test (LEFT JOIN ON)
flush status;
@@ -643,6 +659,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 141
set optimizer_switch='subquery_cache=off';
flush status;
@@ -740,6 +757,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 671
set optimizer_switch='subquery_cache=on';
#single value subquery test (PS)
@@ -1364,6 +1382,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 145
set optimizer_switch='subquery_cache=on';
flush status;
@@ -1393,6 +1412,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 84
#several subqueries (several levels)
set optimizer_switch='subquery_cache=off';
@@ -1425,6 +1445,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 127
set optimizer_switch='subquery_cache=on';
flush status;
@@ -1454,6 +1475,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 69
#clean up
drop table t1,t2;
@@ -1644,6 +1666,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 8
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 57
set optimizer_switch='subquery_cache=on';
flush status;
@@ -1669,6 +1692,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 8
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 37
argument of aggregate function as parameter of subquery (illegal use)
set optimizer_switch='subquery_cache=off';
@@ -1695,6 +1719,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 8
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 57
set optimizer_switch='subquery_cache=on';
flush status;
@@ -1720,6 +1745,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 8
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 41
drop table t1,t2;
#test of flattening subquery optimisations and cache
@@ -1761,6 +1787,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 16
alter table t2 drop primary key;
set optimizer_switch='default,semijoin=off,materialization=off,subquery_cache=off';
@@ -1798,6 +1825,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 151
set optimizer_switch='default,semijoin=off,materialization=off,subquery_cache=on';
explain select * from t1 where a in (select pk from t2);
@@ -1834,6 +1862,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 43
set optimizer_switch='default,semijoin=off,materialization=on,subquery_cache=on';
explain select * from t1 where a in (select pk from t2);
@@ -1870,6 +1899,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 27
drop table t0,t1,t2;
set optimizer_switch='default';
diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result
index 5c750e8b078..097e65fa94f 100644
--- a/mysql-test/r/subselect_mat.result
+++ b/mysql-test/r/subselect_mat.result
@@ -1793,7 +1793,7 @@ SELECT * FROM t1
WHERE a IN ( SELECT MIN(a) FROM t1 );
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
-2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
Warnings:
Note 1003 select 8 AS `a` from dual where <expr_cache><8>(<in_optimizer>(8,<exists>(select min(`test`.`t1`.`a`) from `test`.`t1` having (<cache>(8) = <ref_null_helper>(min(`test`.`t1`.`a`))))))
DROP TABLE t1;
@@ -1811,6 +1811,43 @@ a b c
4 4 2
4 4 4
DROP TABLE t1,t2;
+#
+# BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*)
+#
+CREATE TABLE t1 ( a VARCHAR(3) );
+CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) );
+INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron');
+EXPLAIN
+SELECT * FROM
+( SELECT * FROM t1 ) AS alias1,
+t2 AS alias2
+WHERE b = a AND a IN (
+SELECT alias3.c
+FROM t2 AS alias3, t2 AS alias4
+WHERE alias4.c = alias3.b
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2
+3 MATERIALIZED alias4 index c c 11 NULL 2 Using where; Using index; Using join buffer (flat, BNL join)
+DROP TABLE t1,t2;
+#
+# BUG#928048: Query containing IN subquery with OR in the where clause returns a wrong result
+#
+create table t1 (a int, b int);
+insert into t1 values (7,5), (3,3), (5,4), (9,3);
+create table t2 (a int, b int, index i_a(a));
+insert into t2 values
+(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1);
+explain select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
+2 MATERIALIZED t2 ALL i_a NULL NULL NULL 8 Using where
+select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
+a b
+7 5
+3 3
+drop table t1,t2;
# This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp;
set join_cache_level=@save_join_cache_level;
diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result
index 8ac856857eb..b515ea39f9e 100644
--- a/mysql-test/r/subselect_no_mat.result
+++ b/mysql-test/r/subselect_no_mat.result
@@ -4622,6 +4622,13 @@ CREATE TABLE t1(a1 int);
INSERT INTO t1 VALUES (1),(2);
SELECT @@session.sql_mode INTO @old_sql_mode;
SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+EXPLAIN EXTENDED
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1)))
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1
1
@@ -5324,7 +5331,6 @@ EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
WHERE t1.a = d1.a;
ERROR 42S22: Unknown column 'd1.a' in 'where clause'
DROP TABLE t1;
-End of 5.1 tests.
Set up test tables.
CREATE TABLE t1 (
t1_id INT UNSIGNED,
@@ -5848,10 +5854,159 @@ NULL
NULL
5
DROP TABLE t1, t2, t3;
+#
+# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
+#
+CREATE TABLE t1(a1 int);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2(a1 int);
+INSERT INTO t2 VALUES (3);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
+1
+1
+1
+SET SESSION sql_mode=@old_sql_mode;
+DROP TABLE t1, t2;
+create table t2(i int);
+insert into t2 values(0);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+CREATE VIEW v1 AS
+SELECT 'f' FROM t2 UNION SELECT 'x' FROM t2
+;
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key)
+);
+SELECT t1.pk
+FROM t1
+WHERE t1.col_varchar_key < ALL ( SELECT * FROM v1 )
+;
+pk
+SET SESSION sql_mode=@old_sql_mode;
+drop table t2, t1;
+drop view v1;
+#
+# BUG#50257: Missing info in REF column of the EXPLAIN
+# lines for subselects
+#
+CREATE TABLE t1 (a INT, b INT, INDEX (a));
+INSERT INTO t1 VALUES (3, 10), (2, 20), (7, 10), (5, 20);
+EXPLAIN SELECT * FROM (SELECT * FROM t1 WHERE a=7) t;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref a a 5 const 1
+EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+2 SUBQUERY t1 ref a a 5 const 1 Using index
+DROP TABLE t1;
+#
+# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
+# (duplicate of LP bug #888456)
+#
+CREATE TABLE t1 (f1 varchar(1));
+INSERT INTO t1 VALUES ('v'),('s');
+CREATE TABLE t2 (f1_key varchar(1), KEY (f1_key));
+INSERT INTO t2 VALUES ('j'),('v'),('c'),('m'),('d'),
+('d'),('y'),('t'),('d'),('s');
+EXPLAIN
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY table1 ALL NULL NULL NULL NULL 2
+1 PRIMARY table2 index NULL f1_key 4 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t2 index f1_key f1_key 4 NULL 10 Using where; Using index
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+f1 f1_key
+v j
+s j
+v v
+s v
+v c
+s c
+v m
+s m
+v d
+s d
+v d
+s d
+v y
+s y
+v t
+s t
+v d
+s d
+v s
+s s
+DROP TABLE t1,t2;
+#
+# LP bug 919427: EXPLAIN for a query over a single-row table
+# with IN subquery in WHERE condition
+#
+CREATE TABLE ot (
+col_int_nokey int(11),
+col_varchar_nokey varchar(1)
+) ;
+INSERT INTO ot VALUES (1,'x');
+CREATE TABLE it1(
+col_int_key int(11),
+col_varchar_key varchar(1),
+KEY idx_cvk_cik (col_varchar_key,col_int_key)
+);
+INSERT INTO it1 VALUES (NULL,'x'), (NULL,'f');
+CREATE TABLE it2 (
+col_int_key int(11),
+col_varchar_key varchar(1),
+col_varchar_key2 varchar(1),
+KEY idx_cvk_cvk2_cik (col_varchar_key, col_varchar_key2, col_int_key),
+KEY idx_cvk_cik (col_varchar_key, col_int_key)
+);
+INSERT INTO it2 VALUES (NULL,'x','x'), (NULL,'f','f');
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+1 PRIMARY it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index; FirstMatch(ot)
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+col_int_nokey
+1
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+1 PRIMARY it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index; FirstMatch(ot)
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+col_int_nokey
+1
+DROP TABLE ot,it1,it2;
End of 5.2 tests
#
# BUG#779885: Crash in eliminate_item_equal with materialization=on in
-# maria-5.3
#
CREATE TABLE t1 ( f1 int );
INSERT INTO t1 VALUES (19), (20);
@@ -5898,32 +6053,6 @@ b c
9 NULL
SET optimizer_switch=@save_optimizer_switch;
drop table t1, t2, t3;
-End of 5.3 tests
-#
-# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
-#
-CREATE TABLE t1(a1 int);
-INSERT INTO t1 VALUES (1),(2);
-CREATE TABLE t2(a1 int);
-INSERT INTO t2 VALUES (3);
-SELECT @@session.sql_mode INTO @old_sql_mode;
-SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
-1
-1
-1
-SET SESSION sql_mode=@old_sql_mode;
-DROP TABLE t1, t2;
#
# BUG#50257: Missing info in REF column of the EXPLAIN
# lines for subselects
@@ -5946,6 +6075,54 @@ id select_type table type possible_keys key key_len ref rows Extra
DROP TABLE t1;
#
+# Bug#11764086: Null left operand to NOT IN in WHERE clause
+# behaves differently than real NULL
+#
+CREATE TABLE parent (id int);
+INSERT INTO parent VALUES (1), (2);
+CREATE TABLE child (parent_id int, other int);
+INSERT INTO child VALUES (1,NULL);
+# Offending query (c.parent_id is NULL for null-complemented rows only)
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id NOT IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+);
+id parent_id
+1 1
+2 NULL
+# Some syntactic variations with IS FALSE and IS NOT TRUE
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS NOT TRUE;
+id parent_id
+1 1
+2 NULL
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS FALSE;
+id parent_id
+1 1
+2 NULL
+DROP TABLE parent, child;
+# End of test for bug#11764086.
+#
# Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
# BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
#
@@ -6284,6 +6461,15 @@ SELECT ( SELECT b FROM t2 WHERE b = a OR rand() * 0) FROM t1;
1
NULL
drop table t1,t2,t3;
+#
+# LP BUG#905353 Wrong non-empty result with a constant table,
+# aggregate function in subquery, MyISAM or Aria
+#
+CREATE TABLE t1 ( a INT ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 );
+a
+drop table t1;
# return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp;
set optimizer_switch=default;
diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result
index 518f9366b80..c50ee1bac69 100644
--- a/mysql-test/r/subselect_no_opts.result
+++ b/mysql-test/r/subselect_no_opts.result
@@ -4618,6 +4618,13 @@ CREATE TABLE t1(a1 int);
INSERT INTO t1 VALUES (1),(2);
SELECT @@session.sql_mode INTO @old_sql_mode;
SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+EXPLAIN EXTENDED
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1)))
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1
1
@@ -5320,7 +5327,6 @@ EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
WHERE t1.a = d1.a;
ERROR 42S22: Unknown column 'd1.a' in 'where clause'
DROP TABLE t1;
-End of 5.1 tests.
Set up test tables.
CREATE TABLE t1 (
t1_id INT UNSIGNED,
@@ -5844,10 +5850,159 @@ NULL
NULL
5
DROP TABLE t1, t2, t3;
+#
+# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
+#
+CREATE TABLE t1(a1 int);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2(a1 int);
+INSERT INTO t2 VALUES (3);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
+1
+1
+1
+SET SESSION sql_mode=@old_sql_mode;
+DROP TABLE t1, t2;
+create table t2(i int);
+insert into t2 values(0);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+CREATE VIEW v1 AS
+SELECT 'f' FROM t2 UNION SELECT 'x' FROM t2
+;
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key)
+);
+SELECT t1.pk
+FROM t1
+WHERE t1.col_varchar_key < ALL ( SELECT * FROM v1 )
+;
+pk
+SET SESSION sql_mode=@old_sql_mode;
+drop table t2, t1;
+drop view v1;
+#
+# BUG#50257: Missing info in REF column of the EXPLAIN
+# lines for subselects
+#
+CREATE TABLE t1 (a INT, b INT, INDEX (a));
+INSERT INTO t1 VALUES (3, 10), (2, 20), (7, 10), (5, 20);
+EXPLAIN SELECT * FROM (SELECT * FROM t1 WHERE a=7) t;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref a a 5 const 1
+EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+2 SUBQUERY t1 ref a a 5 const 1 Using index
+DROP TABLE t1;
+#
+# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
+# (duplicate of LP bug #888456)
+#
+CREATE TABLE t1 (f1 varchar(1));
+INSERT INTO t1 VALUES ('v'),('s');
+CREATE TABLE t2 (f1_key varchar(1), KEY (f1_key));
+INSERT INTO t2 VALUES ('j'),('v'),('c'),('m'),('d'),
+('d'),('y'),('t'),('d'),('s');
+EXPLAIN
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY table1 ALL NULL NULL NULL NULL 2
+1 PRIMARY table2 index NULL f1_key 4 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t2 index f1_key f1_key 4 NULL 10 Using where; Using index
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+f1 f1_key
+v j
+s j
+v v
+s v
+v c
+s c
+v m
+s m
+v d
+s d
+v d
+s d
+v y
+s y
+v t
+s t
+v d
+s d
+v s
+s s
+DROP TABLE t1,t2;
+#
+# LP bug 919427: EXPLAIN for a query over a single-row table
+# with IN subquery in WHERE condition
+#
+CREATE TABLE ot (
+col_int_nokey int(11),
+col_varchar_nokey varchar(1)
+) ;
+INSERT INTO ot VALUES (1,'x');
+CREATE TABLE it1(
+col_int_key int(11),
+col_varchar_key varchar(1),
+KEY idx_cvk_cik (col_varchar_key,col_int_key)
+);
+INSERT INTO it1 VALUES (NULL,'x'), (NULL,'f');
+CREATE TABLE it2 (
+col_int_key int(11),
+col_varchar_key varchar(1),
+col_varchar_key2 varchar(1),
+KEY idx_cvk_cvk2_cik (col_varchar_key, col_varchar_key2, col_int_key),
+KEY idx_cvk_cik (col_varchar_key, col_int_key)
+);
+INSERT INTO it2 VALUES (NULL,'x','x'), (NULL,'f','f');
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+2 DEPENDENT SUBQUERY it1 index_subquery idx_cvk_cik idx_cvk_cik 9 func,const 2 Using index; Using where
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+col_int_nokey
+1
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+2 DEPENDENT SUBQUERY it2 index_subquery idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 func,const 1 Using index; Using where
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+col_int_nokey
+1
+DROP TABLE ot,it1,it2;
End of 5.2 tests
#
# BUG#779885: Crash in eliminate_item_equal with materialization=on in
-# maria-5.3
#
CREATE TABLE t1 ( f1 int );
INSERT INTO t1 VALUES (19), (20);
@@ -5894,32 +6049,6 @@ b c
9 NULL
SET optimizer_switch=@save_optimizer_switch;
drop table t1, t2, t3;
-End of 5.3 tests
-#
-# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
-#
-CREATE TABLE t1(a1 int);
-INSERT INTO t1 VALUES (1),(2);
-CREATE TABLE t2(a1 int);
-INSERT INTO t2 VALUES (3);
-SELECT @@session.sql_mode INTO @old_sql_mode;
-SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
-1
-1
-1
-SET SESSION sql_mode=@old_sql_mode;
-DROP TABLE t1, t2;
#
# BUG#50257: Missing info in REF column of the EXPLAIN
# lines for subselects
@@ -5942,6 +6071,54 @@ id select_type table type possible_keys key key_len ref rows Extra
DROP TABLE t1;
#
+# Bug#11764086: Null left operand to NOT IN in WHERE clause
+# behaves differently than real NULL
+#
+CREATE TABLE parent (id int);
+INSERT INTO parent VALUES (1), (2);
+CREATE TABLE child (parent_id int, other int);
+INSERT INTO child VALUES (1,NULL);
+# Offending query (c.parent_id is NULL for null-complemented rows only)
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id NOT IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+);
+id parent_id
+1 1
+2 NULL
+# Some syntactic variations with IS FALSE and IS NOT TRUE
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS NOT TRUE;
+id parent_id
+1 1
+2 NULL
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS FALSE;
+id parent_id
+1 1
+2 NULL
+DROP TABLE parent, child;
+# End of test for bug#11764086.
+#
# Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
# BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
#
@@ -6280,6 +6457,15 @@ SELECT ( SELECT b FROM t2 WHERE b = a OR rand() * 0) FROM t1;
1
NULL
drop table t1,t2,t3;
+#
+# LP BUG#905353 Wrong non-empty result with a constant table,
+# aggregate function in subquery, MyISAM or Aria
+#
+CREATE TABLE t1 ( a INT ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 );
+a
+drop table t1;
# return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null;
diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result
index 320e51da39e..3e2305ebe73 100644
--- a/mysql-test/r/subselect_no_scache.result
+++ b/mysql-test/r/subselect_no_scache.result
@@ -4626,6 +4626,13 @@ CREATE TABLE t1(a1 int);
INSERT INTO t1 VALUES (1),(2);
SELECT @@session.sql_mode INTO @old_sql_mode;
SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+EXPLAIN EXTENDED
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1)))
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1
1
@@ -5328,7 +5335,6 @@ EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
WHERE t1.a = d1.a;
ERROR 42S22: Unknown column 'd1.a' in 'where clause'
DROP TABLE t1;
-End of 5.1 tests.
Set up test tables.
CREATE TABLE t1 (
t1_id INT UNSIGNED,
@@ -5853,10 +5859,161 @@ NULL
NULL
5
DROP TABLE t1, t2, t3;
+#
+# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
+#
+CREATE TABLE t1(a1 int);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2(a1 int);
+INSERT INTO t2 VALUES (3);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
+1
+1
+1
+SET SESSION sql_mode=@old_sql_mode;
+DROP TABLE t1, t2;
+create table t2(i int);
+insert into t2 values(0);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+CREATE VIEW v1 AS
+SELECT 'f' FROM t2 UNION SELECT 'x' FROM t2
+;
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key)
+);
+SELECT t1.pk
+FROM t1
+WHERE t1.col_varchar_key < ALL ( SELECT * FROM v1 )
+;
+pk
+SET SESSION sql_mode=@old_sql_mode;
+drop table t2, t1;
+drop view v1;
+#
+# BUG#50257: Missing info in REF column of the EXPLAIN
+# lines for subselects
+#
+CREATE TABLE t1 (a INT, b INT, INDEX (a));
+INSERT INTO t1 VALUES (3, 10), (2, 20), (7, 10), (5, 20);
+EXPLAIN SELECT * FROM (SELECT * FROM t1 WHERE a=7) t;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref a a 5 const 1
+EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+2 SUBQUERY t1 ref a a 5 const 1 Using index
+DROP TABLE t1;
+#
+# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
+# (duplicate of LP bug #888456)
+#
+CREATE TABLE t1 (f1 varchar(1));
+INSERT INTO t1 VALUES ('v'),('s');
+CREATE TABLE t2 (f1_key varchar(1), KEY (f1_key));
+INSERT INTO t2 VALUES ('j'),('v'),('c'),('m'),('d'),
+('d'),('y'),('t'),('d'),('s');
+EXPLAIN
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY table1 ALL NULL NULL NULL NULL 2
+1 PRIMARY table2 index NULL f1_key 4 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t2 index f1_key f1_key 4 NULL 10 Using where; Using index
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+f1 f1_key
+v j
+s j
+v v
+s v
+v c
+s c
+v m
+s m
+v d
+s d
+v d
+s d
+v y
+s y
+v t
+s t
+v d
+s d
+v s
+s s
+DROP TABLE t1,t2;
+#
+# LP bug 919427: EXPLAIN for a query over a single-row table
+# with IN subquery in WHERE condition
+#
+CREATE TABLE ot (
+col_int_nokey int(11),
+col_varchar_nokey varchar(1)
+) ;
+INSERT INTO ot VALUES (1,'x');
+CREATE TABLE it1(
+col_int_key int(11),
+col_varchar_key varchar(1),
+KEY idx_cvk_cik (col_varchar_key,col_int_key)
+);
+INSERT INTO it1 VALUES (NULL,'x'), (NULL,'f');
+CREATE TABLE it2 (
+col_int_key int(11),
+col_varchar_key varchar(1),
+col_varchar_key2 varchar(1),
+KEY idx_cvk_cvk2_cik (col_varchar_key, col_varchar_key2, col_int_key),
+KEY idx_cvk_cik (col_varchar_key, col_int_key)
+);
+INSERT INTO it2 VALUES (NULL,'x','x'), (NULL,'f','f');
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
+2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+col_int_nokey
+1
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 10 func,func 1
+2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+col_int_nokey
+1
+DROP TABLE ot,it1,it2;
End of 5.2 tests
#
# BUG#779885: Crash in eliminate_item_equal with materialization=on in
-# maria-5.3
#
CREATE TABLE t1 ( f1 int );
INSERT INTO t1 VALUES (19), (20);
@@ -5903,32 +6060,6 @@ b c
9 NULL
SET optimizer_switch=@save_optimizer_switch;
drop table t1, t2, t3;
-End of 5.3 tests
-#
-# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
-#
-CREATE TABLE t1(a1 int);
-INSERT INTO t1 VALUES (1),(2);
-CREATE TABLE t2(a1 int);
-INSERT INTO t2 VALUES (3);
-SELECT @@session.sql_mode INTO @old_sql_mode;
-SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
-1
-1
-1
-SET SESSION sql_mode=@old_sql_mode;
-DROP TABLE t1, t2;
#
# BUG#50257: Missing info in REF column of the EXPLAIN
# lines for subselects
@@ -5951,6 +6082,54 @@ id select_type table type possible_keys key key_len ref rows Extra
DROP TABLE t1;
#
+# Bug#11764086: Null left operand to NOT IN in WHERE clause
+# behaves differently than real NULL
+#
+CREATE TABLE parent (id int);
+INSERT INTO parent VALUES (1), (2);
+CREATE TABLE child (parent_id int, other int);
+INSERT INTO child VALUES (1,NULL);
+# Offending query (c.parent_id is NULL for null-complemented rows only)
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id NOT IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+);
+id parent_id
+1 1
+2 NULL
+# Some syntactic variations with IS FALSE and IS NOT TRUE
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS NOT TRUE;
+id parent_id
+1 1
+2 NULL
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS FALSE;
+id parent_id
+1 1
+2 NULL
+DROP TABLE parent, child;
+# End of test for bug#11764086.
+#
# Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
# BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
#
@@ -6289,6 +6468,15 @@ SELECT ( SELECT b FROM t2 WHERE b = a OR rand() * 0) FROM t1;
1
NULL
drop table t1,t2,t3;
+#
+# LP BUG#905353 Wrong non-empty result with a constant table,
+# aggregate function in subquery, MyISAM or Aria
+#
+CREATE TABLE t1 ( a INT ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 );
+a
+drop table t1;
# return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp;
set optimizer_switch=default;
diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result
index 0c41f612ae9..47368b1eca7 100644
--- a/mysql-test/r/subselect_no_semijoin.result
+++ b/mysql-test/r/subselect_no_semijoin.result
@@ -4618,6 +4618,13 @@ CREATE TABLE t1(a1 int);
INSERT INTO t1 VALUES (1),(2);
SELECT @@session.sql_mode INTO @old_sql_mode;
SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+EXPLAIN EXTENDED
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00
+Warnings:
+Note 1003 select 1 AS `1` from `test`.`t1` where <nop>(<in_optimizer>(1,((select max(`test`.`t1`.`a1`) from `test`.`t1`) > 1)))
SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1);
1
1
@@ -5320,7 +5327,6 @@ EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1,
WHERE t1.a = d1.a;
ERROR 42S22: Unknown column 'd1.a' in 'where clause'
DROP TABLE t1;
-End of 5.1 tests.
Set up test tables.
CREATE TABLE t1 (
t1_id INT UNSIGNED,
@@ -5844,10 +5850,159 @@ NULL
NULL
5
DROP TABLE t1, t2, t3;
+#
+# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
+#
+CREATE TABLE t1(a1 int);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2(a1 int);
+INSERT INTO t2 VALUES (3);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
+1
+1
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
+1
+SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
+1
+1
+1
+SET SESSION sql_mode=@old_sql_mode;
+DROP TABLE t1, t2;
+create table t2(i int);
+insert into t2 values(0);
+SELECT @@session.sql_mode INTO @old_sql_mode;
+SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
+CREATE VIEW v1 AS
+SELECT 'f' FROM t2 UNION SELECT 'x' FROM t2
+;
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key)
+);
+SELECT t1.pk
+FROM t1
+WHERE t1.col_varchar_key < ALL ( SELECT * FROM v1 )
+;
+pk
+SET SESSION sql_mode=@old_sql_mode;
+drop table t2, t1;
+drop view v1;
+#
+# BUG#50257: Missing info in REF column of the EXPLAIN
+# lines for subselects
+#
+CREATE TABLE t1 (a INT, b INT, INDEX (a));
+INSERT INTO t1 VALUES (3, 10), (2, 20), (7, 10), (5, 20);
+EXPLAIN SELECT * FROM (SELECT * FROM t1 WHERE a=7) t;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ref a a 5 const 1
+EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+2 SUBQUERY t1 ref a a 5 const 1 Using index
+DROP TABLE t1;
+#
+# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS)
+# (duplicate of LP bug #888456)
+#
+CREATE TABLE t1 (f1 varchar(1));
+INSERT INTO t1 VALUES ('v'),('s');
+CREATE TABLE t2 (f1_key varchar(1), KEY (f1_key));
+INSERT INTO t2 VALUES ('j'),('v'),('c'),('m'),('d'),
+('d'),('y'),('t'),('d'),('s');
+EXPLAIN
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY table1 ALL NULL NULL NULL NULL 2
+1 PRIMARY table2 index NULL f1_key 4 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t2 index f1_key f1_key 4 NULL 10 Using where; Using index
+SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2
+WHERE EXISTS (SELECT DISTINCT f1_key FROM t2
+WHERE f1_key != table2.f1_key AND f1_key >= table1.f1);
+f1 f1_key
+v j
+s j
+v v
+s v
+v c
+s c
+v m
+s m
+v d
+s d
+v d
+s d
+v y
+s y
+v t
+s t
+v d
+s d
+v s
+s s
+DROP TABLE t1,t2;
+#
+# LP bug 919427: EXPLAIN for a query over a single-row table
+# with IN subquery in WHERE condition
+#
+CREATE TABLE ot (
+col_int_nokey int(11),
+col_varchar_nokey varchar(1)
+) ;
+INSERT INTO ot VALUES (1,'x');
+CREATE TABLE it1(
+col_int_key int(11),
+col_varchar_key varchar(1),
+KEY idx_cvk_cik (col_varchar_key,col_int_key)
+);
+INSERT INTO it1 VALUES (NULL,'x'), (NULL,'f');
+CREATE TABLE it2 (
+col_int_key int(11),
+col_varchar_key varchar(1),
+col_varchar_key2 varchar(1),
+KEY idx_cvk_cvk2_cik (col_varchar_key, col_varchar_key2, col_int_key),
+KEY idx_cvk_cik (col_varchar_key, col_int_key)
+);
+INSERT INTO it2 VALUES (NULL,'x','x'), (NULL,'f','f');
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+2 DEPENDENT SUBQUERY it1 index_subquery idx_cvk_cik idx_cvk_cik 9 func,const 2 Using index; Using where
+SELECT col_int_nokey FROM ot
+WHERE col_varchar_nokey IN
+(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL);
+col_int_nokey
+1
+EXPLAIN
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot system NULL NULL NULL NULL 1
+2 DEPENDENT SUBQUERY it2 index_subquery idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 func,const 1 Using index; Using where
+SELECT col_int_nokey FROM ot
+WHERE (col_varchar_nokey, 'x') IN
+(SELECT col_varchar_key, col_varchar_key2 FROM it2);
+col_int_nokey
+1
+DROP TABLE ot,it1,it2;
End of 5.2 tests
#
# BUG#779885: Crash in eliminate_item_equal with materialization=on in
-# maria-5.3
#
CREATE TABLE t1 ( f1 int );
INSERT INTO t1 VALUES (19), (20);
@@ -5894,32 +6049,6 @@ b c
9 NULL
SET optimizer_switch=@save_optimizer_switch;
drop table t1, t2, t3;
-End of 5.3 tests
-#
-# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER
-#
-CREATE TABLE t1(a1 int);
-INSERT INTO t1 VALUES (1),(2);
-CREATE TABLE t2(a1 int);
-INSERT INTO t2 VALUES (3);
-SELECT @@session.sql_mode INTO @old_sql_mode;
-SET SESSION sql_mode='ONLY_FULL_GROUP_BY';
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2);
-1
-1
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2);
-1
-SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2);
-1
-1
-1
-SET SESSION sql_mode=@old_sql_mode;
-DROP TABLE t1, t2;
#
# BUG#50257: Missing info in REF column of the EXPLAIN
# lines for subselects
@@ -5942,6 +6071,54 @@ id select_type table type possible_keys key key_len ref rows Extra
DROP TABLE t1;
#
+# Bug#11764086: Null left operand to NOT IN in WHERE clause
+# behaves differently than real NULL
+#
+CREATE TABLE parent (id int);
+INSERT INTO parent VALUES (1), (2);
+CREATE TABLE child (parent_id int, other int);
+INSERT INTO child VALUES (1,NULL);
+# Offending query (c.parent_id is NULL for null-complemented rows only)
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id NOT IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+);
+id parent_id
+1 1
+2 NULL
+# Some syntactic variations with IS FALSE and IS NOT TRUE
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS NOT TRUE;
+id parent_id
+1 1
+2 NULL
+SELECT p.id, c.parent_id
+FROM parent p
+LEFT JOIN child c
+ON p.id = c.parent_id
+WHERE c.parent_id IN (
+SELECT parent_id
+FROM child
+WHERE parent_id = 3
+) IS FALSE;
+id parent_id
+1 1
+2 NULL
+DROP TABLE parent, child;
+# End of test for bug#11764086.
+#
# Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
# BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
#
@@ -6280,6 +6457,15 @@ SELECT ( SELECT b FROM t2 WHERE b = a OR rand() * 0) FROM t1;
1
NULL
drop table t1,t2,t3;
+#
+# LP BUG#905353 Wrong non-empty result with a constant table,
+# aggregate function in subquery, MyISAM or Aria
+#
+CREATE TABLE t1 ( a INT ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 );
+a
+drop table t1;
# return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null;
diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result
index 8fcedc5807f..3bc1d1f4293 100644
--- a/mysql-test/r/subselect_sj.result
+++ b/mysql-test/r/subselect_sj.result
@@ -1231,6 +1231,364 @@ IN (SELECT t3.pk, t3.pk FROM t2 LEFT JOIN t3 ON t3.varchar_key)
AND pk = 9;
datetime_key
DROP TABLE t1, t2, t3;
+#
+# BUG#53060: LooseScan semijoin strategy does not return all rows
+#
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=on,materialization=off';
+set optimizer_switch='firstmatch=off,loosescan=on';
+CREATE TABLE t1 (i INTEGER);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE TABLE t2 (i INTEGER, j INTEGER, KEY k(i, j));
+INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1);
+EXPLAIN
+SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 index k k 10 NULL 4 Using where; Using index; LooseScan
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
+i
+1
+2
+DROP TABLE t1, t2;
+set optimizer_switch=@save_optimizer_switch;
+#
+# BUG#49453: re-execution of prepared statement with view
+# and semijoin crashes
+#
+CREATE TABLE t1 (city VARCHAR(50), country_id INT);
+CREATE TABLE t2 (country_id INT, country VARCHAR(50));
+INSERT INTO t1 VALUES
+('Batna',2),('Bchar',2),('Skikda',2),('Tafuna',3),('Algeria',2) ;
+INSERT INTO t2 VALUES (2,'Algeria'),(2,'AlgeriaDup'),(3,'XAmerican Samoa');
+CREATE VIEW v1 AS
+SELECT country_id as vf_country_id
+FROM t2
+WHERE LEFT(country,1) = "A";
+PREPARE stmt FROM "
+SELECT city, country_id
+FROM t1
+WHERE country_id IN (SELECT vf_country_id FROM v1);
+";
+
+EXECUTE stmt;
+city country_id
+Batna 2
+Bchar 2
+Skikda 2
+Algeria 2
+EXECUTE stmt;
+city country_id
+Batna 2
+Bchar 2
+Skikda 2
+Algeria 2
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#
+# Bug#54437 Extra rows with LEFT JOIN + semijoin
+#
+create table t1 (a int);
+create table t2 (a int);
+create table t3 (a int);
+insert into t1 values(1),(1);
+insert into t2 values(1),(1),(1),(1);
+insert into t3 values(2),(2);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='materialization=off';
+set optimizer_switch='semijoin=off';
+explain
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+a
+1
+1
+set optimizer_switch='semijoin=on';
+explain
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; Start temporary
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+a
+1
+1
+set optimizer_switch=@save_optimizer_switch;
+drop table t1,t2,t3;
+#
+# Bug#55955: crash in MEMORY engine with IN(LEFT JOIN (JOIN))
+#
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT);
+CREATE TABLE t3 (a INT);
+INSERT INTO t1 VALUES(1),(1);
+INSERT INTO t2 VALUES(1),(1);
+INSERT INTO t3 VALUES(2),(2);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=off,materialization=off';
+EXPLAIN
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2inner ALL NULL NULL NULL NULL 2
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+a
+1
+1
+set optimizer_switch='semijoin=off,materialization=on';
+EXPLAIN
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2
+2 MATERIALIZED t2inner ALL NULL NULL NULL NULL 2
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using where
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+a
+1
+1
+set optimizer_switch='semijoin=on,materialization=off';
+EXPLAIN
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Start temporary
+1 PRIMARY t2inner ALL NULL NULL NULL NULL 2
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+a
+1
+1
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE t1,t2,t3;
+#
+# BUG#52329 - Wrong result: subquery materialization, IN,
+# non-null field followed by nullable
+#
+CREATE TABLE t1 (a1 CHAR(8) NOT NULL, a2 char(8) NOT NULL);
+CREATE TABLE t2a (b1 char(8), b2 char(8));
+CREATE TABLE t2b (b1 CHAR(8), b2 char(8) NOT NULL);
+CREATE TABLE t2c (b1 CHAR(8) NOT NULL, b2 char(8));
+INSERT INTO t1 VALUES ('1 - 12', '2 - 22');
+INSERT INTO t2a VALUES ('1 - 11', '2 - 21'),
+('1 - 11', '2 - 21'),
+('1 - 12', '2 - 22'),
+('1 - 12', '2 - 22'),
+('1 - 13', '2 - 23');
+INSERT INTO t2b SELECT * FROM t2a;
+INSERT INTO t2c SELECT * FROM t2a;
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=off,materialization=on';
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2c WHERE b1 > '0' GROUP BY b1, b2);
+a1 a2
+1 - 12 2 - 22
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2a WHERE b1 > '0');
+a1 a2
+1 - 12 2 - 22
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2b WHERE b1 > '0');
+a1 a2
+1 - 12 2 - 22
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2c WHERE b1 > '0');
+a1 a2
+1 - 12 2 - 22
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE t1,t2a,t2b,t2c;
+#
+# Bug#57623: subquery within before insert trigger causes crash (sj=on)
+#
+CREATE TABLE ot1(a INT);
+CREATE TABLE ot2(a INT);
+CREATE TABLE ot3(a INT);
+CREATE TABLE it1(a INT);
+INSERT INTO ot1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
+INSERT INTO ot2 VALUES(0),(2),(4),(6);
+INSERT INTO ot3 VALUES(0),(3),(6);
+INSERT INTO it1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=on';
+set optimizer_switch='materialization=off';
+explain SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot1 ALL NULL NULL NULL NULL 8
+1 PRIMARY ot3 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY ot2 ALL NULL NULL NULL NULL 4 Using where
+2 DEPENDENT SUBQUERY it1 ALL NULL NULL NULL NULL 8 Using where
+SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+a a a
+0 0 0
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+6 6 6
+7 NULL NULL
+prepare s from 'SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1)';
+execute s;
+a a a
+0 0 0
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+6 6 6
+7 NULL NULL
+execute s;
+a a a
+0 0 0
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+6 6 6
+7 NULL NULL
+deallocate prepare s;
+set optimizer_switch='materialization=on';
+explain SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot1 ALL NULL NULL NULL NULL 8
+1 PRIMARY ot3 ALL NULL NULL NULL NULL 3 Using where
+1 PRIMARY ot2 ALL NULL NULL NULL NULL 4 Using where
+2 MATERIALIZED it1 ALL NULL NULL NULL NULL 8
+SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+a a a
+0 0 0
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+6 6 6
+7 NULL NULL
+prepare s from 'SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1)';
+execute s;
+a a a
+0 0 0
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+6 6 6
+7 NULL NULL
+execute s;
+a a a
+0 0 0
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+6 6 6
+7 NULL NULL
+deallocate prepare s;
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE ot1, ot2, ot3, it1;
+#
+# Bug#59919/11766739: Crash in tmp_table_param::init() with semijoin=on
+#
+CREATE TABLE t1 (f1 INTEGER) ENGINE=MyISAM;
+CREATE TABLE t2 (f1 INTEGER, f2 INTEGER) ENGINE=MyISAM;
+CREATE TABLE t3 (f1 INTEGER, f2 INTEGER) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1,1), (2,1);
+INSERT INTO t3 VALUES
+(1,1), (2,1), (5,4), (7,3), (8,2), (8,1), (7,3),
+(9,5), (4,3), (7,2), (7,7), (3,1), (5,8), (9,7);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=off,materialization=on';
+EXPLAIN
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t3 ALL NULL NULL NULL NULL 14 Using where
+2 MATERIALIZED t1 system NULL NULL NULL NULL 1
+2 MATERIALIZED b1 ALL NULL NULL NULL NULL 2 Using where
+2 MATERIALIZED b2 ALL NULL NULL NULL NULL 2
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+f1 f2
+1 1
+2 1
+8 1
+3 1
+set optimizer_switch='semijoin=on,materialization=on';
+EXPLAIN
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 system NULL NULL NULL NULL 1
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1
+1 PRIMARY t3 ALL NULL NULL NULL NULL 14 Using where; Using join buffer (flat, BNL join)
+2 MATERIALIZED b1 ALL NULL NULL NULL NULL 2 Using where
+2 MATERIALIZED b2 ALL NULL NULL NULL NULL 2
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+f1 f2
+1 1
+2 1
+8 1
+3 1
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE t1, t2, t3 ;
+#
#
# BUG#784723: Wrong result with semijoin + nested subqueries in maria-5.3
#
@@ -2179,4 +2537,105 @@ WHERE c = b AND b = a
a COUNT(*)
NULL 0
DROP TABLE t1, t2, t3;
+#
+# BUG#920255: Wrong result (extra rows) with loosescan and IN subquery
+#
+CREATE TABLE t1 ( a INT PRIMARY KEY, b INT, KEY(b) );
+INSERT INTO t1 VALUES
+(1,2),(2,1),(3,3),(4,2),(5,5),
+(6,3),(7,1),(8,4),(9,3),(10,2);
+CREATE TABLE t2 ( c INT, d INT, UNIQUE KEY(c) );
+INSERT INTO t2 VALUES
+(1,2),(2,1),(3,3),(4,2),(5,5),(6,3),(7,1);
+SELECT a, b, d FROM t1, t2
+WHERE ( b, d ) IN
+( SELECT b, d FROM t1, t2 WHERE b = c );
+a b d
+2 1 2
+7 1 2
+2 1 2
+7 1 2
+1 2 1
+4 2 1
+10 2 1
+1 2 1
+4 2 1
+10 2 1
+3 3 3
+6 3 3
+9 3 3
+3 3 3
+6 3 3
+9 3 3
+8 4 2
+8 4 2
+5 5 5
+DROP TABLE t1, t2;
+#
+# BUG#920713: Wrong result (missing rows) with firstmatch+BNL, IN subquery, ...
+#
+CREATE TABLE t1 ( a VARCHAR(1) ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('e'),('w'),('a'),('h'),('x'),('k'),('g');
+CREATE TABLE t2 ( b INT, c VARCHAR(1) );
+INSERT INTO t2 VALUES (0,'j'),(8,'v');
+SELECT * FROM t1 alias1, t2 alias2
+WHERE alias2.c IN (
+SELECT alias4.c FROM t1 alias3, t2 alias4
+);
+a b c
+e 0 j
+e 8 v
+w 0 j
+w 8 v
+a 0 j
+a 8 v
+h 0 j
+h 8 v
+x 0 j
+x 8 v
+k 0 j
+k 8 v
+g 0 j
+g 8 v
+DROP TABLE t1, t2;
+#
+# BUG#923246: Loosescan reports different result than other semijoin methods
+#
+set @tmp_923246= @@optimizer_switch;
+set optimizer_switch='mrr=on,materialization=off';
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (kp1 int, kp2 int, c int, filler char(100), key(kp1, kp2));
+insert into t1 select A.a+10*(B.a+10*C.a), 0, 0, 'filler' from t0 A, t0 B, t0 C;
+insert into t1 select * from t1 where kp1 < 20;
+create table t3 (a int);
+insert into t3 select A.a + 10*B.a from t0 A, t0 B;
+select * from t3 where a in (select kp1 from t1 where kp1<20);
+a
+0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+explain select * from t3 where a in (select kp1 from t1 where kp1<20);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range kp1 kp1 5 NULL 48 Using where; Using index; LooseScan
+1 PRIMARY t3 ALL NULL NULL NULL NULL 100 Using where; Using join buffer (flat, BNL join)
+drop table t0,t1,t3;
+set optimizer_switch= @tmp_923246;
set optimizer_switch=@subselect_sj_tmp;
diff --git a/mysql-test/r/subselect_sj2.result b/mysql-test/r/subselect_sj2.result
index 85a3b6971bd..2d8c189942e 100644
--- a/mysql-test/r/subselect_sj2.result
+++ b/mysql-test/r/subselect_sj2.result
@@ -886,5 +886,19 @@ a b b a
c c NULL NULL
DROP VIEW v1;
DROP TABLE t1,t2,t3,t4;
+#
+# BUG#912538: Wrong result (missing rows) with semijoin=on, firstmatch=on, ...
+#
+CREATE TABLE t1 ( a INT NOT NULL, UNIQUE KEY(a) );
+INSERT INTO t1 VALUES (1),(2),(3),(4);
+CREATE TABLE t2 ( b INT, c INT ) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1,1);
+SELECT * FROM t1, t2 WHERE c IN (SELECT c FROM t1, t2 WHERE a = b);
+a b c
+1 1 1
+2 1 1
+3 1 1
+4 1 1
+DROP TABLE t1,t2;
# This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp;
diff --git a/mysql-test/r/subselect_sj2_jcl6.result b/mysql-test/r/subselect_sj2_jcl6.result
index b179a735f20..f2895662196 100644
--- a/mysql-test/r/subselect_sj2_jcl6.result
+++ b/mysql-test/r/subselect_sj2_jcl6.result
@@ -900,6 +900,20 @@ a b b a
c c NULL NULL
DROP VIEW v1;
DROP TABLE t1,t2,t3,t4;
+#
+# BUG#912538: Wrong result (missing rows) with semijoin=on, firstmatch=on, ...
+#
+CREATE TABLE t1 ( a INT NOT NULL, UNIQUE KEY(a) );
+INSERT INTO t1 VALUES (1),(2),(3),(4);
+CREATE TABLE t2 ( b INT, c INT ) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1,1);
+SELECT * FROM t1, t2 WHERE c IN (SELECT c FROM t1, t2 WHERE a = b);
+a b c
+1 1 1
+2 1 1
+3 1 1
+4 1 1
+DROP TABLE t1,t2;
# This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp;
#
@@ -921,9 +935,9 @@ SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b
WHERE c IN (SELECT t4.b FROM t4 JOIN t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 1 Using where
-1 PRIMARY t2 ALL NULL NULL NULL NULL 1
+1 PRIMARY t2 ALL NULL NULL NULL NULL 1 FirstMatch(t3)
1 PRIMARY t1 ref b b 4 test.t3.b 1 Using index
-1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t2)
+1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1)
SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b
WHERE c IN (SELECT t4.b FROM t4 JOIN t2);
b c
@@ -949,12 +963,13 @@ EXPLAIN
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 1
-1 PRIMARY t4 ALL NULL NULL NULL NULL 1 Using where
+1 PRIMARY t4 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t2)
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
-1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1 Using where; FirstMatch(t4)
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1 Using where; FirstMatch(t1)
SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk);
pk a b
1 6 8
+2 8 8
set optimizer_switch=@tmp_optimizer_switch;
set join_cache_level=default;
DROP TABLE t1,t2,t3,t4;
diff --git a/mysql-test/r/subselect_sj2_mat.result b/mysql-test/r/subselect_sj2_mat.result
index 0284bab0972..3e68c9ebeb5 100644
--- a/mysql-test/r/subselect_sj2_mat.result
+++ b/mysql-test/r/subselect_sj2_mat.result
@@ -888,6 +888,20 @@ a b b a
c c NULL NULL
DROP VIEW v1;
DROP TABLE t1,t2,t3,t4;
+#
+# BUG#912538: Wrong result (missing rows) with semijoin=on, firstmatch=on, ...
+#
+CREATE TABLE t1 ( a INT NOT NULL, UNIQUE KEY(a) );
+INSERT INTO t1 VALUES (1),(2),(3),(4);
+CREATE TABLE t2 ( b INT, c INT ) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (1,1);
+SELECT * FROM t1, t2 WHERE c IN (SELECT c FROM t1, t2 WHERE a = b);
+a b c
+1 1 1
+2 1 1
+3 1 1
+4 1 1
+DROP TABLE t1,t2;
# This must be the last in the file:
set optimizer_switch=@subselect_sj2_tmp;
set optimizer_switch=default;
diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result
index 88acba0ebea..8bb262af7ca 100644
--- a/mysql-test/r/subselect_sj_jcl6.result
+++ b/mysql-test/r/subselect_sj_jcl6.result
@@ -1244,6 +1244,364 @@ IN (SELECT t3.pk, t3.pk FROM t2 LEFT JOIN t3 ON t3.varchar_key)
AND pk = 9;
datetime_key
DROP TABLE t1, t2, t3;
+#
+# BUG#53060: LooseScan semijoin strategy does not return all rows
+#
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=on,materialization=off';
+set optimizer_switch='firstmatch=off,loosescan=on';
+CREATE TABLE t1 (i INTEGER);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE TABLE t2 (i INTEGER, j INTEGER, KEY k(i, j));
+INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1);
+EXPLAIN
+SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t2 index k k 10 NULL 4 Using where; Using index; LooseScan
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
+i
+1
+2
+DROP TABLE t1, t2;
+set optimizer_switch=@save_optimizer_switch;
+#
+# BUG#49453: re-execution of prepared statement with view
+# and semijoin crashes
+#
+CREATE TABLE t1 (city VARCHAR(50), country_id INT);
+CREATE TABLE t2 (country_id INT, country VARCHAR(50));
+INSERT INTO t1 VALUES
+('Batna',2),('Bchar',2),('Skikda',2),('Tafuna',3),('Algeria',2) ;
+INSERT INTO t2 VALUES (2,'Algeria'),(2,'AlgeriaDup'),(3,'XAmerican Samoa');
+CREATE VIEW v1 AS
+SELECT country_id as vf_country_id
+FROM t2
+WHERE LEFT(country,1) = "A";
+PREPARE stmt FROM "
+SELECT city, country_id
+FROM t1
+WHERE country_id IN (SELECT vf_country_id FROM v1);
+";
+
+EXECUTE stmt;
+city country_id
+Batna 2
+Bchar 2
+Skikda 2
+Algeria 2
+EXECUTE stmt;
+city country_id
+Batna 2
+Bchar 2
+Skikda 2
+Algeria 2
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#
+# Bug#54437 Extra rows with LEFT JOIN + semijoin
+#
+create table t1 (a int);
+create table t2 (a int);
+create table t3 (a int);
+insert into t1 values(1),(1);
+insert into t2 values(1),(1),(1),(1);
+insert into t3 values(2),(2);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='materialization=off';
+set optimizer_switch='semijoin=off';
+explain
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using where
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+a
+1
+1
+set optimizer_switch='semijoin=on';
+explain
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2
+1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (incremental, BNL join)
+select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
+a
+1
+1
+set optimizer_switch=@save_optimizer_switch;
+drop table t1,t2,t3;
+#
+# Bug#55955: crash in MEMORY engine with IN(LEFT JOIN (JOIN))
+#
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT);
+CREATE TABLE t3 (a INT);
+INSERT INTO t1 VALUES(1),(1);
+INSERT INTO t2 VALUES(1),(1);
+INSERT INTO t3 VALUES(2),(2);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=off,materialization=off';
+EXPLAIN
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
+2 DEPENDENT SUBQUERY t2inner ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
+2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+a
+1
+1
+set optimizer_switch='semijoin=off,materialization=on';
+EXPLAIN
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
+2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2
+2 MATERIALIZED t2inner ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join)
+2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+a
+1
+1
+set optimizer_switch='semijoin=on,materialization=off';
+EXPLAIN
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 2
+1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Start temporary; Using join buffer (flat, BNL join)
+1 PRIMARY t2inner ALL NULL NULL NULL NULL 2 Using join buffer (incremental, BNL join)
+1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (incremental, BNL join)
+SELECT * FROM t1
+WHERE t1.a IN (SELECT t2.a
+FROM t2 LEFT JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
+a
+1
+1
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE t1,t2,t3;
+#
+# BUG#52329 - Wrong result: subquery materialization, IN,
+# non-null field followed by nullable
+#
+CREATE TABLE t1 (a1 CHAR(8) NOT NULL, a2 char(8) NOT NULL);
+CREATE TABLE t2a (b1 char(8), b2 char(8));
+CREATE TABLE t2b (b1 CHAR(8), b2 char(8) NOT NULL);
+CREATE TABLE t2c (b1 CHAR(8) NOT NULL, b2 char(8));
+INSERT INTO t1 VALUES ('1 - 12', '2 - 22');
+INSERT INTO t2a VALUES ('1 - 11', '2 - 21'),
+('1 - 11', '2 - 21'),
+('1 - 12', '2 - 22'),
+('1 - 12', '2 - 22'),
+('1 - 13', '2 - 23');
+INSERT INTO t2b SELECT * FROM t2a;
+INSERT INTO t2c SELECT * FROM t2a;
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=off,materialization=on';
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2c WHERE b1 > '0' GROUP BY b1, b2);
+a1 a2
+1 - 12 2 - 22
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2a WHERE b1 > '0');
+a1 a2
+1 - 12 2 - 22
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2b WHERE b1 > '0');
+a1 a2
+1 - 12 2 - 22
+SELECT * FROM t1
+WHERE (a1, a2) IN (
+SELECT b1, b2 FROM t2c WHERE b1 > '0');
+a1 a2
+1 - 12 2 - 22
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE t1,t2a,t2b,t2c;
+#
+# Bug#57623: subquery within before insert trigger causes crash (sj=on)
+#
+CREATE TABLE ot1(a INT);
+CREATE TABLE ot2(a INT);
+CREATE TABLE ot3(a INT);
+CREATE TABLE it1(a INT);
+INSERT INTO ot1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
+INSERT INTO ot2 VALUES(0),(2),(4),(6);
+INSERT INTO ot3 VALUES(0),(3),(6);
+INSERT INTO it1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=on';
+set optimizer_switch='materialization=off';
+explain SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot1 ALL NULL NULL NULL NULL 8
+1 PRIMARY ot3 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY ot2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (incremental, BNL join)
+2 DEPENDENT SUBQUERY it1 ALL NULL NULL NULL NULL 8 Using where
+SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+a a a
+0 0 0
+6 6 6
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+7 NULL NULL
+prepare s from 'SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1)';
+execute s;
+a a a
+0 0 0
+6 6 6
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+7 NULL NULL
+execute s;
+a a a
+0 0 0
+6 6 6
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+7 NULL NULL
+deallocate prepare s;
+set optimizer_switch='materialization=on';
+explain SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY ot1 ALL NULL NULL NULL NULL 8
+1 PRIMARY ot3 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
+1 PRIMARY ot2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (incremental, BNL join)
+2 MATERIALIZED it1 ALL NULL NULL NULL NULL 8
+SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
+a a a
+0 0 0
+6 6 6
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+7 NULL NULL
+prepare s from 'SELECT *
+FROM ot1
+LEFT JOIN
+(ot2 JOIN ot3 on ot2.a=ot3.a)
+ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1)';
+execute s;
+a a a
+0 0 0
+6 6 6
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+7 NULL NULL
+execute s;
+a a a
+0 0 0
+6 6 6
+1 NULL NULL
+2 NULL NULL
+3 NULL NULL
+4 NULL NULL
+5 NULL NULL
+7 NULL NULL
+deallocate prepare s;
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE ot1, ot2, ot3, it1;
+#
+# Bug#59919/11766739: Crash in tmp_table_param::init() with semijoin=on
+#
+CREATE TABLE t1 (f1 INTEGER) ENGINE=MyISAM;
+CREATE TABLE t2 (f1 INTEGER, f2 INTEGER) ENGINE=MyISAM;
+CREATE TABLE t3 (f1 INTEGER, f2 INTEGER) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (1,1), (2,1);
+INSERT INTO t3 VALUES
+(1,1), (2,1), (5,4), (7,3), (8,2), (8,1), (7,3),
+(9,5), (4,3), (7,2), (7,7), (3,1), (5,8), (9,7);
+set @save_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='semijoin=off,materialization=on';
+EXPLAIN
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t3 ALL NULL NULL NULL NULL 14 Using where
+2 MATERIALIZED t1 system NULL NULL NULL NULL 1
+2 MATERIALIZED b1 ALL NULL NULL NULL NULL 2 Using where
+2 MATERIALIZED b2 ALL NULL NULL NULL NULL 2
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+f1 f2
+1 1
+2 1
+8 1
+3 1
+set optimizer_switch='semijoin=on,materialization=on';
+EXPLAIN
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 system NULL NULL NULL NULL 1
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1
+1 PRIMARY t3 ALL NULL NULL NULL NULL 14 Using where; Using join buffer (flat, BNL join)
+2 MATERIALIZED b1 ALL NULL NULL NULL NULL 2 Using where
+2 MATERIALIZED b2 ALL NULL NULL NULL NULL 2
+SELECT * FROM t3
+WHERE f2 IN (SELECT t1.f1
+FROM t1 LEFT OUTER JOIN (t2 AS b1 JOIN t2 AS b2 ON TRUE) ON TRUE);
+f1 f2
+1 1
+2 1
+8 1
+3 1
+set optimizer_switch=@save_optimizer_switch;
+DROP TABLE t1, t2, t3 ;
+#
#
# BUG#784723: Wrong result with semijoin + nested subqueries in maria-5.3
#
@@ -2193,6 +2551,107 @@ WHERE c = b AND b = a
a COUNT(*)
NULL 0
DROP TABLE t1, t2, t3;
+#
+# BUG#920255: Wrong result (extra rows) with loosescan and IN subquery
+#
+CREATE TABLE t1 ( a INT PRIMARY KEY, b INT, KEY(b) );
+INSERT INTO t1 VALUES
+(1,2),(2,1),(3,3),(4,2),(5,5),
+(6,3),(7,1),(8,4),(9,3),(10,2);
+CREATE TABLE t2 ( c INT, d INT, UNIQUE KEY(c) );
+INSERT INTO t2 VALUES
+(1,2),(2,1),(3,3),(4,2),(5,5),(6,3),(7,1);
+SELECT a, b, d FROM t1, t2
+WHERE ( b, d ) IN
+( SELECT b, d FROM t1, t2 WHERE b = c );
+a b d
+1 2 1
+1 2 1
+2 1 2
+2 1 2
+3 3 3
+3 3 3
+4 2 1
+4 2 1
+5 5 5
+6 3 3
+6 3 3
+7 1 2
+7 1 2
+8 4 2
+8 4 2
+9 3 3
+9 3 3
+10 2 1
+10 2 1
+DROP TABLE t1, t2;
+#
+# BUG#920713: Wrong result (missing rows) with firstmatch+BNL, IN subquery, ...
+#
+CREATE TABLE t1 ( a VARCHAR(1) ) ENGINE=MyISAM;
+INSERT INTO t1 VALUES ('e'),('w'),('a'),('h'),('x'),('k'),('g');
+CREATE TABLE t2 ( b INT, c VARCHAR(1) );
+INSERT INTO t2 VALUES (0,'j'),(8,'v');
+SELECT * FROM t1 alias1, t2 alias2
+WHERE alias2.c IN (
+SELECT alias4.c FROM t1 alias3, t2 alias4
+);
+a b c
+e 0 j
+e 8 v
+w 0 j
+w 8 v
+a 0 j
+a 8 v
+h 0 j
+h 8 v
+x 0 j
+x 8 v
+k 0 j
+k 8 v
+g 0 j
+g 8 v
+DROP TABLE t1, t2;
+#
+# BUG#923246: Loosescan reports different result than other semijoin methods
+#
+set @tmp_923246= @@optimizer_switch;
+set optimizer_switch='mrr=on,materialization=off';
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (kp1 int, kp2 int, c int, filler char(100), key(kp1, kp2));
+insert into t1 select A.a+10*(B.a+10*C.a), 0, 0, 'filler' from t0 A, t0 B, t0 C;
+insert into t1 select * from t1 where kp1 < 20;
+create table t3 (a int);
+insert into t3 select A.a + 10*B.a from t0 A, t0 B;
+select * from t3 where a in (select kp1 from t1 where kp1<20);
+a
+0
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+explain select * from t3 where a in (select kp1 from t1 where kp1<20);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 range kp1 kp1 5 NULL 48 Using where; Using index; LooseScan
+1 PRIMARY t3 ALL NULL NULL NULL NULL 100 Using where; Using join buffer (flat, BNL join)
+drop table t0,t1,t3;
+set optimizer_switch= @tmp_923246;
set optimizer_switch=@subselect_sj_tmp;
#
# BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off
@@ -2274,6 +2733,35 @@ w 5 19:11:10
set optimizer_switch=@save_optimizer_switch;
set join_cache_level=default;
DROP TABLE t1,t2,t3;
+#
+# BUG#912513: Wrong result (missing rows) with join_cache_hashed+materialization+semijoin=on
+#
+set @os_912513= @@optimizer_switch;
+set @jcl_912513= @@join_cache_level;
+SET optimizer_switch = 'semijoin=on,materialization=on,join_cache_hashed=on';
+SET join_cache_level = 3;
+CREATE TABLE t1 ( a INT, b INT, KEY(a) );
+INSERT INTO t1 VALUES
+(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7);
+CREATE TABLE t2 ( c INT );
+INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7);
+SELECT alias1.* FROM
+t1 AS alias1 INNER JOIN t1 AS alias2
+ON alias2.a = alias1.b
+WHERE alias1.b IN (
+SELECT a FROM t1, t2
+);
+a b
+1 1
+2 2
+3 3
+4 4
+5 5
+6 6
+7 7
+DROP table t1, t2;
+set @@optimizer_switch= @os_912513;
+set @@join_cache_level= @jcl_912513;
# End
set join_cache_level=default;
show variables like 'join_cache_level';
diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result
index ee8a365327c..b3a205eb071 100644
--- a/mysql-test/r/subselect_sj_mat.result
+++ b/mysql-test/r/subselect_sj_mat.result
@@ -1849,6 +1849,42 @@ a b c
4 4 2
4 4 4
DROP TABLE t1,t2;
+#
+# BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*)
+#
+CREATE TABLE t1 ( a VARCHAR(3) );
+CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) );
+INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron');
+EXPLAIN
+SELECT * FROM
+( SELECT * FROM t1 ) AS alias1,
+t2 AS alias2
+WHERE b = a AND a IN (
+SELECT alias3.c
+FROM t2 AS alias3, t2 AS alias4
+WHERE alias4.c = alias3.b
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+DROP TABLE t1,t2;
+#
+# BUG#928048: Query containing IN subquery with OR in the where clause returns a wrong result
+#
+create table t1 (a int, b int);
+insert into t1 values (7,5), (3,3), (5,4), (9,3);
+create table t2 (a int, b int, index i_a(a));
+insert into t2 values
+(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1);
+explain select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
+2 MATERIALIZED t2 ALL i_a NULL NULL NULL 8 Using where
+select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
+a b
+7 5
+3 3
+drop table t1,t2;
# This must be at the end:
set optimizer_switch=@subselect_sj_mat_tmp;
set join_cache_level=@save_join_cache_level;
diff --git a/mysql-test/r/sum_distinct.result b/mysql-test/r/sum_distinct.result
index c615817f52d..2746f5a09f4 100644
--- a/mysql-test/r/sum_distinct.result
+++ b/mysql-test/r/sum_distinct.result
@@ -95,3 +95,15 @@ SELECT SUM(DISTINCT id % 11) FROM t1;
SUM(DISTINCT id % 11)
55
DROP TABLE t1;
+#
+# Bug #777654: empty subselect in FROM clause returning
+# SUM(DISTINCT) over non-nullable field
+#
+CREATE TABLE t1 (a int NOT NULL) ;
+SELECT SUM(DISTINCT a) FROM t1;
+SUM(DISTINCT a)
+NULL
+SELECT * FROM (SELECT SUM(DISTINCT a) FROM t1) AS t;
+SUM(DISTINCT a)
+NULL
+DROP TABLE t1;
diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result
index 54170ae3dad..427374fd995 100644
--- a/mysql-test/r/update.result
+++ b/mysql-test/r/update.result
@@ -277,6 +277,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
update t1 set a=9999 order by a limit 1;
@@ -289,6 +290,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 2
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 9
flush status;
delete from t1 order by a limit 1;
@@ -300,6 +302,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
flush status;
delete from t1 order by a desc limit 1;
@@ -311,6 +314,7 @@ Handler_read_last 1
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
alter table t1 disable keys;
flush status;
@@ -323,7 +327,8 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 1
-Handler_read_rnd_next 9
+Handler_read_rnd_deleted 2
+Handler_read_rnd_next 7
select * from t1;
a b
0 0
@@ -377,6 +382,7 @@ Handler_read_last 0
Handler_read_next 1
Handler_read_prev 0
Handler_read_rnd 1
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
drop table t1, t2;
create table t1(f1 int, `*f2` int);
@@ -415,6 +421,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
SELECT user_id FROM t1 WHERE request_id=999999999999999999999999999999;
user_id
@@ -426,6 +433,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
UPDATE t1 SET user_id=null WHERE request_id=9999999999999;
show status like '%Handler_read%';
@@ -436,6 +444,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
UPDATE t1 SET user_id=null WHERE request_id=999999999999999999999999999999;
show status like '%Handler_read%';
@@ -446,6 +455,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 0
DROP TABLE t1;
CREATE TABLE t1 (
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index f2d3820ff58..9b6ae60b3b5 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -304,7 +304,7 @@ a+1
4
explain select * from v1;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <derived2> ALL NULL NULL NULL NULL 4
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
2 DERIVED t1 ALL NULL NULL NULL NULL 4 Using filesort
drop view v1;
drop table t1;
@@ -4045,6 +4045,63 @@ drop table t1,t2;
# -- End of 5.1 tests.
# -----------------------------------------------------------------
#
+# Bug #794005: crash in st_table::mark_virtual_columns_for_write
+#
+CREATE TABLE t1 (a int);
+insert into t1 values (1);
+CREATE TABLE t2 (a int);
+insert into t2 values (1);
+CREATE VIEW v2 AS SELECT * FROM t2;
+CREATE VIEW v1 AS SELECT * FROM v2;
+CREATE VIEW v3 AS SELECT t2.a,v1.a as b FROM t2,v1 where t2.a=v1.a;
+CREATE OR REPLACE ALGORITHM = TEMPTABLE VIEW v2 AS SELECT * FROM t1;
+UPDATE v1 SET a = 10;
+ERROR HY000: The target table v1 of the UPDATE is not updatable
+REPLACE v1 SET a = 10;
+ERROR HY000: The target table v1 of the INSERT is not insertable-into
+INSERT into v1 values (20);
+ERROR HY000: The target table v1 of the INSERT is not insertable-into
+DELETE from v1;
+ERROR HY000: The target table v1 of the DELETE is not updatable
+UPDATE v3 SET b= 10;
+ERROR HY000: The target table v2 of the UPDATE is not updatable
+REPLACE v3 SET b= 10;
+ERROR HY000: The target table v3 of the INSERT is not insertable-into
+INSERT into v3(b) values (20);
+ERROR HY000: The target table v3 of the INSERT is not insertable-into
+DELETE from v3 where b=20;
+ERROR HY000: Can not delete from join view 'test.v3'
+DELETE from v3 where a=20;
+ERROR HY000: Can not delete from join view 'test.v3'
+DELETE v1 from v1,t1 where v1.a=t1.a;
+ERROR HY000: The target table v1 of the DELETE is not updatable
+UPDATE v3 SET a = 10;
+REPLACE v3 SET a = 11;
+INSERT INTO v3(a) values (20);
+select * from t1;
+a
+1
+select * from t2;
+a
+10
+11
+20
+CREATE OR REPLACE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM t2;
+DELETE from v1 where a=11;
+DELETE v1 from v1,t1 where v1.a=t1.a;
+select * from t1;
+a
+1
+select * from t2;
+a
+10
+20
+DROP VIEW v1,v2,v3;
+DROP TABLE t1,t2;
+# -----------------------------------------------------------------
+# -- End of 5.2 tests.
+# -----------------------------------------------------------------
+#
# Bug #59696 Optimizer does not use equalities for conditions over view
#
CREATE TABLE t1 (a int NOT NULL);
@@ -4075,6 +4132,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
CREATE VIEW v AS SELECT * FROM t2;
EXPLAIN EXTENDED
@@ -4097,6 +4155,7 @@ Handler_read_last 0
Handler_read_next 0
Handler_read_prev 0
Handler_read_rnd 0
+Handler_read_rnd_deleted 0
Handler_read_rnd_next 17
DROP VIEW v;
DROP TABLE t1, t2;
@@ -4569,4 +4628,7 @@ NULL NULL 1 0
NULL NULL 1 0
DROP VIEW v2;
DROP TABLE t1, t2, t3;
+# -----------------------------------------------------------------
+# -- End of 5.3 tests.
+# -----------------------------------------------------------------
SET optimizer_switch=@save_optimizer_switch;