mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MWL#68 Subquery optimization: Efficient NOT IN execution with NULLs
This patch does three things: - It adds the possibility to force the execution of top-level [NOT] IN subquery predicates via the IN=>EXISTS transformation. This is done by setting both optimizer switches partial_match_rowid_merge and partial_match_table_scan to "off". - It adjusts all test cases where the complete optimizer_switch is selected because now we have two more switches. - For those test cases where the plan changes because of the new available strategies, we switch off both partial match strategies in order to force the "old" IN=>EXISTS strategy. This is done because most of these test cases specifically test bugs in this strategy. sql/opt_subselect.cc: Adds the possibility to force the execution of top-level [NOT] IN subquery predicates via the IN=>EXISTS transformation. This is done by setting both optimizer switches partial_match_rowid_merge and partial_match_table_scan to "off".
This commit is contained in:
@ -1177,8 +1177,11 @@ DROP TABLE t1;
|
||||
|
||||
create table t1 (a bit(1) not null,b int) engine=myisam;
|
||||
create table t2 (c int) engine=innodb;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch='partial_match_rowid_merge=off,partial_match_table_scan=off';
|
||||
explain
|
||||
select b from t1 where a not in (select b from t1,t2 group by a) group by a;
|
||||
set optimizer_switch=@save_optimizer_switch;
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
--echo End of 5.0 tests
|
||||
|
@ -1419,19 +1419,19 @@ drop table t1;
|
||||
#
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='index_merge=off,index_merge_union=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='index_merge_union=on';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,index_merge_sort_union=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch=4;
|
||||
ERROR 42000: Variable 'optimizer_switch' can't be set to the value of '4'
|
||||
set optimizer_switch=NULL;
|
||||
@ -1458,21 +1458,21 @@ set optimizer_switch=default;
|
||||
set optimizer_switch='index_merge=off,index_merge_union=off,default';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch=default;
|
||||
select @@global.optimizer_switch;
|
||||
@@global.optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set @@global.optimizer_switch=default;
|
||||
select @@global.optimizer_switch;
|
||||
@@global.optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
#
|
||||
# Check index_merge's @@optimizer_switch flags
|
||||
#
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
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, c int, filler char(100),
|
||||
@ -1582,5 +1582,5 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
set optimizer_switch=default;
|
||||
show variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
drop table t0, t1;
|
||||
|
@ -1425,12 +1425,15 @@ DROP TABLE t1;
|
||||
#
|
||||
create table t1 (a bit(1) not null,b int) engine=myisam;
|
||||
create table t2 (c int) engine=innodb;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch='partial_match_rowid_merge=off,partial_match_table_scan=off';
|
||||
explain
|
||||
select b from t1 where a not in (select b from t1,t2 group by a) group by a;
|
||||
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 t1 system NULL NULL NULL NULL 0 const row not found
|
||||
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 1
|
||||
set optimizer_switch=@save_optimizer_switch;
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.0 tests
|
||||
CREATE TABLE `t2` (
|
||||
|
@ -394,7 +394,7 @@ drop table t0, t1;
|
||||
# - engine_condition_pushdown does not affect ICP
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
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, key(a));
|
||||
|
@ -149,6 +149,8 @@ c29 longblob, c30 longtext, c31 enum('one', 'two', 'three'),
|
||||
c32 set('monday', 'tuesday', 'wednesday')
|
||||
) engine = MYISAM ;
|
||||
create table t2 like t1;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
set @stmt= ' explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25 ' ;
|
||||
prepare stmt1 from @stmt ;
|
||||
execute stmt1 ;
|
||||
@ -177,6 +179,7 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
deallocate prepare stmt1;
|
||||
drop tables t1,t2;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
set @arg00=1;
|
||||
prepare stmt1 from ' create table t1 (m int) as select 1 as m ' ;
|
||||
execute stmt1 ;
|
||||
|
@ -1,4 +1,6 @@
|
||||
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
select (select 2);
|
||||
(select 2)
|
||||
2
|
||||
@ -4803,4 +4805,5 @@ SELECT 1 FROM t1 GROUP BY
|
||||
1
|
||||
1
|
||||
DROP TABLE t1;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
End of 5.1 tests.
|
||||
|
@ -63,12 +63,15 @@ Handler_read_rnd_next 11
|
||||
select ' ^ This must show 11' Z;
|
||||
Z
|
||||
^ This must show 11
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
explain extended select a in (select max(ie) from t1 where oref=4 group by grp) 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 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary; Using filesort
|
||||
Warnings:
|
||||
Note 1003 select <in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
drop table t1, t2, t3;
|
||||
create table t1 (a int, oref int, key(a));
|
||||
insert into t1 values
|
||||
@ -692,6 +695,8 @@ a MAX(b) test
|
||||
2 3 h
|
||||
3 4 i
|
||||
DROP TABLE t1, t2;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t2 (b int, PRIMARY KEY(b));
|
||||
INSERT INTO t1 VALUES (1), (NULL), (4);
|
||||
@ -759,6 +764,7 @@ 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 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY PRIMARY 4 func 1 Using index; Using where
|
||||
DROP TABLE t1, t2;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES(1);
|
||||
CREATE TABLE t2 (placeholder CHAR(11));
|
||||
@ -960,7 +966,7 @@ i1 i2
|
||||
# Baseline:
|
||||
SHOW STATUS LIKE '%Handler_read_rnd_next';
|
||||
Variable_name Value
|
||||
Handler_read_rnd_next 17
|
||||
Handler_read_rnd_next 18
|
||||
|
||||
INSERT INTO t1 VALUES (NULL, NULL);
|
||||
FLUSH STATUS;
|
||||
@ -977,7 +983,7 @@ i1 i2
|
||||
# (read record from t1, but do not read from t2)
|
||||
SHOW STATUS LIKE '%Handler_read_rnd_next';
|
||||
Variable_name Value
|
||||
Handler_read_rnd_next 18
|
||||
Handler_read_rnd_next 19
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.1 tests
|
||||
CREATE TABLE t1 (
|
||||
|
@ -67,12 +67,15 @@ Handler_read_rnd_next 11
|
||||
select ' ^ This must show 11' Z;
|
||||
Z
|
||||
^ This must show 11
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
explain extended select a in (select max(ie) from t1 where oref=4 group by grp) 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 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary; Using filesort
|
||||
Warnings:
|
||||
Note 1003 select <in_optimizer>(`test`.`t3`.`a`,<exists>(select max(`test`.`t1`.`ie`) AS `max(ie)` from `test`.`t1` where (`test`.`t1`.`oref` = 4) group by `test`.`t1`.`grp` having trigcond((<cache>(`test`.`t3`.`a`) = <ref_null_helper>(max(`test`.`t1`.`ie`)))))) AS `a in (select max(ie) from t1 where oref=4 group by grp)` from `test`.`t3`
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
drop table t1, t2, t3;
|
||||
create table t1 (a int, oref int, key(a));
|
||||
insert into t1 values
|
||||
@ -696,6 +699,8 @@ a MAX(b) test
|
||||
2 3 h
|
||||
3 4 i
|
||||
DROP TABLE t1, t2;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
CREATE TABLE t1 (a int);
|
||||
CREATE TABLE t2 (b int, PRIMARY KEY(b));
|
||||
INSERT INTO t1 VALUES (1), (NULL), (4);
|
||||
@ -763,6 +768,7 @@ 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 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY PRIMARY 4 func 1 Using index; Using where
|
||||
DROP TABLE t1, t2;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES(1);
|
||||
CREATE TABLE t2 (placeholder CHAR(11));
|
||||
@ -964,7 +970,7 @@ i1 i2
|
||||
# Baseline:
|
||||
SHOW STATUS LIKE '%Handler_read_rnd_next';
|
||||
Variable_name Value
|
||||
Handler_read_rnd_next 17
|
||||
Handler_read_rnd_next 18
|
||||
|
||||
INSERT INTO t1 VALUES (NULL, NULL);
|
||||
FLUSH STATUS;
|
||||
@ -981,7 +987,7 @@ i1 i2
|
||||
# (read record from t1, but do not read from t2)
|
||||
SHOW STATUS LIKE '%Handler_read_rnd_next';
|
||||
Variable_name Value
|
||||
Handler_read_rnd_next 18
|
||||
Handler_read_rnd_next 19
|
||||
DROP TABLE t1,t2;
|
||||
End of 5.1 tests
|
||||
CREATE TABLE t1 (
|
||||
|
@ -1,8 +1,10 @@
|
||||
show variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='materialization=off';
|
||||
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
select (select 2);
|
||||
(select 2)
|
||||
2
|
||||
@ -4807,8 +4809,9 @@ SELECT 1 FROM t1 GROUP BY
|
||||
1
|
||||
1
|
||||
DROP TABLE t1;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
End of 5.1 tests.
|
||||
set optimizer_switch=default;
|
||||
show variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
|
@ -1,8 +1,10 @@
|
||||
show variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='materialization=off,semijoin=off';
|
||||
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
select (select 2);
|
||||
(select 2)
|
||||
2
|
||||
@ -4807,8 +4809,9 @@ SELECT 1 FROM t1 GROUP BY
|
||||
1
|
||||
1
|
||||
DROP TABLE t1;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
End of 5.1 tests.
|
||||
set optimizer_switch=default;
|
||||
show variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
|
@ -1,8 +1,10 @@
|
||||
show variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='semijoin=off';
|
||||
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
select (select 2);
|
||||
(select 2)
|
||||
2
|
||||
@ -4807,8 +4809,9 @@ SELECT 1 FROM t1 GROUP BY
|
||||
1
|
||||
1
|
||||
DROP TABLE t1;
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
End of 5.1 tests.
|
||||
set optimizer_switch=default;
|
||||
show variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
|
@ -202,39 +202,39 @@ BUG#37120 optimizer_switch allowable values not according to specification
|
||||
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,materialization=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off,materialization=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,materialization=off,semijoin=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off,materialization=off,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,materialization=off,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch=default;
|
||||
drop table t0, t1, t2;
|
||||
drop table t10, t11, t12;
|
||||
|
@ -206,39 +206,39 @@ BUG#37120 optimizer_switch allowable values not according to specification
|
||||
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,materialization=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off,materialization=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,materialization=off,semijoin=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=on,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off,materialization=off,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,semijoin=off,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=on,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch='default,materialization=off,loosescan=off';
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_condition_pushdown=on,firstmatch=on,loosescan=off,materialization=off,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on
|
||||
set optimizer_switch=default;
|
||||
drop table t0, t1, t2;
|
||||
drop table t10, t11, t12;
|
||||
|
@ -163,6 +163,9 @@ create table t1
|
||||
) engine = MYISAM ;
|
||||
create table t2 like t1;
|
||||
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
|
||||
set @stmt= ' explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2 GROUP BY t1.c15 LIMIT 1) as scalar_s, exists (select 1.0e+0 from t2 where t2.c3 * 9.0000000000 = t1.c4) as exists_s, c5 * 4 in (select c6 + 0.3e+1 from t2) as in_s, (c7 - 4, c8 - 4) in (select c9 + 4.0, c10 + 40e-1 from t2) as in_row_s FROM t1, (select c25 x, c32 y from t2) tt WHERE x * 1 = c25 ' ;
|
||||
prepare stmt1 from @stmt ;
|
||||
execute stmt1 ;
|
||||
@ -171,6 +174,8 @@ explain SELECT (SELECT SUM(c1 + c12 + 0.0) FROM t2 where (t1.c2 - 0e-3) = t2.c2
|
||||
deallocate prepare stmt1;
|
||||
drop tables t1,t2;
|
||||
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
|
||||
#
|
||||
# parameters from variables (for field creation)
|
||||
#
|
||||
|
@ -11,6 +11,9 @@
|
||||
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
|
||||
--enable_warnings
|
||||
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
|
||||
select (select 2);
|
||||
explain extended select (select 2);
|
||||
SELECT (SELECT 1) UNION SELECT (SELECT 2);
|
||||
@ -4061,4 +4064,6 @@ SELECT 1 FROM t1 GROUP BY
|
||||
(SELECT LAST_INSERT_ID() FROM t1 ORDER BY MIN(a) ASC LIMIT 1);
|
||||
DROP TABLE t1;
|
||||
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
|
||||
--echo End of 5.1 tests.
|
||||
|
@ -59,9 +59,13 @@ select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
|
||||
show status like 'Handler_read_rnd_next';
|
||||
select ' ^ This must show 11' Z;
|
||||
|
||||
set @save_optimizer_switch=@@optimizer_switch;
|
||||
set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=off";
|
||||
|
||||
# This must show trigcond:
|
||||
explain extended select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
|
||||
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
drop table t1, t2, t3;
|
||||
|
||||
#
|
||||
@ -529,6 +533,9 @@ SELECT a, MAX(b),
|
||||
|
||||
DROP TABLE t1, t2;
|
||||
|
||||
# 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";
|
||||
|
||||
#
|
||||
# Bug #27870: crash of an equijoin query with WHERE condition containing
|
||||
@ -588,6 +595,8 @@ EXPLAIN SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2);
|
||||
|
||||
DROP TABLE t1, t2;
|
||||
|
||||
set @@optimizer_switch=@save_optimizer_switch;
|
||||
|
||||
#
|
||||
# Bug #34763: item_subselect.cc:1235:Item_in_subselect::row_value_transformer:
|
||||
# Assertion failed, unexpected error message:
|
||||
|
@ -187,7 +187,11 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
|
||||
does not call setup_subquery_materialization(). We could make
|
||||
SELECT ... FROM DUAL call that function but that doesn't seem
|
||||
to be the case that is worth handling.
|
||||
4. Subquery is non-correlated
|
||||
4. Either the subquery predicate is a top-level predicate, or at
|
||||
least one partial match strategy is enabled. If no partial match
|
||||
strategy is enabled, then materialization cannot be used for
|
||||
non-top-level queries because it cannot handle NULLs correctly.
|
||||
5. Subquery is non-correlated
|
||||
TODO:
|
||||
This is an overly restrictive condition. It can be extended to:
|
||||
(Subquery is non-correlated ||
|
||||
@ -195,13 +199,13 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
|
||||
(Subquery is correlated to the immediate outer query &&
|
||||
Subquery !contains {GROUP BY, ORDER BY [LIMIT],
|
||||
aggregate functions}) && subquery predicate is not under "NOT IN"))
|
||||
5. No execution method was already chosen (by a prepared statement).
|
||||
6. No execution method was already chosen (by a prepared statement).
|
||||
|
||||
(*) The subquery must be part of a SELECT statement. The current
|
||||
condition also excludes multi-table update statements.
|
||||
|
||||
We have to determine whether we will perform subquery materialization
|
||||
before calling the IN=>EXISTS transformation, so that we know whether to
|
||||
Determine whether we will perform subquery materialization before
|
||||
calling the IN=>EXISTS transformation, so that we know whether to
|
||||
perform the whole transformation or only that part of it which wraps
|
||||
Item_in_subselect in an Item_in_optimizer.
|
||||
*/
|
||||
@ -211,11 +215,14 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
|
||||
select_lex->master_unit()->first_select()->leaf_tables && // 3
|
||||
thd->lex->sql_command == SQLCOM_SELECT && // *
|
||||
select_lex->outer_select()->leaf_tables && // 3A
|
||||
subquery_types_allow_materialization(in_subs))
|
||||
{
|
||||
subquery_types_allow_materialization(in_subs) &&
|
||||
// psergey-todo: duplicated_subselect_card_check: where it's done?
|
||||
if (!in_subs->is_correlated && // 4
|
||||
in_subs->exec_method == Item_in_subselect::NOT_TRANSFORMED) // 5
|
||||
(in_subs->is_top_level_item() ||
|
||||
optimizer_flag(thd, OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE) ||
|
||||
optimizer_flag(thd, OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN)) &&//4
|
||||
!in_subs->is_correlated && // 5
|
||||
in_subs->exec_method == Item_in_subselect::NOT_TRANSFORMED) // 6
|
||||
{
|
||||
in_subs->exec_method= Item_in_subselect::MATERIALIZATION;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user