Commit c1de6f8b authored by Sergey Petrunya's avatar Sergey Petrunya

Change the default @@optimizer_switch setting from

  semijoin=on,firstmatch=on,loosescan=on
to
  semijoin=off,firstmatch=off,loosescan=off
Adjust the testcases:
- Modify subselect*.test and join_cache.test so that all tests
  use the same execution paths as before (i.e. optimizations that
  are being tested are enabled)
- Let all other test files run with the new default settings (i.e.
  with new optimizations disabled)
- Copy subquery testcases from these files into t/subselect_extra.test
  which will run them with new optimizations enabled.
parent 3984062b
...@@ -199,16 +199,16 @@ insert into t2 values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1'); ...@@ -199,16 +199,16 @@ insert into t2 values ('2001-01-01 1:1:1'), ('2001-01-01 1:1:1');
flush tables; flush tables;
EXPLAIN SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL ); EXPLAIN SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY OUTR ALL NULL NULL NULL NULL 2 Using where; Start temporary 1 PRIMARY OUTR ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY INNR ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY INNR ALL NULL NULL NULL NULL 2 Using where
flush tables; flush tables;
SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL ); SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN (SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.dt IS NULL );
dt dt
flush tables; flush tables;
EXPLAIN SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN ( SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.t < '2005-11-13 7:41:31' ); EXPLAIN SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN ( SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.t < '2005-11-13 7:41:31' );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY OUTR ALL NULL NULL NULL NULL 2 Using where; Start temporary 1 PRIMARY OUTR ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY INNR ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY INNR ALL NULL NULL NULL NULL 2 Using where
flush tables; flush tables;
SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN ( SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.t < '2005-11-13 7:41:31' ); SELECT OUTR.dt FROM t1 AS OUTR WHERE OUTR.dt IN ( SELECT INNR.dt FROM t2 AS INNR WHERE OUTR.t < '2005-11-13 7:41:31' );
dt dt
......
...@@ -1542,8 +1542,8 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1542,8 +1542,8 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT 1 FROM t1 WHERE a IN EXPLAIN SELECT 1 FROM t1 WHERE a IN
(SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2)); (SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index PRIMARY,i2 PRIMARY 4 NULL 144 Using index 1 PRIMARY t1 index NULL PRIMARY 4 NULL 144 Using where; Using index
1 PRIMARY t1 ALL NULL NULL NULL NULL 144 Using where; FirstMatch(t1) 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 144 Using where
CREATE TABLE t2 (a INT, b INT, KEY(a)); CREATE TABLE t2 (a INT, b INT, KEY(a));
INSERT INTO t2 VALUES (1, 1), (2, 2), (3,3), (4,4); INSERT INTO t2 VALUES (1, 1), (2, 2), (3,3), (4,4);
EXPLAIN SELECT a, SUM(b) FROM t2 GROUP BY a LIMIT 2; EXPLAIN SELECT a, SUM(b) FROM t2 GROUP BY a LIMIT 2;
...@@ -1555,8 +1555,8 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1555,8 +1555,8 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT 1 FROM t2 WHERE a IN EXPLAIN SELECT 1 FROM t2 WHERE a IN
(SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2)); (SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 index a a 5 NULL 4 Using index 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index
1 PRIMARY t1 ALL NULL NULL NULL NULL 144 Using where; FirstMatch(t2) 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 144 Using where
SHOW VARIABLES LIKE 'old'; SHOW VARIABLES LIKE 'old';
Variable_name Value Variable_name Value
old OFF old OFF
......
...@@ -1432,7 +1432,7 @@ group by a1,a2,b; ...@@ -1432,7 +1432,7 @@ group by a1,a2,b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by 1 PRIMARY t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by
2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index 2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index
2 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index; FirstMatch(t2) 3 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index
select a1,a2,b,c,min(c), max(c) from t1 select a1,a2,b,c,min(c), max(c) from t1
where exists ( select * from t2 where exists ( select * from t2
where t2.c in (select c from t3 where t3.c > t1.b) and where t2.c in (select c from t3 where t3.c > t1.b) and
...@@ -1489,7 +1489,7 @@ group by a1,a2,b; ...@@ -1489,7 +1489,7 @@ group by a1,a2,b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index 1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index
2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index 2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index
2 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index; FirstMatch(t2) 3 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index
select a1,a2,b,c,min(c), max(c) from t1 select a1,a2,b,c,min(c), max(c) from t1
where exists ( select * from t2 where exists ( select * from t2
where t2.c in (select c from t3 where t3.c > t1.c) and where t2.c in (select c from t3 where t3.c > t1.c) and
......
DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11; DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
DROP DATABASE IF EXISTS world; DROP DATABASE IF EXISTS world;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
set @@optimizer_switch='semijoin_with_cache=on'; set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on'; set @@optimizer_switch='outer_join_with_cache=on';
set names utf8; set names utf8;
......
This diff is collapsed.
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
drop view if exists v2; drop view if exists v2;
set @save_optimizer_switch=@@optimizer_switch; set @subselect_tmp=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test,
"semijoin=on,firstmatch=on,loosescan=on,partial_match_rowid_merge=off,partial_match_table_scan=off");
select (select 2); select (select 2);
(select 2) (select 2)
2 2
...@@ -4803,7 +4804,6 @@ SELECT 1 FROM t1 GROUP BY ...@@ -4803,7 +4804,6 @@ SELECT 1 FROM t1 GROUP BY
1 1
1 1
DROP TABLE t1; DROP TABLE t1;
set @@optimizer_switch=@save_optimizer_switch;
# #
# Bug #49512 : subquery with aggregate function crash # Bug #49512 : subquery with aggregate function crash
# subselect_single_select_engine::exec() # subselect_single_select_engine::exec()
...@@ -5127,3 +5127,4 @@ ON t2.f10 = t3.f10 ...@@ -5127,3 +5127,4 @@ ON t2.f10 = t3.f10
f1 f1
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
End of 5.3 tests End of 5.3 tests
set optimizer_switch=@subselect_tmp;
drop table if exists t1, t2, t3, t4; drop table if exists t1, t2, t3, t4;
set @subselect2_test_tmp=@@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on';
CREATE TABLE t1 CREATE TABLE t1
( (
DOCID VARCHAR(32)BINARY NOT NULL DOCID VARCHAR(32)BINARY NOT NULL
...@@ -144,3 +146,4 @@ and t2.a='1' AND t1.a=t3.b) > 0; ...@@ -144,3 +146,4 @@ and t2.a='1' AND t1.a=t3.b) > 0;
a a
2 2
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
set optimizer_switch=@subselect2_test_tmp;
drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22; drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22;
set @save_optimizer_switch=@@optimizer_switch; set @subselect3_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
create table t1 (oref int, grp int, ie int) ; create table t1 (oref int, grp int, ie int) ;
insert into t1 (oref, grp, ie) values insert into t1 (oref, grp, ie) values
(1, 1, 1), (1, 1, 1),
...@@ -698,7 +699,6 @@ a MAX(b) test ...@@ -698,7 +699,6 @@ a MAX(b) test
2 3 h 2 3 h
3 4 i 3 4 i
DROP TABLE t1, t2; DROP TABLE t1, t2;
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
CREATE TABLE t1 (a int); CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int, PRIMARY KEY(b)); CREATE TABLE t2 (b int, PRIMARY KEY(b));
...@@ -1084,7 +1084,8 @@ a ...@@ -1084,7 +1084,8 @@ a
17 17
18 18
19 19
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@save_optimizer_switch;
set @@optimizer_switch='materialization=off';
explain select * from t1 where 2 in (select a from t0); explain select * from t1 where 2 in (select a from t0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 11 Using where; FirstMatch 1 PRIMARY t0 ALL NULL NULL NULL NULL 11 Using where; FirstMatch
...@@ -1399,7 +1400,7 @@ drop table t1,t2,t3; ...@@ -1399,7 +1400,7 @@ drop table t1,t2,t3;
# #
# BUG#47367 Crash in Name_resolution_context::process_error # BUG#47367 Crash in Name_resolution_context::process_error
# #
SET SESSION optimizer_switch = 'default,semijoin=off'; SET SESSION optimizer_switch = 'semijoin=off';
CREATE TABLE t1 (f1 INTEGER); CREATE TABLE t1 (f1 INTEGER);
CREATE TABLE t2 LIKE t1; CREATE TABLE t2 LIKE t1;
CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t1 WHERE f1 IN (SELECT f1 FROM t2); END| CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t1 WHERE f1 IN (SELECT f1 FROM t2); END|
...@@ -1421,4 +1422,4 @@ CALL p1; ...@@ -1421,4 +1422,4 @@ CALL p1;
ERROR 42S22: Unknown column 'f1' in 'where clause' ERROR 42S22: Unknown column 'f1' in 'where clause'
DROP PROCEDURE p1; DROP PROCEDURE p1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@subselect3_tmp;
...@@ -6,7 +6,8 @@ show variables like 'join_cache_level'; ...@@ -6,7 +6,8 @@ show variables like 'join_cache_level';
Variable_name Value Variable_name Value
join_cache_level 6 join_cache_level 6
drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22; drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22;
set @save_optimizer_switch=@@optimizer_switch; set @subselect3_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
create table t1 (oref int, grp int, ie int) ; create table t1 (oref int, grp int, ie int) ;
insert into t1 (oref, grp, ie) values insert into t1 (oref, grp, ie) values
(1, 1, 1), (1, 1, 1),
...@@ -705,7 +706,6 @@ a MAX(b) test ...@@ -705,7 +706,6 @@ a MAX(b) test
2 3 h 2 3 h
3 4 i 3 4 i
DROP TABLE t1, t2; DROP TABLE t1, t2;
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
CREATE TABLE t1 (a int); CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int, PRIMARY KEY(b)); CREATE TABLE t2 (b int, PRIMARY KEY(b));
...@@ -1091,7 +1091,8 @@ a ...@@ -1091,7 +1091,8 @@ a
17 17
18 18
19 19
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@save_optimizer_switch;
set @@optimizer_switch='materialization=off';
explain select * from t1 where 2 in (select a from t0); explain select * from t1 where 2 in (select a from t0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 11 Using where; FirstMatch 1 PRIMARY t0 ALL NULL NULL NULL NULL 11 Using where; FirstMatch
...@@ -1406,7 +1407,7 @@ drop table t1,t2,t3; ...@@ -1406,7 +1407,7 @@ drop table t1,t2,t3;
# #
# BUG#47367 Crash in Name_resolution_context::process_error # BUG#47367 Crash in Name_resolution_context::process_error
# #
SET SESSION optimizer_switch = 'default,semijoin=off'; SET SESSION optimizer_switch = 'semijoin=off';
CREATE TABLE t1 (f1 INTEGER); CREATE TABLE t1 (f1 INTEGER);
CREATE TABLE t2 LIKE t1; CREATE TABLE t2 LIKE t1;
CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t1 WHERE f1 IN (SELECT f1 FROM t2); END| CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t1 WHERE f1 IN (SELECT f1 FROM t2); END|
...@@ -1428,7 +1429,7 @@ CALL p1; ...@@ -1428,7 +1429,7 @@ CALL p1;
ERROR 42S22: Unknown column 'f1' in 'where clause' ERROR 42S22: Unknown column 'f1' in 'where clause'
DROP PROCEDURE p1; DROP PROCEDURE p1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@subselect3_tmp;
set join_cache_level=default; set join_cache_level=default;
show variables like 'join_cache_level'; show variables like 'join_cache_level';
Variable_name Value Variable_name Value
......
drop table if exists t1,t2,t3,t4,t5,t6; drop table if exists t1,t2,t3,t4,t5,t6;
set @subselect4_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
# #
# Bug #46791: Assertion failed:(table->key_read==0),function unknown # Bug #46791: Assertion failed:(table->key_read==0),function unknown
# function,file sql_base.cc # function,file sql_base.cc
...@@ -1736,3 +1738,4 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1736,3 +1738,4 @@ id select_type table type possible_keys key key_len ref rows Extra
2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 2 SUBQUERY t3 ALL NULL NULL NULL NULL 2
3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary 3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary
drop table t1, t2, t3; drop table t1, t2, t3;
set optimizer_switch=@subselect4_tmp;
set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; set @subselect_mat_test_optimizer_switch_value='materialization=on,in_to_exists=off,semijoin=off';
set @subselect_sj_mat_tmp= @@optimizer_switch;
set optimizer_switch=ifnull(@subselect_mat_test_optimizer_switch_value, 'semijoin=on,firstmatch=on,loosescan=on');
set @optimizer_switch_local_default= @@optimizer_switch;
drop table if exists t1, t2, t3, t1i, t2i, t3i; drop table if exists t1, t2, t3, t1i, t2i, t3i;
drop table if exists columns; drop table if exists columns;
drop table if exists t1_16, t2_16, t3_16; drop table if exists t1_16, t2_16, t3_16;
...@@ -180,28 +183,34 @@ a1 a2 ...@@ -180,28 +183,34 @@ a1 a2
select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1); select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1);
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
prepare st1 from prepare st1 from
"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
1 - 02 2 - 02 1 - 02 2 - 02
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
1 - 02 2 - 02 1 - 02 2 - 02
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
prepare st1 from prepare st1 from
"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
1 - 02 2 - 02 1 - 02 2 - 02
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
...@@ -1145,28 +1154,31 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -1145,28 +1154,31 @@ id select_type table type possible_keys key key_len ref rows Extra
select min(a1) from t1 where 7 in (select b1 from t2 group by b1); select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
min(a1) min(a1)
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1); explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found 2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found
select min(a1) from t1 where 7 in (select b1 from t2 group by b1); select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
min(a1) min(a1)
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
min(a1) min(a1)
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
# with MariaDB and MWL#90, this particular case is solved: # with MariaDB and MWL#90, this particular case is solved:
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
id select_type table type possible_keys key key_len ref rows Extra 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 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
min(a1) min(a1)
NULL
# but when we go around MWL#90 code, the problem still shows up: # but when we go around MWL#90 code, the problem still shows up:
explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
...@@ -1199,7 +1211,8 @@ CREATE TABLE t2 LIKE t1; ...@@ -1199,7 +1211,8 @@ CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1, 1.789); INSERT INTO t2 VALUES (1, 1.789);
INSERT INTO t2 VALUES (13, 1.454); INSERT INTO t2 VALUES (13, 1.454);
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
SET @@optimizer_switch='default,semijoin=on,materialization=on'; set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
id select_type table type possible_keys key key_len ref rows Extra 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 <subquery2> ALL distinct_key NULL NULL NULL 2
...@@ -1222,7 +1235,8 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff'); ...@@ -1222,7 +1235,8 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
CREATE TABLE t2 LIKE t1; CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
SET @@optimizer_switch='default,semijoin=on,materialization=on'; set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 2
...@@ -1320,6 +1334,8 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1, ...@@ -1320,6 +1334,8 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,
left(a1,7) left(a2,7) left(a1,7) left(a2,7)
1 - 01x 2 - 01x 1 - 01x 2 - 01x
drop table t1_1024, t2_1024; drop table t1_1024, t2_1024;
set optimizer_switch=@subselect_sj_mat_tmp;
set @subselect_mat_test_optimizer_switch_value=null;
set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2); insert into t0 values (0),(1),(2);
......
...@@ -4,8 +4,9 @@ select @@optimizer_switch like '%materialization=on%'; ...@@ -4,8 +4,9 @@ select @@optimizer_switch like '%materialization=on%';
set optimizer_switch='materialization=off'; set optimizer_switch='materialization=off';
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
drop view if exists v2; drop view if exists v2;
set @save_optimizer_switch=@@optimizer_switch; set @subselect_tmp=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test,
"semijoin=on,firstmatch=on,loosescan=on,partial_match_rowid_merge=off,partial_match_table_scan=off");
select (select 2); select (select 2);
(select 2) (select 2)
2 2
...@@ -4807,7 +4808,6 @@ SELECT 1 FROM t1 GROUP BY ...@@ -4807,7 +4808,6 @@ SELECT 1 FROM t1 GROUP BY
1 1
1 1
DROP TABLE t1; DROP TABLE t1;
set @@optimizer_switch=@save_optimizer_switch;
# #
# Bug #49512 : subquery with aggregate function crash # Bug #49512 : subquery with aggregate function crash
# subselect_single_select_engine::exec() # subselect_single_select_engine::exec()
...@@ -5131,6 +5131,7 @@ ON t2.f10 = t3.f10 ...@@ -5131,6 +5131,7 @@ ON t2.f10 = t3.f10
f1 f1
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
End of 5.3 tests End of 5.3 tests
set optimizer_switch=@subselect_tmp;
set optimizer_switch=default; set optimizer_switch=default;
select @@optimizer_switch like '%materialization=on%'; select @@optimizer_switch like '%materialization=on%';
@@optimizer_switch like '%materialization=on%' @@optimizer_switch like '%materialization=on%'
......
set optimizer_switch='materialization=off,semijoin=off'; set @optimizer_switch_for_subselect_test='materialization=off,semijoin=off';
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
drop view if exists v2; drop view if exists v2;
set @save_optimizer_switch=@@optimizer_switch; set @subselect_tmp=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test,
"semijoin=on,firstmatch=on,loosescan=on,partial_match_rowid_merge=off,partial_match_table_scan=off");
select (select 2); select (select 2);
(select 2) (select 2)
2 2
...@@ -4804,7 +4805,6 @@ SELECT 1 FROM t1 GROUP BY ...@@ -4804,7 +4805,6 @@ SELECT 1 FROM t1 GROUP BY
1 1
1 1
DROP TABLE t1; DROP TABLE t1;
set @@optimizer_switch=@save_optimizer_switch;
# #
# Bug #49512 : subquery with aggregate function crash # Bug #49512 : subquery with aggregate function crash
# subselect_single_select_engine::exec() # subselect_single_select_engine::exec()
...@@ -5128,4 +5128,5 @@ ON t2.f10 = t3.f10 ...@@ -5128,4 +5128,5 @@ ON t2.f10 = t3.f10
f1 f1
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
End of 5.3 tests End of 5.3 tests
set optimizer_switch=default; set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null;
set optimizer_switch='semijoin=off'; set @optimizer_switch_for_subselect_test='semijoin=off';
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
drop view if exists v2; drop view if exists v2;
set @save_optimizer_switch=@@optimizer_switch; set @subselect_tmp=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test,
"semijoin=on,firstmatch=on,loosescan=on,partial_match_rowid_merge=off,partial_match_table_scan=off");
select (select 2); select (select 2);
(select 2) (select 2)
2 2
...@@ -4804,7 +4805,6 @@ SELECT 1 FROM t1 GROUP BY ...@@ -4804,7 +4805,6 @@ SELECT 1 FROM t1 GROUP BY
1 1
1 1
DROP TABLE t1; DROP TABLE t1;
set @@optimizer_switch=@save_optimizer_switch;
# #
# Bug #49512 : subquery with aggregate function crash # Bug #49512 : subquery with aggregate function crash
# subselect_single_select_engine::exec() # subselect_single_select_engine::exec()
...@@ -5128,4 +5128,5 @@ ON t2.f10 = t3.f10 ...@@ -5128,4 +5128,5 @@ ON t2.f10 = t3.f10
f1 f1
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
End of 5.3 tests End of 5.3 tests
set optimizer_switch=default; set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null;
drop table if exists t0, t1, t2, t3, t4, t10, t11, t12; drop table if exists t0, t1, t2, t3, t4, t10, t11, t12;
drop view if exists v1, v2; drop view if exists v1, v2;
drop procedure if exists p1; drop procedure if exists p1;
set @subselect_sj_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
...@@ -1536,4 +1538,4 @@ AND t1.f1 = t2.f1 ; ...@@ -1536,4 +1538,4 @@ AND t1.f1 = t2.f1 ;
f1 f1 f1 f1
DROP TABLE t1, t2; DROP TABLE t1, t2;
set optimizer_switch=@save_802965; set optimizer_switch=@save_802965;
set @@optimizer_switch=@save_optimizer_switch; set optimizer_switch=@subselect_sj_tmp;
set @subselect_sj2_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
drop table if exists t0, t1, t2, t3; drop table if exists t0, t1, t2, t3;
drop view if exists v1; drop view if exists v1;
create table t0 (a int); create table t0 (a int);
...@@ -744,3 +746,4 @@ LEFT JOIN t2 AS SQ4_alias3 ON SQ4_alias3.f10 ...@@ -744,3 +746,4 @@ LEFT JOIN t2 AS SQ4_alias3 ON SQ4_alias3.f10
GROUP BY field2; GROUP BY field2;
field2 field2
drop table t1, t2, t3; drop table t1, t2, t3;
set optimizer_switch=@subselect_sj2_tmp;
...@@ -5,6 +5,8 @@ set join_cache_level=6; ...@@ -5,6 +5,8 @@ set join_cache_level=6;
show variables like 'join_cache_level'; show variables like 'join_cache_level';
Variable_name Value Variable_name Value
join_cache_level 6 join_cache_level 6
set @subselect_sj2_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
drop table if exists t0, t1, t2, t3; drop table if exists t0, t1, t2, t3;
drop view if exists v1; drop view if exists v1;
create table t0 (a int); create table t0 (a int);
...@@ -753,6 +755,7 @@ LEFT JOIN t2 AS SQ4_alias3 ON SQ4_alias3.f10 ...@@ -753,6 +755,7 @@ LEFT JOIN t2 AS SQ4_alias3 ON SQ4_alias3.f10
GROUP BY field2; GROUP BY field2;
field2 field2
drop table t1, t2, t3; drop table t1, t2, t3;
set optimizer_switch=@subselect_sj2_tmp;
set join_cache_level=default; set join_cache_level=default;
show variables like 'join_cache_level'; show variables like 'join_cache_level';
Variable_name Value Variable_name Value
......
set optimizer_switch='materialization=on'; set optimizer_switch='materialization=on';
set @subselect_sj2_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
drop table if exists t0, t1, t2, t3; drop table if exists t0, t1, t2, t3;
drop view if exists v1; drop view if exists v1;
create table t0 (a int); create table t0 (a int);
...@@ -755,6 +757,7 @@ LEFT JOIN t2 AS SQ4_alias3 ON SQ4_alias3.f10 ...@@ -755,6 +757,7 @@ LEFT JOIN t2 AS SQ4_alias3 ON SQ4_alias3.f10
GROUP BY field2; GROUP BY field2;
field2 field2
drop table t1, t2, t3; drop table t1, t2, t3;
set optimizer_switch=@subselect_sj2_tmp;
set optimizer_switch=default; set optimizer_switch=default;
select @@optimizer_switch like '%materialization=on%'; select @@optimizer_switch like '%materialization=on%';
@@optimizer_switch like '%materialization=on%' @@optimizer_switch like '%materialization=on%'
......
set @save_optimizer_switch_jcl6=@@optimizer_switch; set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
set @@optimizer_switch='semijoin_with_cache=on'; set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on'; set @@optimizer_switch='outer_join_with_cache=on';
set @@optimizer_switch='join_cache_hashed=off'; set @@optimizer_switch='join_cache_hashed=off';
...@@ -9,6 +10,8 @@ join_cache_level 6 ...@@ -9,6 +10,8 @@ join_cache_level 6
drop table if exists t0, t1, t2, t3, t4, t10, t11, t12; drop table if exists t0, t1, t2, t3, t4, t10, t11, t12;
drop view if exists v1, v2; drop view if exists v1, v2;
drop procedure if exists p1; drop procedure if exists p1;
set @subselect_sj_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
...@@ -1544,7 +1547,7 @@ AND t1.f1 = t2.f1 ; ...@@ -1544,7 +1547,7 @@ AND t1.f1 = t2.f1 ;
f1 f1 f1 f1
DROP TABLE t1, t2; DROP TABLE t1, t2;
set optimizer_switch=@save_802965; set optimizer_switch=@save_802965;
set @@optimizer_switch=@save_optimizer_switch; set optimizer_switch=@subselect_sj_tmp;
# #
# BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off # BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off
# #
......
set @subselect_sj_mat_tmp= @@optimizer_switch;
set optimizer_switch=ifnull(@subselect_mat_test_optimizer_switch_value, 'semijoin=on,firstmatch=on,loosescan=on');
set @optimizer_switch_local_default= @@optimizer_switch;
drop table if exists t1, t2, t3, t1i, t2i, t3i; drop table if exists t1, t2, t3, t1i, t2i, t3i;
drop table if exists columns; drop table if exists columns;
drop table if exists t1_16, t2_16, t3_16; drop table if exists t1_16, t2_16, t3_16;
...@@ -190,28 +193,34 @@ a1 a2 ...@@ -190,28 +193,34 @@ a1 a2
select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1); select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1);
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
prepare st1 from prepare st1 from
"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
1 - 02 2 - 02 1 - 02 2 - 02
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
1 - 02 2 - 02 1 - 02 2 - 02
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
prepare st1 from prepare st1 from
"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
1 - 02 2 - 02 1 - 02 2 - 02
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
execute st1; execute st1;
a1 a2 a1 a2
1 - 01 2 - 01 1 - 01 2 - 01
...@@ -1182,21 +1191,24 @@ select min(a1) from t1 where 7 in (select b1 from t2 group by b1); ...@@ -1182,21 +1191,24 @@ select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
min(a1) min(a1)
NULL NULL
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1); explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found 2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found
select min(a1) from t1 where 7 in (select b1 from t2 group by b1); select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
min(a1) min(a1)
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
min(a1) min(a1)
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
# with MariaDB and MWL#90, this particular case is solved: # with MariaDB and MWL#90, this particular case is solved:
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
...@@ -1237,7 +1249,8 @@ CREATE TABLE t2 LIKE t1; ...@@ -1237,7 +1249,8 @@ CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1, 1.789); INSERT INTO t2 VALUES (1, 1.789);
INSERT INTO t2 VALUES (13, 1.454); INSERT INTO t2 VALUES (13, 1.454);
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
SET @@optimizer_switch='default,semijoin=on,materialization=on'; set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
id select_type table type possible_keys key key_len ref rows Extra 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 <subquery2> ALL distinct_key NULL NULL NULL 2
...@@ -1260,7 +1273,8 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff'); ...@@ -1260,7 +1273,8 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
CREATE TABLE t2 LIKE t1; CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
SET @@optimizer_switch='default,semijoin=on,materialization=on'; set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 2
...@@ -1358,3 +1372,4 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1, ...@@ -1358,3 +1372,4 @@ select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,
left(a1,7) left(a2,7) left(a1,7) left(a2,7)
1 - 01x 2 - 01x 1 - 01x 2 - 01x
drop table t1_1024, t2_1024; drop table t1_1024, t2_1024;
set optimizer_switch=@subselect_sj_mat_tmp;
drop table if exists t0, t1, t2, t3, t4; drop table if exists t0, t1, t2, t3, t4;
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='materialization=on'; set optimizer_switch='semijoin=on,materialization=on';
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 as select * from t0; create table t1 as select * from t0;
......
...@@ -514,10 +514,11 @@ explain extended ...@@ -514,10 +514,11 @@ explain extended
select * from t1 select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null)); where id in (select id from t1 as x1 where (t1.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select 1 AS `id`,'2007-04-25 18:30:22' AS `cur_date` from `test`.`t1` semi join (`test`.`t1` `x1`) where (('2007-04-25 18:30:22' = 0)) Note 1003 select 1 AS `id`,'2007-04-25 18:30:22' AS `cur_date` from `test`.`t1` where <expr_cache><1,'2007-04-25 18:30:22'>(<in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t1` `x1` where 0)))
select * from t1 select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null)); where id in (select id from t1 as x1 where (t1.cur_date is null));
id cur_date id cur_date
...@@ -525,10 +526,11 @@ explain extended ...@@ -525,10 +526,11 @@ explain extended
select * from t2 select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null)); where id in (select id from t2 as x1 where (t2.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY t2 system NULL NULL NULL NULL 1 100.00
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings: Warnings:
Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select 1 AS `id`,'2007-04-25' AS `cur_date` from `test`.`t2` semi join (`test`.`t2` `x1`) where (('2007-04-25' = 0)) Note 1003 select 1 AS `id`,'2007-04-25' AS `cur_date` from `test`.`t2` where <expr_cache><1,'2007-04-25'>(<in_optimizer>(1,<exists>(select `test`.`x1`.`id` from `test`.`t2` `x1` where 0)))
select * from t2 select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null)); where id in (select id from t2 as x1 where (t2.cur_date is null));
id cur_date id cur_date
...@@ -538,11 +540,11 @@ explain extended ...@@ -538,11 +540,11 @@ explain extended
select * from t1 select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null)); where id in (select id from t1 as x1 where (t1.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra 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 Using where; Start temporary 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; End temporary; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY x1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` semi join (`test`.`t1` `x1`) where ((`test`.`x1`.`id` = `test`.`t1`.`id`) and (`test`.`t1`.`cur_date` = 0)) Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` where <expr_cache><`test`.`t1`.`id`,`test`.`t1`.`cur_date`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(select `test`.`x1`.`id` from `test`.`t1` `x1` where ((`test`.`t1`.`cur_date` = 0) and (<cache>(`test`.`t1`.`id`) = `test`.`x1`.`id`)))))
select * from t1 select * from t1
where id in (select id from t1 as x1 where (t1.cur_date is null)); where id in (select id from t1 as x1 where (t1.cur_date is null));
id cur_date id cur_date
...@@ -550,11 +552,11 @@ explain extended ...@@ -550,11 +552,11 @@ explain extended
select * from t2 select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null)); where id in (select id from t2 as x1 where (t2.cur_date is null));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; End temporary; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY x1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings: Warnings:
Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` semi join (`test`.`t2` `x1`) where ((`test`.`x1`.`id` = `test`.`t2`.`id`) and (`test`.`t2`.`cur_date` = 0)) Note 1003 select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`,`test`.`t2`.`cur_date`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select `test`.`x1`.`id` from `test`.`t2` `x1` where ((`test`.`t2`.`cur_date` = 0) and (<cache>(`test`.`t2`.`id`) = `test`.`x1`.`id`)))))
select * from t2 select * from t2
where id in (select id from t2 as x1 where (t2.cur_date is null)); where id in (select id from t2 as x1 where (t2.cur_date is null));
id cur_date id cur_date
......
This diff is collapsed.
...@@ -63,8 +63,8 @@ a b c ...@@ -63,8 +63,8 @@ a b c
3 -3 -3 3 -3 -3
explain select * from t1 where b in (select c from t3); explain select * from t1 where b in (select c from t3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index c c 5 NULL 3 Using index 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t3 index_subquery c c 5 func 1 Using index
# select_type=PRIMARY, type=range,ref # select_type=PRIMARY, type=range,ref
select * from t1 where c in (select c from t3 where c between -2 and -1); select * from t1 where c in (select c from t3 where c between -2 and -1);
a b c a b c
...@@ -73,8 +73,8 @@ a b c ...@@ -73,8 +73,8 @@ a b c
1 -1 -1 1 -1 -1
explain select * from t1 where c in (select c from t3 where c between -2 and -1); explain select * from t1 where c in (select c from t3 where c between -2 and -1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index c c 5 NULL 3 Using where; Using index 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
1 PRIMARY t1 ref c c 5 test.t3.c 1 2 DEPENDENT SUBQUERY t3 index_subquery c c 5 func 1 Using index; Using where
# select_type=UNION, type=system # select_type=UNION, type=system
# select_type=UNION RESULT, type=<union1,2> # select_type=UNION RESULT, type=<union1,2>
select * from t1 union select * from t2; select * from t1 union select * from t2;
......
...@@ -63,8 +63,8 @@ a b c ...@@ -63,8 +63,8 @@ a b c
3 -3 -3 3 -3 -3
explain select * from t1 where b in (select c from t3); explain select * from t1 where b in (select c from t3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index c c 5 NULL 3 Using index 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t3 index_subquery c c 5 func 2 Using index
# select_type=PRIMARY, type=range,ref # select_type=PRIMARY, type=range,ref
select * from t1 where c in (select c from t3 where c between -2 and -1); select * from t1 where c in (select c from t3 where c between -2 and -1);
a b c a b c
...@@ -73,8 +73,8 @@ a b c ...@@ -73,8 +73,8 @@ a b c
1 -1 -1 1 -1 -1
explain select * from t1 where c in (select c from t3 where c between -2 and -1); explain select * from t1 where c in (select c from t3 where c between -2 and -1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index c c 5 NULL 3 Using where; Using index 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
1 PRIMARY t1 ref c c 5 test.t3.c 2 2 DEPENDENT SUBQUERY t3 index_subquery c c 5 func 2 Using index; Using where
# select_type=UNION, type=system # select_type=UNION, type=system
# select_type=UNION RESULT, type=<union1,2> # select_type=UNION RESULT, type=<union1,2>
select * from t1 union select * from t2; select * from t1 union select * from t2;
......
...@@ -4,6 +4,7 @@ DROP DATABASE IF EXISTS world; ...@@ -4,6 +4,7 @@ DROP DATABASE IF EXISTS world;
--enable_warnings --enable_warnings
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
set @@optimizer_switch='semijoin_with_cache=on'; set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on'; set @@optimizer_switch='outer_join_with_cache=on';
......
...@@ -12,8 +12,9 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; ...@@ -12,8 +12,9 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
drop view if exists v2; drop view if exists v2;
--enable_warnings --enable_warnings
set @save_optimizer_switch=@@optimizer_switch; set @subselect_tmp=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test,
"semijoin=on,firstmatch=on,loosescan=on,partial_match_rowid_merge=off,partial_match_table_scan=off");
select (select 2); select (select 2);
explain extended select (select 2); explain extended select (select 2);
...@@ -4066,7 +4067,7 @@ SELECT 1 FROM t1 GROUP BY ...@@ -4066,7 +4067,7 @@ SELECT 1 FROM t1 GROUP BY
(SELECT LAST_INSERT_ID() FROM t1 ORDER BY MIN(a) ASC LIMIT 1); (SELECT LAST_INSERT_ID() FROM t1 ORDER BY MIN(a) ASC LIMIT 1);
DROP TABLE t1; DROP TABLE t1;
set @@optimizer_switch=@save_optimizer_switch; #Seems to be not needed here: set @@optimizer_switch=@subselect_tmp;
--echo # --echo #
--echo # Bug #49512 : subquery with aggregate function crash --echo # Bug #49512 : subquery with aggregate function crash
--echo # subselect_single_select_engine::exec() --echo # subselect_single_select_engine::exec()
...@@ -4402,3 +4403,4 @@ WHERE ...@@ -4402,3 +4403,4 @@ WHERE
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
--echo End of 5.3 tests --echo End of 5.3 tests
set optimizer_switch=@subselect_tmp;
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
drop table if exists t1, t2, t3, t4; drop table if exists t1, t2, t3, t4;
--enable_warnings --enable_warnings
set @subselect2_test_tmp=@@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on';
CREATE TABLE t1 CREATE TABLE t1
( (
DOCID VARCHAR(32)BINARY NOT NULL DOCID VARCHAR(32)BINARY NOT NULL
...@@ -168,3 +171,6 @@ SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a ...@@ -168,3 +171,6 @@ SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a
and t2.a='1' AND t1.a=t3.b) > 0; and t2.a='1' AND t1.a=t3.b) > 0;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
set optimizer_switch=@subselect2_test_tmp;
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22; drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22;
--enable_warnings --enable_warnings
set @save_optimizer_switch=@@optimizer_switch; set @subselect3_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
# #
# 1. Subquery with GROUP/HAVING # 1. Subquery with GROUP/HAVING
...@@ -538,7 +539,6 @@ SELECT a, MAX(b), ...@@ -538,7 +539,6 @@ SELECT a, MAX(b),
DROP TABLE t1, t2; DROP TABLE t1, t2;
# The next three test cases must be executed with the IN=>EXISTS strategy # The next three test cases must be executed with the IN=>EXISTS strategy
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off"; set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
# #
...@@ -906,7 +906,8 @@ set @@optimizer_switch='firstmatch=off,materialization=off'; ...@@ -906,7 +906,8 @@ set @@optimizer_switch='firstmatch=off,materialization=off';
insert into t0 values(2); insert into t0 values(2);
explain select * from t1 where 2 in (select a from t0); explain select * from t1 where 2 in (select a from t0);
select * from t1 where 2 in (select a from t0); select * from t1 where 2 in (select a from t0);
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@save_optimizer_switch;
set @@optimizer_switch='materialization=off';
explain select * from t1 where 2 in (select a from t0); explain select * from t1 where 2 in (select a from t0);
select * from t1 where 2 in (select a from t0); select * from t1 where 2 in (select a from t0);
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@save_optimizer_switch;
...@@ -1160,7 +1161,7 @@ drop table t1,t2,t3; ...@@ -1160,7 +1161,7 @@ drop table t1,t2,t3;
--echo # BUG#47367 Crash in Name_resolution_context::process_error --echo # BUG#47367 Crash in Name_resolution_context::process_error
--echo # --echo #
SET SESSION optimizer_switch = 'default,semijoin=off'; SET SESSION optimizer_switch = 'semijoin=off';
CREATE TABLE t1 (f1 INTEGER); CREATE TABLE t1 (f1 INTEGER);
CREATE TABLE t2 LIKE t1; CREATE TABLE t2 LIKE t1;
delimiter |; delimiter |;
...@@ -1186,4 +1187,4 @@ DROP PROCEDURE p1; ...@@ -1186,4 +1187,4 @@ DROP PROCEDURE p1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
# The following command must be the last one the file # The following command must be the last one the file
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@subselect3_tmp;
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
drop table if exists t1,t2,t3,t4,t5,t6; drop table if exists t1,t2,t3,t4,t5,t6;
--enable_warnings --enable_warnings
set @subselect4_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
--echo # --echo #
--echo # Bug #46791: Assertion failed:(table->key_read==0),function unknown --echo # Bug #46791: Assertion failed:(table->key_read==0),function unknown
--echo # function,file sql_base.cc --echo # function,file sql_base.cc
...@@ -1415,3 +1418,5 @@ WHERE t2.f1 = ( ...@@ -1415,3 +1418,5 @@ WHERE t2.f1 = (
FROM t1)); FROM t1));
drop table t1, t2, t3; drop table t1, t2, t3;
set optimizer_switch=@subselect4_tmp;
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
# force the use of materialization # force the use of materialization
set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; set @subselect_mat_test_optimizer_switch_value='materialization=on,in_to_exists=off,semijoin=off';
--source t/subselect_sj_mat.test --source t/subselect_sj_mat.test
set @subselect_mat_test_optimizer_switch_value=null;
set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';
# #
# Test that the contents of the temp table of a materialized subquery is # Test that the contents of the temp table of a materialized subquery is
......
# #
# Run subselect.test without semi-join and materialization optimizations # Run subselect.test without semi-join and materialization optimizations
# (test in-to-exists) # (test in-to-exists)
set optimizer_switch='materialization=off,semijoin=off';
set @optimizer_switch_for_subselect_test='materialization=off,semijoin=off';
--source t/subselect.test --source t/subselect.test
set optimizer_switch=default; set @optimizer_switch_for_subselect_test=null;
# #
# Run subselect.test without semi-join optimization (test materialize) # Run subselect.test without semi-join optimization (test materialize)
# #
set optimizer_switch='semijoin=off'; set @optimizer_switch_for_subselect_test='semijoin=off';
--source t/subselect.test --source t/subselect.test
set optimizer_switch=default; set @optimizer_switch_for_subselect_test=null;
...@@ -7,6 +7,9 @@ drop view if exists v1, v2; ...@@ -7,6 +7,9 @@ drop view if exists v1, v2;
drop procedure if exists p1; drop procedure if exists p1;
--enable_warnings --enable_warnings
set @subselect_sj_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
# The 'default' value within the scope of this test:
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
# #
...@@ -1396,4 +1399,4 @@ DROP TABLE t1, t2; ...@@ -1396,4 +1399,4 @@ DROP TABLE t1, t2;
set optimizer_switch=@save_802965; set optimizer_switch=@save_802965;
# The following command must be the last one the file # The following command must be the last one the file
set @@optimizer_switch=@save_optimizer_switch; set optimizer_switch=@subselect_sj_tmp;
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# DuplicateElimination strategy test # DuplicateElimination strategy test
# #
--source include/have_innodb.inc --source include/have_innodb.inc
set @subselect_sj2_tmp= @@optimizer_switch;
set optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
--disable_warnings --disable_warnings
drop table if exists t0, t1, t2, t3; drop table if exists t0, t1, t2, t3;
drop view if exists v1; drop view if exists v1;
...@@ -939,3 +942,5 @@ WHERE alias2.f11 IN ( ...@@ -939,3 +942,5 @@ WHERE alias2.f11 IN (
) )
GROUP BY field2; GROUP BY field2;
drop table t1, t2, t3; drop table t1, t2, t3;
set optimizer_switch=@subselect_sj2_tmp;
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# #
set @save_optimizer_switch_jcl6=@@optimizer_switch; set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
set @@optimizer_switch='semijoin_with_cache=on'; set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on'; set @@optimizer_switch='outer_join_with_cache=on';
set @@optimizer_switch='join_cache_hashed=off'; set @@optimizer_switch='join_cache_hashed=off';
......
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
# (WL#1110: Subquery optimization: materialization) # (WL#1110: Subquery optimization: materialization)
# #
set @subselect_sj_mat_tmp= @@optimizer_switch;
set optimizer_switch=ifnull(@subselect_mat_test_optimizer_switch_value, 'semijoin=on,firstmatch=on,loosescan=on');
set @optimizer_switch_local_default= @@optimizer_switch;
--disable_warnings --disable_warnings
drop table if exists t1, t2, t3, t1i, t2i, t3i; drop table if exists t1, t2, t3, t1i, t2i, t3i;
drop table if exists columns; drop table if exists columns;
...@@ -121,20 +125,26 @@ select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1); ...@@ -121,20 +125,26 @@ select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1);
# test re-optimization/re-execution with different execution methods # test re-optimization/re-execution with different execution methods
# prepare once, exec with different modes # prepare once, exec with different modes
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
prepare st1 from prepare st1 from
"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
execute st1; execute st1;
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
execute st1; execute st1;
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
prepare st1 from prepare st1 from
"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
execute st1; execute st1;
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
execute st1; execute st1;
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@save_optimizer_switch;
...@@ -826,18 +836,21 @@ explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1); ...@@ -826,18 +836,21 @@ explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
select min(a1) from t1 where 7 in (select b1 from t2 group by b1); select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
# Query with group by, executed via IN=>EXISTS # Query with group by, executed via IN=>EXISTS
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1); explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
select min(a1) from t1 where 7 in (select b1 from t2 group by b1); select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
# Executed with materialization # Executed with materialization
set @@optimizer_switch='default,semijoin=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='semijoin=off';
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
# Executed with semi-join. Notice, this time we get a different result (NULL). # Executed with semi-join. Notice, this time we get a different result (NULL).
# This is the only correct result of all four queries. This difference is # This is the only correct result of all four queries. This difference is
# filed as BUG#40037. # filed as BUG#40037.
set @@optimizer_switch='default,materialization=off'; set @@optimizer_switch=@optimizer_switch_local_default;
set @@optimizer_switch='materialization=off,in_to_exists=on';
-- echo # with MariaDB and MWL#90, this particular case is solved: -- echo # with MariaDB and MWL#90, this particular case is solved:
explain select min(a1) from t1 where 7 in (select b1 from t2); explain select min(a1) from t1 where 7 in (select b1 from t2);
select min(a1) from t1 where 7 in (select b1 from t2); select min(a1) from t1 where 7 in (select b1 from t2);
...@@ -875,7 +888,8 @@ INSERT INTO t2 VALUES (1, 1.789); ...@@ -875,7 +888,8 @@ INSERT INTO t2 VALUES (1, 1.789);
INSERT INTO t2 VALUES (13, 1.454); INSERT INTO t2 VALUES (13, 1.454);
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
SET @@optimizer_switch='default,semijoin=on,materialization=on'; set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
set @@optimizer_switch= @save_optimizer_switch; set @@optimizer_switch= @save_optimizer_switch;
...@@ -899,7 +913,8 @@ CREATE TABLE t2 LIKE t1; ...@@ -899,7 +913,8 @@ CREATE TABLE t2 LIKE t1;
INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
SET @@optimizer_switch='default,semijoin=on,materialization=on'; set @@optimizer_switch=@optimizer_switch_local_default;
SET @@optimizer_switch='semijoin=on,materialization=on';
EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0); SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0);
...@@ -972,3 +987,6 @@ explain select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select subst ...@@ -972,3 +987,6 @@ explain select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select subst
select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0'); select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0');
drop table t1_1024, t2_1024; drop table t1_1024, t2_1024;
set optimizer_switch=@subselect_sj_mat_tmp;
...@@ -6,7 +6,7 @@ drop table if exists t0, t1, t2, t3, t4; ...@@ -6,7 +6,7 @@ drop table if exists t0, t1, t2, t3, t4;
--enable_warnings --enable_warnings
set @save_optimizer_switch=@@optimizer_switch; set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='materialization=on'; set optimizer_switch='semijoin=on,materialization=on';
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
......
...@@ -615,10 +615,7 @@ enabled by default, add OPTIMIZER_SWITCH_MATERIALIZATION ...@@ -615,10 +615,7 @@ enabled by default, add OPTIMIZER_SWITCH_MATERIALIZATION
OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN | \ OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN | \
OPTIMIZER_SWITCH_DERIVED_MERGE | \ OPTIMIZER_SWITCH_DERIVED_MERGE | \
OPTIMIZER_SWITCH_DERIVED_WITH_KEYS | \ OPTIMIZER_SWITCH_DERIVED_WITH_KEYS | \
OPTIMIZER_SWITCH_FIRSTMATCH | \
OPTIMIZER_SWITCH_LOOSE_SCAN | \
OPTIMIZER_SWITCH_IN_TO_EXISTS | \ OPTIMIZER_SWITCH_IN_TO_EXISTS | \
OPTIMIZER_SWITCH_SEMIJOIN | \
OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\ OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\
OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\ OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\
OPTIMIZER_SWITCH_SUBQUERY_CACHE|\ OPTIMIZER_SWITCH_SUBQUERY_CACHE|\
...@@ -638,10 +635,7 @@ enabled by default, add OPTIMIZER_SWITCH_MATERIALIZATION ...@@ -638,10 +635,7 @@ enabled by default, add OPTIMIZER_SWITCH_MATERIALIZATION
OPTIMIZER_SWITCH_DERIVED_MERGE | \ OPTIMIZER_SWITCH_DERIVED_MERGE | \
OPTIMIZER_SWITCH_DERIVED_WITH_KEYS | \ OPTIMIZER_SWITCH_DERIVED_WITH_KEYS | \
OPTIMIZER_SWITCH_TABLE_ELIMINATION | \ OPTIMIZER_SWITCH_TABLE_ELIMINATION | \
OPTIMIZER_SWITCH_FIRSTMATCH | \
OPTIMIZER_SWITCH_LOOSE_SCAN | \
OPTIMIZER_SWITCH_IN_TO_EXISTS | \ OPTIMIZER_SWITCH_IN_TO_EXISTS | \
OPTIMIZER_SWITCH_SEMIJOIN | \
OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\ OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\
OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\ OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\
OPTIMIZER_SWITCH_SUBQUERY_CACHE|\ OPTIMIZER_SWITCH_SUBQUERY_CACHE|\
......
...@@ -488,11 +488,11 @@ static const char *optimizer_switch_str="index_merge=on,index_merge_union=on," ...@@ -488,11 +488,11 @@ static const char *optimizer_switch_str="index_merge=on,index_merge_union=on,"
"index_condition_pushdown=on," "index_condition_pushdown=on,"
"derived_merge=on," "derived_merge=on,"
"derived_with_keys=on," "derived_with_keys=on,"
"firstmatch=on," "firstmatch=off,"
"loosescan=on," "loosescan=off,"
"materialization=off," "materialization=off,"
"in_to_exists=on," "in_to_exists=on,"
"semijoin=on," "semijoin=off,"
"partial_match_rowid_merge=on," "partial_match_rowid_merge=on,"
"partial_match_table_scan=on," "partial_match_table_scan=on,"
"subquery_cache=on," "subquery_cache=on,"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment