This commit is contained in:
Igor Babaev 2010-08-31 09:40:10 -07:00
commit 3165c74918
31 changed files with 4511 additions and 1870 deletions

View file

@ -123,6 +123,7 @@ analyze table t1;
select count(*) from t1;
--replace_column 9 REF
--replace_result i2,i1 i1,i2
explain select count(*) from t1 where
key1a = 2 and key1b is null and key2a = 2 and key2b is null;
@ -130,6 +131,7 @@ select count(*) from t1 where
key1a = 2 and key1b is null and key2a = 2 and key2b is null;
--replace_column 9 REF
--replace_result i3,i1 i1,i3
explain select count(*) from t1 where
key1a = 2 and key1b is null and key3a = 2 and key3b is null;

1147
mysql-test/r/join_cache.result Normal file → Executable file

File diff suppressed because it is too large Load diff

4
mysql-test/r/join_nested_jcl6.result Normal file → Executable file
View file

@ -1,3 +1,6 @@
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
Variable_name Value
@ -1854,3 +1857,4 @@ set join_cache_level=default;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
set @@optimizer_switch=@save_optimizer_switch_jcl6;

4
mysql-test/r/join_outer_jcl6.result Normal file → Executable file
View file

@ -1,3 +1,6 @@
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
Variable_name Value
@ -1317,3 +1320,4 @@ set join_cache_level=default;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
set @@optimizer_switch=@save_optimizer_switch_jcl6;

34
mysql-test/r/optimizer_switch.result Normal file → Executable file
View file

@ -4,19 +4,19 @@
#
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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch=4;
ERROR 42000: Variable 'optimizer_switch' can't be set to the value of '4'
set optimizer_switch=NULL;
@ -43,57 +43,57 @@ 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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=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,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=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,subquery_cache=on,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on
set optimizer_switch=default;

4
mysql-test/r/select_jcl6.result Normal file → Executable file
View file

@ -1,3 +1,6 @@
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
Variable_name Value
@ -4790,3 +4793,4 @@ set join_cache_level=default;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
set @@optimizer_switch=@save_optimizer_switch_jcl6;

12
mysql-test/r/subselect3.result Normal file → Executable file
View file

@ -1,4 +1,5 @@
drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22;
set @save_optimizer_switch=@@optimizer_switch;
create table t1 (oref int, grp int, ie int) ;
insert into t1 (oref, grp, ie) values
(1, 1, 1),
@ -1046,7 +1047,7 @@ select (select max(Y.a) from t1 Y where a in (select a from t1 Z) and a < X.a) a
subq
NULL
0
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t1;
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
@ -1107,7 +1108,7 @@ a
17
18
19
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
explain select * from (select a from t0) X where a in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 11
@ -1153,7 +1154,7 @@ show status like 'Created_tmp_disk_tables';
Variable_name Value
Created_tmp_disk_tables 1
set @save_max_heap_table_size=@@max_heap_table_size;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t0, t1;
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
@ -1203,7 +1204,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Start temporary
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer
drop table t1;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 as select * from t1;
@ -1285,7 +1286,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY subselect2 eq_ref unique_key unique_key 10 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 100
set @@optimizer_search_depth=@save_optimizer_search_depth;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t0, t1, t2;
create table t0 (a decimal(4,2));
insert into t0 values (10.24), (22.11);
@ -1426,3 +1427,4 @@ CALL p1;
ERROR 42S22: Unknown column 'f1' in 'where clause'
DROP PROCEDURE p1;
DROP TABLE t1, t2;
set @@optimizer_switch=@save_optimizer_switch;

16
mysql-test/r/subselect3_jcl6.result Normal file → Executable file
View file

@ -1,8 +1,12 @@
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 6
drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22;
set @save_optimizer_switch=@@optimizer_switch;
create table t1 (oref int, grp int, ie int) ;
insert into t1 (oref, grp, ie) values
(1, 1, 1),
@ -1051,7 +1055,7 @@ select (select max(Y.a) from t1 Y where a in (select a from t1 Z) and a < X.a) a
subq
NULL
0
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t1;
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
@ -1112,7 +1116,7 @@ a
17
18
19
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
explain select * from (select a from t0) X where a in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 11
@ -1158,7 +1162,7 @@ show status like 'Created_tmp_disk_tables';
Variable_name Value
Created_tmp_disk_tables 1
set @save_max_heap_table_size=@@max_heap_table_size;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t0, t1;
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
@ -1208,7 +1212,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Start temporary
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer
drop table t1;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 as select * from t1;
@ -1290,7 +1294,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY subselect2 eq_ref unique_key unique_key 10 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 100
set @@optimizer_search_depth=@save_optimizer_search_depth;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t0, t1, t2;
create table t0 (a decimal(4,2));
insert into t0 values (10.24), (22.11);
@ -1431,7 +1435,9 @@ CALL p1;
ERROR 42S22: Unknown column 'f1' in 'where clause'
DROP PROCEDURE p1;
DROP TABLE t1, t2;
set @@optimizer_switch=@save_optimizer_switch;
set join_cache_level=default;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
set @@optimizer_switch=@save_optimizer_switch;

11
mysql-test/r/subselect_sj.result Normal file → Executable file
View file

@ -1,4 +1,5 @@
drop table if exists t0, t1, t2, t3, t4, t10, t11, t12;
set @save_optimizer_switch=@@optimizer_switch;
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);
@ -322,7 +323,8 @@ INSERT INTO WORKS VALUES ('E3','P2',20);
INSERT INTO WORKS VALUES ('E4','P2',20);
INSERT INTO WORKS VALUES ('E4','P4',40);
INSERT INTO WORKS VALUES ('E4','P5',80);
set optimizer_switch='default,materialization=off';
set optimizer_switch=@save_optimizer_switch;
set optimizer_switch='materialization=off';
explain SELECT EMPNUM, EMPNAME
FROM STAFF
WHERE EMPNUM IN
@ -344,7 +346,7 @@ E1 Alice
E2 Betty
E3 Carmen
E4 Don
set optimizer_switch='default';
set optimizer_switch=@save_optimizer_switch;
drop table STAFF,WORKS,PROJ;
# End of bug#45191
#
@ -450,7 +452,7 @@ COUNT(*)
drop table t1, t2;
drop view v1;
drop procedure p1;
set SESSION optimizer_switch='default';
set SESSION optimizer_switch=@save_optimizer_switch;
# End of bug#46744
Bug#46797 "Crash in fix_semijoin_strategies_for_picked_join_order
@ -601,7 +603,7 @@ v1field
DROP TABLE t1,t2;
DROP VIEW v1,v2;
DROP PROCEDURE p1;
set SESSION optimizer_switch='default';
set SESSION optimizer_switch=@save_optimizer_switch;
# End of BUG#48834
Bug#49097 subquery with view generates wrong result with
@ -1075,3 +1077,4 @@ DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
# End of Bug#48623
set @@optimizer_switch=@save_optimizer_switch;

4
mysql-test/r/subselect_sj2_jcl6.result Normal file → Executable file
View file

@ -1,3 +1,6 @@
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
Variable_name Value
@ -733,3 +736,4 @@ set join_cache_level=default;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
set @@optimizer_switch=@save_optimizer_switch_jcl6;

15
mysql-test/r/subselect_sj_jcl6.result Normal file → Executable file
View file

@ -1,8 +1,12 @@
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 6
drop table if exists t0, t1, t2, t3, t4, t10, t11, t12;
set @save_optimizer_switch=@@optimizer_switch;
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);
@ -326,7 +330,8 @@ INSERT INTO WORKS VALUES ('E3','P2',20);
INSERT INTO WORKS VALUES ('E4','P2',20);
INSERT INTO WORKS VALUES ('E4','P4',40);
INSERT INTO WORKS VALUES ('E4','P5',80);
set optimizer_switch='default,materialization=off';
set optimizer_switch=@save_optimizer_switch;
set optimizer_switch='materialization=off';
explain SELECT EMPNUM, EMPNAME
FROM STAFF
WHERE EMPNUM IN
@ -348,7 +353,7 @@ E1 Alice
E2 Betty
E3 Carmen
E4 Don
set optimizer_switch='default';
set optimizer_switch=@save_optimizer_switch;
drop table STAFF,WORKS,PROJ;
# End of bug#45191
#
@ -454,7 +459,7 @@ COUNT(*)
drop table t1, t2;
drop view v1;
drop procedure p1;
set SESSION optimizer_switch='default';
set SESSION optimizer_switch=@save_optimizer_switch;
# End of bug#46744
Bug#46797 "Crash in fix_semijoin_strategies_for_picked_join_order
@ -605,7 +610,7 @@ v1field
DROP TABLE t1,t2;
DROP VIEW v1,v2;
DROP PROCEDURE p1;
set SESSION optimizer_switch='default';
set SESSION optimizer_switch=@save_optimizer_switch;
# End of BUG#48834
Bug#49097 subquery with view generates wrong result with
@ -1079,6 +1084,7 @@ DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
# End of Bug#48623
set @@optimizer_switch=@save_optimizer_switch;
#
# BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off
#
@ -1114,3 +1120,4 @@ set join_cache_level=default;
show variables like 'join_cache_level';
Variable_name Value
join_cache_level 1
set @@optimizer_switch=@save_optimizer_switch_jcl6;

259
mysql-test/t/join_cache.test Normal file → Executable file
View file

@ -3,6 +3,10 @@ DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
DROP DATABASE IF EXISTS world;
--enable_warnings
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set names utf8;
CREATE DATABASE world;
@ -160,7 +164,7 @@ use world;
--enable_query_log
show variables like 'join_buffer_size';
set join_cache_level=5;
set join_cache_level=3;
show variables like 'join_cache_level';
EXPLAIN
@ -187,14 +191,106 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
EXPLAIN
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
WHERE
Country.Population > 10000000;
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
WHERE
Country.Population > 10000000;
show variables like 'join_buffer_size';
set join_cache_level=4;
show variables like 'join_cache_level';
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
EXPLAIN
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
WHERE
Country.Population > 10000000;
SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
FROM Country LEFT JOIN CountryLanguage ON
(CountryLanguage.Country=Country.Code AND Language='English')
WHERE
Country.Population > 10000000;
show variables like 'join_buffer_size';
set join_cache_level=5;
show variables like 'join_cache_level';
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
EXPLAIN
SELECT Name FROM City
@ -245,15 +341,6 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@ -303,15 +390,6 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@ -361,15 +439,6 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@ -395,7 +464,7 @@ SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.P
set join_buffer_size=256;
show variables like 'join_buffer_size';
set join_cache_level=5;
set join_cache_level=3;
show variables like 'join_cache_level';
EXPLAIN
@ -422,14 +491,77 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
set join_cache_level=4;
show variables like 'join_cache_level';
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
City.Population > 100000;
set join_cache_level=5;
show variables like 'join_cache_level';
EXPLAIN
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND
Country.Name LIKE 'L%' AND City.Population > 100000;
EXPLAIN
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND
CountryLanguage.Country=Country.Code AND
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
EXPLAIN
SELECT Name FROM City
@ -467,15 +599,6 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@ -512,15 +635,6 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@ -557,15 +671,6 @@ SELECT City.Name, Country.Name, CountryLanguage.Language
City.Name LIKE 'L%' AND Country.Population > 3000000 AND
CountryLanguage.Percentage > 50;
--echo # !!!NB igor: after backporting the SJ code the following should return
--echo # EXPLAIN
--echo # SELECT Name FROM City
--echo # WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
--echo # City.Population > 100000;
--echo # id select_type table type possible_keys key key_len ref rows Extra
--echo # 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Using MRR
--echo # 1 PRIMARY City ref Population,Country Country 3 world.Country.Code 18 Using where; Using join buffer
EXPLAIN
SELECT Name FROM City
WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
@ -587,7 +692,7 @@ SELECT City.Name, Country.Name FROM City,Country
WHERE City.Country=Country.Code AND City.Population > 3000000;
set join_cache_level=8;
set join_buffer_size=256;
set join_buffer_size=384;
--replace_column 9 #
EXPLAIN
@ -997,7 +1102,7 @@ select * from t1 left join t2 on (1=0);
explain select * from t1 left join t2 on (1=0) where a=40;
select * from t1 left join t2 on (1=0) where a=40;
set join_cache_level=1;
set join_cache_level=0;
explain select * from t1 left join t2 on (1=0);
set join_cache_level=default;
@ -1131,6 +1236,8 @@ INSERT INTO t3(a,b) VALUES
(5,30), (5,40), (5,50), (5,60), (5,70), (5,80),
(7,30), (7,40), (7,50), (7,60), (7,70), (7,80);
set join_cache_level=0;
SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
WHERE t1.a=t2.a;
@ -1148,7 +1255,7 @@ SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
WHERE t1.a=t2.a;
DROP INDEX idx ON t3;
set join_cache_level=4;
set join_cache_level=2;
EXPLAIN
SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
@ -1847,3 +1954,5 @@ select t1.* from t1,t2,t3;
set join_cache_level=default;
drop table t1,t2,t3;
set @@optimizer_switch=@save_optimizer_switch;

6
mysql-test/t/join_nested_jcl6.test Normal file → Executable file
View file

@ -2,6 +2,10 @@
# Run join_nested.test with BKA enabled
#
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
@ -93,3 +97,5 @@ DROP TABLE t5,t6,t7,t8;
set join_cache_level=default;
show variables like 'join_cache_level';
set @@optimizer_switch=@save_optimizer_switch_jcl6;

6
mysql-test/t/join_outer_jcl6.test Normal file → Executable file
View file

@ -2,6 +2,10 @@
# Run join_outer.test with BKA enabled
#
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
@ -9,3 +13,5 @@ show variables like 'join_cache_level';
set join_cache_level=default;
show variables like 'join_cache_level';
set @@optimizer_switch=@save_optimizer_switch_jcl6;

6
mysql-test/t/select_jcl6.test Normal file → Executable file
View file

@ -2,6 +2,10 @@
# Run select.test with BKA enabled
#
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
@ -9,3 +13,5 @@ show variables like 'join_cache_level';
set join_cache_level=default;
show variables like 'join_cache_level';
set @@optimizer_switch=@save_optimizer_switch_jcl6;

15
mysql-test/t/subselect3.test Normal file → Executable file
View file

@ -2,6 +2,8 @@
drop table if exists t0, t1, t2, t3, t4, t5, t11, t12, t21, t22;
--enable_warnings
set @save_optimizer_switch=@@optimizer_switch;
#
# 1. Subquery with GROUP/HAVING
#
@ -888,7 +890,7 @@ set @@optimizer_switch='firstmatch=off';
explain
select (select max(Y.a) from t1 Y where a in (select a from t1 Z) and a < X.a) as subq from t1 X;
select (select max(Y.a) from t1 Y where a in (select a from t1 Z) and a < X.a) as subq from t1 X;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t1;
@ -906,7 +908,7 @@ select * from t1 where 2 in (select a from t0);
set @@optimizer_switch='default,materialization=off';
explain select * from t1 where 2 in (select a from t0);
select * from t1 where 2 in (select a from t0);
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
#
@ -952,7 +954,7 @@ flush status;
select count(*) from t0 A, t0 B, t0 C, t0 D where D.a in (select a from t1 E);
show status like 'Created_tmp_disk_tables';
set @save_max_heap_table_size=@@max_heap_table_size;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t0, t1;
#
@ -990,7 +992,7 @@ create table t1 (a decimal);
insert into t1 values (1),(2);
explain select * from t1 where a in (select a from t1);
drop table t1;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
#
# SJ-Materialization-scan for non-first table
@ -1051,7 +1053,7 @@ set @save_optimizer_search_depth=@@optimizer_search_depth;
set @@optimizer_search_depth=63;
explain select * from t1 where (a,b) in (select a,b from t2);
set @@optimizer_search_depth=@save_optimizer_search_depth;
set @@optimizer_switch=default;
set @@optimizer_switch=@save_optimizer_switch;
drop table t0, t1, t2;
@ -1181,3 +1183,6 @@ ALTER TABLE t2 CHANGE COLUMN f1 my_column INT;
CALL p1;
DROP PROCEDURE p1;
DROP TABLE t1, t2;
# The following command must be the last one the file
set @@optimizer_switch=@save_optimizer_switch;

6
mysql-test/t/subselect3_jcl6.test Normal file → Executable file
View file

@ -2,6 +2,10 @@
# Run subselect3.test with BKA enabled
#
set @save_optimizer_switch=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
@ -9,3 +13,5 @@ show variables like 'join_cache_level';
set join_cache_level=default;
show variables like 'join_cache_level';
set @@optimizer_switch=@save_optimizer_switch;

14
mysql-test/t/subselect_sj.test Normal file → Executable file
View file

@ -5,6 +5,8 @@
drop table if exists t0, t1, t2, t3, t4, t10, t11, t12;
--enable_warnings
set @save_optimizer_switch=@@optimizer_switch;
#
# 1. Subqueries that are converted into semi-joins
#
@ -224,7 +226,8 @@ INSERT INTO WORKS VALUES ('E4','P2',20);
INSERT INTO WORKS VALUES ('E4','P4',40);
INSERT INTO WORKS VALUES ('E4','P5',80);
set optimizer_switch='default,materialization=off';
set optimizer_switch=@save_optimizer_switch;
set optimizer_switch='materialization=off';
explain SELECT EMPNUM, EMPNAME
FROM STAFF
@ -240,7 +243,7 @@ WHERE EMPNUM IN
WHERE PNUM IN
(SELECT PNUM FROM PROJ));
set optimizer_switch='default';
set optimizer_switch=@save_optimizer_switch;
drop table STAFF,WORKS,PROJ;
@ -359,7 +362,7 @@ drop table t1, t2;
drop view v1;
drop procedure p1;
set SESSION optimizer_switch='default';
set SESSION optimizer_switch=@save_optimizer_switch;
--echo # End of bug#46744
@ -526,7 +529,7 @@ DROP TABLE t1,t2;
DROP VIEW v1,v2;
DROP PROCEDURE p1;
set SESSION optimizer_switch='default';
set SESSION optimizer_switch=@save_optimizer_switch;
--echo # End of BUG#48834
@ -935,3 +938,6 @@ DROP TABLE t2;
DROP TABLE t3;
--echo # End of Bug#48623
# The following command must be the last one the file
set @@optimizer_switch=@save_optimizer_switch;

