Commit 92283083 authored by Sergey Petrunya's avatar Sergey Petrunya

Merge 5.3-main -> MWL#90

parents 5dc9a53d 037e1658
...@@ -1364,7 +1364,7 @@ explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1 ...@@ -1364,7 +1364,7 @@ explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index 1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index 1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.61 Using index; FirstMatch(t2) 1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
Warnings: Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` = `test`.`t3`.`a`)) Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` = `test`.`t3`.`a`))
insert into t1 values (3,31); insert into t1 values (3,31);
......
drop table if exists t1,t2,t3,t4,t5,t6;
# #
# Bug #46791: Assertion failed:(table->key_read==0),function unknown # Bug #46791: Assertion failed:(table->key_read==0),function unknown
# function,file sql_base.cc # function,file sql_base.cc
...@@ -356,7 +357,7 @@ FROM t2 ...@@ -356,7 +357,7 @@ FROM t2
WHERE PTYPE = 'Design')); WHERE PTYPE = 'Design'));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
PREPARE stmt FROM "EXPLAIN SELECT EMPNAME PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
...@@ -371,13 +372,13 @@ WHERE EMPNUM IN ...@@ -371,13 +372,13 @@ WHERE EMPNUM IN
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5 1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5
1 SIMPLE subselect2 eq_ref unique_key unique_key 3 func 1 1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
...@@ -394,7 +395,7 @@ FROM t2 ...@@ -394,7 +395,7 @@ FROM t2
WHERE PTYPE = 'Design')); WHERE PTYPE = 'Design'));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
PREPARE stmt FROM "EXPLAIN SELECT EMPNAME PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
...@@ -409,13 +410,13 @@ WHERE EMPNUM IN ...@@ -409,13 +410,13 @@ WHERE EMPNUM IN
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5 1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5
1 SIMPLE subselect2 eq_ref unique_key unique_key 3 func 1 1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
...@@ -431,7 +432,7 @@ FROM t2 ...@@ -431,7 +432,7 @@ FROM t2
WHERE PTYPE = 'Design')); WHERE PTYPE = 'Design'));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 1 PRIMARY t1 ALL NULL NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
PREPARE stmt FROM "EXPLAIN SELECT EMPNAME PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
...@@ -446,13 +447,13 @@ WHERE EMPNUM IN ...@@ -446,13 +447,13 @@ WHERE EMPNUM IN
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 1 PRIMARY t1 ALL NULL NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t1 ALL NULL NULL NULL NULL 5
1 SIMPLE subselect2 eq_ref unique_key unique_key 3 func 1 1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
...@@ -579,7 +580,7 @@ FROM t2 ...@@ -579,7 +580,7 @@ FROM t2
WHERE PTYPE = 'Design')); WHERE PTYPE = 'Design'));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
PREPARE stmt FROM "EXPLAIN SELECT EMPNAME PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
...@@ -594,13 +595,13 @@ WHERE EMPNUM IN ...@@ -594,13 +595,13 @@ WHERE EMPNUM IN
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5 1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5
1 SIMPLE subselect2 eq_ref unique_key unique_key 3 func 1 1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
...@@ -617,7 +618,7 @@ FROM t2 ...@@ -617,7 +618,7 @@ FROM t2
WHERE PTYPE = 'Design')); WHERE PTYPE = 'Design'));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
PREPARE stmt FROM "EXPLAIN SELECT EMPNAME PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
...@@ -632,13 +633,13 @@ WHERE EMPNUM IN ...@@ -632,13 +633,13 @@ WHERE EMPNUM IN
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5 1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5
1 SIMPLE subselect2 eq_ref unique_key unique_key 3 func 1 1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
...@@ -654,7 +655,7 @@ FROM t2 ...@@ -654,7 +655,7 @@ FROM t2
WHERE PTYPE = 'Design')); WHERE PTYPE = 'Design'));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 1 PRIMARY t1 ALL NULL NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
PREPARE stmt FROM "EXPLAIN SELECT EMPNAME PREPARE stmt FROM "EXPLAIN SELECT EMPNAME
...@@ -669,13 +670,13 @@ WHERE EMPNUM IN ...@@ -669,13 +670,13 @@ WHERE EMPNUM IN
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 1 PRIMARY t1 ALL NULL NULL NULL NULL 5
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t1 ALL NULL NULL NULL NULL 5
1 SIMPLE subselect2 eq_ref unique_key unique_key 3 func 1 1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 2 SUBQUERY t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
...@@ -735,6 +736,7 @@ WHERE ( t1.f10 ) IN ( SELECT f11 FROM t2 GROUP BY f11 )); ...@@ -735,6 +736,7 @@ WHERE ( t1.f10 ) IN ( SELECT f11 FROM t2 GROUP BY f11 ));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 5 test.t1.f10 1
3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary 3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary
SELECT * FROM t1 SELECT * FROM t1
WHERE f3 = ( WHERE f3 = (
...@@ -749,6 +751,7 @@ WHERE ( f10, f10 ) IN ( SELECT f11, f11 FROM t2 GROUP BY f11 )); ...@@ -749,6 +751,7 @@ WHERE ( f10, f10 ) IN ( SELECT f11, f11 FROM t2 GROUP BY f11 ));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 10 test.t1.f10,test.t1.f10 1
3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary 3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary
SELECT * FROM t1 SELECT * FROM t1
WHERE f3 = ( WHERE f3 = (
......
This diff is collapsed.
...@@ -1368,7 +1368,7 @@ explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1 ...@@ -1368,7 +1368,7 @@ explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index 1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index
1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index 1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index
1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.61 Using index; FirstMatch(t2) 1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2)
Warnings: Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` = `test`.`t3`.`a`)) Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` = `test`.`t3`.`a`))
insert into t1 values (3,31); insert into t1 values (3,31);
......
...@@ -961,7 +961,7 @@ FROM t1 ...@@ -961,7 +961,7 @@ FROM t1
WHERE `varchar_nokey` < 'n' XOR `pk` ) ; WHERE `varchar_nokey` < 'n' XOR `pk` ) ;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 18 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 18 100.00
1 PRIMARY t1 ref varchar_key varchar_key 3 test.t2.varchar_nokey 2 105.00 Using where; FirstMatch(t2) 1 PRIMARY t1 ref varchar_key varchar_key 3 test.t2.varchar_nokey 2 100.00 Using where; FirstMatch(t2)
Warnings: Warnings:
Note 1003 select `test`.`t2`.`varchar_nokey` AS `varchar_nokey` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`varchar_key` = `test`.`t2`.`varchar_nokey`) and (`test`.`t1`.`varchar_nokey` = `test`.`t2`.`varchar_nokey`) and ((`test`.`t2`.`varchar_nokey` < 'n') xor `test`.`t1`.`pk`)) Note 1003 select `test`.`t2`.`varchar_nokey` AS `varchar_nokey` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`varchar_key` = `test`.`t2`.`varchar_nokey`) and (`test`.`t1`.`varchar_nokey` = `test`.`t2`.`varchar_nokey`) and ((`test`.`t2`.`varchar_nokey` < 'n') xor `test`.`t1`.`pk`))
SELECT varchar_nokey SELECT varchar_nokey
......
...@@ -354,6 +354,10 @@ Canada ...@@ -354,6 +354,10 @@ Canada
China China
Czech Republic Czech Republic
drop table t1, t2; drop table t1, t2;
drop procedure if exists p1;
drop procedure if exists p2;
drop procedure if exists p3;
drop procedure if exists p4;
CREATE TABLE t1(a INT); CREATE TABLE t1(a INT);
CREATE TABLE t2(c INT); CREATE TABLE t2(c INT);
CREATE PROCEDURE p1(v1 int) CREATE PROCEDURE p1(v1 int)
......
...@@ -361,6 +361,10 @@ Canada ...@@ -361,6 +361,10 @@ Canada
China China
Czech Republic Czech Republic
drop table t1, t2; drop table t1, t2;
drop procedure if exists p1;
drop procedure if exists p2;
drop procedure if exists p3;
drop procedure if exists p4;
CREATE TABLE t1(a INT); CREATE TABLE t1(a INT);
CREATE TABLE t2(c INT); CREATE TABLE t2(c INT);
CREATE PROCEDURE p1(v1 int) CREATE PROCEDURE p1(v1 int)
......
...@@ -33,7 +33,7 @@ a b ...@@ -33,7 +33,7 @@ a b
9 5 9 5
explain select * from t2 where b in (select a from t1); explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY subselect2 ALL unique_key NULL NULL NULL 3 1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
1 PRIMARY t2 ref b b 5 test.t1.a 2 1 PRIMARY t2 ref b b 5 test.t1.a 2
2 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where 2 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where
select * from t2 where b in (select a from t1); select * from t2 where b in (select a from t1);
...@@ -53,7 +53,7 @@ insert into t3 select a,a, a,a,a from t0; ...@@ -53,7 +53,7 @@ insert into t3 select a,a, a,a,a from t0;
explain select * from t3 where b in (select a from t1); explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL b NULL NULL NULL 10 1 PRIMARY t3 ALL b NULL NULL NULL 10
1 PRIMARY subselect2 eq_ref unique_key unique_key 5 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
2 SUBQUERY t1 ALL NULL NULL NULL NULL 3 2 SUBQUERY t1 ALL NULL NULL NULL NULL 3
select * from t3 where b in (select a from t1); select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3 a b pk1 pk2 pk3
...@@ -76,7 +76,7 @@ A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a ...@@ -76,7 +76,7 @@ A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a
from t0 A, t0 B where B.a <5; from t0 A, t0 B where B.a <5;
explain select * from t3 where b in (select a from t0); explain select * from t3 where b in (select a from t0);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY subselect2 ALL unique_key NULL NULL NULL 10 1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 10
1 PRIMARY t3 ref b b 5 test.t0.a 1 1 PRIMARY t3 ref b b 5 test.t0.a 1
2 SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where 2 SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where
set @save_ecp= @@engine_condition_pushdown; set @save_ecp= @@engine_condition_pushdown;
...@@ -103,7 +103,7 @@ set max_heap_table_size= @save_max_heap_table_size; ...@@ -103,7 +103,7 @@ set max_heap_table_size= @save_max_heap_table_size;
explain select * from t1 where a in (select b from t2); explain select * from t1 where a in (select b from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 1 PRIMARY t1 ALL NULL NULL NULL NULL 3
1 PRIMARY subselect2 eq_ref unique_key unique_key 5 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
2 SUBQUERY t2 index b b 5 NULL 10 Using index 2 SUBQUERY t2 index b b 5 NULL 10 Using index
select * from t1; select * from t1;
a b a b
...@@ -131,7 +131,7 @@ explain select ...@@ -131,7 +131,7 @@ explain select
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
from t1 ot where a in (select a from t2 it); from t1 ot where a in (select a from t2 it);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY subselect2 ALL unique_key NULL NULL NULL 22 1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 22
1 PRIMARY ot ALL NULL NULL NULL NULL 32 Using where; Using join buffer (flat, BNL join) 1 PRIMARY ot ALL NULL NULL NULL NULL 32 Using where; Using join buffer (flat, BNL join)
2 SUBQUERY it ALL NULL NULL NULL NULL 22 2 SUBQUERY it ALL NULL NULL NULL NULL 22
select select
...@@ -165,7 +165,7 @@ a, mid(filler1, 1,10), length(filler1)=length(filler2) ...@@ -165,7 +165,7 @@ a, mid(filler1, 1,10), length(filler1)=length(filler2)
from t2 ot where a in (select a from t1 it); from t2 ot where a in (select a from t1 it);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot ALL NULL NULL NULL NULL 22 1 PRIMARY ot ALL NULL NULL NULL NULL 22
1 PRIMARY subselect2 eq_ref unique_key unique_key 5 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
2 SUBQUERY it ALL NULL NULL NULL NULL 32 2 SUBQUERY it ALL NULL NULL NULL NULL 32
select select
a, mid(filler1, 1,10), length(filler1)=length(filler2) a, mid(filler1, 1,10), length(filler1)=length(filler2)
...@@ -199,7 +199,7 @@ explain select ...@@ -199,7 +199,7 @@ explain select
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
from t1 ot where a in (select a from t2 it); from t1 ot where a in (select a from t2 it);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY subselect2 ALL unique_key NULL NULL NULL 22 1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 22
1 PRIMARY ot ALL NULL NULL NULL NULL 52 Using where; Using join buffer (flat, BNL join) 1 PRIMARY ot ALL NULL NULL NULL NULL 52 Using where; Using join buffer (flat, BNL join)
2 SUBQUERY it ALL NULL NULL NULL NULL 22 2 SUBQUERY it ALL NULL NULL NULL NULL 22
select select
...@@ -233,7 +233,7 @@ a, mid(filler1, 1,10), length(filler1)=length(filler2) ...@@ -233,7 +233,7 @@ a, mid(filler1, 1,10), length(filler1)=length(filler2)
from t2 ot where a in (select a from t1 it); from t2 ot where a in (select a from t1 it);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ot ALL NULL NULL NULL NULL 22 1 PRIMARY ot ALL NULL NULL NULL NULL 22
1 PRIMARY subselect2 eq_ref unique_key unique_key 5 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
2 SUBQUERY it ALL NULL NULL NULL NULL 52 2 SUBQUERY it ALL NULL NULL NULL NULL 52
select select
a, mid(filler1, 1,10), length(filler1)=length(filler2) a, mid(filler1, 1,10), length(filler1)=length(filler2)
...@@ -353,7 +353,7 @@ WHERE t1.Code IN ( ...@@ -353,7 +353,7 @@ WHERE t1.Code IN (
SELECT t2.CountryCode FROM t2 WHERE Population > 5000000); SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 31 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 31
1 PRIMARY subselect2 eq_ref unique_key unique_key 3 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1
2 SUBQUERY t2 ALL CountryCode NULL NULL NULL 545 Using where 2 SUBQUERY t2 ALL CountryCode NULL NULL NULL 545 Using where
SELECT Name FROM t1 SELECT Name FROM t1
WHERE t1.Code IN ( WHERE t1.Code IN (
...@@ -364,6 +364,10 @@ Canada ...@@ -364,6 +364,10 @@ Canada
China China
Czech Republic Czech Republic
drop table t1, t2; drop table t1, t2;
drop procedure if exists p1;
drop procedure if exists p2;
drop procedure if exists p3;
drop procedure if exists p4;
CREATE TABLE t1(a INT); CREATE TABLE t1(a INT);
CREATE TABLE t2(c INT); CREATE TABLE t2(c INT);
CREATE PROCEDURE p1(v1 int) CREATE PROCEDURE p1(v1 int)
...@@ -697,7 +701,7 @@ The following must use loose index scan over t3, key a: ...@@ -697,7 +701,7 @@ The following must use loose index scan over t3, key a:
explain select count(a) from t2 where a in ( SELECT a FROM t3); explain select count(a) from t2 where a in ( SELECT a FROM t3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 index a a 5 NULL 1000 Using index 1 PRIMARY t2 index a a 5 NULL 1000 Using index
1 PRIMARY subselect2 eq_ref unique_key unique_key 5 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
2 SUBQUERY t3 index a a 5 NULL 30000 Using index 2 SUBQUERY t3 index a a 5 NULL 30000 Using index
select count(a) from t2 where a in ( SELECT a FROM t3); select count(a) from t2 where a in ( SELECT a FROM t3);
count(a) count(a)
......
...@@ -969,7 +969,7 @@ FROM t1 ...@@ -969,7 +969,7 @@ FROM t1
WHERE `varchar_nokey` < 'n' XOR `pk` ) ; WHERE `varchar_nokey` < 'n' XOR `pk` ) ;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 18 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 18 100.00
1 PRIMARY t1 ref varchar_key varchar_key 3 test.t2.varchar_nokey 2 105.00 Using where; FirstMatch(t2); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 PRIMARY t1 ref varchar_key varchar_key 3 test.t2.varchar_nokey 2 100.00 Using where; FirstMatch(t2); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
Warnings: Warnings:
Note 1003 select `test`.`t2`.`varchar_nokey` AS `varchar_nokey` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`varchar_key` = `test`.`t2`.`varchar_nokey`) and (`test`.`t1`.`varchar_nokey` = `test`.`t2`.`varchar_nokey`) and ((`test`.`t2`.`varchar_nokey` < 'n') xor `test`.`t1`.`pk`)) Note 1003 select `test`.`t2`.`varchar_nokey` AS `varchar_nokey` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`varchar_key` = `test`.`t2`.`varchar_nokey`) and (`test`.`t1`.`varchar_nokey` = `test`.`t2`.`varchar_nokey`) and ((`test`.`t2`.`varchar_nokey` < 'n') xor `test`.`t1`.`pk`))
SELECT varchar_nokey SELECT varchar_nokey
......
This diff is collapsed.
drop table if exists t0, t1, t2, t3, t4;
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='materialization=on';
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 as select * from t0;
# The following should use full scan on <subquery2> and it must scan 1 row:
explain select * from t0 where a in (select max(a) from t1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1
1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join)
2 SUBQUERY t1 ALL NULL NULL NULL NULL 10
select * from t0 where a in (select max(a) from t1);
a
9
insert into t1 values (11);
select * from t0 where a in (select max(a) from t1);
a
delete from t1 where a=11;
insert into t0 values (NULL);
select * from t0 where a in (select max(a) from t1);
a
9
delete from t0 where a is NULL;
delete from t1;
select * from t0 where a in (select max(a) from t1);
a
insert into t0 values (NULL);
select * from t0 where a in (select max(a) from t1);
a
delete from t0 where a is NULL;
drop table t1;
create table t1 (a int, b int);
insert into t1 select a,a from t0;
create table t2 as select * from t1 where a<5;
create table t3 as select (A.a + 10*B.a) as a from t0 A, t0 B;
alter table t3 add primary key(a);
# The following should have do a full scan on <subquery2> and scan 5 rows
# (despite that subquery's join output estimate is 50 rows)
explain select * from t3 where a in (select max(t2.a) from t1, t2 group by t2.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 Using where
1 PRIMARY t3 eq_ref PRIMARY PRIMARY 8 <subquery2>.max(t2.a) 1 Using where; Using index
2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using temporary
2 SUBQUERY t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
# Compare to this which really will have 50 record combinations:
explain select * from t3 where a in (select max(t2.a) from t1, t2 group by t2.b, t1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 50 Using where
1 PRIMARY t3 eq_ref PRIMARY PRIMARY 8 <subquery2>.max(t2.a) 1 Using where; Using index
2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using temporary
2 SUBQUERY t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
# Outer joins also work:
explain select * from t3
where a in (select max(t2.a) from t1 left join t2 on t1.a=t2.a group by t2.b, t1.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 50 Using where
1 PRIMARY t3 eq_ref PRIMARY PRIMARY 8 <subquery2>.max(t2.a) 1 Using where; Using index
2 SUBQUERY t1 ALL NULL NULL NULL NULL 10 Using temporary
2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where
create table t4 (a int, b int, filler char(20), unique key(a,b));
insert into t4 select A.a + 10*B.a, A.a + 10*B.a, 'filler' from t0 A, t0 B;
explain select * from t0, t4 where
t4.b=t0.a and t4.a in (select max(t2.a) from t1, t2 group by t2.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 10
1 PRIMARY t4 ALL a NULL NULL NULL 100 Using where; Using join buffer (flat, BNL join)
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 test.t4.a 1
2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using temporary
2 SUBQUERY t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
insert into t4 select 100 + (B.a *100 + A.a), 100 + (B.a*100 + A.a), 'filler' from t4 A, t0 B;
explain select * from t4 where
t4.a in (select max(t2.a) from t1, t2 group by t2.b) and
t4.b in (select max(t2.a) from t1, t2 group by t2.b);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 Using where
1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t4 ref a a 10 <subquery2>.max(t2.a),<subquery3>.max(t2.a) 12
3 SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using temporary
3 SUBQUERY t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using temporary
2 SUBQUERY t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join)
drop table t1,t2,t3,t4;
drop table t0;
#
# BUG#780359: Crash with get_fanout_with_deps in maria-5.3-mwl90
#
CREATE TABLE t1 (f1 int);
INSERT INTO t1 VALUES (2),(2);
CREATE TABLE t2 (f3 int);
INSERT INTO t2 VALUES (2),(2);
SELECT *
FROM t1
WHERE ( f1 ) IN (
SELECT t2.f3
FROM t2
WHERE t2.f3 = 97
AND t2.f3 = 50
GROUP BY 1
);
f1
DROP TABLE t1, t2;
set optimizer_switch=@save_optimizer_switch;
...@@ -69,10 +69,14 @@ create table t1 (a int not null, ...@@ -69,10 +69,14 @@ create table t1 (a int not null,
insert into t1 (a) values (1), (2), (3), (4); insert into t1 (a) values (1), (2), (3), (4);
create view v1 as select b+1 from t1 order by 1 desc limit 2; create view v1 as select b+1 from t1 order by 1 desc limit 2;
select * from v1; select * from v1;
--echo MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1.
--echo MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed
explain select * from v1; explain select * from v1;
drop view v1; drop view v1;
create view v1 as select c+1 from t1 order by 1 desc limit 2; create view v1 as select c+1 from t1 order by 1 desc limit 2;
select * from v1; select * from v1;
--echo MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1.
--echo MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed
explain select * from v1; explain select * from v1;
drop view v1; drop view v1;
drop table t1; drop table t1;
......
...@@ -103,6 +103,8 @@ select * from v1; ...@@ -103,6 +103,8 @@ select * from v1;
b+1 b+1
0 0
-1 -1
MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1.
MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed
explain select * from v1; explain select * from v1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
...@@ -113,6 +115,8 @@ select * from v1; ...@@ -113,6 +115,8 @@ select * from v1;
c+1 c+1
0 0
-1 -1
MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1.
MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed
explain select * from v1; explain select * from v1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
......
...@@ -103,6 +103,8 @@ select * from v1; ...@@ -103,6 +103,8 @@ select * from v1;
b+1 b+1
0 0
-1 -1
MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1.
MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed
explain select * from v1; explain select * from v1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
...@@ -113,6 +115,8 @@ select * from v1; ...@@ -113,6 +115,8 @@ select * from v1;
c+1 c+1
0 0
-1 -1
MariaDB-5.3: the following EXPLAIN produces incorrect #rows for table t1.
MariaDB-5.3: this is expected to go away when FROM subquery optimizations are pushed
explain select * from v1; explain select * from v1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
......
# General purpose bug fix tests go here : subselect.test too large # General purpose bug fix tests go here : subselect.test too large
--disable_warnings
drop table if exists t1,t2,t3,t4,t5,t6;
--enable_warnings
--echo # --echo #
--echo # Bug #46791: Assertion failed:(table->key_read==0),function unknown --echo # Bug #46791: Assertion failed:(table->key_read==0),function unknown
......
This diff is collapsed.
...@@ -494,6 +494,12 @@ drop table t1, t2; ...@@ -494,6 +494,12 @@ drop table t1, t2;
# Bug#33062: subquery in stored routine cause crash # Bug#33062: subquery in stored routine cause crash
# #
--disable_warnings
drop procedure if exists p1;
drop procedure if exists p2;
drop procedure if exists p3;
drop procedure if exists p4;
--enable_warnings
CREATE TABLE t1(a INT); CREATE TABLE t1(a INT);
CREATE TABLE t2(c INT); CREATE TABLE t2(c INT);
......
This diff is collapsed.
#
# Tests for non-merged semi-joins
#
--disable_warnings
drop table if exists t0, t1, t2, t3, t4;
--enable_warnings
set @save_optimizer_switch=@@optimizer_switch;
set optimizer_switch='materialization=on';
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
# Check the case of subquery having agggregates but not having grouping
create table t1 as select * from t0;
--echo # The following should use full scan on <subquery2> and it must scan 1 row:
explain select * from t0 where a in (select max(a) from t1);
select * from t0 where a in (select max(a) from t1);
# Ok, now check the trivial match/no-match/NULL on the left/NULL on the right cases
insert into t1 values (11);
select * from t0 where a in (select max(a) from t1);
delete from t1 where a=11;
insert into t0 values (NULL);
select * from t0 where a in (select max(a) from t1);
delete from t0 where a is NULL;
delete from t1;
select * from t0 where a in (select max(a) from t1);
insert into t0 values (NULL);
select * from t0 where a in (select max(a) from t1);
delete from t0 where a is NULL;
drop table t1;
#
# Try with join subqueries
#
create table t1 (a int, b int);
insert into t1 select a,a from t0; # 10 rows
create table t2 as select * from t1 where a<5; # 5 rows
create table t3 as select (A.a + 10*B.a) as a from t0 A, t0 B; # 100 rows
alter table t3 add primary key(a);
--echo # The following should have do a full scan on <subquery2> and scan 5 rows
--echo # (despite that subquery's join output estimate is 50 rows)
explain select * from t3 where a in (select max(t2.a) from t1, t2 group by t2.b);
--echo # Compare to this which really will have 50 record combinations:
explain select * from t3 where a in (select max(t2.a) from t1, t2 group by t2.b, t1.b);
--echo # Outer joins also work:
explain select * from t3
where a in (select max(t2.a) from t1 left join t2 on t1.a=t2.a group by t2.b, t1.b);
#
# Check if joins on the outer side also work
#
create table t4 (a int, b int, filler char(20), unique key(a,b));
insert into t4 select A.a + 10*B.a, A.a + 10*B.a, 'filler' from t0 A, t0 B; # 100 rows
explain select * from t0, t4 where
t4.b=t0.a and t4.a in (select max(t2.a) from t1, t2 group by t2.b);
insert into t4 select 100 + (B.a *100 + A.a), 100 + (B.a*100 + A.a), 'filler' from t4 A, t0 B;
explain select * from t4 where
t4.a in (select max(t2.a) from t1, t2 group by t2.b) and
t4.b in (select max(t2.a) from t1, t2 group by t2.b);
drop table t1,t2,t3,t4;
drop table t0;
--echo #
--echo # BUG#780359: Crash with get_fanout_with_deps in maria-5.3-mwl90
--echo #
CREATE TABLE t1 (f1 int);
INSERT INTO t1 VALUES (2),(2);
CREATE TABLE t2 (f3 int);
INSERT INTO t2 VALUES (2),(2);
SELECT *
FROM t1
WHERE ( f1 ) IN (
SELECT t2.f3
FROM t2
WHERE t2.f3 = 97
AND t2.f3 = 50
GROUP BY 1
);
DROP TABLE t1, t2;
set optimizer_switch=@save_optimizer_switch;
#!@PERL@ #!@PERL@
# Test of table elimination feature # Test of table elimination feature
......
...@@ -1249,7 +1249,8 @@ class Item { ...@@ -1249,7 +1249,8 @@ class Item {
virtual Item_equal *find_item_equal(COND_EQUAL *cond_equal) { return NULL; } virtual Item_equal *find_item_equal(COND_EQUAL *cond_equal) { return NULL; }
/** /**
Set the join tab index to the minimal (left-most) JOIN_TAB to which this Set the join tab index to the minimal (left-most) JOIN_TAB to which this
Item is attached. Item is attached. The number is an index is depth_first_tab() traversal
order.
*/ */
virtual void set_join_tab_idx(uint join_tab_idx_arg) virtual void set_join_tab_idx(uint join_tab_idx_arg)
{ {
......
...@@ -5813,28 +5813,12 @@ Item* Item_equal::get_first(Item *field_item) ...@@ -5813,28 +5813,12 @@ Item* Item_equal::get_first(Item *field_item)
{ {
/* /*
It's a field from an materialized semi-join. We can substitute it only It's a field from an materialized semi-join. We can substitute it only
for a field from the same semi-join. for a field from the same semi-join. Find the first of such items.
*/ */
JOIN_TAB *first= field_tab;
JOIN *join= field_tab->join;
int tab_idx= field_tab - field_tab->join->join_tab;
DBUG_ASSERT(join->join_tab[tab_idx].table->map &
emb_nest->sj_inner_tables);
/* Find the first table of this semi-join nest */
for (int i= tab_idx-1; i >= (int)join->const_tables; i--)
{
if (join->join_tab[i].table->map & emb_nest->sj_inner_tables)
first= join->join_tab + i;
else
// Found first tab that doesn't belong to current SJ.
break;
}
/* Find an item to substitute for. */
while ((item= it++)) while ((item= it++))
{ {
if (it.get_curr_field()->table->reginfo.join_tab >= first) if (it.get_curr_field()->table->pos_in_table_list->embedding == emb_nest)
{ {
/* /*
If we found given field then return NULL to avoid unnecessary If we found given field then return NULL to avoid unnecessary
...@@ -5846,33 +5830,28 @@ Item* Item_equal::get_first(Item *field_item) ...@@ -5846,33 +5830,28 @@ Item* Item_equal::get_first(Item *field_item)
} }
else else
{ {
#if TO_BE_DELETED
/* /*
The field is not in SJ-Materialization nest. We must return the first The field is not in SJ-Materialization nest. We must return the first
field that's not embedded in a SJ-Materialization nest. field in the join order. The field may be inside a semi-join nest, i.e
Example: suppose we have a join order: a join order may look like this:
SJ-Mat(it1 it2) ot1 ot2 SJ-Mat(it1 it2) ot1 ot2
and equality ot2.col = ot1.col = it2.col where we're looking what to substitute ot2.col for. In this case we must
If we're looking for best substitute for 'ot2.col', we should pick still return it1.col, here's a proof why:
ot1.col and not it2.col, because when we run a join between ot1 and ot2
execution of SJ-Mat(...) has already finished and we can't rely on the First let's note that either it1.col or it2.col participates in
value of it*.*. subquery's IN-equality. It can't be otherwise, because materialization is
psergey-fix-fix: ^^ THAT IS INCORRECT ^^. Pick the first, whatever that only applicable to uncorrelated subqueries, so the only way we could
is. infer "it1.col=ot1.col" is from the IN-equality. Ok, so IN-eqality has
it1.col or it2.col on its inner side. it1.col is first such item in the
join order, so it's not possible for SJ-Mat to be
SJ-Materialization-lookup, it is SJ-Materialization-Scan. The scan part
of this strategy will unpack value of it1.col=it2.col into it1.col
(that's the first equal item inside the subquery), and we'll be able to
get it from there. qed.
*/ */
while ((item= it++))
{
Item_field *fld_item= (Item_field *) (item->real_item());
TABLE_LIST *emb_nest= fld_item->field->table->pos_in_table_list->embedding;
if (!emb_nest || !emb_nest->sj_mat_info ||
!emb_nest->sj_mat_info->is_used)
{
return item;
}
}
#endif
return equal_items.head(); return equal_items.head();
} }
// Shouldn't get here. // Shouldn't get here.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* */ /*
Semi-join subquery optimization code definitions
*/
#ifdef USE_PRAGMA_INTERFACE #ifdef USE_PRAGMA_INTERFACE
#pragma interface /* gcc class implementation */ #pragma interface /* gcc class implementation */
...@@ -366,4 +368,10 @@ int clear_sj_tmp_tables(JOIN *join); ...@@ -366,4 +368,10 @@ int clear_sj_tmp_tables(JOIN *join);
int rewrite_to_index_subquery_engine(JOIN *join); int rewrite_to_index_subquery_engine(JOIN *join);
void get_delayed_table_estimates(TABLE *table,
ha_rows *out_rows,
double *scan_time,
double *startup_cost);
enum_nested_loop_state join_tab_execution_startup(JOIN_TAB *tab);
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment