diff options
Diffstat (limited to 'mysql-test/main/derived_split_innodb.test')
-rw-r--r-- | mysql-test/main/derived_split_innodb.test | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/mysql-test/main/derived_split_innodb.test b/mysql-test/main/derived_split_innodb.test index 86a2b6d73b0..e7c5cc8f274 100644 --- a/mysql-test/main/derived_split_innodb.test +++ b/mysql-test/main/derived_split_innodb.test @@ -233,4 +233,251 @@ drop table t3, t4; --echo # End of 10.3 tests + +--echo # +--echo # MDEV-26301: Split optimization refills temporary table too many times +--echo # + +# 5 values +create table t1(a int, b int); +insert into t1 select seq,seq from seq_1_to_5; + +# 5 value groups of size 2 each +create table t2(a int, b int, key(a)); +insert into t2 +select A.seq,B.seq from seq_1_to_25 A, seq_1_to_2 B; + +# 5 value groups of size 3 each +create table t3(a int, b int, key(a)); +insert into t3 +select A.seq,B.seq from seq_1_to_5 A, seq_1_to_3 B; + +analyze table t1,t2,t3 persistent for all; + +explain +select * from + (t1 left join t2 on t2.a=t1.b) left join t3 on t3.a=t1.b; + +# Now, create tables for Groups. + +create table t10 ( + grp_id int, + col1 int, + key(grp_id) +); + +# 100 groups of 100 values each +insert into t10 +select + A.seq, + B.seq +from + seq_1_to_100 A, + seq_1_to_100 B; + +# and X10 multiplier + +create table t11 ( + col1 int, + col2 int +); +insert into t11 +select A.seq, A.seq from seq_1_to_10 A; + +analyze table t10,t11 persistent for all; + +let $q1= +select * from + ( + (t1 left join t2 on t2.a=t1.b) + left join t3 on t3.a=t1.b + ) left join (select grp_id, count(*) + from t10 left join t11 on t11.col1=t10.col1 + group by grp_id) T on T.grp_id=t1.b; + +eval +explain $q1; + +--echo # The important part in the below output is: +--echo # "lateral": 1, +--echo # "query_block": { +--echo # "select_id": 2, +--echo # "r_loops": 5, <-- must be 5, not 30. +--source include/analyze-format.inc + +eval +analyze format=json $q1; + +create table t21 (pk int primary key); +insert into t21 values (1),(2),(3); + +create table t22 (pk int primary key); +insert into t22 values (1),(2),(3); + +# Same as above but throw in a couple of const tables. +explain +select * from + t21, t22, + ( + (t1 left join t2 on t2.a=t1.b) + left join t3 on t3.a=t1.b + ) left join (select grp_id, count(*) + from t10 left join t11 on t11.col1=t10.col1 + group by grp_id) T on T.grp_id=t1.b +where + t21.pk=1 and t22.pk=2; + +explain +select * from + t21, + ( + (t1 left join t2 on t2.a=t1.b) + left join t3 on t3.a=t1.b + ) left join (select grp_id, count(*) + from + t22 join t10 left join t11 on t11.col1=t10.col1 + where + t22.pk=1 + group by grp_id) T on T.grp_id=t1.b +where + t21.pk=1; + +# And also add a non-const table + +create table t5 ( + pk int primary key + ); +insert into t5 select seq from seq_1_to_1000; + +explain +select * from + t21, + ( + (((t1 join t5 on t5.pk=t1.b)) left join t2 on t2.a=t1.b) + left join t3 on t3.a=t1.b + ) left join (select grp_id, count(*) + from + t22 join t10 left join t11 on t11.col1=t10.col1 + where + t22.pk=1 + group by grp_id) T on T.grp_id=t1.b +where + t21.pk=1; + +drop table t1,t2,t3,t5, t10, t11, t21, t22; + +# 5 values +create table t1(a int, b int); +insert into t1 select seq,seq from seq_1_to_5; + +# 5 value groups of size 2 each +create table t2(a int, b int, key(a)); +insert into t2 +select A.seq,B.seq from seq_1_to_25 A, seq_1_to_2 B; + +# 5 value groups of size 3 each +create table t3(a int, b int, key(a)); +insert into t3 +select A.seq,B.seq from seq_1_to_5 A, seq_1_to_3 B; + +analyze table t1,t2,t3 persistent for all; + +create table t10 ( + grp_id int, + col1 int, + key(grp_id) +); + +# 100 groups of 100 values each +insert into t10 +select + A.seq, + B.seq +from + seq_1_to_100 A, + seq_1_to_100 B; + +# and X10 multiplier + +create table t11 ( + col1 int, + col2 int +); +insert into t11 +select A.seq, A.seq from seq_1_to_10 A; + +analyze table t10,t11 persistent for all; + +let $q= +select * +from + ( + (t1 left join t2 on t2.a=t1.b) + left join + t3 + on t3.a=t1.b + ) + left join + ( + select grp_id, count(*) + from t10 left join t11 on t11.col1=t10.col1 + group by grp_id + )dt + on dt.grp_id=t1.b; + +eval explain $q; +eval $q; + +set join_cache_level=4; +set optimizer_trace=1; +set @tmp=@@optimizer_switch, optimizer_switch='hash_join_cardinality=off'; +# Need table t11 to be larger in 11.0: +insert into t11 +select A.seq, A.seq from seq_11_to_100 A; +analyze table t11 persistent for all; + +eval explain $q; +eval $q; + +set optimizer_switch=@tmp; +set join_cache_level=default; + +delete from t11; +insert into t11 select A.seq, A.seq from seq_1_to_10 A; +analyze table t11 persistent for all; + +drop index a on t2; +drop index a on t3; + +eval explain $q; +eval $q; + +drop table t1,t2,t3; +drop table t10, t11; + + +--echo # +--echo # MDEV-31194: Server crash or assertion failure with join_cache_level=4 +--echo # (a followup to the above bug, MDEV-26301) +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (3),(4); + +CREATE TABLE t2 (id INT PRIMARY KEY) ENGINE=Aria; +INSERT INTO t2 VALUES (1),(2); + +set @tmp1= @@optimizer_switch, @tmp2= @@join_cache_level; +set + optimizer_switch= 'derived_with_keys=off', + join_cache_level= 4; + +SELECT t1.* FROM t1 JOIN (SELECT id, COUNT(*) FROM t2 GROUP BY id) sq ON sq.id= t1.a; + +set optimizer_switch= @tmp1, join_cache_level= @tmp2; + +# Cleanup +DROP TABLE t1, t2; + +--echo # End of 10.4 tests + SET GLOBAL innodb_stats_persistent=@save_innodb_stats_persistent; |