7
mysql-test/t/subselect_sj2_jcl6.test Normal file → Executable file
View file

@ -2,6 +2,10 @@
# Run subselect_sj2.test with BKA enabled
#
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
@ -9,3 +13,6 @@ show variables like 'join_cache_level';
set join_cache_level=default;
show variables like 'join_cache_level';
set @@optimizer_switch=@save_optimizer_switch_jcl6;

6
mysql-test/t/subselect_sj_jcl6.test Normal file → Executable file
View file

@ -2,6 +2,10 @@
# Run subselect_sj.test with BKA enabled
#
set @save_optimizer_switch_jcl6=@@optimizer_switch;
set @@optimizer_switch='semijoin_with_cache=on';
set @@optimizer_switch='outer_join_with_cache=on';
set join_cache_level=6;
show variables like 'join_cache_level';
@ -37,3 +41,5 @@ drop table t0, t1, t2;
set join_cache_level=default;
show variables like 'join_cache_level';
set @@optimizer_switch=@save_optimizer_switch_jcl6;

View file

@ -1211,6 +1211,8 @@ typedef struct st_range_seq_if
bool (*skip_index_tuple) (range_seq_t seq, char *range_info);
} RANGE_SEQ_IF;
typedef bool (*SKIP_INDEX_TUPLE_FUNC) (range_seq_t seq, char *range_info);
class COST_VECT
{
public:

21
sql/mysql_priv.h Normal file → Executable file
View file

@ -571,12 +571,17 @@ protected:
#define OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE 512
#define OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN 1024
#define OPTIMIZER_SWITCH_SUBQUERY_CACHE (1<<11)
#define OPTIMIZER_SWITCH_OUTER_JOIN_WITH_CACHE (1<<12)
#define OPTIMIZER_SWITCH_SEMIJOIN_WITH_CACHE (1<<13)
#define OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL (1<<14)
#define OPTIMIZER_SWITCH_JOIN_CACHE_HASHED (1<<15)
#define OPTIMIZER_SWITCH_JOIN_CACHE_BKA (1<<16)
#ifdef DBUG_OFF
# define OPTIMIZER_SWITCH_LAST (1<<12)
# define OPTIMIZER_SWITCH_LAST (1<<17)
#else
# define OPTIMIZER_SWITCH_TABLE_ELIMINATION (1<<12)
# define OPTIMIZER_SWITCH_LAST (1<<13)
# define OPTIMIZER_SWITCH_TABLE_ELIMINATION (1<<17)
# define OPTIMIZER_SWITCH_LAST (1<<18)
#endif
#ifdef DBUG_OFF
@ -592,7 +597,10 @@ protected:
OPTIMIZER_SWITCH_SEMIJOIN | \
OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\
OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\
OPTIMIZER_SWITCH_SUBQUERY_CACHE)
OPTIMIZER_SWITCH_SUBQUERY_CACHE | \
OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL | \
OPTIMIZER_SWITCH_JOIN_CACHE_HASHED | \
OPTIMIZER_SWITCH_JOIN_CACHE_BKA)
#else
# define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
@ -606,7 +614,10 @@ protected:
OPTIMIZER_SWITCH_SEMIJOIN | \
OPTIMIZER_SWITCH_PARTIAL_MATCH_ROWID_MERGE|\
OPTIMIZER_SWITCH_PARTIAL_MATCH_TABLE_SCAN|\
OPTIMIZER_SWITCH_SUBQUERY_CACHE)
OPTIMIZER_SWITCH_SUBQUERY_CACHE | \
OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL | \
OPTIMIZER_SWITCH_JOIN_CACHE_HASHED | \
OPTIMIZER_SWITCH_JOIN_CACHE_BKA)
#endif
/*

29
sql/mysqld.cc Normal file → Executable file
View file

@ -308,6 +308,11 @@ static const char *optimizer_switch_names[]=
"partial_match_rowid_merge",
"partial_match_table_scan",
"subquery_cache",
"outer_join_with_cache",
"semijoin_with_cache",
"join_cache_incremental",
"join_cache_hashed",
"join_cache_bka",
#ifndef DBUG_OFF
"table_elimination",
#endif
@ -329,6 +334,11 @@ static const unsigned int optimizer_switch_names_len[]=
sizeof("partial_match_rowid_merge") - 1,
sizeof("partial_match_table_scan") - 1,
sizeof("subquery_cache") - 1,
sizeof("outer_join_with_cache") - 1,
sizeof("semijoin_with_cache") - 1,
sizeof("join_cache_incremental") - 1,
sizeof("join_cache_hashed") - 1,
sizeof("join_cache_bka") - 1,
#ifndef DBUG_OFF
sizeof("table_elimination") - 1,
#endif
@ -415,7 +425,10 @@ static const char *optimizer_switch_str="index_merge=on,index_merge_union=on,"
"semijoin=on,"
"partial_match_rowid_merge=on,"
"partial_match_table_scan=on,"
"subquery_cache=on"
"subquery_cache=on,"
"join_cache_incremental=on,"
"join_cache_hashed=on,"
"join_cache_bka=on"
#ifndef DBUG_OFF
",table_elimination=on";
#else
@ -5865,7 +5878,8 @@ enum options_mysqld
OPT_DELAYED_INSERT_LIMIT, OPT_DELAYED_QUEUE_SIZE,
OPT_FLUSH_TIME, OPT_FT_MIN_WORD_LEN, OPT_FT_BOOLEAN_SYNTAX,
OPT_FT_MAX_WORD_LEN, OPT_FT_QUERY_EXPANSION_LIMIT, OPT_FT_STOPWORD_FILE,
OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE, OPT_JOIN_CACHE_LEVEL,
OPT_INTERACTIVE_TIMEOUT, OPT_JOIN_BUFF_SIZE,
OPT_JOIN_BUFF_SPACE_LIMIT, OPT_JOIN_CACHE_LEVEL,
OPT_KEY_BUFFER_SIZE, OPT_KEY_CACHE_BLOCK_SIZE,
OPT_KEY_CACHE_DIVISION_LIMIT, OPT_KEY_CACHE_AGE_THRESHOLD,
OPT_KEY_CACHE_PARTITIONS,
@ -6958,11 +6972,17 @@ log and this option does nothing anymore.",
(uchar**) &max_system_variables.net_interactive_timeout, 0,
GET_ULONG, REQUIRED_ARG, NET_WAIT_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
{"join_buffer_size", OPT_JOIN_BUFF_SIZE,
"The size of the buffer that is used for full joins.",
"The size of the buffer that is used for joins.",
(uchar**) &global_system_variables.join_buff_size,
(uchar**) &max_system_variables.join_buff_size, 0, GET_ULONG,
REQUIRED_ARG, 128*1024L, 128+MALLOC_OVERHEAD, (longlong) ULONG_MAX,
MALLOC_OVERHEAD, 128, 0},
{"join_buffer_space_limit", OPT_JOIN_BUFF_SPACE_LIMIT,
"The limit of the space for all join buffers used by a query.",
(uchar**) &global_system_variables.join_buff_space_limit,
(uchar**) &max_system_variables.join_buff_space_limit, 0, GET_ULL,
REQUIRED_ARG, 8*128*1024L, 2048+MALLOC_OVERHEAD, (longlong) ULONGLONG_MAX,
MALLOC_OVERHEAD, 2048, 0},
{"join_cache_level", OPT_JOIN_CACHE_LEVEL,
"Controls what join operations can be executed with join buffers. Odd numbers are used for plain join buffers while even numbers are used for linked buffers",
(uchar**) &global_system_variables.join_cache_level,
@ -7235,7 +7255,8 @@ The minimum value for this variable is 4096.",
"index_merge_union, index_merge_sort_union, index_merge_intersection, "
"index_condition_pushdown, firstmatch, loosescan, materialization, "
"semijoin, partial_match_rowid_merge, partial_match_table_scan, "
"subquery_cache"
"subquery_cache, outer_join_with_cache, semijoin_with_cache, "
"join_cache_incremental, join_cache_hashed, join_cache_bka"
#ifndef DBUG_OFF
", table_elimination"
#endif

3
sql/opt_subselect.h Normal file → Executable file
View file

@ -199,7 +199,8 @@ public:
double records= rows2double(s->table->file->stats.records);
/* The cost is entire index scan cost (divided by 2) */
double read_time= s->table->file->keyread_read_time(key, 1, records);
double read_time=
s->table->file->keyread_read_time(key, 1, (ha_rows) records);
/*
Now find out how many different keys we will get (for now we

5
sql/set_var.cc Normal file → Executable file
View file

@ -319,6 +319,9 @@ static sys_var_thd_ulong sys_interactive_timeout(&vars, "interactive_timeout",
&SV::net_interactive_timeout);
static sys_var_thd_ulong sys_join_buffer_size(&vars, "join_buffer_size",
&SV::join_buff_size);
static sys_var_thd_ulonglong sys_join_buffer_space_limit(&vars,
"join_buffer_space_limit",
&SV::join_buff_space_limit);
static sys_var_thd_ulong sys_join_cache_level(&vars, "join_cache_level",
&SV::join_cache_level);
static sys_var_key_buffer_size sys_key_buffer_size(&vars, "key_buffer_size");
@ -4045,7 +4048,7 @@ bool
sys_var_thd_optimizer_switch::
symbolic_mode_representation(THD *thd, ulonglong val, LEX_STRING *rep)
{
char buff[STRING_BUFFER_USUAL_SIZE*8];
char buff[STRING_BUFFER_USUAL_SIZE*18];
String tmp(buff, sizeof(buff), &my_charset_latin1);
int i;
ulonglong bit;

1
sql/sql_class.h Normal file → Executable file
View file

@ -376,6 +376,7 @@ struct system_variables
ulonglong max_heap_table_size;
ulonglong tmp_table_size;
ulonglong long_query_time;
ulonglong join_buff_space_limit;
ha_rows select_limit;
ha_rows max_join_size;
ulong auto_increment_increment, auto_increment_offset;

3479
sql/sql_join_cache.cc Normal file → Executable file

File diff suppressed because it is too large Load diff

289
sql/sql_select.cc Normal file → Executable file
View file

@ -94,6 +94,7 @@ static void make_outerjoin_info(JOIN *join);
static Item*
make_cond_after_sjm(Item *root_cond, Item *cond, table_map tables, table_map sjm_tables);
static bool make_join_select(JOIN *join,SQL_SELECT *select,COND *item);
static void revise_cache_usage(JOIN_TAB *join_tab);
static bool make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after);
static bool only_eq_ref_tables(JOIN *join, ORDER *order, table_map tables);
static void update_depend_map(JOIN *join);
@ -1671,6 +1672,62 @@ void JOIN::restore_tmp()
}
/*
Shrink join buffers used for preceding tables to reduce the occupied space
SYNOPSIS
shrink_join_buffers()
jt table up to which the buffers are to be shrunk
curr_space the size of the space used by the buffers for tables 1..jt
needed_space the size of the space that has to be used by these buffers
DESCRIPTION
The function makes an attempt to shrink all join buffers used for the
tables starting from the first up to jt to reduce the total size of the
space occupied by the buffers used for tables 1,...,jt from curr_space
to needed_space.
The function assumes that the buffer for the table jt has not been
allocated yet.
RETURN
FALSE if all buffer have been successfully shrunk
TRUE otherwise
*/
bool JOIN::shrink_join_buffers(JOIN_TAB *jt,
ulonglong curr_space,
ulonglong needed_space)
{
JOIN_CACHE *cache;
for (JOIN_TAB *tab= join_tab+const_tables; tab < jt; tab++)
{
cache= tab->cache;
if (cache)
{
ulong buff_size;
if (needed_space < cache->get_min_join_buffer_size())
return TRUE;
if (cache->shrink_join_buffer_in_ratio(curr_space, needed_space))
{
revise_cache_usage(tab);
return TRUE;
}
buff_size= cache->get_join_buffer_size();
curr_space-= buff_size;
needed_space-= buff_size;
}
}
cache= jt->cache;
DBUG_ASSERT(cache);
if (needed_space < cache->get_min_join_buffer_size())
return TRUE;
cache->set_join_buffer_size(needed_space);
return FALSE;
}
int
JOIN::reinit()
{
@ -4617,7 +4674,8 @@ best_access_path(JOIN *join,
if (table->covering_keys.is_set(key))
{
/* we can use only index tree */
tmp= record_count * table->file->keyread_read_time(key, 1, tmp);
tmp= record_count *
table->file->keyread_read_time(key, 1, (ha_rows) tmp);
}
else
tmp= record_count*min(tmp,s->worst_seeks);
@ -4782,7 +4840,8 @@ best_access_path(JOIN *join,
if (table->covering_keys.is_set(key))
{
/* we can use only index tree */
tmp= record_count * table->file->keyread_read_time(key, 1, tmp);
tmp= record_count *
table->file->keyread_read_time(key, 1, (ha_rows) tmp);
}
else
tmp= record_count * min(tmp,s->worst_seeks);
@ -5848,15 +5907,15 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
Find how much space the prevous read not const tables takes in cache.
*/
void calc_used_field_length(THD *thd, JOIN_TAB *join_tab)
void JOIN_TAB::calc_used_field_length(bool max_fl)
{
uint null_fields,blobs,fields,rec_length;
Field **f_ptr,*field;
uint uneven_bit_fields;
MY_BITMAP *read_set= join_tab->table->read_set;
MY_BITMAP *read_set= table->read_set;
uneven_bit_fields= null_fields= blobs= fields= rec_length=0;
for (f_ptr=join_tab->table->field ; (field= *f_ptr) ; f_ptr++)
for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++)
{
if (bitmap_is_set(read_set, field->field_index))
{
@ -5873,24 +5932,31 @@ void calc_used_field_length(THD *thd, JOIN_TAB *join_tab)
}
}
if (null_fields || uneven_bit_fields)
rec_length+=(join_tab->table->s->null_fields+7)/8;
if (join_tab->table->maybe_null)
rec_length+=(table->s->null_fields+7)/8;
if (table->maybe_null)
rec_length+=sizeof(my_bool);
if (blobs)
if (max_fl)
{
uint blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
(join_tab->table->s->reclength-rec_length));
rec_length+=(uint) max(4,blob_length);
}
// TODO: to improve this estimate for max expected length if the record
if (blobs)
{
uint blob_length=(uint) (table->file->stats.mean_rec_length-
(table->s->reclength-rec_length));
rec_length+=(uint) max(4,blob_length);
}
}
else
rec_length= table->file->stats.mean_rec_length;
/*
psergey-todo: why we don't count here rowid that we might need to store
when using DuplicateElimination?
*/
join_tab->used_fields=fields;
join_tab->used_fieldlength=rec_length;
join_tab->used_blobs=blobs;
join_tab->used_null_fields= null_fields;
join_tab->used_uneven_bit_fields= uneven_bit_fields;
used_fields=fields;
used_fieldlength=rec_length;
used_blobs=blobs;
used_null_fields= null_fields;
used_uneven_bit_fields= uneven_bit_fields;
}
@ -5899,16 +5965,13 @@ cache_record_length(JOIN *join,uint idx)
{
uint length=0;
JOIN_TAB **pos,**end;
THD *thd=join->thd;
for (pos=join->best_ref+join->const_tables,end=join->best_ref+idx ;
pos != end ;
pos++)
{
JOIN_TAB *join_tab= *pos;
if (!join_tab->used_fieldlength) /* Not calced yet */
calc_used_field_length(thd, join_tab);
length+=join_tab->used_fieldlength;
length+= join_tab->get_used_fieldlength();
}
return length;
}
@ -7344,24 +7407,66 @@ end_sj_materialize(JOIN *join, JOIN_TAB *join_tab, bool end_of_records)
depend on:
- the access method to access rows of the joined table
- whether the join table is an inner table of an outer join or semi-join
- whether the optimizer switches
outer_join_with_cache, semijoin_with_cache, join_cache_incremental,
join_cache_hashed, join_cache_bka,
are set on or off
- the join cache level set for the query
- the join 'options'.
In any case join buffer is not used if the number of the joined table is
greater than 'no_jbuf_after'. It's also never used if the value of
join_cache_level is equal to 0.
The other valid settings of join_cache_level lay in the interval 1..8.
If join_cache_level==1|2 then join buffer is used only for inner joins
with 'JT_ALL' access method.
If join_cache_level==3|4 then join buffer is used for any join operation
(inner join, outer join, semi-join) with 'JT_ALL' access method.
If 'JT_ALL' access method is used to read rows of the joined table then
always a JOIN_CACHE_BNL object is employed.
If the optimizer switch outer_join_with_cache is off no join buffer is
used for outer join operations.
If the optimizer switch semijoin_with_cache is off no join buffer is used
for semi-join operations.
If the optimizer switch join_cache_incremental is off no incremental join
buffers are used.
If the optimizer switch join_cache_hashed is off then the optimizer does
not use neither BNLH algorithm, nor BKAH algorithm to perform join
operations.
If the optimizer switch join_cache_bka is off then the optimizer does not
use neither BKA algprithm, nor BKAH algorithm to perform join operation.
The valid settings for join_cache_level lay in the interval 0..8.
If it set to 0 no join buffers are used to perform join operations.
Currently we differentiate between join caches of 8 levels:
1 : non-incremental join cache used for BNL join algorithm
2 : incremental join cache used for BNL join algorithm
3 : non-incremental join cache used for BNLH join algorithm
4 : incremental join cache used for BNLH join algorithm
5 : non-incremental join cache used for BKA join algorithm
6 : incremental join cache used for BKA join algorithm
7 : non-incremental join cache used for BKAH join algorithm
8 : incremental join cache used for BKAH join algorithm
If the value of join_cache_level is set to n then no join caches of
levels higher than n can be employed.
If the optimizer switches outer_join_with_cache, semijoin_with_cache,
join_cache_incremental, join_cache_hashed, join_cache_bka are all on
the following rules are applied.
If join_cache_level==1|2 then join buffer is used for inner joins, outer
joins and semi-joins with 'JT_ALL' access method. In this case a
JOIN_CACHE_BNL object is employed.
If join_cache_level==3|4 and then join buffer is used for a join operation
(inner join, outer join, semi-join) with 'JT_REF'/'JT_EQREF' access method
then a JOIN_CACHE_BNLH object is employed.
If an index is used to access rows of the joined table and the value of
join_cache_level==5|6 then a JOIN_CACHE_BKA object is employed.
If an index is used to access rows of the joined table and the value of
join_cache_level==7|8 then a JOIN_CACHE_BKA_UNIQUE object is employed.
join_cache_level==7|8 then a JOIN_CACHE_BKAH object is employed.
If the value of join_cache_level is odd then creation of a non-linked
join cache is forced.
Currently for any join operation a join cache of the level of the
highest allowed and applicable level is used.
For example, if join_cache_level is set to 6 and the optimizer switch
join_cache_bka is off, while the optimizer switch join_cache_hashed is
on then for any inner join operation with JT_REF/JT_EQREF access method
to the joined table the BNLH join algorithm will be used, while for
the table accessed by the JT_ALL methods the BNL algorithm will be used.
If the function decides that a join buffer can be used to join the table
'tab' then it sets the value of tab->use_join_buffer to TRUE and assigns
the selected join cache object to the field 'cache' of the previous
@ -7378,10 +7483,13 @@ end_sj_materialize(JOIN *join, JOIN_TAB *join_tab, bool end_of_records)
For a nested outer join/semi-join, currently, we either use join buffers for
all inner tables or for none of them.
Some engines (e.g. Falcon) currently allow to use only a join cache
of the type JOIN_CACHE_BKA_UNIQUE when the joined table is accessed through
of the type JOIN_CACHE_BKAH when the joined table is accessed through
an index. For these engines setting the value of join_cache_level to 5 or 6
results in that no join buffer is used to join the table.
RETURN VALUE
cache level if cache is used, otherwise returns 0
TODO
Support BKA inside SJ-Materialization nests. When doing this, we'll need
to only store sj-inner tables in the join buffer.
@ -7405,10 +7513,6 @@ end_sj_materialize(JOIN *join, JOIN_TAB *join_tab, bool end_of_records)
first_tab= join->join_tab + first_sjm_table;
}
#endif
RETURN
cache level if cache is used, otherwise returns 0
*/
static
@ -7423,7 +7527,12 @@ uint check_join_cache_usage(JOIN_TAB *tab,
uint bufsz= 4096;
JOIN_CACHE *prev_cache=0;
uint cache_level= join->thd->variables.join_cache_level;
bool force_unlinked_cache= test(cache_level & 1);
bool force_unlinked_cache=
!optimizer_flag(join->thd, OPTIMIZER_SWITCH_JOIN_CACHE_INCREMENTAL);
bool no_hashed_cache=
!optimizer_flag(join->thd, OPTIMIZER_SWITCH_JOIN_CACHE_HASHED);
bool no_bka_cache=
!optimizer_flag(join->thd, OPTIMIZER_SWITCH_JOIN_CACHE_BKA);
uint i= tab - join->join_tab;
*icp_other_tables_ok= TRUE;
@ -7438,16 +7547,23 @@ uint check_join_cache_usage(JOIN_TAB *tab,
*/
if (tab->use_quick == 2)
goto no_join_cache;
if (tab->is_inner_table_of_semi_join_with_first_match() &&
!optimizer_flag(join->thd, OPTIMIZER_SWITCH_SEMIJOIN_WITH_CACHE))
goto no_join_cache;
if (tab->is_inner_table_of_outer_join() &&
!optimizer_flag(join->thd, OPTIMIZER_SWITCH_OUTER_JOIN_WITH_CACHE))
goto no_join_cache;
/*
Non-linked join buffers can't guarantee one match
*/
if (force_unlinked_cache &&
(!tab->type == JT_ALL || cache_level <= 4) &&
((tab->is_inner_table_of_semi_join_with_first_match() &&
!tab->is_single_inner_of_semi_join_with_first_match()) ||
(tab->is_inner_table_of_outer_join() &&
!tab->is_single_inner_of_outer_join())))
goto no_join_cache;
if (force_unlinked_cache &&
((tab->is_inner_table_of_semi_join_with_first_match() &&
!tab->is_single_inner_of_semi_join_with_first_match()) ||
(tab->is_inner_table_of_outer_join() &&
!tab->is_single_inner_of_outer_join())))
goto no_join_cache;
/*
Don't use join buffering if we're dictated not to by no_jbuf_after (this
@ -7492,43 +7608,76 @@ uint check_join_cache_usage(JOIN_TAB *tab,
switch (tab->type) {
case JT_ALL:
if (cache_level <= 2 && (tab->first_inner || tab->first_sj_inner_tab))
goto no_join_cache;
if (cache_level == 1)
prev_cache= 0;
if ((options & SELECT_DESCRIBE) ||
(((tab->cache= new JOIN_CACHE_BNL(join, tab, prev_cache))) &&
!tab->cache->init()))
{
*icp_other_tables_ok= FALSE;
return cache_level;
return (2-test(!prev_cache));
}
goto no_join_cache;
case JT_SYSTEM:
case JT_CONST:
case JT_REF:
case JT_EQ_REF:
if (cache_level <= 4)
return 0;
if (cache_level <=2 || (no_hashed_cache && no_bka_cache))
goto no_join_cache;
flags= HA_MRR_NO_NULL_ENDPOINTS;
if (tab->table->covering_keys.is_set(tab->ref.key))
flags|= HA_MRR_INDEX_ONLY;
rows= tab->table->file->multi_range_read_info(tab->ref.key, 10, 20,
&bufsz, &flags, &cost);
if ((rows != HA_POS_ERROR) && !(flags & HA_MRR_USE_DEFAULT_IMPL) &&
(!(flags & HA_MRR_NO_ASSOCIATION) || cache_level > 6) &&
((options & SELECT_DESCRIBE) ||
(((cache_level <= 6 &&
(tab->cache= new JOIN_CACHE_BKA(join, tab, flags, prev_cache))) ||
(cache_level > 6 &&
(tab->cache= new JOIN_CACHE_BKA_UNIQUE(join, tab, flags, prev_cache)))
) && !tab->cache->init())))
return cache_level;
if ((cache_level <=4 && !no_hashed_cache) || no_bka_cache ||
(flags & HA_MRR_NO_ASSOCIATION) && cache_level <=6)
{
if (cache_level == 3)
prev_cache= 0;
if ((options & SELECT_DESCRIBE) ||
((tab->cache= new JOIN_CACHE_BNLH(join, tab, prev_cache)) &&
!tab->cache->init()))
return (4-test(!prev_cache));
goto no_join_cache;
}
if (cache_level > 4 && no_bka_cache)
goto no_join_cache;
if ((flags & HA_MRR_NO_ASSOCIATION) &&
(cache_level <= 6 || no_hashed_cache))
goto no_join_cache;
if ((rows != HA_POS_ERROR) && !(flags & HA_MRR_USE_DEFAULT_IMPL))
{
if (cache_level <= 6 || no_hashed_cache)
{
if (cache_level == 5)
prev_cache= 0;
if ((options & SELECT_DESCRIBE) ||
((tab->cache= new JOIN_CACHE_BKA(join, tab, flags, prev_cache)) &&
!tab->cache->init()))
return (6-test(!prev_cache));
goto no_join_cache;
}
else
{
if (cache_level == 7)
prev_cache= 0;
if ((options & SELECT_DESCRIBE) ||
((tab->cache= new JOIN_CACHE_BKAH(join, tab, flags, prev_cache)) &&
!tab->cache->init()))
return (8-test(!prev_cache));
goto no_join_cache;
}
}
goto no_join_cache;
default : ;
}
no_join_cache:
if (cache_level>2)
revise_cache_usage(tab);
revise_cache_usage(tab);
return 0;
}
@ -7559,6 +7708,7 @@ static bool
make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
{
uint i;
uint jcl;
bool statistics= test(!(join->select_options & SELECT_DESCRIBE));
bool sorted= 1;
uint first_sjm_table= MAX_TABLES;
@ -7610,27 +7760,26 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
/* Only happens with outer joins */
tab->read_first_record= tab->type == JT_SYSTEM ?
join_read_system :join_read_const;
if (check_join_cache_usage(tab, join, options, no_jbuf_after,
&icp_other_tables_ok))
if ((jcl= check_join_cache_usage(tab, join, options,
no_jbuf_after, &icp_other_tables_ok)))
{
tab->use_join_cache= TRUE;
tab[-1].next_select=sub_select_cache;
}
else
if (table->covering_keys.is_set(tab->ref.key) &&
!table->no_keyread)
{
table->key_read=1;
table->file->extra(HA_EXTRA_KEYREAD);
}
else
else if (!jcl || jcl > 4)
push_index_cond(tab, tab->ref.key, icp_other_tables_ok);
break;
case JT_EQ_REF:
tab->read_record.unlock_row= join_read_key_unlock_row;
/* fall through */
if (check_join_cache_usage(tab, join, options, no_jbuf_after,
&icp_other_tables_ok))
if ((jcl= check_join_cache_usage(tab, join, options,
no_jbuf_after, &icp_other_tables_ok)))
{
tab->use_join_cache= TRUE;
tab[-1].next_select=sub_select_cache;
@ -7641,7 +7790,7 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
table->key_read=1;
table->file->extra(HA_EXTRA_KEYREAD);
}
else
else if (!jcl || jcl > 4)
push_index_cond(tab, tab->ref.key, icp_other_tables_ok );
break;
case JT_REF_OR_NULL:
@ -7653,8 +7802,8 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
}
delete tab->quick;
tab->quick=0;
if (check_join_cache_usage(tab, join, options, no_jbuf_after,
&icp_other_tables_ok))
if ((jcl= check_join_cache_usage(tab, join, options,
no_jbuf_after, &icp_other_tables_ok)))
{
tab->use_join_cache= TRUE;
tab[-1].next_select=sub_select_cache;
@ -7662,7 +7811,7 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
if (table->covering_keys.is_set(tab->ref.key) &&
!table->no_keyread)
table->enable_keyread();
else
else if (!jcl || jcl > 4)
push_index_cond(tab, tab->ref.key, icp_other_tables_ok);
break;
case JT_ALL:
@ -18308,8 +18457,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
item_list.push_back(new Item_string("func", strlen("func"), cs));
}
/* rows */
ha_rows rows= (sj_strategy == SJ_OPT_MATERIALIZE_SCAN)?
tab->emb_sj_nest->sj_mat_info->rows : 1;
ha_rows rows= (ha_rows) ((sj_strategy == SJ_OPT_MATERIALIZE_SCAN)?
tab->emb_sj_nest->sj_mat_info->rows : 1);
item_list.push_back(new Item_int((longlong)rows,
MY_INT64_NUM_DECIMAL_DIGITS));
/* filtered */

971
sql/sql_select.h Normal file → Executable file

File diff suppressed because it is too large Load diff

View file

@ -6458,6 +6458,7 @@ ha_innobase::info(
}
stats.check_time = 0;
stats.mrr_length_per_rec= ref_length + 8; // 8 = max(sizeof(void *));
if (stats.records == 0) {
stats.mean_rec_length = 0;

View file

@ -7534,6 +7534,8 @@ ha_innobase::info(
}
stats.check_time = 0;
stats.mrr_length_per_rec= ref_length + 8; // 8 = max(sizeof(void *));
if (stats.records == 0) {
stats.mean_rec_length = 0;